/* ══════════════════════════════════════════════════════════════════════════
   FLUXFLOW — industrial-neon UI shell.
   The canvas owns the spectacle; this layer stays quiet, legible and fast.
   ══════════════════════════════════════════════════════════════════════════ */
:root {
  --bg: #050a12;
  --panel: rgba(10, 18, 28, 0.88);
  --edge: rgba(120, 200, 235, 0.20);
  --edge-strong: rgba(120, 210, 245, 0.45);
  --ink: #e8f4ff;
  --ink-dim: #8ba6bd;
  --accent: #3ad7ff;
  --accent2: #4ff0d0;
  --warn: #ff6b6b;
  --gold: #ffd23d;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 700px at 50% -10%, var(--zone-1, #0d2237) 0%, var(--zone-0, #050a12) 62%);
  transition: background 0.8s ease;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#attract {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
  /* Full strength here: the overlay above it does all the dimming, and stacking two
     scrims on top of each other buried the attract board entirely. */
  opacity: 1;
  transition: opacity 0.5s ease;
}
#attract.off { opacity: 0; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 1; }
kbd {
  font: 600 10px/1 var(--mono);
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 4px; padding: 2px 4px; vertical-align: middle;
}

/* ───────────────────────── HUD ───────────────────────── */
#stage { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 10px; gap: 10px; }
#stage[hidden] { display: none; }

#hud {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05);
  flex-wrap: wrap;
}
.hud-block { display: flex; flex-direction: column; gap: 3px; min-width: 62px; }
.hud-block.grow { flex: 1; min-width: 150px; }
.hud-label {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-dim); display: flex; justify-content: space-between; gap: 8px;
}
.hud-label em { font-style: normal; color: var(--accent2); font-variant-numeric: tabular-nums; }
.hud-value { font-size: 22px; font-weight: 800; line-height: 1; letter-spacing: -0.01em; }
.hud-value.tabular { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.hud-sub { font-size: 10px; color: var(--ink-dim); letter-spacing: 0.06em; }
#hudScore { color: var(--gold); }
#hudLives { color: var(--warn); letter-spacing: 2px; font-size: 18px; }
#hudTimer.urgent { color: var(--warn); animation: throb 0.55s ease-in-out infinite; }
@keyframes throb { 50% { opacity: 0.35; } }

.meter {
  height: 9px; border-radius: 99px; overflow: hidden;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.08);
}
.meter-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  box-shadow: 0 0 14px var(--accent2);
  transition: width 0.25s ease;
}
.meter-fill.met { background: linear-gradient(90deg, var(--gold), #fff0a8); box-shadow: 0 0 16px var(--gold); }

.icon-btn {
  margin-left: auto; width: 38px; height: 38px; border-radius: 10px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--edge);
  color: var(--ink); font-size: 12px; cursor: pointer; transition: 0.15s;
}
.icon-btn:hover { background: rgba(255,255,255,0.14); border-color: var(--edge-strong); }

/* ───────────────────────── play area ───────────────────────── */
#playArea { flex: 1; display: flex; gap: 10px; min-height: 0; align-items: center; justify-content: center; }

#queuePanel {
  width: 128px; flex: 0 0 128px;
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 10px;
  background: var(--panel); border: 1px solid var(--edge);
  border-radius: 14px; backdrop-filter: blur(10px);
}
.queue-title { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-dim); text-align: center; }
#queue { display: flex; flex-direction: column; gap: 7px; align-items: center; }
.qslot {
  width: 62px; height: 62px; border-radius: 12px; position: relative;
  background: linear-gradient(160deg, rgba(255,255,255,0.09), rgba(255,255,255,0.02));
  border: 1px solid var(--edge); display: grid; place-items: center;
  transition: transform 0.18s cubic-bezier(.2,1.4,.4,1), border-color 0.18s, box-shadow 0.18s;
}
.qslot.head {
  border-color: var(--accent2);
  box-shadow: 0 0 0 1px var(--accent2), 0 0 24px rgba(79,240,208,0.35);
  transform: scale(1.06);
}
.qslot svg { width: 78%; height: 78%; }
.qslot:not(.head) { opacity: 0.62; transform: scale(0.86); }

.ghost-btn {
  padding: 8px; border-radius: 9px; cursor: pointer;
  background: rgba(255,255,255,0.05); border: 1px solid var(--edge);
  color: var(--ink-dim); font: 600 11px/1.2 var(--font);
  letter-spacing: 0.06em; transition: 0.15s;
}
.ghost-btn:hover { color: var(--ink); background: rgba(255,255,255,0.12); border-color: var(--edge-strong); }
.ghost-btn.accent { color: var(--accent2); border-color: rgba(79,240,208,0.4); }
.ghost-btn:disabled { opacity: 0.3; cursor: default; }
.hint { margin-top: auto; font-size: 10px; line-height: 1.5; color: var(--ink-dim); text-align: center; }

#canvasWrap {
  flex: 1 1 auto; min-width: 0; min-height: 0; position: relative;
  align-self: stretch;
  border-radius: 14px; overflow: hidden;
  border: 1px solid var(--edge);
  background: #030811;
}
#board { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: manipulation; }

#banner {
  position: absolute; left: 50%; top: 16%; transform: translateX(-50%);
  font-size: clamp(20px, 4vw, 40px); font-weight: 900; letter-spacing: 0.06em;
  text-shadow: 0 4px 24px rgba(0,0,0,0.8); pointer-events: none;
  opacity: 0; transition: opacity 0.25s;
}
#banner.show { opacity: 1; animation: pop 0.5s cubic-bezier(.2,1.5,.4,1); }
@keyframes pop { from { transform: translateX(-50%) scale(0.6); } }

/* ───────────────────────── overlays ───────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(3, 8, 16, 0.55); backdrop-filter: blur(7px) saturate(0.9);
  opacity: 1; transition: opacity 0.25s;
}
.overlay[hidden] { display: none; }
.overlay.fading { opacity: 0; pointer-events: none; }

.panel {
  width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  padding: 28px 30px 26px;
  background: linear-gradient(170deg, rgba(16,28,42,0.96), rgba(7,14,22,0.97));
  border: 1px solid var(--edge-strong); border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.07);
  animation: rise 0.32s cubic-bezier(.2,1,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } }

.logo {
  font-size: clamp(38px, 9vw, 62px); font-weight: 900; line-height: 0.92;
  letter-spacing: -0.03em; margin: 0 0 4px;
  background: linear-gradient(100deg, #4ff0d0, #3ad7ff 40%, #b57bff 80%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 22px rgba(58,215,255,0.35));
}
.tagline { margin: 0 0 20px; color: var(--ink-dim); font-size: 13px; letter-spacing: 0.1em; text-transform: uppercase; }
h2.title { margin: 0 0 6px; font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
h2.title.win { color: var(--accent2); }
h2.title.lose { color: var(--warn); }
.sub { margin: 0 0 18px; color: var(--ink-dim); font-size: 13px; line-height: 1.6; }

.btn {
  display: block; width: 100%; margin-bottom: 9px; padding: 13px 16px;
  border-radius: 12px; cursor: pointer; font: 700 14px/1 var(--font);
  letter-spacing: 0.05em; text-align: left;
  background: rgba(255,255,255,0.055); border: 1px solid var(--edge);
  color: var(--ink); transition: 0.16s;
}
.btn:hover { background: rgba(255,255,255,0.13); border-color: var(--edge-strong); transform: translateX(3px); }
.btn.primary {
  background: linear-gradient(100deg, rgba(79,240,208,0.22), rgba(58,215,255,0.18));
  border-color: rgba(79,240,208,0.55); color: #ddfff7;
}
.btn.primary:hover { background: linear-gradient(100deg, rgba(79,240,208,0.34), rgba(58,215,255,0.3)); }
.btn small { display: block; margin-top: 5px; font-weight: 500; font-size: 11px; color: var(--ink-dim); letter-spacing: 0.02em; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 4px 0 20px; }
.stat { padding: 12px; border-radius: 12px; background: rgba(255,255,255,0.045); border: 1px solid var(--edge); }
.stat .k { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.stat .v { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .v.gold { color: var(--gold); }

.rows { margin: 0 0 18px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px;
  border-radius: 10px; font-size: 13px;
}
.row + .row { margin-top: 4px; }
.row:nth-child(odd) { background: rgba(255,255,255,0.035); }
.row.you { background: rgba(79,240,208,0.14); border: 1px solid rgba(79,240,208,0.4); }
.row .rank { width: 26px; color: var(--ink-dim); font-weight: 700; font-variant-numeric: tabular-nums; }
.row .who { flex: 1; font-weight: 600; }
.row .lv { color: var(--ink-dim); font-size: 11px; }
.row .pts { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); }

.setting { display: flex; align-items: center; gap: 14px; padding: 11px 2px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.setting label { flex: 1; font-size: 13px; font-weight: 600; }
.setting label small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-dim); margin-top: 2px; }
.setting input[type=range] { width: 130px; accent-color: var(--accent2); }
.toggle {
  width: 46px; height: 26px; border-radius: 99px; cursor: pointer; position: relative;
  background: rgba(255,255,255,0.10); border: 1px solid var(--edge); transition: 0.2s; flex: 0 0 auto;
}
.toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--ink-dim); transition: 0.2s;
}
.toggle[aria-pressed=true] { background: rgba(79,240,208,0.3); border-color: var(--accent2); }
.toggle[aria-pressed=true]::after { left: 22px; background: var(--accent2); }

.name-row { border-bottom: none; margin-bottom: 8px; }
.name-row input[type=text] {
  width: 150px; padding: 9px 11px; border-radius: 9px;
  background: rgba(255,255,255,0.07); border: 1px solid var(--edge);
  color: var(--ink); font: 700 13px/1 var(--font); letter-spacing: 0.04em;
}
.name-row input[type=text]:focus { outline: none; border-color: var(--accent2); background: rgba(79,240,208,0.10); }

.legend { display: grid; gap: 10px; margin: 0 0 18px; }
.legend-item { display: flex; gap: 12px; align-items: center; font-size: 13px; line-height: 1.5; }
.legend-item svg { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 9px; background: rgba(255,255,255,0.05); border: 1px solid var(--edge); }
.legend-item b { color: var(--accent2); }
.foot { margin-top: 14px; font-size: 11px; color: var(--ink-dim); text-align: center; line-height: 1.6; }

/* ───────────────────────── responsive ───────────────────────── */
@media (max-width: 780px) {
  #stage { padding: 7px; gap: 7px; }
  #playArea { flex-direction: column-reverse; }
  #queuePanel {
    width: auto; flex: 0 0 auto; flex-direction: row; align-items: center;
    padding: 7px 8px; gap: 6px;
  }
  #queue { flex-direction: row; flex: 1; min-width: 0; justify-content: flex-start; }
  /* aspect-ratio only governs once the item stops being flex-stretched, which is what
     collapses the empty canvas above and below a wide board on a portrait screen. */
  #canvasWrap { flex: 0 1 auto; align-self: center; width: 100%; height: auto; max-height: 100%; }
  /* column-reverse, so flex-start packs the board and queue against the bottom of the
     screen — where the thumbs are. */
  #playArea { justify-content: flex-start; }
  .queue-title, .hint { display: none; }
  .qslot { width: 44px; height: 44px; flex: 0 0 auto; }
  /* Four upcoming pieces is plenty of lookahead on a phone, and it stops the bar
     from overflowing the buttons off-screen. */
  .qslot:nth-child(n+5) { display: none; }
  .ghost-btn { flex: 0 0 auto; padding: 8px 9px; font-size: 10px; }
  .ghost-btn kbd { display: none; }
  #hud { gap: 10px 14px; padding: 8px 11px; }
  .hud-value { font-size: 16px; }
  .hud-sub { display: none; }
  .hud-block { min-width: 46px; }
  .icon-btn { width: 32px; height: 32px; }
}
/* Very small screens: the queue is the first thing that can go. */
@media (max-width: 400px) {
  .qslot:nth-child(n+4) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
