/* Color Sort (newellabs.com/play/ball-sort). Self-contained; system fonts only. */
:root {
  color-scheme: light dark;
  --bg: #eef2f8; --well: #e2e8f1; --card: #ffffff;
  --ink: #172033; --ink-2: #364157; --muted: #556074; --faint: #9aa5b8;
  --line: #d6deea; --line-strong: #b9c4d6;
  --accent: #2f4fc4; --accent-ink: #ffffff; --accent-soft: rgba(47, 79, 196, .22);
  --focus: #1f5fe0; --good: #13805a; --good-soft: rgba(19, 128, 90, .25); --warn: #a8450f;
  --glass-a: rgba(255, 255, 255, .92); --glass-b: rgba(255, 255, 255, .5); --glass-line: #a9b6ca; --glass-floor: rgba(23, 32, 51, .05);
  --lid: #8e9bb2; --veil: rgba(238, 242, 248, .72);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --round: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Ball colors: picked so every pair stays apart (CIELAB distance >= 18) under normal vision and simulated
     protanopia, deuteranopia and tritanopia (see README). Each also has a symbol. */
  --c0: #e23a2e; --c1: #1f4fd6; --c2: #f5d22e; --c3: #7fe0c0; --c4: #6e1630; --c5: #c9b8f2;
  --c6: #1b2a5e; --c7: #0f8c82; --c8: #ff8a7a; --c9: #b9e36a; --c10: #b46ae8; --c11: #c99a12;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d; --well: #191f2b; --card: #1b2231;
    --ink: #e9edf4; --ink-2: #ccd3df; --muted: #a2abbc; --faint: #5c6578;
    --line: #283044; --line-strong: #3b4560;
    --accent: #8da3ff; --accent-ink: #0f1424; --accent-soft: rgba(141, 163, 255, .28);
    --focus: #9ab7ff; --good: #4fd19c; --good-soft: rgba(79, 209, 156, .25); --warn: #ffb27a;
    --glass-a: rgba(255, 255, 255, .10); --glass-b: rgba(255, 255, 255, .03); --glass-line: #56627c; --glass-floor: rgba(255, 255, 255, .04);
    --lid: #7d8aa6; --veil: rgba(17, 21, 29, .72);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.6 var(--sans); overflow-x: hidden; }
a { color: inherit; text-decoration-color: var(--accent); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button { font: inherit; color: inherit; touch-action: manipulation; }
kbd { font: 500 .82em/1 var(--mono); display: inline-block; min-width: 1.6em; padding: .22em .38em; text-align: center; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--card); color: var(--ink); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }
.fine-only { display: none; }
.vh { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; }
.skip:focus { left: 16px; }

/* Header, hero, footer (same as the other toys) */
.top { border-bottom: 1px solid var(--line); }
.top-in { min-height: 54px; display: flex; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 9px; min-height: 44px; text-decoration: none; font-weight: 650; font-size: 15px; padding: 8px 0; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.brand-sub { color: var(--muted); font-weight: 500; margin-left: 2px; }
.brand-sub::before { content: "/"; margin-right: 6px; color: var(--faint); }
.hero { padding-top: 18px; }
h1 { font: 800 clamp(1.9rem, 7vw, 2.8rem)/1.05 var(--round); letter-spacing: -.01em; margin: 0 0 6px; }
.lede { margin: 0; color: var(--ink-2); max-width: 640px; font-size: .98rem; line-height: 1.45; }
.foot { border-top: 1px solid var(--line); margin-top: 56px; padding: 22px 0 32px; color: var(--muted); font-size: .9rem; }
.foot p { margin: 0; }
.foot-in { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 20px; }
.foot a { color: var(--muted); display: inline-block; padding: 12px 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--card); font-size: 15px; font-weight: 650; cursor: pointer; transition: border-color .15s, background-color .15s, color .15s, opacity .15s; -webkit-tap-highlight-color: transparent; }
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .42; cursor: default; transform: none; border-color: var(--line-strong); }
.btn svg { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-sm { min-height: 44px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.06); }
.link-btn { background: none; border: 0; padding: 4px 2px; min-height: 44px; color: var(--ink-2); text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; cursor: pointer; font-size: 15px; }

/* Stage */
.stage { padding-top: 14px; }
.challenge { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; padding: 6px 6px 6px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.challenge p { margin: 0; font-size: 15px; line-height: 1.35; }
.challenge .btn { width: 44px; padding: 0; flex: none; }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; margin: 0 0 6px; }
.seg { display: inline-flex; align-items: center; background: var(--well); border: 1px solid var(--line); border-radius: 13px; padding: 3px; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.seg label { min-height: 44px; min-width: 72px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; font-weight: 650; font-size: 15px; color: var(--ink-2); cursor: pointer; white-space: nowrap; transition: background-color .15s, color .15s; touch-action: manipulation; }
.seg input:checked + label { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 0 0 1px var(--line); }
.seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }
.hud { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud b { color: var(--ink); font-weight: 750; }
.hud-title { color: var(--ink); font-weight: 750; }
.hud-item.beat b { color: var(--accent); }

/* Board */
.board-wrap { position: relative; margin: 0 -8px; min-height: 280px; display: flex; flex-direction: column; justify-content: center; }
.board { --b: 44px; --cell: 64px; --cap: 4; --pad: 7px; --rowgap: 6px;
  display: flex; flex-wrap: wrap; justify-content: center; row-gap: var(--rowgap); padding: 4px 0; outline: none; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.board.loading { visibility: hidden; }
.board-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); font-weight: 600; }
.tube { position: relative; width: var(--cell); height: calc(var(--b) * (var(--cap) + var(--head, .9)) + var(--pad) + 6px); padding: 0; margin: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; border-radius: 14px; }
.tube:focus-visible { outline: 3px solid var(--focus); outline-offset: -2px; }
.glass { position: absolute; left: 50%; bottom: 4px; width: calc(var(--b) + 8px); height: calc(var(--b) * var(--cap) + var(--pad) + 6px); transform: translateX(-50%);
  border: 2px solid var(--glass-line); border-top: 0; border-radius: 4px 4px calc(var(--b) / 2 + 5px) calc(var(--b) / 2 + 5px);
  background: linear-gradient(90deg, var(--glass-b), var(--glass-a) 28%, var(--glass-b) 62%, var(--glass-a)); box-shadow: inset 0 -6px 10px var(--glass-floor);
  transition: border-color .15s, box-shadow .15s; }
.glass::before { content: ""; position: absolute; left: -3px; right: -3px; top: -2px; height: 5px; border-radius: 3px; background: var(--glass-line); }
.tube[aria-pressed="true"] .glass { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), inset 0 -6px 10px var(--glass-floor); }
.tube[aria-pressed="true"] .glass::before { background: var(--accent); }
.tube.done .glass { border-color: var(--good); box-shadow: 0 0 0 3px var(--good-soft), inset 0 -6px 10px var(--glass-floor); }
.tube.done .glass::before { background: var(--good); height: 9px; top: -8px; left: -3px; right: -3px; border-radius: 5px 5px 2px 2px; }
.tube.shake .glass { animation: shake .32s ease-in-out; }
@keyframes shake { 0%, 100% { transform: translateX(-50%); } 20% { transform: translateX(calc(-50% - 5px)); } 45% { transform: translateX(calc(-50% + 5px)); } 70% { transform: translateX(calc(-50% - 3px)); } }
.tube.hint-from .glass, .tube.hint-to .glass { border-color: var(--good); animation: hintpulse 1s ease-in-out 3; }
.tube.hint-to::after { content: ""; position: absolute; left: 50%; top: -4px; width: 0; height: 0; transform: translateX(-50%); border: 9px solid transparent; border-top: 12px solid var(--good); animation: hintbob .8s ease-in-out infinite alternate; }
@keyframes hintpulse { 50% { box-shadow: 0 0 0 6px var(--good-soft), inset 0 -6px 10px var(--glass-floor); } }
@keyframes hintbob { to { transform: translate(-50%, 6px); } }
.tube.added .glass { animation: pop .35s ease-out; }
@keyframes pop { from { transform: translateX(-50%) scale(.6); opacity: 0; } }

/* Balls */
.ball { position: absolute; left: calc(50% - var(--b) / 2 + 1px); bottom: calc(4px + var(--pad) / 2 + var(--i, 0) * var(--b) + 1px); width: calc(var(--b) - 2px); height: calc(var(--b) - 2px); border-radius: 50%;
  background: radial-gradient(circle at 33% 28%, rgba(255, 255, 255, .78) 0 7%, rgba(255, 255, 255, 0) 34%), radial-gradient(circle at 50% 42%, var(--c) 58%, var(--cd) 100%);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .22), 0 1px 2px rgba(0, 0, 0, .28);
  translate: 0 0; transition: translate .15s cubic-bezier(.3, .7, .4, 1); pointer-events: none; will-change: transform; }
.ball.up { translate: 0 var(--up, -20px); }
/* Symbols are the color-blind aid, so each one keeps at least 3:1 contrast with its ball (checked by the e2e suite). */
.ball svg { position: absolute; left: 21%; top: 21%; width: 58%; height: 58%; fill: var(--sym); stroke: none; }
.no-sym .ball svg { display: none; }
.k0 { --c: var(--c0); --cd: #a8241c; --sym: #fff; }
.k1 { --c: var(--c1); --cd: #12318f; --sym: #fff; }
.k2 { --c: var(--c2); --cd: #c9a10e; --sym: rgba(40, 30, 0, .78); }
.k3 { --c: var(--c3); --cd: #3fae8c; --sym: rgba(0, 45, 32, .78); }
.k4 { --c: var(--c4); --cd: #45091c; --sym: #fff; }
.k5 { --c: var(--c5); --cd: #9a85d6; --sym: rgba(35, 20, 75, .8); }
.k6 { --c: var(--c6); --cd: #0d1638; --sym: #fff; }
.k7 { --c: var(--c7); --cd: #075c55; --sym: #fff; }
.k8 { --c: var(--c8); --cd: #e0574a; --sym: rgba(70, 10, 5, .78); }
.k9 { --c: var(--c9); --cd: #86b536; --sym: rgba(25, 45, 0, .8); }
.k10 { --c: var(--c10); --cd: #8240c0; --sym: #fff; }
.k11 { --c: var(--c11); --cd: #92700a; --sym: rgba(40, 30, 0, .82); }
@media (prefers-color-scheme: dark) {
  .ball { box-shadow: inset 0 -2px 3px rgba(0, 0, 0, .25), 0 0 0 1px rgba(255, 255, 255, .16); }
}

/* Solved */
.win { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 12px; background: var(--veil); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.win-card { width: min(100%, 360px); text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px 18px 10px; box-shadow: 0 18px 50px -18px rgba(0, 0, 0, .45); animation: rise .35s cubic-bezier(.2, .8, .3, 1.2); }
@keyframes rise { from { transform: translateY(14px) scale(.96); opacity: 0; } }
.win h2 { font: 800 1.7rem/1.1 var(--round); margin: 0 0 6px; }
.win-line { margin: 0; font-size: 1.05rem; font-weight: 650; }
.win-sub { margin: 4px 0 14px; color: var(--muted); font-size: .95rem; line-height: 1.4; }
.win-sub:empty { display: none; }
.win-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.win-btns .btn { flex: 1 1 130px; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 6; }
.confetti i { position: absolute; top: 40%; left: 50%; width: 9px; height: 13px; border-radius: 2px; background: var(--c); opacity: 0; }

/* Status, tools, prefs */
.status { margin: 6px 0 8px; min-height: 2.8em; font-size: 15px; line-height: 1.4; color: var(--ink-2); text-align: center; }
.status.warn { color: var(--warn); font-weight: 600; }
.actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; max-width: 560px; margin: 0 auto; }
.act { position: relative; flex-direction: column; gap: 2px; min-height: 58px; padding: 6px 4px; font-size: 13.5px; }
.act svg { width: 21px; height: 21px; }
.act .badge { position: absolute; top: 5px; right: 6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--well); border: 1px solid var(--line); font: 700 12px/18px var(--sans); color: var(--ink-2); }
.act.nudge { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.act.confirm { border-color: var(--warn); color: var(--warn); }
.prefs { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 10px; margin-top: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 12px 0 8px; border: 1px solid var(--line); border-radius: 999px; background: transparent; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.toggle .knob { position: relative; width: 30px; height: 18px; border-radius: 9px; background: var(--line-strong); transition: background-color .15s; flex: none; }
.toggle .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.toggle[aria-pressed="true"] .knob { background: var(--accent); }
.toggle[aria-pressed="true"] .knob::after { transform: translateX(12px); }
.keyhint { width: 100%; text-align: center; margin: 4px 0 0; font-size: 13.5px; color: var(--muted); }

/* Content */
.prose { margin-top: 44px; }
.prose > * { max-width: 700px; }
.prose h2 { font: 800 1.45rem/1.2 var(--round); margin: 36px 0 12px; }
.prose h3 { font-size: 1.02rem; margin: 22px 0 4px; line-height: 1.35; }
.prose p { margin: 0 0 10px; color: var(--ink-2); }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 10px; color: var(--ink-2); }
.prose li { margin: 0 0 10px; }
.prose li::marker { color: var(--accent); font-weight: 700; }
.prose strong { color: var(--ink); }

.more-toys { margin-top: 48px; }
.more-toys h2 { font: 800 1.35rem/1.2 var(--round); margin: 0 0 12px; }
.more-toys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.more-toys a { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: center; column-gap: 14px; min-height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink); text-decoration: none; }
.more-toys a:hover { border-color: var(--accent); color: var(--ink); }
.more-toys img { grid-row: 1 / 3; display: block; width: 112px; height: 63px; border-radius: 10px; object-fit: cover; background: var(--well); }
.more-toys b { align-self: end; font-weight: 700; }
.more-toys span { align-self: start; font-size: .88rem; line-height: 1.35; color: var(--muted); }
.more-toys + .foot { margin-top: 40px; }

.toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 40; width: max-content; max-width: calc(100vw - 32px); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .45); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast input { display: block; width: min(560px, calc(100vw - 64px)); margin-top: 8px; padding: 8px; border-radius: 8px; border: 0; font: 13px var(--mono); color: var(--ink); background: var(--card); }

/* Phones (and phones held sideways): the puzzle gets the first screen. Real phone browsers show their toolbars, so an
   iPhone 12-15 in Safari has 390x664 to work with and an iPhone SE 375x553: a short hero, a one-line intro, the HUD on
   the same row as the Levels/Daily switch, and slimmer status and tool rows. The full intro is in the page for wider
   screens; the FAQ below says the same things. */
@media (max-width: 599px), (max-height: 500px) {
  .top-in { min-height: 48px; }
  .hero { padding-top: 10px; }
  h1 { font-size: 1.65rem; margin: 0 0 2px; }
  .lede { font-size: .94rem; line-height: 1.4; }
  .lede-more { display: none; }
  .stage { padding-top: 8px; }
  .challenge { margin-bottom: 8px; padding: 2px 2px 2px 12px; }
  .challenge p { font-size: 14px; line-height: 1.3; }
  .bar { gap: 4px 10px; margin-bottom: 4px; }
  .seg label { min-width: 62px; padding: 0 10px; font-size: 14.5px; }
  .hud { gap: 2px 10px; font-size: 14px; }
  .board-wrap { min-height: 240px; }
  .status { margin: 4px 0 6px; min-height: 2.7em; font-size: 14px; line-height: 1.35; }
  .act { min-height: 52px; gap: 0; padding: 4px; font-size: 13px; }
}
@media (max-width: 399px) {
  .hud-kind { display: none; }
}
@media (min-width: 600px) {
  .board-wrap { margin: 0; }
  .status { min-height: 1.4em; }
  .act { flex-direction: row; gap: 8px; min-height: 48px; font-size: 15px; }
  .act .badge { position: static; }
}
@media (hover: hover) and (pointer: fine) {
  .fine-only { display: block; }
  .tube:hover .glass { border-color: var(--ink-2); }
  .tube[aria-pressed="true"]:hover .glass { border-color: var(--accent); }
  .tube.done:hover .glass { border-color: var(--good); }
}
@media (prefers-reduced-motion: reduce) {
  .ball { transition: none; }
  .tube.shake .glass, .tube.hint-from .glass, .tube.hint-to .glass, .tube.hint-to::after, .tube.added .glass, .win-card { animation: none; }
  .toast { transition: none; }
}
