/* Layout: an instrument strip above a gridded survey field, one centred column. */
:root {
  --paper: #e6ecf1;
  --ink: #17212b;
  --muted: #586979;
  --tile: #b3c1cf;
  --tile-top: #cfd9e3;
  --tile-edge: #8496a9;
  --dug: #f7f9fb;
  --grid: #d2dae2;
  --signal: #d9480f;
  --signal-ink: #ffffff;
  --ok: #2b8a3e;
  --focus: #1c7ed6;
  --proven: #8f3b14;
  --proven-bg: #ead9cf;
  --fresh: #e3eefb;
  --hint: #c98a00;
  --hint-glow: rgba(240, 180, 20, 0.55);
  --n1: #1c5fd6; --n2: #2b8a3e; --n3: #c92a2a; --n4: #3b2f9e;
  --n5: #8f2d14; --n6: #0b7285; --n7: #17212b; --n8: #6b7785;

  --font-display: 'Dela Gothic One', 'Hiragino Sans', 'Yu Gothic', sans-serif;
  --font-body: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Yu Gothic', system-ui, sans-serif;
  --font-num: 'Chakra Petch', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --cell: 32px;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f141a; --ink: #e2e8ee; --muted: #93a3b3;
    --tile: #344150; --tile-top: #435262; --tile-edge: #1e2730;
    --dug: #19212a; --grid: #26313c;
    --signal: #ff7a3d; --signal-ink: #1a0e06; --ok: #69db7c; --focus: #74c0fc;
    --proven: #ffa36b; --proven-bg: #3a2418; --fresh: #1d2a3a;
    --hint: #ffcc4d; --hint-glow: rgba(255, 204, 77, 0.45);
    --n1: #74a9ff; --n2: #69db7c; --n3: #ff8787; --n4: #b197fc;
    --n5: #ffa94d; --n6: #3bc9db; --n7: #e2e8ee; --n8: #a5b1bd;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f141a; --ink: #e2e8ee; --muted: #93a3b3;
  --tile: #344150; --tile-top: #435262; --tile-edge: #1e2730;
  --dug: #19212a; --grid: #26313c;
  --signal: #ff7a3d; --signal-ink: #1a0e06; --ok: #69db7c; --focus: #74c0fc;
  --proven: #ffa36b; --proven-bg: #3a2418; --fresh: #1d2a3a;
  --hint: #ffcc4d; --hint-glow: rgba(255, 204, 77, 0.45);
  --n1: #74a9ff; --n2: #69db7c; --n3: #ff8787; --n4: #b197fc;
  --n5: #ffa94d; --n6: #3bc9db; --n7: #e2e8ee; --n8: #a5b1bd;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; align-items: center; }

.masthead { width: 100%; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; }
.brand { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tagline { margin: 0; color: var(--muted); font-size: 13px; }
.title { font-family: var(--font-display); font-weight: 400; font-size: clamp(22px, 5vw, 30px); letter-spacing: 0.02em; margin: 0; line-height: 1.2; text-wrap: balance; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; }

.btn, select {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--tile-top); border: 1px solid var(--tile-edge); border-radius: var(--radius);
  padding: 7px 12px; cursor: pointer; min-height: 38px;
}
.btn:hover, select:hover { background: var(--tile); }
.btn:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; padding: 0 4px; cursor: pointer; min-height: 38px; }
.check input { width: 18px; height: 18px; accent-color: var(--signal); }
.toggle[aria-pressed="true"] { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); }

.runbar { width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px;
  padding: 8px 12px; border-radius: var(--radius); background: var(--dug); border: 1px solid var(--grid); }
.runbar-name { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.04em; }
.runbar-note { font-size: 12px; color: var(--muted); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.pips { list-style: none; display: flex; gap: 6px; margin: 0; padding: 0; }
.pip { width: 14px; height: 14px; border-radius: 3px; background: var(--tile); box-shadow: inset 0 -2px 0 var(--tile-edge); }
.pip.deep { border-radius: 50%; }
.pip.current { outline: 2px solid var(--focus); outline-offset: 2px; }
.pip.cleared { background: var(--ok); box-shadow: none; }
.pip.perfect { background: var(--ok); box-shadow: 0 0 0 2px var(--dug), 0 0 0 3px var(--ok); }
.pip.failed { background: var(--signal); box-shadow: none; }
.instruments { width: 100%; display: flex; flex-wrap: wrap; gap: 10px; align-items: stretch; justify-content: center; }
.gauge { display: flex; align-items: baseline; gap: 8px; padding: 6px 12px; border: 1px solid var(--grid); border-radius: var(--radius); background: var(--dug); }
.gauge-label { font-size: 12px; color: var(--muted); letter-spacing: 0.08em; }
.gauge-value { font-family: var(--font-num); font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; min-width: 2.5ch; text-align: right; }

.gauge-sub { font-family: var(--font-num); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hearts { display: inline-flex; gap: 4px; align-items: center; min-height: 22px; }
.heart { width: 14px; height: 13px; background: var(--signal); clip-path: path('M7 13 L1.2 6.9 A3.6 3.6 0 0 1 7 2.6 A3.6 3.6 0 0 1 12.8 6.9 Z'); }
.heart.lost { background: var(--grid); }
.app:not(.chain) .chain-only { display: none; }
.flag-glyph { display: inline-block; width: 10px; height: 14px; margin-right: 6px; vertical-align: -2px;
  background: linear-gradient(currentColor, currentColor) left / 2px 100% no-repeat;
  position: relative; }
.flag-glyph::after { content: ""; position: absolute; left: 2px; top: 0; border-left: 8px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent; }

.board-wrap { max-width: 100%; overflow-x: auto; padding: 4px; }
.board {
  --cols: 9;
  display: grid;
  width: max-content;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: 2px;
  padding: 8px;
  background: var(--grid);
  border-radius: 10px;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

.cell {
  all: unset;
  box-sizing: border-box;
  width: var(--cell); height: var(--cell);
  display: grid; place-items: center;
  font-family: var(--font-num); font-weight: 700; font-size: calc(var(--cell) * 0.58);
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
  background: linear-gradient(var(--tile-top), var(--tile));
  box-shadow: inset 0 -2px 0 var(--tile-edge);
  -webkit-touch-callout: none;
}
.cell:hover { filter: brightness(1.06); }
.cell:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; z-index: 1; }
.cell.open { background: var(--dug); box-shadow: none; cursor: default; }
.cell.open.n { cursor: pointer; }
.cell.n1 { color: var(--n1); } .cell.n2 { color: var(--n2); } .cell.n3 { color: var(--n3); } .cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); } .cell.n6 { color: var(--n6); } .cell.n7 { color: var(--n7); } .cell.n8 { color: var(--n8); }

.cell.flag::after { content: ""; width: 42%; height: 52%;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 0 / 2px 100% no-repeat,
    conic-gradient(from 90deg at 2px 0, var(--signal) 0 25%, transparent 0) 0 0 / 100% 60% no-repeat;
  clip-path: polygon(0 0, 100% 30%, 2px 60%, 2px 100%, 0 100%);
}
.cell.proven { background: var(--proven-bg); box-shadow: none; cursor: default; }
.cell.proven::after { content: ""; width: 40%; height: 40%; background: var(--proven); transform: rotate(45deg); border-radius: 2px; }
.cell.mine { background: var(--dug); box-shadow: none; }
.cell.mine::after { content: ""; width: 46%; height: 46%; border-radius: 50%; background: var(--ink);
  box-shadow: 0 0 0 2px var(--dug), 0 0 0 3px var(--ink); }
.cell.exploded { background: var(--signal); }
.cell.exploded::after { background: var(--signal-ink); box-shadow: 0 0 0 2px var(--signal), 0 0 0 3px var(--signal-ink); }
.cell.proven.blown { background: var(--signal); }
.cell.proven.blown::after { background: var(--signal-ink); }
.cell.open.wrongclaim { box-shadow: inset 0 0 0 2px var(--signal); }
.cell.open.fresh { background: var(--fresh); }
.cell.proven.fresh { box-shadow: inset 0 0 0 2px var(--proven); }
.cell.wrong { background: var(--dug); box-shadow: none; }
.cell.wrong::after { content: "×"; font-family: var(--font-num); color: var(--signal); font-size: calc(var(--cell) * 0.7); width: auto; height: auto; background: none; clip-path: none; }

.cell.pop { animation: pop 260ms ease-out both; animation-delay: var(--d, 0ms); }
@keyframes pop { from { transform: scale(0.82); opacity: 0.4; } to { transform: none; opacity: 1; } }

.statusline { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; padding: 9px 18px; }
.btn.primary:hover { filter: brightness(1.15); background: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.status.good { color: var(--ink); font-weight: 700; }
.cell.proven.claimed::after { width: 42%; height: 52%; border-radius: 0; transform: none;
  background: linear-gradient(var(--proven), var(--proven)) 0 0 / 2px 100% no-repeat,
    conic-gradient(from 90deg at 2px 0, var(--proven) 0 25%, transparent 0) 0 0 / 100% 60% no-repeat;
  clip-path: polygon(0 0, 100% 30%, 2px 60%, 2px 100%, 0 100%); }
.cell.clue { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 3px; text-decoration-color: var(--focus); }
.summary { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--grid); border-radius: var(--radius); background: var(--dug); }
.summary-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.summary-list li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dashed var(--grid);
  font-variant-numeric: tabular-nums; }
.summary-list li.perfect span:first-child::before { content: "◆ "; color: var(--ok); }
.summary-list li.cleared span:first-child::before { content: "◇ "; color: var(--ok); }
.summary-list li.failed { color: var(--signal); }
.summary-list li.todo { color: var(--muted); }
.summary-score { margin: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.share { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.share code { flex: 1 1 220px; min-width: 0; font-family: var(--font-num); font-size: 13px; padding: 6px 8px; border-radius: 4px;
  background: var(--paper); overflow-wrap: anywhere; user-select: all; }
.cell.hinted { outline: 3px solid var(--hint); outline-offset: -3px; box-shadow: 0 0 0 3px var(--hint-glow), 0 0 14px 2px var(--hint-glow); z-index: 1; animation: beacon 1.6s ease-in-out infinite; }
@keyframes beacon { 50% { box-shadow: 0 0 0 1px var(--hint-glow), 0 0 4px 0 var(--hint-glow); } }
.cell.clue { text-decoration-color: var(--hint); }
.status, .help, .tagline, .summary { line-break: strict; word-break: auto-phrase; }
.status { margin: 0; min-height: 1.6em; text-align: center; color: var(--muted); max-width: 60ch; }
.status.won { color: var(--ok); font-weight: 700; }
.status.lost { color: var(--signal); font-weight: 700; }
.status.warn { color: var(--signal); }
.rank { display: inline-grid; place-items: center; width: 1.8em; height: 1.8em; margin-right: 6px; border-radius: 50%;
  font-family: var(--font-display); font-weight: 400; background: var(--ok); color: var(--dug); vertical-align: middle; }

.help { width: 100%; max-width: 640px; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--ink); }
.help ul { padding-left: 1.2em; margin: 8px 0 0; }

@media (prefers-reduced-motion: reduce) {
  .cell.pop { animation: none; }
  .cell.proven.claimed::after { width: 42%; height: 52%; border-radius: 0; transform: none;
  background: linear-gradient(var(--proven), var(--proven)) 0 0 / 2px 100% no-repeat,
    conic-gradient(from 90deg at 2px 0, var(--proven) 0 25%, transparent 0) 0 0 / 100% 60% no-repeat;
  clip-path: polygon(0 0, 100% 30%, 2px 60%, 2px 100%, 0 100%); }
.cell.clue { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 3px; text-decoration-color: var(--focus); }
.summary { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px;
  border: 1px solid var(--grid); border-radius: var(--radius); background: var(--dug); }
.summary-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.summary-list li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dashed var(--grid);
  font-variant-numeric: tabular-nums; }
.summary-list li.perfect span:first-child::before { content: "◆ "; color: var(--ok); }
.summary-list li.cleared span:first-child::before { content: "◇ "; color: var(--ok); }
.summary-list li.failed { color: var(--signal); }
.summary-list li.todo { color: var(--muted); }
.summary-score { margin: 0; font-size: 14px; font-variant-numeric: tabular-nums; }
.share { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.share code { flex: 1 1 220px; min-width: 0; font-family: var(--font-num); font-size: 13px; padding: 6px 8px; border-radius: 4px;
  background: var(--paper); overflow-wrap: anywhere; user-select: all; }
.cell.hinted { animation: none; }
}

/* phones: keep the instruments compact so the board starts higher */
@media (max-width: 480px) {
  .controls { width: 100%; flex-wrap: nowrap; }
  .controls select { flex: 1 1 auto; min-width: 0; }
  .controls .btn { flex: 0 0 auto; white-space: nowrap; }
  .controls .check { white-space: nowrap; }
  .controls:has(#noguess-wrap:not([hidden])) { flex-wrap: wrap; }
  .controls:has(#noguess-wrap:not([hidden])) select { flex-basis: 100%; }
  .app { gap: 10px; }
  .instruments { gap: 6px; }
  .gauge { padding: 4px 8px; gap: 6px; }
  .gauge-label { font-size: 11px; letter-spacing: 0.04em; }
  .gauge-value { font-size: 18px; min-width: 1.6ch; }
  .instruments .btn { min-height: 34px; padding: 5px 10px; font-size: 13px; }
  .tagline { font-size: 12px; }
  .runbar { padding: 6px 10px; gap: 6px 10px; }
}
