/* Colour Sort — liquid edition: navy doodle chalkboard, thin white-rimmed glasses, stacked liquid bands. */
:root {
  --bg: #1b2a4a; --ink: #ffffff; --muted: rgba(255,255,255,.78); --accent: #9ec5ff;
  --c1: #1ee3f2; --c2: #ff9a1f; --c3: #3af04a; --c4: #ff2f9e; --c5: #7c3aff; --c6: #2b45ff; --c7: #ffe12e; --c8: #ff2e2e;
  --c9: #d42cff; --c10: #19c9a0; --c11: #f6f4ff; --c12: #3a3a52;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { touch-action: manipulation; }
html, body { margin: 0; height: 100%; color: var(--ink); font: 20px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' opacity='.07'%3E%3Ccircle cx='28' cy='30' r='12'/%3E%3Cpath d='M100 20l4 9 10 1-7 7 2 10-9-5-9 5 2-10-7-7 10-1z'/%3E%3Cpath d='M20 110q10-14 20 0t20 0'/%3E%3Cpath d='M120 100a10 10 0 1 1 10 10v8m0 8v1'/%3E%3Cpath d='M70 70l20 20m0-20l-20 20'/%3E%3Ccircle cx='140' cy='40' r='4'/%3E%3Cpath d='M60 140h30'/%3E%3C/svg%3E"),
    radial-gradient(120% 80% at 50% 0%, #2b2466 0%, #181340 55%, #0e0b28 100%);
  background-attachment: fixed;
}
/* Page: quiet header, a board that breathes and centres its rack, actions pinned to the bottom. */
#app { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 12px calc(16px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto; }
.hud { width: 100%; display: flex; align-items: center; justify-content: space-between; }
.back { font-size: 18px; font-weight: 700; color: var(--accent); text-decoration: none; padding: 10px; min-height: 48px; display: flex; align-items: center; }
.title { text-align: center; line-height: 1.15; }
.title b { display: block; font-size: 26px; font-weight: 800; color: #fff; letter-spacing: .2px; }
.title small { display: block; font-size: 15px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.icon { font-size: 24px; background: none; border: 0; min-width: 48px; min-height: 48px; cursor: pointer; }
.tip { margin: 10px 0 0; color: rgba(255,255,255,.6); font-size: 15px; font-weight: 600; text-align: center; min-height: 1.4em; }

/* glasses: --u is one liquid unit, --tw the glass width. Rows (max 6 glasses) are balanced in JS and
   each row stands on a chalk shelf. The board takes the free height and centres the rack in it. */
.board { --u: 17px; --tw: 30px; flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; column-gap: 12px; row-gap: 34px; width: 100%; padding: 28px 4px 20px; }
.board .row { position: relative; display: flex; justify-content: center; align-items: flex-end; column-gap: inherit; padding: 0 0 8px; }
.board .row::after { content: ''; position: absolute; left: -18px; right: -18px; bottom: 0; height: 5px; border-radius: 5px; background: rgba(255,255,255,.26); box-shadow: 0 8px 14px rgba(0,0,0,.4); }
.board.few { --u: 18px; --tw: 32px; column-gap: 16px; }
.board.many { --u: 16px; --tw: 28px; column-gap: 10px; }
.board.huge { --u: 16px; --tw: 28px; column-gap: 10px; row-gap: 30px; }
.actions { margin-top: auto; }
/* A glass is a wrapper (.tube: position, tilt, lip, shine) around a clipping bowl (.bowl: rim, glass, shadow)
   that holds the liquid. The wrapper's transform is driven by --dx/--dy/--tilt so selection, hover and the
   pour all compose. */
.tube {
  position: relative; width: var(--tw); height: calc(var(--u) * 8 + 16px); flex: none; cursor: pointer; touch-action: manipulation;
  transform: translate(var(--dx, 0px), var(--dy, 0px)) rotate(var(--tilt, 0deg));
  transition: transform .16s cubic-bezier(.3,.9,.4,1.1); will-change: transform;
}
/* The bowl is the glass wall: a true semicircular bottom, a pale blue-white wall with a thin bright edge,
   depth from an inner bottom shadow, and a soft shadow onto the shelf. */
.bowl {
  position: absolute; inset: 0; overflow: hidden;
  border: 2px solid rgba(255,255,255,.9); border-top: 0; border-radius: 0 0 calc(var(--tw) / 2) calc(var(--tw) / 2);
  background: linear-gradient(90deg, rgba(255,255,255,.12), rgba(255,255,255,.04) 45%, rgba(255,255,255,.14));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), inset 0 -8px 12px rgba(0,0,0,.22), 0 10px 14px rgba(0,0,0,.5);
  transition: box-shadow .16s, border-color .16s;
}
/* .glass sits over the liquid inside the bowl: the specular strip on the left, a thin one on the right,
   and the bright arc where the rounded bottom catches light. */
.glass { position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background:
    linear-gradient(90deg, rgba(255,255,255,0) 8%, rgba(255,255,255,.22) 15%, rgba(255,255,255,.08) 24%, rgba(255,255,255,0) 36%, rgba(255,255,255,0) 86%, rgba(255,255,255,.14) 94%, rgba(255,255,255,0) 100%),
    radial-gradient(60% 26% at 50% 100%, rgba(255,255,255,.2), rgba(255,255,255,0) 100%);
  border-radius: inherit; }
.tube::before { content: ''; position: absolute; left: -7px; right: -7px; top: -8px; height: 17px; border-radius: 50%; background: linear-gradient(#f6f0ff 0%, #cbb7f4 50%, #a08adf 100%); box-shadow: 0 3px 4px rgba(0,0,0,.45), inset 0 2px 0 #fff, inset 0 -3px 0 rgba(70,40,130,.4); z-index: 4; }
.tube::after { content: ''; position: absolute; left: 3px; right: 3px; top: -5px; height: 10px; border-radius: 50%; background: radial-gradient(ellipse at 50% 35%, #2a1f52, #4b3a86 80%); box-shadow: inset 0 1px 3px rgba(0,0,0,.6); z-index: 5; pointer-events: none; }
.tube.selected { --dy: -12px; }
.tube.selected .bowl { border-color: #ffd54a; box-shadow: 0 0 0 3px rgba(255,213,74,.35), 0 0 22px 4px rgba(255,213,74,.55), 0 18px 16px rgba(0,0,0,.4); }
.tube.target .bowl { border-color: #5cff8a; box-shadow: 0 0 0 3px rgba(92,255,138,.3), 0 0 22px 3px rgba(92,255,138,.55), 0 12px 18px rgba(0,0,0,.4); animation: breathe .9s ease-in-out infinite alternate; }
.tube.done .bowl { border-color: #5cff8a; }
.tube.done::before { background: linear-gradient(#ffe066, #f2b400); }
.tube.cheer { animation: cheer .6s cubic-bezier(.3,1.4,.5,1); }
.tube.shake { animation: shake .3s; }
.liquid { position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--u) * 8 + 2px); display: flex; flex-direction: column-reverse; }

/* one band of liquid: cylinder shading (light left, dark right), a shallow elliptical boundary at its top, and on the top band a brighter elliptical surface. */
.seg {
  --c: #999; position: relative; flex: none; height: var(--u); background-color: var(--c);
  background-image: linear-gradient(90deg, rgba(255,255,255,.06) 0, rgba(255,255,255,.06) 13%, rgba(255,255,255,.4) 19%, rgba(255,255,255,.4) 29%, rgba(255,255,255,0) 38%, rgba(0,0,0,0) 72%, rgba(0,0,0,.22) 100%);
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: calc(var(--u) * .62); color: rgba(255,255,255,.85); text-shadow: 0 1px 2px rgba(0,0,0,.5);
  transition: height var(--d, .28s) cubic-bezier(.25,.85,.35,1);
}

/* Pouring. The glass flies over the target and tips to 135° (150° while draining) so the mouth is its lowest
   point. The bands ride with the glass; the stack slides toward the mouth (translateY on .liquid) and a level
   free surface is cut by a clip-path polygon on .pool, computed in JS for the current tilt. */
.pool { position: absolute; inset: 0; }
.tube.pouring { z-index: 6; transform-origin: 50% 0; transition: transform .24s cubic-bezier(.35,.9,.45,1.04); }
.tube.pouring.fly { transition-duration: .42s; transition-timing-function: cubic-bezier(.4,.1,.35,1); }
.tube.pouring.fly .pool, .tube.pouring.fly .liquid { transition-duration: .42s; transition-timing-function: cubic-bezier(.4,.1,.35,1); }
.tube.pouring.lift { transition-duration: .1s; transition-timing-function: ease-out; }
.tube.pouring.land { transition-duration: .18s; transition-timing-function: cubic-bezier(.3,1.6,.5,1); }
.tube.pouring .pool { transition: clip-path .2s cubic-bezier(.3,.8,.4,1); }
.tube.pouring .liquid { transition: transform .2s cubic-bezier(.3,.8,.4,1); }
.tube.pouring .seg { transition: height var(--d, .28s) linear; color: transparent; }
.tube.pouring.draining, .tube.pouring.draining .pool, .tube.pouring.draining .liquid { transition-duration: var(--d); transition-timing-function: linear; }
.tube.pouring.back { transition-duration: .38s; transition-timing-function: cubic-bezier(.4,.1,.35,1); }
.tube.pouring.back .pool, .tube.pouring.back .liquid { transition-duration: .38s; transition-timing-function: cubic-bezier(.4,.1,.35,1); }
.tube.calm .seg { transition: none !important; }
.tube.no-anim, .tube.no-anim .pool, .tube.no-anim .liquid, .tube.no-anim .seg { transition: none !important; }
.seg::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: rgba(255,255,255,.22); }
.seg:last-child::after { content: ''; position: absolute; left: 0; right: 0; top: -4px; height: 8px; border-radius: 50%; background: color-mix(in srgb, var(--c) 55%, white); box-shadow: inset 0 -1px 0 rgba(0,0,0,.12); }
.seg.hid { --c: #7f8899; color: rgba(255,255,255,.55); font-size: calc(var(--u) * .55); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.1) 0 4px, transparent 4px 9px); }
.seg[data-c="1"] { --c: var(--c1); } .seg[data-c="2"] { --c: var(--c2); } .seg[data-c="3"] { --c: var(--c3); } .seg[data-c="4"] { --c: var(--c4); }
.seg[data-c="5"] { --c: var(--c5); } .seg[data-c="6"] { --c: var(--c6); } .seg[data-c="7"] { --c: var(--c7); } .seg[data-c="8"] { --c: var(--c8); }
.seg[data-c="9"] { --c: var(--c9); } .seg[data-c="10"] { --c: var(--c10); } .seg[data-c="11"] { --c: var(--c11); } .seg[data-c="12"] { --c: var(--c12); }
.seg.hid[data-c] { --c: #7f8899; }

/* the falling stream between glasses */
.fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.stream { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; transition: opacity .16s; }
.stream path { fill: none; stroke: var(--c); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; transition: stroke-dashoffset .18s ease-in; filter: drop-shadow(0 0 3px rgba(0,0,0,.35)); }
.stream path.gloss { stroke: rgba(255,255,255,.45); stroke-width: 2; transform: translate(-1.5px, 0); }
.stream.on path { stroke-dashoffset: 0; }
.stream.prep path { transition: none; }
.stream.off { opacity: 0; }
.drop { position: absolute; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: var(--c); box-shadow: 0 0 4px rgba(0,0,0,.3); animation: droplet .5s cubic-bezier(.2,.7,.4,1) forwards; }

/* chunky buttons */
.actions { display: flex; gap: 10px; width: 100%; }
.btn { flex: 1; min-height: 56px; font: inherit; font-size: 18px; font-weight: 800; border: 0; border-radius: 16px; color: #fff; cursor: pointer; padding: 0 6px; text-shadow: 0 1px 0 rgba(0,0,0,.3);
  background: linear-gradient(#4f7dff, #2a4fd8); box-shadow: 0 5px 0 #15297d, 0 8px 14px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.45); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #15297d, inset 0 1px 0 rgba(255,255,255,.45); }
.btn:disabled { opacity: .4; }
.btn.primary { background: linear-gradient(#5fe07a, #2fa84a); box-shadow: 0 5px 0 #1b6b30, 0 8px 14px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.5); }
.btn.primary:active { box-shadow: 0 2px 0 #1b6b30; }
.btn:focus-visible, .tube:focus-visible { outline: 4px solid #ffd54a; outline-offset: 2px; }

/* Blot */
.blot { position: fixed; left: 0; top: 0; width: 64px; height: 64px; z-index: 30; pointer-events: none; transition: transform .45s cubic-bezier(.3,1.3,.5,1); filter: drop-shadow(0 8px 8px rgba(0,0,0,.5)); }
.blot svg { animation: bob 1.8s ease-in-out infinite; }
.blot.strike svg { animation: strike .5s; }
.blot-say { position: absolute; top: -6px; inset-inline-start: 60px; background: #fff; color: #1e1b16; font-weight: 800; font-size: 16px; border-radius: 14px; padding: 6px 12px; white-space: nowrap; box-shadow: 0 4px 0 #c5cbd8, 0 6px 10px rgba(0,0,0,.4); animation: popin .25s; }
.blot-say::before { content: ''; position: absolute; top: 12px; inset-inline-start: -8px; border: 6px solid transparent; border-inline-end-color: #fff; }
.intro-blot svg { width: 110px; height: 110px; animation: bob 1.8s ease-in-out infinite; filter: drop-shadow(0 10px 10px rgba(0,0,0,.5)); }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(8,14,30,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.card { background: linear-gradient(#2e4577, #1b2a4a); border: 2px solid rgba(255,255,255,.3); border-radius: 26px; padding: 26px 22px; width: 100%; max-width: 440px; text-align: center; animation: popin .25s; box-shadow: 0 8px 0 #0d1730, 0 24px 40px rgba(0,0,0,.5); color: #fff; }
.card h2 { font-size: 32px; margin: 0 0 6px; }
.card p { font-size: 20px; color: var(--muted); margin: 0 0 16px; }
.card .stars { font-size: 52px; letter-spacing: 6px; margin: 4px 0 10px; color: #ffd21f; text-shadow: 0 3px 0 #b8860b, 0 8px 14px rgba(0,0,0,.5); }
.card .stars .off { color: rgba(255,255,255,.2); text-shadow: none; }
.card .btn { width: 100%; margin-top: 8px; }
.confetti { position: fixed; top: -20px; left: var(--x); width: 12px; height: 18px; background: var(--col); animation: fall var(--d) linear forwards; z-index: 60; border-radius: 3px; }

@keyframes popin { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes flow { to { background-position: 0 0, 0 18px; } }
@keyframes droplet { 0% { opacity: 1; transform: translate(0, 0) scale(1); } 100% { opacity: 0; transform: translate(var(--ddx), var(--ddy)) scale(.4); } }
@keyframes cheer { 0% { transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(1); } 40% { transform: translate(var(--dx, 0px), -10px) scale(1.08); filter: brightness(1.35); } 100% { transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(1); } }
@keyframes breathe { from { filter: brightness(1); } to { filter: brightness(1.18); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-4px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .8; } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
@keyframes strike { 0% { transform: scale(1); } 50% { transform: scale(1.35) rotate(10deg); } 100% { transform: scale(1); } }
@media (max-width: 400px) { .board { --u: 16px; --tw: 26px; column-gap: 10px; } .board.few { --u: 17px; --tw: 28px; column-gap: 14px; } .board.many, .board.huge { --u: 15px; --tw: 24px; column-gap: 8px; } .btn { font-size: 16px; padding: 0 4px; } }
@media (prefers-reduced-motion: reduce) { .tube, .seg, .stream, .liquid { transition: none; } .confetti, .blot svg, .tube.target .bowl, .tube.cheer, .stream, .drop { animation: none; } }
