/* ════════════════════════════════════════════════════════════
   Sudoku — game-specific styles. Shared chrome (header, .brand, .hud,
   .stat, .btn, .icon-btn, .segmented, .menu-pop, overlays, start screen)
   comes from common.css; only the board, number pad, and a few local
   bits live here.
   ════════════════════════════════════════════════════════════ */

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 2.2vw, 18px);
  padding: clamp(12px, 3vw, 22px) 14px 28px;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  /* body locks overflow (common.css); make main the scroll container so the
     number pad + controls stay reachable on short / landscape viewports
     (mirrors the word-game fix, BL-013). */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ── Top bar: difficulty + actions ─────────────────────────── */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  width: 100%;
  /* Positioning context for the settings dropdown (BL-033): anchor the panel
     to the full-width topbar's right gutter, not to the narrow gear wrapper,
     which wanders when .topbar-actions wraps + centres on a phone. */
  position: relative;
}
.topbar .segmented { flex-wrap: wrap; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Static so the panel below positions against .topbar (above), not this
   ~44px wrapper — see BL-033. */
.menu-wrap { position: static; }

/* Settings dropdown body (shell + title come from common.css .menu-pop, which
   sets top:calc(100%+6px) + right:clamp(8px,2vw,18px) — now resolved against
   the full-width .topbar). Cap the width to the viewport so a 248px panel can
   never overrun a screen edge on a narrow phone (BL-033). */
.menu-pop { width: min(248px, calc(100vw - 24px)); }
.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}
.menu-label {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
}
.segmented.small button,
.segmented.small .seg { padding: 7px 14px; min-height: 36px; font-size: 12px; }
.menu-note {
  font-family: var(--sans);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-soft);
  margin: 4px 0 0;
}

/* ── The 9x9 board ─────────────────────────────────────────── */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);   /* explicit equal rows — don't rely on auto-row stretch */
  width: min(92vw, 520px);
  aspect-ratio: 1 / 1;
  flex-shrink: 0;
  background: var(--surface-1);
  border: 2.5px solid var(--gold);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-2);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
  cursor: pointer;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--gold-bright);
  line-height: 1;
  transition: background 0.12s var(--ease);
}
/* Thick 3x3 box separators */
.cell.br { border-right: 2.5px solid var(--gold-dim); }
.cell.bb { border-bottom: 2.5px solid var(--gold-dim); }

/* Larger digits (S16/BL-034) — the cell/board geometry is fixed by .board
   (width + aspect-ratio) and the 9x9 1fr grid, so a bigger glyph does not
   resize cells; board overflow:hidden crops rather than reflows. */
.cell .val { font-size: clamp(20px, 6.4vw, 34px); }

/* Givens — fixed clues, brighter + heavier, not clickable-looking */
.cell.given {
  color: var(--text);
  font-weight: 700;
  background: var(--surface-1);
  cursor: default;
}
/* Player entries */
.cell.filled .val { color: var(--gold-bright); }

/* Highlights */
.cell.peer { background: rgba(205, 170, 102, 0.07); }
.cell.same { background: rgba(205, 170, 102, 0.18); }
/* Number-pad highlighter — every instance of the chosen digit, made boldly
   prominent (strong gold fill + bright ring + white glyph) so the numbers
   clearly glow, distinct from the subtle selected-cell same-number glow above. */
.cell.hl {
  background: rgba(205, 170, 102, 0.5);
  box-shadow: inset 0 0 0 2px var(--gold-bright);
}
.cell.hl .val { color: #fff; font-weight: 700; }
/* Keep the glow visible even on a given clue's lighter cell. */
.cell.given.hl { background: rgba(205, 170, 102, 0.5); }
.cell.selected {
  background: rgba(205, 170, 102, 0.28);
  box-shadow: inset 0 0 0 2px var(--gold-bright);
  z-index: 2;
}
/* Conflicts / wrong entries */
.cell.bad .val { color: #ff8a8a; }
.cell.bad { background: rgba(220, 70, 70, 0.20); }
.cell.bad.selected { box-shadow: inset 0 0 0 2px #ff8a8a; }

/* Pencil-mark notes — 3x3 mini-grid */
.cell .notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}
.cell .notes .note {
  display: grid;
  place-items: center;
  font-size: clamp(7px, 1.9vw, 11px);
  color: var(--text-soft);
  font-weight: 500;
}

/* Paused — board content hidden (anti-peek) */
.board.paused .cell { background: var(--surface-1); cursor: default; }
.board.paused .cell::after {
  content: '';
  position: absolute;
  inset: 16%;
  border-radius: 3px;
  background: var(--surface-3);
  opacity: 0.5;
}

/* ── Number pad ────────────────────────────────────────────── */
.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  width: min(92vw, 520px);
}
.numkey {
  position: relative;
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  color: var(--gold-bright);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  min-height: 48px;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.numkey .digit { font-size: clamp(17px, 5vw, 26px); }
.numkey .rem {
  position: absolute;
  top: 3px; right: 5px;
  font-family: var(--sans);
  font-size: 9px;
  color: var(--text-soft);
  letter-spacing: 0;
}
.numkey:hover { border-color: var(--gold); background: var(--surface-3); }
.numkey:active { transform: scale(0.94); }
.numkey:focus-visible { outline: none; box-shadow: var(--ring); }
.numkey.done { opacity: 0.4; }
.numkey.done .rem { color: transparent; }
/* Lit while this digit is being highlighted on the board (S16/BL-034). */
.numkey.active {
  background: var(--gold);
  border-color: var(--gold-bright);
  color: var(--bg-1);
  opacity: 1;
}
.numkey.active .digit { color: var(--bg-1); }
.numkey.active .rem { color: rgba(26, 31, 58, 0.7); }

@media (max-width: 380px) {
  .numpad { gap: 4px; }
  .numkey { min-height: 44px; }
}

/* ── Cell halo: a ring of bare numbers around the tapped cell (S16) ── */
/* No panel background — just the numbers, each a circular hit target with a
   text-shadow for legibility over the board, and erase at the centre. The
   container size + per-key positions are set inline by buildHaloDOM(). */
.halo {
  position: fixed;
  z-index: 80;
  /* A semi-transparent scrim (board stays partly visible through it) that
     frames the ring of numbers. Circular to match the ring. */
  background: rgba(15, 18, 38, 0.5);
  border: 1px solid rgba(205, 170, 102, 0.18);
  border-radius: 50%;
  box-shadow: none;
  padding: 0;
  pointer-events: auto;            /* the ring area catches taps to dismiss */
  touch-action: manipulation;
  animation: halo-in 0.14s var(--ease);
}
.halo[hidden] { display: none; }
.halo-key {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 44px;
  height: 44px;
  padding: 0 4px;
  display: grid;
  place-items: center;
  appearance: none;
  border: none;
  background: none;                /* only the number — no chip behind it */
  color: var(--gold-bright);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.85);
  transition: transform 0.08s var(--ease), color 0.12s var(--ease);
}
.halo-key:hover { color: #fff; }
.halo-key:active { transform: translate(-50%, -50%) scale(0.86); }
.halo-key:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; color: #fff; }
/* The cell's current value (or a set pencil mark, in notes mode) reads as lit. */
.halo-key.on { color: #fff; text-shadow: 0 0 10px var(--gold-bright), 0 1px 2px rgba(0, 0, 0, 0.95); }
.halo-erase { color: #ff8a8a; font-size: 19px; }
@keyframes halo-in { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .halo { animation: none; }
  .halo-key { transition: none; }
  .halo-key:active { transform: translate(-50%, -50%); }
}

/* ── Controls ──────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.controls .btn {
  min-height: 44px;
  padding: 10px 16px;
  letter-spacing: 0.06em;
}
.controls .ctrl-ico { font-size: 15px; letter-spacing: 0; }
.controls #notesBtn.active {
  background: var(--gold);
  color: var(--bg-1);
  border-color: var(--gold-bright);
}
.controls .btn:disabled { opacity: 0.35; pointer-events: none; }

/* ── Feedback line ─────────────────────────────────────────── */
.feedback {
  min-height: 18px;
  font-family: var(--sans);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--gold-dim);
  text-align: center;
}
.feedback.error { color: #ff8a8a; }

/* ── Header American flag (standing design requirement) ────── */
.flag-mark { display: flex; align-items: center; flex-shrink: 0; }
.flag-mark svg {
  width: 28px; height: 18px; border-radius: 3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ── Win overlay flag stripe (American-flag requirement) ───── */
.flag-stripe {
  height: 5px;
  width: 96px;
  margin: 0 auto 14px;
  border-radius: 3px;
  background: linear-gradient(90deg,
    #B22234 0 33.3%, #ffffff 33.3% 66.6%, #3C3B6E 66.6% 100%);
  box-shadow: 0 0 0 1px var(--hairline);
}

@media (prefers-reduced-motion: reduce) {
  .cell, .numkey { transition: none; }
}
