/* Fixed scheme: black page, white puzzle squares with black type — a printed
   puzzle laid on a dark surface. Deliberately not theme-aware; the puzzle must
   look the same on every phone. */
:root {
  --page: #000000;        /* the page behind everything */
  --page-ink: #f0efec;    /* type on the black page */
  --page-dim: #9a9a9a;    /* secondary type on the black page */
  --cell: #ffffff;        /* a puzzle square */
  --cell-ink: #111111;    /* type inside a puzzle square */
  --rule: #c3c3c3;        /* hairline between squares */
  --rule-heavy: #111111;  /* sudoku 3x3 box rules */
  --edge: #3a3a3a;        /* chrome borders on the black page */
  --accent: #7fb3e8;
  --wrong: #c0392b;
  /* Selection must stay distinct from every highlighter colour. */
  --sel-bg: #1c3a5c;
  --sel-ink: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  /* The phone nav bar overlaps fixed content without this. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    calc(env(safe-area-inset-bottom) + 12px) env(safe-area-inset-left);
  background: var(--page);
  color: var(--page-ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.bar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--edge);
  position: sticky;
  top: 0;
  background: var(--page);
  z-index: 2;
}

.bar select {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--page-ink);
  padding: 8px 26px 8px 8px;
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 8px;
}
.bar select option { color: #111; background: #fff; }

.progress, .timer {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: var(--page-dim);
  white-space: nowrap;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.board {
  display: grid;
  gap: 1px;
  background: var(--rule); /* shows through the gaps as hairlines */
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  touch-action: none; /* we own the drag gesture */
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  aspect-ratio: 1;
  position: relative;
  display: grid;
  place-items: center;
  background: var(--cell);
  color: var(--cell-ink);
  font-weight: 600;
  font-size: clamp(11px, 3.2vw, 20px);
  text-transform: uppercase;
}

.cell.sel { background: var(--sel-bg); color: var(--sel-ink); }
/* A square two answers share gets a hairline so the split reads as deliberate. */
.cell.crossing { box-shadow: inset 0 0 0 1px #0000002e; }

/* --- sudoku --- */
.board.sudoku { gap: 0; background: var(--cell); }
.board.sudoku .cell { border: 0.5px solid var(--rule); font-weight: 500; }
.board.sudoku .cell.given { font-weight: 800; }
.board.sudoku .cell.wrong { color: var(--wrong); }
.board.sudoku .cell.box-left { border-left: 2px solid var(--rule-heavy); }
.board.sudoku .cell.box-top { border-top: 2px solid var(--rule-heavy); }

.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding-top: 18px;
}
.numpad button {
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  padding: 14px 0;
  color: var(--page-ink);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 10px;
  cursor: pointer;
}
.numpad button:active { background: #ffffff1f; }

button.hint {
  width: 100%;
  margin-top: 12px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--edge);
}
.hint-note { margin: 8px 0 0; font-size: 13px; color: var(--page-dim); text-align: center; }

/* --- crossword --- */
/* Blocked squares are black like the page, so the board keeps an outline of its
   own — without it the puzzle's shape would dissolve into the background. */
.board.crossword { gap: 0; background: var(--page); border-color: var(--rule); }
.board.crossword .cell { border: 0.5px solid var(--cell-ink); font-size: clamp(10px, 2.8vw, 18px); }
.board.crossword .cell.blocked { background: #000; border-color: #000; }
.board.crossword .num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: 9px;
  font-weight: 700;
  color: var(--cell-ink);
}
.clues { list-style: none; padding: 0; margin: 0 0 14px; }
.clues li { padding: 4px 0; font-size: 14px; cursor: pointer; color: var(--page-ink); }
.clues li:hover { color: var(--accent); }
.sidebar h3 {
  margin: 16px 0 4px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--page-dim);
}

/* --- word search --- */
.words {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 18px 2px 0;
  margin: 0;
}
.words li {
  font-size: 15px;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--page-ink);
  transition: background 160ms ease, color 160ms ease;
}
.words li.found {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  font-weight: 600;
}

/* A found word pops once, so the hit registers even on a crowded grid. */
.cell.found { animation: pop 220ms ease-out; }
@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.18); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .cell.found { animation: none; }
}

/* `display` on the element would otherwise beat the `hidden` attribute */
.done[hidden] { display: none; }

.done {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000000c9;
  padding: 24px;
}

.done-card {
  background: var(--cell);
  color: var(--cell-ink);
  border-radius: 16px;
  padding: 28px;
  text-align: center;
  max-width: 320px;
}
.done-card h2 { margin: 0 0 6px; }
.done-card p { margin: 0 0 18px; color: #555; }

button {
  font: inherit;
  font-weight: 600;
  color: #ffffff;
  background: var(--sel-bg);
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  cursor: pointer;
}
