:root {
  --bg: #0f172a;
  --panel: #1a2439;
  --border: #334155;
  --muted: #94a3b8;
  --text-light: #e2e8f0;
  --tile-hidden: #e2e8f0;
  --tile-hover: #dbeafe;
  --tile-face: #f8fafc;
  --given: #1e293b;
  --user: #2563eb;
  --error: #dc2626;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --good: #16a34a;
  --amber: #fbbf24;
  --cell: min(14vw, 72px);
  --gap: 4px;
  /* line colours for clues */
  --l0: #fecaca;
  --l1: #bbf7d0;
  --l2: #fde68a;
  --l3: #bfdbfe;
  --l4: #ddd6fe;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-light);
  display: flex;
  justify-content: center;
  padding: 24px 12px 48px;
}

.app {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

/* ---------- header ---------- */
.top { display: flex; flex-direction: column; gap: 14px; }
h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}
h1 .amp { color: var(--muted); }

.hud {
  display: flex;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 16px;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 70px; }
.stat .label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat output { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
#round-score.bump { animation: bump 0.3s ease; }
@keyframes bump { 50% { transform: scale(1.2); color: var(--amber); } }

/* ---------- board ---------- */
.board-wrap { display: flex; justify-content: center; }

.board {
  display: grid;
  grid-template-columns: repeat(6, var(--cell));
  grid-template-rows: repeat(6, var(--cell));
  gap: var(--gap);
  padding: var(--gap);
  background: var(--border);
  border: 3px solid var(--border);
  border-radius: 6px;
  user-select: none;
}

.tile {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  perspective: 600px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
.tile-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.3s ease;
  transform-style: preserve-3d;
}
.tile.revealed .tile-inner { transform: rotateY(180deg); }
.tile.revealed { cursor: default; }

.face {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
}
.front { background: var(--tile-hidden); }
.tile:not(.revealed):hover .front { background: var(--tile-hover); }
.back {
  transform: rotateY(180deg);
  background: var(--tile-face);
  color: var(--given);
  font-size: calc(var(--cell) * 0.45);
  font-weight: 600;
}
.back.v2, .back.v3 { color: var(--user); font-weight: 700; }
.back.v0 { background: #fee2e2; color: var(--error); }
.back svg { width: 60%; height: 60%; }
.tile.boom .back { background: var(--error); color: #fff; animation: shake 0.4s; }
@keyframes shake {
  25% { transform: rotateY(180deg) translateX(-4px); }
  75% { transform: rotateY(180deg) translateX(4px); }
}
.tile.late .back { opacity: 0.5; }

/* notes */
.marks { position: absolute; inset: 0; pointer-events: none; }
.mark {
  position: absolute;
  font-size: calc(var(--cell) * 0.19);
  font-weight: 500;
  line-height: 1;
  color: #64748b;
  display: none;
}
.mark.on { display: block; }
.mark[data-m="B"] { top: 4px; left: 5px; color: var(--error); }
.mark[data-m="1"] { top: 4px; right: 5px; }
.mark[data-m="2"] { bottom: 5px; left: 5px; }
.mark[data-m="3"] { bottom: 5px; right: 5px; }
.mark svg { width: calc(var(--cell) * 0.2); height: calc(var(--cell) * 0.2); }

.board.marking .tile:not(.revealed) .front { box-shadow: inset 0 0 0 2px var(--accent); }

/* clues */
.clue {
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  color: var(--given);
  font-weight: 700;
}
.clue .sum { font-size: calc(var(--cell) * 0.32); line-height: 1; font-variant-numeric: tabular-nums; }
.clue .bombs { display: flex; align-items: center; gap: 3px; font-size: calc(var(--cell) * 0.22); line-height: 1; }
.clue .bombs svg { width: calc(var(--cell) * 0.22); height: calc(var(--cell) * 0.22); }
.clue.l0 { background: var(--l0); }
.clue.l1 { background: var(--l1); }
.clue.l2 { background: var(--l2); }
.clue.l3 { background: var(--l3); }
.clue.l4 { background: var(--l4); }

.corner {
  display: grid;
  place-items: center;
  background: var(--panel);
  border-radius: 3px;
  color: var(--muted);
  font-size: calc(var(--cell) * 0.17);
  text-align: center;
  line-height: 1.2;
}

/* ---------- message & controls ---------- */
.message {
  margin: 0;
  min-height: 20px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--amber);
}
.message.win { color: #4ade80; }
.message.lose { color: #f87171; }
.message.cash { color: var(--amber); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; }
.controls > .btn { flex: 1 1 auto; }

button, .btn {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-light);
  padding: 8px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }

.mark-picker { display: flex; gap: 6px; }
.mark-picker[hidden] { display: none; }
.mark-btn {
  width: 40px;
  height: 38px;
  padding: 0;
  font-weight: 700;
}
.mark-btn.selected { border-color: var(--accent); color: #93c5fd; }

/* ---------- help & footer ---------- */
.help {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 16px;
}
.help summary { cursor: pointer; font-weight: 600; }
.help ul { padding-left: 20px; line-height: 1.55; color: #cbd5e1; font-size: 0.92rem; }
kbd { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: 0.85em; }

.foot { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; color: var(--muted); font-size: 0.85rem; }
.foot b { color: var(--text-light); }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; }
.link:hover { color: #f87171; }

@media (max-width: 420px) {
  :root { --gap: 3px; }
}
