/* Colour Sort — scoped styles, prefix: cc-colour-sort */

.cc-colour-sort {
  --cc-cs-cream: #FFF0F4;
  --cc-cs-coral: #D4715A;
  --cc-cs-pink: #FF6B8A;
  --cc-cs-sage: #7A9B8A;
  --cc-cs-gold: #FFB800;
  --cc-cs-dark: #243B45;
  --cc-cs-cols: 4;

  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: clamp(6px, 2vh, 12px);
  padding: 10px 8px;
  background: var(--cc-cs-cream);
  color: var(--cc-cs-dark);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  border-radius: 20px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cc-colour-sort * {
  box-sizing: border-box;
}

/* ---------- toolbar ---------- */

.cc-colour-sort-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex: 0 0 auto;
}

.cc-colour-sort-hint {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font-size: clamp(10px, 3.2vw, 12px);
  font-weight: 600;
  color: var(--cc-cs-dark);
  opacity: 0.6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 4px;
}

.cc-colour-sort-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(11px, 3.4vw, 13px);
  color: #fff;
  background: var(--cc-cs-coral);
  border-radius: 14px;
  padding: 8px 12px;
  white-space: nowrap;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s ease, box-shadow 0.1s ease, opacity 0.15s ease;
  flex: 0 0 auto;
}

.cc-colour-sort-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

.cc-colour-sort-btn.cc-colour-sort-new {
  background: var(--cc-cs-sage);
}

.cc-colour-sort-undo-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.35);
  font-size: 10px;
}

.cc-colour-sort-btn:disabled {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  transform: none;
}

.cc-colour-sort-undo-icon {
  font-size: 14px;
  line-height: 1;
}

/* ---------- board ---------- */

.cc-colour-sort-board {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(var(--cc-cs-cols), 1fr);
  align-content: center;
  justify-items: center;
  align-items: end;
  gap: clamp(6px, 2vw, 12px) clamp(4px, 1.6vw, 10px);
  padding: 4px 2px 8px;
}

.cc-colour-sort-bottle {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transform: translateY(0);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cc-colour-sort-bottle.is-selected {
  transform: translateY(-12px);
}

.cc-colour-sort-bottle.is-invalid {
  animation: cc-cs-shake 0.3s ease;
}

/* teat / nipple — a rounded bulb sitting on the collar */
.cc-colour-sort-bottle::before {
  content: "";
  display: block;
  width: 34%;
  height: 15%;
  min-height: 14px;
  background: linear-gradient(160deg, #FFD98A, #E8B450);
  border: 2.5px solid var(--cc-cs-dark);
  border-bottom: none;
  border-radius: 50% 50% 40% 40% / 75% 75% 30% 30%;
  margin-bottom: -3px;
  position: relative;
  z-index: 2;
}

/* ribbed screw-ring collar between the teat and the bottle body */
.cc-colour-sort-bottle-neck {
  width: 58%;
  height: 11%;
  min-height: 9px;
  background-color: #BEE3F0;
  background-image: repeating-linear-gradient(
    to right,
    rgba(36, 59, 69, 0.32) 0,
    rgba(36, 59, 69, 0.32) 2px,
    transparent 2px,
    transparent 16%
  );
  border: 2.5px solid var(--cc-cs-dark);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  margin-bottom: -3px;
  position: relative;
  z-index: 1;
}

.cc-colour-sort-bottle-tube {
  width: 100%;
  aspect-ratio: 1 / 2;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.65);
  border: 2.5px solid var(--cc-cs-dark);
  border-radius: 26% 26% 44% 44% / 16% 16% 26% 26%;
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.1);
  position: relative;
}

/* glossy shine plus ounce-marking ticks, like a real baby bottle */
.cc-colour-sort-bottle-tube::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(
      118deg,
      rgba(255, 255, 255, 0.65) 0%,
      rgba(255, 255, 255, 0.65) 9%,
      rgba(255, 255, 255, 0) 22%,
      rgba(255, 255, 255, 0) 100%
    ),
    repeating-linear-gradient(
      to bottom,
      rgba(36, 59, 69, 0.3) 0,
      rgba(36, 59, 69, 0.3) 2px,
      transparent 2px,
      transparent 25%
    );
  background-position: 0 0, left top;
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, 9px 100%;
  background-origin: border-box, content-box;
  padding-left: 14%;
  pointer-events: none;
}

.cc-colour-sort-bottle.is-selected .cc-colour-sort-bottle-tube {
  box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.1), 0 8px 12px rgba(36, 59, 69, 0.25);
}

.cc-colour-sort-layer {
  flex: 1 1 0;
  width: 100%;
  transition: background-color 0.15s ease;
}

.cc-colour-sort-layer.is-empty {
  background: transparent;
}

.cc-colour-sort-layer.is-filled {
  background: var(--cc-cs-layer-color, var(--cc-cs-pink));
  box-shadow: inset 0 2px 3px rgba(255, 255, 255, 0.35), inset 0 -2px 3px rgba(0, 0, 0, 0.12);
}

.cc-colour-sort-layer.is-new {
  animation: cc-cs-pop 0.22s ease;
}

/* ---------- win overlay ---------- */

.cc-colour-sort-win {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(36, 59, 69, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  border-radius: 20px;
  padding: 12px;
}

.cc-colour-sort-win[hidden] {
  display: flex;
}

.cc-colour-sort-win.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.cc-colour-sort-win-card {
  background: var(--cc-cs-cream);
  border-radius: 24px;
  padding: 24px 22px;
  text-align: center;
  max-width: 86%;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
  transform: scale(0.85);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cc-colour-sort-win.is-visible .cc-colour-sort-win-card {
  transform: scale(1);
}

.cc-colour-sort-win-emoji {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 6px;
}

.cc-colour-sort-win-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  color: var(--cc-cs-coral);
}

.cc-colour-sort-win-text {
  margin: 0 0 16px;
  font-size: 13px;
  opacity: 0.75;
}

.cc-colour-sort-play-again {
  background: var(--cc-cs-coral);
  padding: 10px 20px;
  border-radius: 16px;
  font-size: 14px;
}

/* ---------- animations ---------- */

@keyframes cc-cs-pop {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes cc-cs-shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* pause all animation/transition work while tab is hidden */
.cc-colour-sort.cc-colour-sort-is-hidden,
.cc-colour-sort.cc-colour-sort-is-hidden * {
  animation-play-state: paused !important;
  transition: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .cc-colour-sort * {
    animation: none !important;
    transition: none !important;
  }
}

/* small phones */
@media (max-width: 340px) {
  .cc-colour-sort-hint {
    display: none;
  }
}
