:root {
  --bg: #0b0f1a;
  --bg-2: #141b2e;
  --panel: #10172a;
  --line: #233052;
  --ink: #ece6da;
  --ink-dim: #8c97b3;
  --amber: #f2b545;
  --amber-soft: rgba(242, 181, 69, 0.14);
  --time: #8fd3ff;
  --bad: #ff7a6b;
  --side: 340px;
  /* SF Pro on Apple devices (it ships as the system font), Inter everywhere else */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "SF Pro", Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); overflow: hidden; }
button { white-space: nowrap; font: inherit; color: var(--ink); background: var(--bg-2); border: 1px solid var(--line); border-radius: 0; padding: 6px 12px; cursor: pointer; transition: border-color .15s, background .15s; }
button:hover { border-color: var(--amber); }
button.icon { width: 32px; padding: 6px 0; text-align: center; }

#app { display: flex; height: 100%; }
#stage { position: relative; flex: 1; min-width: 0; background: radial-gradient(ellipse at 50% 40%, #1a2440 0%, var(--bg) 70%); }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#date { margin-right: auto; font-weight: 600; font-size: 15px; color: var(--ink); white-space: nowrap; }
#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 14px 18px; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#btn-timer { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; color: var(--ink-dim); background: transparent; border-color: transparent; }
#btn-timer:hover { border-color: var(--line); }
#btn-timer .pause-glyph { width: 8px; height: 10px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; font-size: 0; opacity: .75; }
.menu { position: relative; }
.menu-list { display: none; position: absolute; top: calc(100% + 6px); right: 0; min-width: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 30px rgba(0,0,0,.45); z-index: 6; }
.menu.open .menu-list { display: flex; flex-direction: column; }
.menu-list button { border: none; background: transparent; text-align: left; padding: 7px 10px; }
.menu-list button:hover { background: rgba(255,255,255,.06); }
.menu-list .toggle { border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-list .toggle::after { content: "off"; float: right; color: var(--ink-dim); font-size: 12px; }
.menu-list .toggle.on::after { content: "on"; color: var(--amber); }
#btn-pencil.on { background: var(--amber); color: #1a1408; border-color: var(--amber); }
body.paused #scene, body.paused #clues, body.paused #dock { filter: blur(14px); pointer-events: none; }

.card { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); background: rgba(16, 23, 42, .94); border: 1px solid var(--line); border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.5); backdrop-filter: blur(8px); z-index: 5; }
.card h2 { margin: 0 0 8px; font: 600 22px var(--font); }
.card p { color: #c9cfdd; margin: 0 0 12px; }
.card ul { padding-left: 18px; margin: 0 0 16px; color: #c9cfdd; }
.card li { margin: 4px 0; }
.card button { background: var(--amber); color: #1a1408; border: none; font-weight: 600; }
.card button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.card .row { display: flex; gap: 8px; }
.card .note { color: var(--ink-dim); font-size: 13px; }
.star { font-size: 40px; line-height: 1; color: #f5c518; margin-bottom: 6px; text-shadow: 0 0 18px rgba(245,197,24,.5); }
.star.blue { color: #4ea6ff; text-shadow: 0 0 18px rgba(78,166,255,.5); }
kbd { font: 12px var(--font); background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

#dock { position: absolute; left: 0; right: 0; bottom: 0; padding: 0 18px 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; }
#dock > * { pointer-events: auto; }

#timeline { width: 100%; max-width: 640px; display: flex; align-items: flex-end; gap: 12px; background: rgba(16, 23, 42, .88); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px 8px; backdrop-filter: blur(6px); }
#btn-play { flex: none; margin-bottom: 14px; }
#track-wrap { position: relative; flex: 1; padding: 0 9px; }
#strip { position: relative; height: 30px; margin-bottom: 2px; }
#strip .slot { position: absolute; bottom: 0; width: 26px; height: 26px; transform: translateX(-50%); border: 1px solid rgba(143, 211, 255, .35); border-radius: 5px; display: grid; place-items: center; font: 600 15px var(--font); color: var(--ink); background: rgba(143, 211, 255, .06); transition: background .15s, border-color .15s; }
#strip .slot.on { background: rgba(143, 211, 255, .2); border-color: var(--time); }
#strip .slot.blue { color: #7cc4ff; }
#strip .slot.pencil { color: var(--ink-dim); font-weight: 400; }
#strip .slot.wrong { background: linear-gradient(to top right, transparent 46%, #ff5a4e 47%, #ff5a4e 53%, transparent 54%), rgba(143, 211, 255, .06); }
#time { width: 100%; margin: 0; -webkit-appearance: none; appearance: none; background: transparent; height: 22px; cursor: pointer; }
#time::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, #2c3a60, #8fd3ff); }
#time::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, #2c3a60, #8fd3ff); }
#time::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: var(--ink); border: 3px solid var(--time); box-shadow: 0 0 12px rgba(143, 211, 255, .6); }
#time::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 3px solid var(--time); }
#ticks { position: relative; height: 16px; }
#ticks span { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--ink-dim); letter-spacing: .06em; cursor: pointer; }
#ticks span.on { color: var(--time); font-weight: 600; }

#keys { position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

#clues { width: var(--side); flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 16px 40px; }
#clues h3 { margin: 18px 0 6px; font: 600 14px var(--font); color: var(--ink-dim); }
#clues h3:first-child { margin-top: 0; }
#clues ol { list-style: none; margin: 0; padding: 0; }
#clues li { display: flex; gap: 10px; padding: 6px 8px; border-radius: 7px; cursor: pointer; border-left: 3px solid transparent; }
#clues li:hover { background: rgba(255,255,255,.03); }
#clues li .n { font-weight: 600; min-width: 18px; text-align: right; color: var(--ink-dim); }
#clues li.active { background: var(--amber-soft); border-left-color: var(--amber); }
#clues li.active.time { background: rgba(143, 211, 255, .12); border-left-color: var(--time); }
#clues li.cross { background: rgba(255,255,255,.04); }
#clues li.done .c { color: var(--ink-dim); }
#clues li .len { color: var(--ink-dim); }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  #stage { flex: 1; }
  #clues { width: 100%; height: 34%; border-left: none; border-top: 1px solid var(--line); padding: 12px 16px 24px; }
  #topbar { padding: 10px 16px; align-items: flex-start; }
  #dock { padding: 0 16px 10px; gap: 8px; }
  #topbar { align-items: center; gap: 8px; }
  .tools { gap: 5px; flex-wrap: nowrap; }
  .tools button { padding: 6px 8px; font-size: 13px; }
  .tools .caret, #btn-timer .pause-glyph { display: none; }
  #btn-timer { padding: 6px 2px; }
  #date { font-size: 14px; }
}
