:root {
  --bg: #f4f2ee;
  --surface: #fff;
  --ink: #1d1d1d;
  --muted: #666;
  --line: #2b2b2b;
  --accent: #0a66c2;
  --good: #2e7d32;
  --bad: #d32f2f;
  --radius: 10px;
  color-scheme: light;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
main { max-width: 560px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
button, .button {
  font: inherit; cursor: pointer; padding: 8px 14px; border-radius: 999px;
  border: 1px solid #bbb; background: var(--surface); color: var(--ink); text-decoration: none;
  display: inline-block; touch-action: manipulation;
}
button:disabled { opacity: 0.45; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* Hub */
.hub-head h1 { margin: 8px 0 0; }
.hub { list-style: none; padding: 0; display: grid; gap: 10px; }
.card {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--surface);
  border-radius: var(--radius); color: inherit; text-decoration: none; box-shadow: 0 1px 2px #0002;
}
.card:hover { box-shadow: 0 2px 8px #0003; }
.card-icon { font-size: 2rem; width: 2.5rem; text-align: center; }
.card-body { display: flex; flex-direction: column; flex: 1; }
.card-status { display: flex; flex-direction: column; align-items: end; font-size: 0.9rem; }
footer { margin-top: 24px; font-size: 0.85rem; text-align: center; }

/* Game frame */
.game-head { display: flex; align-items: center; gap: 12px; }
.game-head h1 { font-size: 1.3rem; flex: 1; margin: 0; }
.back { font-size: 1.5rem; text-decoration: none; }
.level-nav { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.level-nav a, .level-nav .disabled { font-size: 1.4rem; text-decoration: none; padding: 0 4px; }
.level-nav .disabled { opacity: 0.3; }
.level-nav [hidden] { display: inline; visibility: hidden; }
.toolbar { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 1.1rem; }
.spacer { flex: 1; }
.board { display: flex; flex-direction: column; align-items: center; gap: 12px; }
dialog.rules { border: none; border-radius: 16px; padding: 20px 24px; max-width: 420px; width: 90vw; }
dialog.rules::backdrop { background: #0006; }
dialog.rules p.muted { margin: 0; }
dialog.rules h2 { margin: 4px 0 8px; }
.rules-body ul { padding-left: 1.2em; margin: 0 0 16px; line-height: 1.45; }
.rules-body li + li { margin-top: 6px; }
dialog.rules form { display: flex; justify-content: center; }
dialog.rules form button { min-width: 140px; }
.toolbar .help { width: 40px; height: 40px; padding: 0; font-weight: 700; }
.message { min-height: 1.3em; margin: 0; color: var(--bad); text-align: center; font-size: 0.9rem; }

dialog.result { border: none; border-radius: 16px; padding: 24px; max-width: 360px; width: 90vw; text-align: center; }
dialog.result::backdrop { background: #0006; }
dialog .big { font-size: 2.2rem; font-weight: 700; margin: 4px 0; }
.stats { display: flex; justify-content: space-around; margin: 16px 0; }
.stats dt { font-size: 0.8rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.4rem; font-weight: 600; }

/* Shared grid */
.grid {
  --n: 6;
  position: relative; display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr);
  width: min(100%, 480px); aspect-ratio: 1; border: 3px solid var(--line); border-radius: 6px;
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none; background: var(--surface);
}
.grid .cell {
  display: flex; align-items: center; justify-content: center; border: 0 solid var(--line);
  border-width: 0 1px 1px 0; font-size: calc(min(100vw, 480px) / var(--n) * 0.45); padding: 0;
  border-radius: 0; background: var(--surface); min-width: 0; min-height: 0; color: var(--ink); overflow: hidden; line-height: 1;
}

/* Queens */
.queens .cell { border-width: 1px; border-color: #3338; cursor: pointer; }
.queens .cell[style*='3px'] { border-color: var(--line); }
.queens .cell.mark { font-size: calc(min(100vw, 480px) / var(--n) * 0.3); color: #0008; }
.queens .cell.bad { box-shadow: inset 0 0 0 100px #d32f2f55; }

/* Tango */
.tango .cell svg { width: 60%; height: 60%; }
.tango .sun circle { fill: #ffb300; stroke: #e65100; stroke-width: 2; }
.tango .moon path { fill: #5c8de0; stroke: #1e4fa3; stroke-width: 2; }
.tango .cell.given { background: #eceae6; }
.tango .cell.bad { box-shadow: inset 0 0 0 3px var(--bad); }
.tango .sign {
  position: absolute; transform: translate(-50%, -50%); width: 20px; height: 20px; line-height: 18px;
  text-align: center; background: var(--surface); border-radius: 50%; font-weight: 700; font-size: 15px;
  color: #6b5a3a; pointer-events: none; z-index: 1;
}
.tango .sign.bad { color: #fff; background: var(--bad); }

/* Zip */
.zip .cell { position: relative; border-color: #ccc; }
.zip .cell[style*='4px'] { border-color: var(--line); }
.zip .cell.on { background: #fde8d5; }
.zip .trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.zip .trail polyline { fill: none; stroke: #f26b1d; stroke-width: 0.38; stroke-linecap: round; stroke-linejoin: round; }
.zip .num {
  position: relative; z-index: 2; width: 62%; aspect-ratio: 1; border-radius: 50%; background: #111; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: calc(min(100vw, 480px) / var(--n) * 0.32);
}
.zip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Sudoku */
.sudoku .cell { cursor: pointer; font-weight: 500; color: var(--accent); }
.sudoku .cell.given { color: var(--ink); font-weight: 700; background: #f0eeea; }
.sudoku .cell.selected { background: #cfe3fb; }
.sudoku .cell.same { background: #e3eefb; }
.sudoku .cell.bad { color: var(--bad); }
.notes { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; height: 100%; padding: 2px; }
.notes span { font-size: calc(min(100vw, 480px) / var(--n) * 0.18); color: var(--muted); display: flex; align-items: center; justify-content: center; }
.pad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(100%, 480px); }
.pad button { font-size: 1.2rem; border-radius: var(--radius); padding: 12px 0; }
.pad .toggle { grid-column: span 2; font-size: 1rem; }
.pad .toggle[aria-pressed='true'] { background: var(--accent); color: #fff; }
