:root {
  color-scheme: dark;
  --bg: #0f1222; --panel: #171b31; --line: #262b4a; --ink: #e8eaf6; --muted: #8a90b8;
  --accent: #ffc145; --accent2: #ff7a59;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: radial-gradient(120% 80% at 50% 0%, #1b2042 0%, var(--bg) 60%);
  color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
header { display: flex; align-items: center; justify-content: space-between; padding: .5rem .9rem; }
h1 { margin: 0; font-size: 1.35rem; letter-spacing: .02em; font-weight: 800; }
h1 span { color: var(--accent); }
.head-actions { display: flex; gap: .4rem; }
button {
  font: inherit; color: inherit; border-radius: .7rem; border: 1px solid var(--line);
  background: var(--panel); min-height: 44px; min-width: 44px; padding: .4rem .8rem; cursor: pointer;
}
button:active { transform: scale(.96); }
button.ghost { background: transparent; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #1a1205; border: 0; font-weight: 700; padding: .6rem 1.6rem; }
button[hidden] { display: none; }

#game { flex: 1; min-height: 0; display: flex; gap: .6rem; justify-content: center; align-items: center; padding: 0 .6rem; }
#board-wrap { position: relative; flex: 0 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; }
#board { display: block; border-radius: .6rem; border: 1px solid var(--line); background: #0b0e1b; touch-action: none; }
#overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: .6rem; padding: 1rem; border-radius: .6rem;
  background: rgba(11, 14, 27, .82); backdrop-filter: blur(3px);
}
#overlay[hidden] { display: none; }
#overlay h2 { margin: 0; font-size: 1.6rem; }
#overlay p { margin: 0; color: var(--muted); max-width: 16rem; }
#overlay .hint { font-size: .78rem; }
#side { flex: 0 0 auto; width: 92px; display: flex; flex-direction: column; gap: .5rem; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: .6rem; padding: .4rem; text-align: center; }
.panel h3 { margin: 0 0 .2rem; font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.panel canvas { display: block; margin: 0 auto; width: 72px; height: auto; }
.stats { display: grid; gap: .35rem; }
.stats output { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }

#controls {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: .4rem;
  padding: .6rem .6rem .5rem; max-width: 34rem; width: 100%; margin: 0 auto;
}
#controls button { min-height: 58px; font-size: 1.3rem; padding: 0; touch-action: none; }
#controls button[data-act="hold"] { font-size: .8rem; }
#controls button.down { background: #23284a; border-color: var(--accent); }
#lab-offline-status { margin: 0; text-align: center; font-size: .75rem; color: var(--muted); min-height: 0; }
#lab-offline-status:empty { display: none; }

dialog { max-width: min(26rem, 90vw); border-radius: .9rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog button { margin: .2rem; }

@media (hover: hover) and (pointer: fine) and (min-width: 700px) {
  #controls { display: none; }
  #side { width: 120px; }
  .panel canvas { width: 96px; }
}
