/* Minesweeper Classic — mobile-first styles.
 * System theme via prefers-color-scheme (no JS toggle), plus
 * color-scheme so form controls follow the OS theme too.
 * Banner reserve: anchored adaptive banners are up to 90dp tall on
 * phones — body padding-bottom reserves it and fixed overlays
 * (toast, sheet) carry their own --banner-h offset.
 * The whole game view fits above the banner with no scrolling:
 * topbar + HUD + status + stage + controls = 100dvh minus the
 * banner reserve (the board is centred in the stage, so the
 * controls row always lands exactly on the banner zone).
 */
:root {
  color-scheme: light dark;
  --banner-h: 0px;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #e2e9f1;
  --ink: #101820;
  --ink-2: #46525e;
  --ink-3: #76828e;
  --line: #c9d3dd;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #dbeafe;
  --danger: #b3261e;
  --warn: #8a5a00;
  --good: #15803d;
  --radius: 16px;
  --cell: 36px;
  --cell-covered: #b8c4d4;
  --cell-covered-2: #a9b8cc;
  --cell-open: #e8edf3;
  --cell-open-2: #dfe6ee;
  --cell-flag: #dc2626;
  --glyph-ink: #0f172a;      /* flag pole / mine ink on a covered or revealed cell */
  --board-bg: #8fa1b5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f16;
    --surface: #141b28;
    --surface-2: #1d2739;
    --ink: #eef2f8;
    --ink-2: #b9c4d4;
    --ink-3: #7e8ba0;
    --line: #2a3448;
    --accent: #60a5fa;
    --accent-ink: #0b1526;
    --accent-soft: #1e3a5f;
    --danger: #ff8a80;
    --warn: #ffcf7d;
    --good: #4ade80;
    --cell-covered: #3a4a61;
    --cell-covered-2: #33415a;
    --cell-open: #1d2739;
    --cell-open-2: #1a2334;
    --cell-flag: #f87171;
    --glyph-ink: #eef2f8;
    --board-bg: #232f45;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--banner-h);
  overflow: hidden;
}
body, button, input { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
button { touch-action: manipulation; }
button, a { -webkit-touch-callout: none; user-select: none; }

.app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  padding: 0 12px;
}

/* ---- top bar ---- */
/* The top bar sits ABOVE the sheet scrim (z-index 45 vs 40) so the
   sound and About buttons stay reachable on the home screen, where
   the menu sheet covers the whole viewport. */
.topbar {
  position: relative; z-index: 45;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px; padding-top: 6px; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 30px; height: 30px; display: block; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-word { font-size: 21px; font-weight: 800; letter-spacing: -0.02em; }
.brand-word span { color: var(--accent); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.about-button {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; cursor: pointer;
}
.icon-button {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 20px;
}

/* ---- HUD + status ---- */
.hud {
  display: flex; align-items: center; gap: 14px;
  min-height: 34px; flex-shrink: 0;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-3);
}
.hud strong { color: var(--ink); font-size: 14px; }
.hud-item strong { font-variant-numeric: tabular-nums; }
#timeLine { font-variant-numeric: tabular-nums; }
.status {
  min-height: 26px; flex-shrink: 0;
  font-size: 14px; color: var(--ink-2); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- board stage ---- */
.stage {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 4px 0;
}
.board-wrap {
  display: flex; align-items: center; justify-content: flex-start;   /* start, not center: a
      centred flex row hides the left edge of an overflowing (dense) board from the scroller */
  min-height: 0; max-height: 100%;
  max-width: 100%;
  overflow: auto;                                                    /* expert pans both ways */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px;
  border-radius: 12px;
  background: var(--board-bg);
}
.board {
  display: grid;
  margin: auto;                 /* centres the board when it fits, keeps both edges reachable when it does not */
  gap: 1px;
  touch-action: none;          /* the board owns the gesture; JS pans .board-wrap by hand */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.board.shake { animation: shake 0.25s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.cell {
  width: var(--cell);
  height: var(--cell);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: var(--cell-font, 14px);
  line-height: 1;
  border-radius: 3px;
  cursor: pointer;
  padding: 0;
  border: none;
  background: var(--cell-covered);
  color: var(--ink);
}
.cell.alt { background: var(--cell-covered-2); }        /* (row+col) parity set in JS */
.cell.revealed { background: var(--cell-open); cursor: default; }
.cell.revealed.alt { background: var(--cell-open-2); }
.cell.flagged, .cell.mine { color: var(--glyph-ink); }
.cell.flagged svg .ff { fill: var(--cell-flag); }
.cell.mine svg .mg { fill: var(--cell-open); }
.cell.pressing { filter: brightness(0.85); }
.cell.flagged svg, .cell.mine svg { width: 78%; height: 78%; display: block; }
.cell.fatal { background: var(--danger); }
.cell.fatal svg * { stroke: #fff; }
.cell.wrong-flag { background: var(--cell-open); text-decoration: line-through; }
.cell.n1 { color: #2563eb; }
.cell.n2 { color: #15803d; }
.cell.n3 { color: #dc2626; }
.cell.n4 { color: #7c3aed; }
.cell.n5 { color: #b45309; }
.cell.n6 { color: #0891b2; }
.cell.n7 { color: #111827; }
.cell.n8 { color: #6b7280; }
@media (prefers-color-scheme: dark) {
  .cell.n1 { color: #60a5fa; }
  .cell.n2 { color: #4ade80; }
  .cell.n3 { color: #f87171; }
  .cell.n4 { color: #c084fc; }
  .cell.n5 { color: #fbbf24; }
  .cell.n6 { color: #22d3ee; }
  .cell.n7 { color: #e5e7eb; }
  .cell.n8 { color: #9ca3af; }
}
.board-hint {
  margin-top: 8px; font-size: 13px; color: var(--ink-3); flex-shrink: 0;
  text-align: center;
}

/* ---- controls ---- */
.controls {
  display: flex; gap: 8px; flex-shrink: 0;
  padding: 8px 0 4px;
}
.ctl-btn {
  min-height: 48px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; cursor: pointer; padding: 0 12px;
  white-space: nowrap;
}
.ctl-btn.ctl-wide { flex: 1; }
.ctl-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ctl-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---- sheets ---- */
.sheet {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  padding-bottom: var(--banner-h);
}
.sheet-center { align-items: center; padding-bottom: var(--banner-h); }
.sheet-card {
  background: var(--surface); color: var(--ink);
  width: 100%; max-width: 560px;
  max-height: calc(100dvh - var(--banner-h) - 24px);
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
}
.sheet-center .sheet-card { border-radius: 20px; }
.sheet-card h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.2; }
.sheet-card h2 { margin: 0; font-size: 20px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.menu-sub { margin: 0 0 8px; color: var(--ink-2); font-size: 14px; }
.menu-best { margin: 0 0 14px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.menu-first { margin: 12px 0 4px; font-size: 14px; }
.menu-help { margin: 0 0 10px; font-size: 13px; color: var(--ink-2); }
.about-body { margin: 0 0 10px; font-size: 14px; color: var(--ink-2); }
.about-meta { margin: 12px 0 0; font-size: 12px; color: var(--ink-3); }
.seg-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--ink-3); margin: 12px 0 6px; text-transform: uppercase; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  flex: 1 1 auto; min-height: 48px; padding: 0 10px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-weight: 700; cursor: pointer;
  font-size: 14px; white-space: nowrap;
}
.seg-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button {
  display: block; width: 100%; min-height: 52px;
  border-radius: 14px; border: none; cursor: pointer;
  font-weight: 800; font-size: 16px; margin: 6px 0;
}
.button-primary { background: var(--accent); color: var(--accent-ink); }
.button-secondary { background: var(--surface-2); color: var(--ink); }
.footer-link {
  display: block; margin: 10px auto 0; padding: 8px 12px;
  background: none; border: none; cursor: pointer;
  color: var(--accent); font-weight: 700; font-size: 14px;
  min-height: 44px;
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(96px + var(--banner-h));
  z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
