/**
 * PRS Daily Puzzles — a newspaper page you can play.
 *
 * Everything is sized in `rem` against a root that the browser scales, so the same sheet
 * serves a 390px phone and a desktop without a second set of rules. The one exception is the
 * crossword grid, which has to stay square and is sized from the viewport.
 *
 * No web fonts. The cabinet has to work offline and from `file://`, and a font that fails to
 * load on a slow connection is the difference between a playable puzzle and a blank page.
 */

:root {
  --ink: #1a1714;
  --ink-soft: #5a534c;
  --paper: #fbf7ef;
  --rule: #c9c0b2;
  --rule-soft: #e6ded0;
  --accent: #b8860b;
  --good: #1f7a3d;
  --bad: #b3261e;
  --focus: #2b6cb0;
  --radius: 6px;
  --pad: clamp(12px, 3vw, 24px);
  font-size: clamp(15px, 1.6vw + 10px, 18px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  -webkit-text-size-adjust: 100%;
}

/* A newspaper is a column of type, not a full-bleed app. */
body { display: flex; flex-direction: column; min-height: 100vh; }

#masthead, #stage, #result, #colophon {
  width: min(100%, 720px);
  margin-inline: auto;
  padding-inline: var(--pad);
}

/* ── masthead ────────────────────────────────────────────────────────────── */

#masthead-rule { border-top: 3px double var(--ink); margin: 0; }

#masthead-main {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: baseline;
  justify-content: space-between;
  padding-block: 10px 6px;
}

#masthead h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
  font-weight: 700;
}

#masthead-date {
  font-size: 0.8rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

#masthead-right { display: flex; gap: 14px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat-k { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-soft); }
.stat-v { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#stat-player { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── tabs ────────────────────────────────────────────────────────────────── */

#tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  margin-top: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 700; }
.tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* A tab whose puzzle is finished today. The tick is the whole reason to come back. */
.tab.done::after { content: ' ✓'; color: var(--good); font-weight: 700; }

/* ── difficulty ──────────────────────────────────────────────────────────── */

#modes {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-block: 9px 2px;
  flex-wrap: wrap;
}

.mode {
  appearance: none;
  font: inherit;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 13px;
  min-height: 34px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-soft);
  cursor: pointer;
}
.mode:hover { border-color: var(--ink-soft); color: var(--ink); }
.mode[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  font-weight: 700;
}
.mode:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

#mode-note {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-style: italic;
  margin-left: 4px;
}

/* ── the hint button ─────────────────────────────────────────────────────── */

#hint-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
#hint-btn {
  appearance: none;
  font: inherit;
  font-size: 0.8rem;
  padding: 8px 14px;
  min-height: 40px;
  background: #fff;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
}
#hint-btn:hover { background: var(--rule-soft); }
#hint-btn[disabled] { opacity: 0.45; cursor: default; }
#hint-count { font-size: 0.75rem; color: var(--ink-soft); }

/* ── panels ──────────────────────────────────────────────────────────────── */

.panel { padding-block: 20px; }
.panel h2 { margin: 0 0 6px; font-size: 1.25rem; }
.panel h3 { margin: 26px 0 8px; font-size: 1rem; font-weight: 700; }
.panel p { margin: 0 0 14px; color: var(--ink-soft); line-height: 1.5; font-size: 0.92rem; }

.big {
  appearance: none;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 11px 22px;
  min-height: 44px;              /* the minimum comfortable tap target */
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
}
.big:hover { background: #000; }
.big:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.big[disabled] { opacity: 0.45; cursor: default; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.note { font-size: 0.76rem; color: var(--ink-soft); margin-top: 10px; }

/* ── the stamp ───────────────────────────────────────────────────────────── */

/* A solved-daily stamp, the one bit of ceremony in the page. */
.stamp {
  display: inline-block;
  border: 2px solid var(--good);
  color: var(--good);
  border-radius: var(--radius);
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transform: rotate(-2deg);
  margin-bottom: 8px;
}

#result-score { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 10px; }
#result-points { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
#result-unit { font-size: 0.85rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; }

/* ── board ───────────────────────────────────────────────────────────────── */

.board { border-top: 1px solid var(--rule); margin-bottom: 6px; }

.board-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 7px 2px;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.9rem;
}
.board-rank { color: var(--ink-soft); font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.board-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.board-row.me { background: #efe6d3; }
.board-row.me .board-name { font-weight: 700; }
.board-empty { padding: 12px 2px; color: var(--ink-soft); font-size: 0.85rem; font-style: italic; }

/* ── scramble ────────────────────────────────────────────────────────────── */

.scramble-word { border-bottom: 1px solid var(--rule-soft); padding: 12px 0; }
.scramble-word:last-child { border-bottom: 0; }

.scramble-letters {
  font-family: 'Courier New', monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
}
.scramble-word.solved .scramble-letters { color: var(--good); }

.scramble-clue { font-size: 0.88rem; color: var(--ink-soft); margin-bottom: 8px; }

.scramble-input {
  font: inherit;
  font-family: 'Courier New', monospace;
  font-size: 1.05rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  width: 100%;
  max-width: 22ch;
  padding: 9px 10px;
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.scramble-input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ── word search ─────────────────────────────────────────────────────────── */

#search-wrap { display: flex; flex-direction: column; gap: 14px; }

/* The grid must stay square, so it is capped by BOTH the width and a share of the height —
   on a phone in landscape, width alone pushes the word list off the screen. */
#search-grid {
  display: grid;
  /* grid-template-columns is set from JS, from the puzzle's own size — a hard-coded 12 here
     would silently disagree with the data the day the grid size changes, and the failure mode
     is every cell stacking in one column, which still looks like a grid at a glance. */
  gap: 1px;
  width: 100%;
  max-width: min(100%, 46vh, 520px);
  aspect-ratio: 1;
  margin-inline: auto;
  touch-action: none;              /* a drag selects letters; it must not pan the page */
  user-select: none;
  background: var(--rule);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
}

.search-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: clamp(0.62rem, 2.4vw, 1.05rem);
  color: var(--ink);
  cursor: pointer;
}
.search-cell.selecting { background: #f3e6c4; }
.search-cell.found { background: #d8ecd9; color: var(--good); }

#search-words { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; }
.search-word { font-size: 0.85rem; letter-spacing: 0.05em; color: var(--ink-soft); }
.search-word.found { color: var(--good); font-weight: 700; text-decoration: line-through; }

/* ── crossword ───────────────────────────────────────────────────────────── */

#cw-wrap { display: flex; flex-direction: column; gap: 14px; }

/* Square for the same reason as the search grid: a 5x5 that is not square stops looking
   like a crossword and the rows stop reading as entries. */
#cw-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: 100%;
  /* Sized from the width first: a 5x5 wants square cells and the largest target the screen
     allows. The height term only stops it running under the clue list on a short landscape
     screen, and 52vh rather than 34vh means a portrait phone gets near-full-width cells. */
  max-width: min(100%, 52vh, 460px);
  aspect-ratio: 1;
  margin-inline: auto;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: manipulation;
}

.cw-cell {
  position: relative;
  border: 1px solid var(--rule);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', monospace;
  font-size: clamp(1rem, 5vw, 1.9rem);
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cw-cell.entry-active { background: #f7ecd2; }
/* The cell being typed into is the strongest signal on the board. */
.cw-cell.active {
  background: #ffe9a8;
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cw-cell.wrong { color: var(--bad); }
.cw-cell.correct { color: var(--good); }
.cw-num {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 0.52rem;
  font-weight: 400;
  color: var(--ink-soft);
}

#cw-clues { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
@media (max-width: 460px) { #cw-clues { grid-template-columns: 1fr; } }
.cw-clues-col h4 {
  margin: 4px 0 6px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}
.cw-clue {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  background: none;
  border: 0;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--ink);
  padding: 5px 6px;
  border-radius: 4px;
  cursor: pointer;
}
.cw-clue:hover { background: var(--rule-soft); }
.cw-clue.active { background: #fdf3d8; font-weight: 700; }
.cw-clue.solved { color: var(--good); }
.cw-clue .n { font-weight: 700; margin-right: 4px; }
.cw-clue:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ── keyboard, for the crossword ─────────────────────────────────────────── */

/* The on-screen keyboard is the only way to type into a crossword on a phone, and it also
   gives a desktop the same layout. `display:none` on a wide screen would break the phone. */
#kb { display: flex; flex-direction: column; gap: 4px; align-items: center; width: 100%; }
.kb-row { display: flex; gap: 3px; justify-content: center; width: 100%; }
.kb-key {
  appearance: none;
  font-family: 'Courier New', monospace;
  font-size: 0.95rem;
  font-weight: 700;
  /* `flex: 1` with a small min-width lets ten keys share the width on a narrow phone instead
     of overflowing, while the min keeps each one tappable. */
  flex: 1 1 0;
  min-width: 26px;
  min-height: 40px;
  padding: 0 2px;
  background: #fff;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.kb-row:nth-child(2) { padding-inline: 4%; }
.kb-row:nth-child(3) { padding-inline: 12%; }
.kb-key:active { background: var(--rule-soft); }
.kb-key.wide { flex: 1.4 1 0; font-size: 0.7rem; letter-spacing: 0.04em; }

/* ── misc ────────────────────────────────────────────────────────────────── */

#colophon {
  margin-top: auto;
  padding-block: 18px;
  font-size: 0.75rem;
  color: var(--ink-soft);
  text-align: center;
}
#offline-note { color: var(--accent); }

[hidden] { display: none !important; }

button:disabled { cursor: default; }

/* Respect a player who has asked for less motion. There is very little here, but the stamp
   rotating is exactly the kind of decoration this setting exists to remove. */
@media (prefers-reduced-motion: reduce) {
  .stamp { transform: none; }
  * { transition: none !important; animation: none !important; }
}

/* ── sockdoku ──────────────────────────────────────────────────────────────
   Folded in from the standalone cabinet (2026-11-18). Class names carry the
   sd- prefix so the sudoku board can never collide with the newspaper chrome
   above — the standalone's .cell/.digit were unprefixed, and this stylesheet
   is hand-maintained enough that an unprefixed .cell would eventually bite.

   The board is the art: heavy ink borders, quiet surfaces, no decoration
   between the player and the grid. Sizing is carried over from the
   standalone, where it was measured at 320px wide — the grid never gets wider
   than the viewport allows, so the number pad stays reachable. */
#sd-wrap { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }

#sd-grid {
  width: min(100%, calc(100vh - 340px));
  min-width: 280px;
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
  background: var(--ink); /* the 1px gaps between cells read as the thin grid lines */
  gap: 1px;
  user-select: none;
  touch-action: manipulation;
}

.sd-cell {
  border: 0;
  padding: 0;
  margin: 0;
  background: #fffdf7;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  font-size: clamp(1rem, 4.4vw, 1.45rem);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}
/* Box separators: thick on every third column/row, drawn as an inset shadow so it
   survives any cell size. */
.sd-cell.sd-bx-right { box-shadow: inset -2px 0 0 var(--ink); }
.sd-cell.sd-bx-bottom { box-shadow: inset 0 -2px 0 var(--ink); }
.sd-cell.sd-bx-right.sd-bx-bottom { box-shadow: inset -2px 0 0 var(--ink), inset 0 -2px 0 var(--ink); }

.sd-cell.sd-played { color: #8B47E8; }
.sd-cell.sd-selected { background: #ffe9f4; outline: 3px solid #FF3DA6; outline-offset: -3px; }
.sd-cell.sd-peer { background: #f4ecff; }
.sd-cell.sd-same { background: #e8f7ff; }

/* A conflict is never colour alone: the glyph is what a colour-blind player reads, and it
   survives a greyscale screenshot. */
.sd-cell.sd-conflict { background: #ffd6d6; color: #a8002e; }
.sd-cell.sd-conflict::after {
  content: "!";
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.55em;
  font-weight: 900;
  color: #a8002e;
}

/* Pencil marks: a 3x3 lattice inside the cell, so the digit keeps its position and the
   marks stay legible at the smallest cell size. */
.sd-marks {
  position: absolute;
  inset: 1px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(0.34rem, 1.5vw, 0.5rem);
  font-weight: 700;
  color: #6b5b7b;
  line-height: 1;
}
.sd-marks span { display: flex; align-items: center; justify-content: center; }

/* ── number pad ── */
#sd-pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.sd-digit {
  position: relative;
  padding: 10px 0 8px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: #fff;
  font: inherit;
  font-weight: 900;
  font-size: clamp(0.95rem, 4vw, 1.2rem);
  cursor: pointer;
}
.sd-digit .sd-left {
  display: block;
  font-size: 0.5rem;
  font-weight: 700;
  color: #6b5b7b;
  margin-top: 1px;
}
.sd-digit.sd-done { opacity: 0.35; }

/* ── tools ── */
#sd-tools { display: flex; gap: 6px; }
.sd-tool {
  flex: 1;
  padding: 9px 6px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 0.72rem;
  cursor: pointer;
}
.sd-tool[aria-pressed="true"] { background: #22D3EE; }
.sd-kbd {
  display: inline-block;
  margin-left: 3px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(29, 11, 51, 0.08);
  font-size: 0.6rem;
  font-weight: 700;
}

.sd-cell:focus-visible { outline: 3px solid #8B47E8; outline-offset: 2px; }

/* Short windows: shrink the board rather than scrolling the pad out of reach. */
@media (max-height: 720px) {
  #sd-grid { width: min(100%, calc(100vh - 300px)); }
}
