:root {
  --ink: #1b1d2a;
  --muted: #6b7085;
  --line: rgba(27, 29, 42, .1);
  --card: rgba(255, 255, 255, .86);
  --brand: #5b5bff;
  --brand-2: #ff6a3d;
  --amber: #ffd500;
  --good: #22c55e;
  --chip: #eef0f7;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --bar-h: 138px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; color: var(--ink);
  font: 600 15px/1.4 var(--font);
  background:
    radial-gradient(60vmax 60vmax at 10% 0%, #ffe6d5 0%, transparent 60%),
    radial-gradient(70vmax 70vmax at 95% 100%, #d8e2ff 0%, transparent 60%),
    radial-gradient(50vmax 50vmax at 80% 10%, #fff4c2 0%, transparent 55%),
    #f4f5fb;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button {
  font: inherit; font-weight: 800; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 14px; cursor: pointer; transition: transform .1s, box-shadow .15s, background .15s;
  box-shadow: 0 2px 0 rgba(27, 29, 42, .06);
}
button:hover:not(.cta):not(.seg button) { background: #fafbff; }
button:active { transform: translateY(1px) scale(.98); box-shadow: none; }
button:disabled { opacity: .4; cursor: default; transform: none; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 2px; }
.cta {
  color: #fff; border: 0; background: linear-gradient(135deg, var(--brand), #8b5cf6 60%, var(--brand-2));
  background-size: 200% 200%; box-shadow: 0 8px 24px rgba(91, 91, 255, .35); letter-spacing: .01em;
  animation: shimmer 6s ease infinite;
}
.cta:hover { background-position: 100% 50%; filter: brightness(1.08); }
.cta.small { padding: 8px 14px; box-shadow: 0 4px 14px rgba(91, 91, 255, .3); }
@keyframes shimmer { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; display: grid; place-items: center; font-weight: 900; }

/* top bar */
#top {
  position: fixed; top: 0; left: 0; right: 0; padding: 14px 16px; display: flex; align-items: center; gap: 12px;
  pointer-events: none;
}
#top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px; background:
    conic-gradient(from 0deg, #ffd500 0 25%, #ff6a00 0 50%, #0051ba 0 75%, #00a651 0) ;
  box-shadow: inset 0 0 0 3px #1b1d2a;
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 900; letter-spacing: -.01em; }
.brand h1 span { color: var(--brand); }
.stats { margin-left: auto; display: flex; gap: 6px; }
.pill {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; font-size: 13px;
  backdrop-filter: blur(10px); white-space: nowrap;
}
.pill b { font-variant-numeric: tabular-nums; }
#stats[hidden] { display: none; }
#helpBtn { margin-left: auto; }
.stats:not([hidden]) + #helpBtn { margin-left: 0; }

/* toast / hint */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 10px + var(--safe-b)); z-index: 5; transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px)); background: var(--card); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 12px 40px rgba(27, 29, 42, .12);
  font-size: 14px; animation: pop .25s ease;
}
#toast[hidden] { display: none; }
#toast .mv {
  display: inline-grid; place-items: center; min-width: 44px; height: 44px; padding: 0 10px; margin-right: 10px; border-radius: 12px;
  background: var(--amber); font-size: 22px; font-weight: 900; font-family: ui-monospace, Menlo, Consolas, monospace; vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}
#toast .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
#toast .row button { white-space: nowrap; }
#toast .muted { color: var(--muted); font-weight: 600; font-size: 13px; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 8px) scale(.97); } }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* bottom bar */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(12px + var(--safe-b));
  display: grid; gap: 10px; justify-items: center;
  background: linear-gradient(to top, rgba(244, 245, 251, .95), rgba(244, 245, 251, 0));
}
.primary { display: flex; align-items: center; gap: 10px; }
.primary .cta { padding: 14px 28px; font-size: 18px; border-radius: 999px; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; backdrop-filter: blur(10px); }
.seg button { border: 0; background: transparent; box-shadow: none; padding: 8px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.seg button:hover { color: var(--ink); }
.seg button.on, .seg button.on:hover { background: var(--ink); color: #fff; }
.actions { display: flex; gap: 6px; }
.actions button {
  min-width: 64px; padding: 8px 6px; font-size: 12px; font-weight: 800; display: grid; gap: 2px; justify-items: center;
  background: var(--card); backdrop-filter: blur(10px);
}
.actions i { font-style: normal; font-size: 20px; line-height: 1; }
.actions button.on { border-color: var(--brand); color: var(--brand); }

/* sheet (drawer) */
#sheet {
  position: fixed; left: 0; right: 0; bottom: calc(var(--bar-h) + var(--safe-b)); max-height: 52vh; overflow: auto; padding: 8px 16px 16px;
  background: var(--card); backdrop-filter: blur(18px); border-radius: 22px 22px 0 0; border: 1px solid var(--line);
  box-shadow: 0 -12px 40px rgba(27, 29, 42, .15); animation: up .28s cubic-bezier(.2, .8, .2, 1);
}
#sheet[hidden] { display: none; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
#sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 6px; }
#sheet header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#sheet h2 { margin: 0; font-size: 17px; font-weight: 900; }
#sheet h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid button { padding: 12px 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; }
.view { display: flex; gap: 6px; }
.view button { flex: 1; padding: 10px 0; }
.tip { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.playbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.playbar label { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 140px; }
.playbar input[type=range] { flex: 1; accent-color: var(--brand); }
.stage { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-top: 8px; }
.stage h4 { margin: 0; font-size: 14px; display: flex; justify-content: space-between; }
.stage h4 small { color: var(--muted); font-weight: 600; }
.stage p { margin: 4px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.stage.active { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255, 213, 0, .35); }
.stage.notice { background: #fff8d6; color: var(--ink); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--chip); border-radius: 7px; padding: 3px 7px; font: 800 13px/1.4 ui-monospace, Menlo, Consolas, monospace; }
.chip.done { background: #d1fae5; } .chip.now { background: var(--amber); }

/* dialogs */
dialog {
  border: 0; border-radius: 24px; padding: 26px 24px; max-width: 420px; width: calc(100% - 32px); color: var(--ink);
  box-shadow: 0 30px 80px rgba(27, 29, 42, .3); text-align: center; animation: pop2 .3s cubic-bezier(.2, .8, .2, 1);
}
dialog::backdrop { background: rgba(27, 29, 42, .45); backdrop-filter: blur(4px); }
@keyframes pop2 { from { transform: scale(.9); opacity: 0; } }
dialog h1 { margin: 0 0 6px; font-size: 26px; font-weight: 900; }
dialog p { margin: 6px 0; color: var(--muted); }
dialog .big { font-size: 64px; line-height: 1; animation: bounce .8s ease infinite alternate; }
@keyframes bounce { to { transform: translateY(-8px) rotate(-6deg); } }
.statgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.statgrid div { background: var(--chip); border-radius: 14px; padding: 10px 6px; }
.statgrid b { display: block; font-size: 22px; font-weight: 900; }
.statgrid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
dialog .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
dialog .cta { width: 100%; margin-top: 6px; }
.how { text-align: left; padding-left: 20px; margin: 10px 0; }
.how li { margin: 8px 0; }
kbd { font: 800 12px ui-monospace, Menlo, Consolas, monospace; background: var(--chip); padding: 1px 6px; border-radius: 6px; }

/* confetti */
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; border-radius: 3px; pointer-events: none; z-index: 50; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .8; } }

@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; } }

/* desktop: sheet becomes a side panel */
@media (min-width: 900px) {
  #sheet { left: auto; right: 16px; top: 76px; bottom: 16px; width: 380px; max-height: none; border-radius: 22px; animation: side .28s cubic-bezier(.2, .8, .2, 1); }
  #sheet .grab { display: none; }
  @keyframes side { from { transform: translateX(30px); opacity: 0; } }
  .actions button { min-width: 84px; }
}
@media (max-width: 480px) {
  .brand h1 span { display: none; }
  #top:has(#stats:not([hidden])) .brand h1 { display: none; } /* stats need the room while playing */
  .primary .cta { padding: 12px 22px; font-size: 16px; }
  .seg button { padding: 8px 10px; font-size: 12px; }
  .actions button { min-width: 58px; font-size: 11px; }
}
