:root {
  --bg: #05060d; --panel: rgba(14, 17, 34, 0.78); --panel-solid: #0e1122; --line: rgba(140, 170, 255, 0.18);
  --ink: #e8ecff; --muted: #8d96c4; --accent: #6ee7ff; --accent2: #b47cff; --gold: #ffcf5a;
  --radius: 14px; --ui: 44px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overflow: hidden;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#sky { position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(1200px 800px at 85% -10%, rgba(120, 80, 255, 0.18), transparent 60%),
    radial-gradient(900px 700px at -10% 110%, rgba(40, 200, 255, 0.14), transparent 60%),
    radial-gradient(circle at 50% 50%, #0a0d1f, #04050b 70%); }
#stars { position: fixed; inset: 0; pointer-events: none; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
#scene.dragging { cursor: grabbing; }

/* board */
.frame-glow { fill: none; stroke: rgba(110, 231, 255, 0.28); stroke-width: 6; }
.hole { fill: rgba(30, 38, 70, 0.55); stroke: rgba(110, 231, 255, 0.35); stroke-width: 2.2; transition: opacity 1.2s; }
.holes-done .hole { opacity: 0; }

/* sheets */
.sheet-bg { fill: rgba(16, 20, 44, 0.78); stroke: rgba(140, 170, 255, 0.22); stroke-width: 3; }
.sheet-title { fill: #c9d2ff; font: 700 70px system-ui, sans-serif; letter-spacing: 6px; }
.ghost { fill: rgba(110, 231, 255, 0.03); stroke: rgba(150, 175, 255, 0.35); stroke-width: 2; stroke-dasharray: 7 6; }

/* pieces: real black, a thin edge highlight like a real puzzle */
.piece path { fill: url(#pieceFill); stroke: rgba(255, 255, 255, 0.16); stroke-width: 1.2; stroke-linejoin: round; }
.piece.real path { stroke: var(--gold); stroke-width: 2.4; }
.piece.flying { filter: url(#glow); }
.piece.flying path { stroke: rgba(200, 245, 255, 0.95); stroke-width: 2; }
.piece.land path { animation: land .7s ease-out; }
@keyframes land { 0% { stroke: #fff; stroke-width: 4; } 100% { stroke: rgba(255, 255, 255, 0.16); stroke-width: 1.2; } }
.trail path { fill: rgba(110, 231, 255, 0.22); stroke: none; }

/* colour by fit quality (button ◐, off by default) */
:root { --fit-good: #2bd4a0; --fit-fair: #ffcf5a; --fit-poor: #ff4d6d; }
.fit-on .piece.placed[data-fit="good"] path { fill: rgba(43, 212, 160, 0.42); stroke: var(--fit-good); stroke-width: 1.6; }
.fit-on .piece.placed[data-fit="fair"] path { fill: rgba(255, 207, 90, 0.45); stroke: var(--fit-fair); stroke-width: 1.6; }
.fit-on .piece.placed[data-fit="poor"] path { fill: rgba(255, 77, 109, 0.55); stroke: var(--fit-poor); stroke-width: 1.6; }
#fitBtn[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#fitLegend { position: fixed; left: 12px; top: 74px; display: flex; flex-direction: column; gap: 4px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; backdrop-filter: blur(8px); font-size: 13px; max-width: 260px; }
#fitLegend.hidden { display: none; }
#fitLegend em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }
#fitLegend small { color: var(--muted); font-size: 11px; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.good { background: var(--fit-good); } .sw.fair { background: var(--fit-fair); } .sw.poor { background: var(--fit-poor); }
.ring { fill: none; stroke-width: 6; }

/* HUD */
header { position: fixed; top: 0; left: 0; right: 0; padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  display: flex; gap: 12px; align-items: center; pointer-events: none;
  background: linear-gradient(180deg, rgba(5, 6, 13, 0.9), rgba(5, 6, 13, 0)); }
header > * { pointer-events: auto; }
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: .3px; white-space: nowrap;
  background: linear-gradient(90deg, #fff, var(--accent) 60%, var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font: 700 11px/1 system-ui, sans-serif; letter-spacing: 1.5px; padding: 6px 8px; border-radius: 999px;
  color: #0b0d1c; background: linear-gradient(90deg, var(--accent), var(--accent2)); white-space: nowrap; }
.stat { margin-left: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px;
  text-align: right; backdrop-filter: blur(8px); }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }
#progress { position: fixed; left: 0; right: 0; top: 0; height: 3px; background: rgba(255, 255, 255, 0.06); }
#progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow: 0 0 12px var(--accent); }

button, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  min-width: var(--ui); height: var(--ui); padding: 0 10px; cursor: pointer; backdrop-filter: blur(8px); }
button:hover { border-color: rgba(110, 231, 255, 0.55); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#play { width: 64px; font-size: 20px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #07091a; border: 0; font-weight: 800; }
#zoom { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }

footer { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; background: linear-gradient(0deg, rgba(5, 6, 13, 0.95), rgba(5, 6, 13, 0)); }
.row { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
#slider { flex: 1; min-width: 160px; max-width: 900px; accent-color: var(--accent); height: 28px; }
#count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 80px; text-align: center; }

#caption { position: fixed; left: 50%; bottom: 128px; transform: translateX(-50%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; backdrop-filter: blur(10px);
  font-variant-numeric: tabular-nums; white-space: nowrap; transition: opacity .4s; }
#caption.hidden { opacity: 0; }
#caption b { color: var(--accent); }

#about { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(3, 4, 10, 0.7); backdrop-filter: blur(6px); }
#about.hidden { display: none; }
#about .box { max-width: 560px; margin: 16px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; padding: 20px; }
#about h3 { margin: 0 0 8px; }
#about p { color: #c7cdf0; margin: 8px 0; }
#about kbd { background: rgba(255, 255, 255, 0.08); border-radius: 6px; padding: 1px 6px; font-size: 12px; }
#about .right { text-align: right; }

#finale { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
#finale.hidden { display: none; }
#finale div { text-align: center; animation: pop 1.2s cubic-bezier(.2, 1.6, .4, 1) both; }
#finale b { display: block; font-size: clamp(56px, 14vw, 140px); font-weight: 900; line-height: 1;
  background: linear-gradient(90deg, #fff, var(--accent), var(--accent2), #ff7cf5); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 30px rgba(110, 231, 255, 0.6)); }
#finale span { display: block; color: #dfe6ff; font-size: clamp(14px, 3.5vw, 20px); letter-spacing: 3px; text-transform: uppercase; }
#finale small { display: block; color: var(--muted); margin-top: 10px; letter-spacing: 1px; }
@keyframes pop { 0% { transform: scale(.3); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

@media (max-width: 700px) {
  :root { --ui: 40px; }
  header { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .brand h1 { font-size: 15px; }
  .brand small { display: none; }
  .badge { font-size: 9px; padding: 5px 6px; letter-spacing: 1px; }
  .stat { padding: 4px 8px; } .stat b { font-size: 16px; }
  #play { width: 56px; }
  #zoom { top: auto; bottom: 140px; transform: none; }
  #caption { bottom: 118px; font-size: 13px; }
  #fitLegend { top: 64px; left: 10px; font-size: 12px; padding: 6px 10px; }
  #fitLegend small { display: none; }
}
@media (prefers-reduced-motion: reduce) { .piece.land path { animation: none; } }
