:root {
  color-scheme: dark;
  --bg: #0b1524;
  --panel: #14263d;
  --tile: #1d3453;
  --tile-hi: #2a4a73;
  --gold: #f5c451;
  --text: #eaf2ff;
  --muted: #9fb3cc;
  --cols: 8;
  --rows: 8;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 0%, #1d3b5c 0%, transparent 55%),
    radial-gradient(circle at 90% 100%, #25304f 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(0.75rem, env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 34rem; margin: 0 auto; }
h1 {
  margin: 0; font-size: clamp(1.5rem, 6vw, 2rem); letter-spacing: 0.02em;
  background: linear-gradient(90deg, #ff6b6b, #f5c451, #7ee081, #7cc7ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbar { text-align: center; margin-bottom: 0.75rem; }
.tagline { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.85rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.stat {
  background: var(--panel); border-radius: 0.75rem; padding: 0.4rem 0.6rem;
  display: flex; flex-direction: column; align-items: center;
  border: 1px solid rgba(255,255,255,0.07);
}
.stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.goal { height: 0.4rem; background: var(--panel); border-radius: 999px; margin: 0.5rem 0 0.6rem; overflow: hidden; }
.goal-fill { height: 100%; width: 0; background: linear-gradient(90deg, #7ee081, #f5c451); transition: width 0.25s ease; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: clamp(3px, 1.2vw, 6px);
  background: linear-gradient(160deg, #10213a, #0c1a2e);
  padding: clamp(5px, 1.6vw, 10px);
  border-radius: 1rem;
  border: 1px solid rgba(124, 199, 255, 0.18);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4), inset 0 0 40px rgba(60, 120, 200, 0.08);
  touch-action: none;
}
.tile {
  min-width: 0; min-height: 0;
  aspect-ratio: 1;
  display: grid; place-items: center;
  font-size: clamp(1.05rem, 5.2vw, 1.8rem);
  line-height: 1;
  background: linear-gradient(180deg, var(--tile-hi), var(--tile));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 0.55rem;
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  user-select: none;
}
.tile:hover { background: linear-gradient(180deg, #335a88, #22405f); }
.tile:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.tile[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(245, 196, 81, 0.6);
  transform: scale(1.05);
}
.tile.nudge { animation: nudge 0.25s ease; }
.tile.pop { animation: pop 0.18s ease; }
.tile.hint-a, .tile.hint-b { animation: glow 0.9s ease-in-out infinite alternate; }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-3px) rotate(-4deg); }
  70% { transform: translateX(3px) rotate(4deg); }
}
@keyframes pop { 0% { transform: scale(1); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes glow {
  from { box-shadow: 0 0 0 2px rgba(126, 224, 129, 0.35); }
  to { box-shadow: 0 0 0 2px rgba(126, 224, 129, 1), 0 0 12px rgba(126, 224, 129, 0.7); }
}
@media (prefers-reduced-motion: reduce) {
  .tile, .goal-fill { transition: none; }
  .tile.nudge, .tile.pop, .tile.hint-a, .tile.hint-b { animation: none; }
}
.status { min-height: 2.6em; margin: 0.6rem 0 0.4rem; text-align: center; color: var(--muted); font-size: 0.9rem; }
.controls { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
button {
  min-height: 44px; padding: 0.55rem 1rem; cursor: pointer;
  border-radius: 0.6rem; border: 1px solid rgba(255,255,255,0.15);
  background: var(--panel); color: var(--text); font: inherit; font-weight: 600;
}
button:hover { background: var(--tile-hi); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#lab-offline-status { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0; }
.howto { margin-top: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.howto summary { cursor: pointer; color: var(--text); }
.howto p { margin: 0.4rem 0 0; }
dialog { max-width: min(26rem, 90vw); border-radius: 0.9rem; border: 1px solid rgba(245,196,81,0.5); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(4, 10, 20, 0.75); }
dialog h2 { margin-top: 0; }
