/* Count On It. Tokens are written by the look engine at runtime. */
:root {
  --bg: #0b0b10; --bg2: #14141c; --ink: #f4f4f6; --muted: #a3a3ad; --line: #2a2a35; --surface: #121219;
  --surface-a: rgba(18,18,25,.9); --accent: #9be15d; --accent2: #5dc8e1; --on-accent: #0a0a0f; --accent-soft: rgba(155,225,93,.16);
  --f-display: system-ui, sans-serif; --f-ui: system-ui, sans-serif; --f-mono: ui-monospace, monospace;
  --radius: 10px; --tracking: 0em; --fs: 120px; --per-row: 4;
  --t-fast: 220ms; --t-base: 420ms; --t-slow: 760ms;
  --ease-out: cubic-bezier(.16,1,.3,1); --ease-io: cubic-bezier(.65,0,.35,1); --spring: cubic-bezier(.34,1.56,.64,1);
  --dock-w: 392px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-ui); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
#bg { position: fixed; inset: 0; z-index: -2; display: block; }
.grain { position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: .07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
.grain::after { content: ""; position: absolute; inset: 0; background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(0,0,0,.45)); mix-blend-mode: normal; opacity: 1; }
[data-scheme="light"] .grain::after { opacity: .5; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Bar */
.bar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 16px 24px; padding-top: max(16px, env(safe-area-inset-top)); }
.is-create .bar { right: var(--dock-w); }
.mark { font-family: var(--f-display); font-weight: 800; font-size: 18px; letter-spacing: var(--tracking); color: var(--ink); text-decoration: none; }
.bar-note { color: var(--muted); font-size: 14px; }
.actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* Stage */
.stage { min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 96px 24px 72px; gap: 14px; }
.is-create .stage { margin-right: var(--dock-w); }
.prefix { margin: 0; font-family: var(--f-mono); color: var(--muted); font-size: clamp(14px, 1.4vw, 18px); }
.title { margin: 0; font-family: var(--f-display); font-weight: 800; letter-spacing: var(--tracking); font-size: clamp(28px, 4.6vw, 68px); line-height: 1.05; max-width: 20ch; text-wrap: balance; overflow-wrap: anywhere; }
.title.is-placeholder { color: var(--muted); opacity: .7; }
.phase { margin: 4px 0 0; font-family: var(--f-mono); color: var(--accent); font-size: clamp(15px, 1.6vw, 20px); }
.meta { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.joined { margin: 0; font-size: 14px; color: var(--ink); opacity: .85; }
.progress { width: min(560px, 80%); height: 3px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(0); }
.celebrate .title { animation: cele 1.2s var(--ease-out) both; }
@keyframes cele { 0% { transform: scale(.9); letter-spacing: .2em; opacity: .3; } 100% { transform: none; opacity: 1; } }

/* Numbers base */
.nums { font-size: var(--fs); font-family: var(--f-display); font-weight: 800; line-height: 1; letter-spacing: var(--tracking); display: grid; grid-template-columns: repeat(var(--per-row), auto); justify-content: center; column-gap: .42em; row-gap: .3em; margin: 18px 0 6px; font-variant-numeric: tabular-nums; user-select: none; }
.unit { display: flex; flex-direction: column; align-items: center; }
.digits { display: flex; gap: .04em; }
.lbl { font-family: var(--f-mono); font-weight: 400; color: var(--muted); font-size: max(12px, .11em); letter-spacing: 0; margin-top: .55em; }
body[data-phase="done"] .nums { color: var(--accent); }

/* 1 Odometer */
.od { display: inline-block; height: 1em; overflow: hidden; width: 1.02ch; position: relative; }
.od-col { display: flex; flex-direction: column; transform: translateY(calc(var(--n) * -1em)); transition: transform var(--t-slow) var(--spring); }
.od-col span { height: 1em; display: block; text-align: center; }

/* 2 Split flap */
.fl { position: relative; width: calc(1ch + .14em); height: 1.12em; perspective: 4em; display: inline-block; font-size: .9em; }
.fl-top, .fl-bot, .fl-front, .fl-back { position: absolute; left: 0; right: 0; height: 50%; overflow: hidden; background: var(--surface); border-radius: calc(var(--radius) * .4); }
.fl-top, .fl-front { top: 0; border-bottom: 1px solid var(--bg); }
.fl-bot { bottom: 0; }
.fl b, .fl b { position: absolute; left: 0; right: 0; height: 200%; line-height: 1.12em; text-align: center; font-weight: inherit; top: 0; }
.fl-bot b, .fl-back b { top: -100%; }
.fl-leaf { position: absolute; left: 0; right: 0; top: 0; height: 50%; transform-origin: 50% 100%; transform-style: preserve-3d; z-index: 2; }
.fl-front, .fl-back { inset: 0; height: 100%; backface-visibility: hidden; }
.fl-back { transform: rotateX(180deg); }
.fl.go .fl-leaf { animation: flipdown 560ms var(--ease-io) both; }
@keyframes flipdown { from { transform: rotateX(0); } to { transform: rotateX(-180deg); } }
.s-flip .digits { gap: .06em; }

/* 3 Scramble */
.sc { display: inline-block; width: 1.02ch; text-align: center; transition: color var(--t-fast); }
.sc.hot { color: var(--accent); }

/* 4 Seven segment */
.sg { width: .62em; height: 1em; overflow: visible; }
.sg rect { fill: currentColor; opacity: .07; transition: opacity var(--t-fast) var(--ease-out), fill var(--t-fast); }
.sg rect.on { opacity: 1; fill: var(--accent); filter: drop-shadow(0 0 .06em var(--accent)); }
[data-scheme="light"] .sg rect.on { filter: none; fill: var(--ink); }

/* 5 Dot matrix */
.mx { display: grid; grid-template-columns: repeat(5, 1fr); gap: .03em; width: .62em; height: 1em; }
.mx i { display: block; border-radius: 50%; background: currentColor; opacity: .08; transform: scale(.55); transition: opacity 300ms var(--ease-out), transform 420ms var(--spring), background 300ms; }
.mx i.on { opacity: 1; transform: scale(1); background: var(--accent); }

/* 6 Variable weight wave */
.s-weight .nums, .s-weight { font-family: "Big Shoulders Display", var(--f-display); }
.vw { display: inline-block; width: .52em; text-align: center; font-weight: 700; animation: breathe 3.2s var(--ease-io) infinite; }
.s-weight .unit:nth-child(2) .vw { animation-delay: -.8s; } .s-weight .unit:nth-child(3) .vw { animation-delay: -1.6s; } .s-weight .unit:nth-child(4) .vw { animation-delay: -2.4s; }
.vw.hit { animation: hit 700ms var(--ease-out), breathe 3.2s var(--ease-io) 700ms infinite; }
@keyframes breathe { 50% { font-weight: 300; } }
@keyframes hit { 0% { font-weight: 100; color: var(--accent); transform: scaleY(1.12); } 100% { font-weight: 700; transform: none; } }

/* 7 Glitch */
.gl { position: relative; display: inline-block; width: 1.02ch; text-align: center; }
.gl::before, .gl::after { content: attr(data-ch); position: absolute; inset: 0; opacity: 0; }
.gl::before { color: var(--accent); } .gl::after { color: var(--accent2); }
.gl.go::before { animation: gl1 360ms steps(2) both; } .gl.go::after { animation: gl2 360ms steps(2) both; }
.gl.go { animation: gl0 360ms steps(3) both; }
@keyframes gl0 { 30% { transform: translateX(.03em) skewX(-8deg); } 60% { transform: translateX(-.02em); } }
@keyframes gl1 { 0% { opacity: .9; transform: translate(-.06em, 0); clip-path: inset(10% 0 55% 0); } 50% { clip-path: inset(60% 0 10% 0); transform: translate(.05em, 0); } 100% { opacity: 0; } }
@keyframes gl2 { 0% { opacity: .9; transform: translate(.06em, 0); clip-path: inset(50% 0 20% 0); } 50% { clip-path: inset(5% 0 70% 0); transform: translate(-.04em, 0); } 100% { opacity: 0; } }

/* 8 Orbit rings */
.s-rings { column-gap: .25em; }
.ring { position: relative; width: 2em; }
.ring svg { width: 2em; height: 2em; overflow: visible; }
.ring .rt { fill: none; stroke: var(--line); stroke-width: 3; }
.ring .rp { fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 1000; transform: rotate(-90deg); transform-origin: 60px 60px; }
.ring .rd { fill: var(--accent2); }
.ring .rn { position: absolute; top: 0; left: 0; display: grid; place-items: center; font-size: .62em; width: 3.23em; height: 3.23em; }
.ring .rn.pop { animation: pop 420ms var(--spring); }
@keyframes pop { from { transform: scale(.82); opacity: .4; } }
.ring .lbl { margin-top: .2em; }

/* 9 Liquid */
.lq { position: relative; display: inline-block; width: 1.02ch; text-align: center; }
.lq-o { color: transparent; -webkit-text-stroke: max(1.5px, .012em) var(--accent); }
.lq-f { position: absolute; inset: 0; color: var(--accent); }

/* 10 Swarm */
.s-particles { display: block; width: 100%; }
.s-particles canvas { display: block; margin: 0 auto; }

/* Buttons and inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-a); color: var(--ink); font: 600 15px/1.2 var(--f-ui); text-decoration: none; cursor: pointer; transition: transform var(--t-fast) var(--spring), background var(--t-fast), border-color var(--t-fast), translate 300ms var(--ease-out); }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.is-view .btn.ghost { background: var(--surface-a); }
.btn.big { min-height: 52px; font-size: 16px; padding: 12px 22px; }
.btn.small { min-height: 36px; font-size: 13px; padding: 6px 12px; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn[hidden] { display: none; }
input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 15px/1.3 var(--f-ui); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { font-family: var(--f-mono); font-size: 12px; resize: vertical; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.field[hidden], .pane[hidden] { display: none; }
.chk { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; color: var(--ink); cursor: pointer; padding: 6px 0; }
.chk input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); margin: 1px 0 0; flex: none; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.fine { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.err { color: var(--ink); background: var(--accent-soft); border-left: 3px solid var(--accent); padding: 8px 12px; font-size: 14px; margin: 8px 0; }
.err[hidden] { display: none; }

/* Dock */
.dock { position: fixed; top: 0; right: 0; bottom: 0; width: var(--dock-w); z-index: 30; background: var(--surface-a); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.dock-handle { display: none; }
.dock-body { overflow-y: auto; padding: 22px 24px 40px; overscroll-behavior: contain; }
.dock section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.dock section:last-child { border-bottom: 0; }
.dock h2 { font-family: var(--f-display); font-size: 17px; letter-spacing: var(--tracking); margin: 0 0 12px; font-weight: 700; }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 12px; }
.seg button { min-height: 44px; border-radius: var(--radius); border: 1px solid var(--line); background: transparent; color: var(--ink); font: 600 14px/1.2 var(--f-ui); cursor: pointer; padding: 8px; transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--ink); font: 13px var(--f-ui); cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.dur { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.dur .field { margin-bottom: 0; }
.styles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.style-chip { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 12px; text-align: left; border-radius: var(--radius); border: 1px solid var(--line); background: transparent; color: var(--ink); font: 600 14px var(--f-ui); cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.style-no { font-family: var(--f-mono); color: var(--muted); font-weight: 400; width: 1.4em; }
.style-chip[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); }
.style-chip[aria-checked="true"] .style-no { color: var(--accent); }
.look { display: flex; flex-wrap: wrap; gap: 8px; }
.look .btn.big { flex: 1 1 200px; }
.get form[hidden], .share[hidden] { display: none; }
.get .btn.big { width: 100%; margin-top: 8px; }
.share-head { font-family: var(--f-display); font-size: 20px; margin: 0 0 10px; }
.share-url { display: flex; gap: 8px; margin-bottom: 10px; }
.share-url input { font-family: var(--f-mono); font-size: 13px; }
.share-nets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.share-nets .btn { min-height: 40px; padding: 8px 12px; font-size: 14px; }
.share-qr { background: #fff; padding: 14px; border-radius: var(--radius); width: max-content; margin: 6px 0 12px; color: #0b0b10; font-size: 13px; }
.share-qr[hidden] { display: none; }
.share-embed summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 6px 0; }
.share-embed textarea { margin: 6px 0; }
.share > .btn.primary { margin-top: 12px; width: 100%; }

/* Dialogs */
dialog { border: 1px solid var(--line); border-radius: calc(var(--radius) + 6px); background: var(--surface); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100svh - 32px); }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog[open] { animation: dlg-in var(--t-base) var(--ease-out); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }
.dlg { padding: 26px; display: grid; gap: 14px; }
.dlg h2 { margin: 0; font-family: var(--f-display); font-size: 24px; letter-spacing: var(--tracking); }
.dlg p { margin: 0; color: var(--muted); }
.own-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { text-align: left; display: grid; gap: 6px; padding: 18px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; font: 14px/1.4 var(--f-ui); transition: border-color var(--t-fast), transform var(--t-fast) var(--spring); }
.choice strong { font-family: var(--f-display); font-size: 17px; }
.choice span { color: var(--muted); }
.choice:hover { border-color: var(--accent); }
.choice:active { transform: scale(.97); }

/* Credit and embed */
.credit { position: fixed; left: 24px; bottom: 16px; font-size: 13px; color: var(--muted); text-decoration: none; z-index: 10; }
.credit:hover { color: var(--accent); }
.is-create .credit { display: none; }
.embed .bar, .embed .meta, .embed .joined, .embed #btn-restart { display: none; }
.embed .stage { padding: 24px; min-height: 100vh; }
.burst { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* Theme wave (A22) */
::view-transition-old(root) { animation: none; }
::view-transition-new(root) { animation: wave var(--t-slow) var(--ease-io); }
@keyframes wave { from { clip-path: circle(0 at var(--vt-x) var(--vt-y)); } to { clip-path: circle(var(--vt-r) at var(--vt-x) var(--vt-y)); } }

/* Responsive */
@media (max-width: 900px) {
  :root { --dock-w: 0px; }
  .is-create .bar { right: 0; }
  .is-create .stage { margin-right: 0; padding-bottom: 120px; }
  .bar-note { display: none; }
  .dock { top: auto; left: 0; width: auto; max-height: 78svh; border-left: 0; border-top: 1px solid var(--line); border-radius: calc(var(--radius) + 8px) calc(var(--radius) + 8px) 0 0; transition: transform var(--t-base) var(--ease-out); padding-bottom: env(safe-area-inset-bottom); }
  .dock.collapsed { transform: translateY(calc(100% - 64px)); }
  .dock-handle { display: flex; align-items: center; justify-content: center; min-height: 64px; width: 100%; border: 0; background: transparent; color: var(--ink); font: 700 16px var(--f-display); cursor: pointer; flex: none; position: relative; }
  .dock-handle::before { content: ""; position: absolute; top: 8px; width: 40px; height: 4px; border-radius: 4px; background: var(--line); }
  .dock-body { padding-top: 0; }
  .actions .btn { min-height: 40px; padding: 8px 12px; font-size: 14px; }
  .bar { flex-wrap: wrap; }
  .is-view .bar { position: absolute; }
  .credit { left: 16px; right: 16px; text-align: center; }
}
@media (max-width: 560px) {
  .own-choices { grid-template-columns: 1fr; }
  .dur { grid-template-columns: repeat(2, 1fr); }
  .is-view .actions { justify-content: flex-start; }
  #btn-remix, #btn-style { flex: 1 1 40%; }
}

/* Reduced motion: meaningful still state */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .vw { animation: none !important; }
}
