/* Plenum. Newspaper puzzle page, wooden tiles. */

:root {
  --paper: #f3eee3;
  --paper-deep: #e8e0cd;
  --ink: #1d1b18;
  --ink-soft: #5f584d;
  --rule: #c9bfab;
  --accent: #a3302a;
  --tile: #e6d3a8;
  --tile-edge: #b39463;
  --tile-line: #7a6442;
  --tile-ink: #1d1b18;
  --slot: #b7ab94;
  --t: 44px;
  --gap: 5px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #23201c;
    --paper-deep: #2e2a25;
    --ink: #ece5d7;
    --ink-soft: #a9a092;
    --rule: #4a443c;
    --accent: #e27c6e;
    --tile: #d8c296;
    --tile-edge: #9a7d51;
    --tile-line: #4f4029;
    --tile-ink: #1d1b18;
    --slot: #5d564c;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Newsreader", Georgia, "Times New Roman", serif;
  font-size: 1.125rem;
  line-height: 1.45;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
a, button { -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
#board:focus { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip { position: absolute; left: -9999px; top: 8px; z-index: 10; padding: 8px 12px; background: var(--paper); border: 1px solid var(--ink); }
.skip:focus { left: 16px; }

.page { max-width: 33rem; margin: 0 auto; padding: 0 16px; }

/* Small section heads: letterspaced serif capitals, as on a printed puzzle page. */
.label {
  margin: 0;
  font-family: "Newsreader", Georgia, serif;
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.textlink {
  padding: 10px 0;
  min-height: 44px;
  min-width: 44px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.95rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  cursor: pointer;
}
.textlink:hover { text-decoration-thickness: 2px; }
.textlink:active { color: var(--ink-soft); }

/* ---- Masthead ---------------------------------------------------------- */

.masthead { padding-top: 6px; }

.nameplate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 3px double var(--ink);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  font-size: 1.85rem;
  font-weight: 600;
  font-style: italic;
  letter-spacing: -0.015em;
  line-height: 1.1;
  text-decoration: none;
  padding: 4px 0 6px;
}

.masthead-links { display: flex; gap: 16px; }

.folio {
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 5px 0 4px;
  border-bottom: 1px solid var(--ink);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---- Tiles ------------------------------------------------------------- */

.tile {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--t);
  height: var(--t);
  margin: 0;
  padding: 0 0 3px;
  background: var(--tile);
  color: var(--tile-ink);
  border: 1px solid var(--tile-line);
  border-radius: 3px;
  box-shadow: inset 0 -3px 0 var(--tile-edge), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  font: 700 calc(var(--t) * 0.47)/1 "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  text-transform: uppercase;
  transform: rotate(var(--rot, 0deg));
  transition: transform 150ms ease-out, box-shadow 120ms ease-out;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.tile:active:not(:disabled) {
  box-shadow: inset 0 -1px 0 var(--tile-edge);
  padding-bottom: 1px;
}
.tile:disabled { cursor: default; opacity: 1; }
.row .tile { transform: none; }

/* ---- Board ------------------------------------------------------------- */

.board { margin-top: 10px; }

.row {
  position: relative;
  padding: 8px 10px 6px;
  margin: 0 -10px;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  transition: background-color 150ms ease-out;
}
.row:last-child { border-bottom: 0; }
.row.is-active { background: var(--paper-deep); }
.game.is-done .row { cursor: default; background: transparent; }

.row-head { display: flex; align-items: baseline; gap: 10px; }

.row-label {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-height: 30px;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: 600 1.08rem/1.2 "Newsreader", Georgia, serif;
  cursor: pointer;
}
/* The whole row is the row button's tap target. Tiles sit above it. */
.row-label::after { content: ""; position: absolute; inset: 0; }
.row-label:focus-visible { outline: none; }
.row-label:focus-visible::after { outline: 2px solid var(--ink); outline-offset: -2px; }
.row-tiles { position: relative; z-index: 1; }
.row-num { display: inline-block; min-width: 1.1em; }
.row.is-active .row-num { color: var(--accent); }
.game.is-done .row-num { color: var(--ink); }

.row-len {
  margin-left: auto;
  font: 500 0.72rem/1 "IBM Plex Mono", ui-monospace, monospace;
  color: var(--ink-soft);
}

.row-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  min-height: var(--t);
  margin-top: 4px;
}

.cursor {
  width: var(--t);
  height: var(--t);
  border: 1px dashed var(--slot);
  border-radius: 3px;
}
/* An untouched row keeps a faint empty slot, so it reads as a place for tiles, not a gap. */
.row:not(.is-active) .cursor { opacity: 0.55; }
.row:not(.is-active) .row-tiles:has(.tile) .cursor { display: none; }
.game.is-done .cursor { display: none; }

.row-status {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 1.5em;
  margin: 4px 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.row.is-good .row-status { color: var(--ink); }
.row.is-bad .row-status { color: var(--accent); }
.mark { flex: none; width: 14px; height: 14px; }

/* ---- Tray -------------------------------------------------------------- */

.tray { margin-top: 12px; border-top: 1px solid var(--ink); }

.tray-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.tray-head .label { color: var(--ink); }
.left-count { font: 500 0.78rem/1 "IBM Plex Mono", ui-monospace, monospace; color: var(--ink-soft); }
#shuffle { margin-left: auto; }

.pool {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px var(--gap);
  padding: 8px 0 16px;
}

.slot { width: var(--t); height: var(--t); border-radius: 3px; }
.slot.is-empty { border: 1px dashed var(--slot); }

/* ---- Actions ----------------------------------------------------------- */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--rule);
}

.btn {
  min-height: 48px;
  padding: 8px 18px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font: 600 1.05rem/1 "Newsreader", Georgia, serif;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); background: var(--paper-deep); }
.btn-ink { background: var(--ink); color: var(--paper); }
.btn-ink:active { background: var(--ink); opacity: 0.85; }
@media (hover: hover) {
  .btn:hover { background: var(--paper-deep); }
  .btn-ink:hover { background: var(--ink); opacity: 0.9; }
}
.sheet:focus { outline: none; }

.message { min-height: 1.5em; margin: 6px 0 0; font-size: 0.95rem; font-style: italic; color: var(--ink-soft); }
.game.is-done .message:empty { display: none; }
.game.is-done .pool { padding-bottom: 6px; }

/* ---- Result ------------------------------------------------------------ */

.result { margin-top: 10px; padding-top: 14px; border-top: 3px double var(--ink); }

.result-head { display: flex; align-items: center; gap: 16px; }
.result-head h2 { margin: 0; font-size: 1.6rem; font-weight: 600; line-height: 1.15; }
.result-head h2:focus { outline: none; }

.stamp {
  flex: none;
  padding: 3px 9px 2px;
  border: 2px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font: 700 0.95rem/1.1 "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  transform: rotate(-8deg);
  opacity: 0.88;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='40'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.2 1.9'/%3E%3C/filter%3E%3Crect width='90' height='40' filter='url(%23n)'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='40'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -2.2 1.9'/%3E%3C/filter%3E%3Crect width='90' height='40' filter='url(%23n)'/%3E%3C/svg%3E");
}
.stamp.is-new { animation: stamp 170ms ease-out both; }
@keyframes stamp {
  from { transform: rotate(-8deg) scale(1.5); opacity: 0; }
  to { transform: rotate(-8deg) scale(1); opacity: 0.88; }
}

.best { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--rule); }
.best-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  align-items: center;
  margin: 8px 0 0;
}
.best-list dt { font-size: 0.95rem; color: var(--ink-soft); }
.best-list dd { margin: 0; }
.best-left { display: flex; align-items: center; gap: 14px; margin: 10px 0 0; font-size: 0.95rem; color: var(--ink-soft); }
.best-same { margin: 4px 0 0; font-size: 0.95rem; font-style: italic; color: var(--ink-soft); }

.mini-tiles { display: flex; flex-wrap: wrap; gap: 3px; }
.mini-tiles span, .mini {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding-bottom: 2px;
  background: var(--tile);
  color: var(--tile-ink);
  border: 1px solid var(--tile-line);
  border-radius: 2px;
  box-shadow: inset 0 -2px 0 var(--tile-edge);
  font: 700 0.8rem/1 "IBM Plex Mono", ui-monospace, monospace;
  text-transform: uppercase;
}

.note { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--rule); }
.note p { margin: 6px 0 0; font-style: italic; }

.share-row { display: flex; align-items: center; gap: 14px; margin-top: 18px; }
.copied { font-size: 0.95rem; font-style: italic; color: var(--ink-soft); }
.share-fallback {
  margin: 10px 0 0;
  padding: 10px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font: 0.85rem/1.4 "IBM Plex Mono", ui-monospace, monospace;
  white-space: pre-wrap;
  user-select: all;
}
.next { margin: 14px 0 0; font-size: 0.95rem; color: var(--ink-soft); }
.countdown { font: 500 0.95rem/1 "IBM Plex Mono", ui-monospace, monospace; color: var(--ink); }

/* ---- Ad slot: below the game, never inside it ---------------------------- */

.ad { margin-top: 28px; padding-top: 8px; border-top: 1px solid var(--rule); }
.ad::before { content: "Advertisement"; display: block; margin-bottom: 6px; font: 500 0.65rem/1 "IBM Plex Mono", ui-monospace, monospace; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }

/* ---- Footer ------------------------------------------------------------ */

.colophon {
  margin-top: 28px;
  padding: 10px 0 32px;
  border-top: 1px solid var(--ink);
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.colophon nav { display: flex; flex-wrap: wrap; column-gap: 18px; }
.colophon nav a { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
.colophon p { margin: 4px 0 0; }

/* ---- Dialogs ------------------------------------------------------------ */

.sheet {
  width: min(28rem, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100dvh - 24px);
  margin: auto;
  padding: 6px 20px 18px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
  overflow: auto;
}
.sheet::backdrop { background: rgba(29, 27, 24, 0.45); }
.sheet[open] { animation: sheet-in 140ms ease-out; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(6px); } }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px double var(--ink);
  margin-bottom: 10px;
}
.sheet-head h2 { margin: 0; font-size: 1.4rem; font-weight: 600; font-style: italic; }
.sheet p { margin: 0 0 10px; }
.sheet-foot { margin: 14px 0 0 !important; }
.sheet-foot .btn { min-width: 8rem; }

.example { margin: 12px 0; padding: 10px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.example .label { margin-bottom: 6px; }
.example p { margin: 8px 0 0; }
.example-words { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; margin: 10px 0 0; }
.example-words dt { color: var(--ink-soft); }
.example-words dd { margin: 0; font: 700 0.95rem/1.4 "IBM Plex Mono", ui-monospace, monospace; text-transform: uppercase; }

.figures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 16px; }
.figures div { border-right: 1px solid var(--rule); }
.figures div:last-child { border-right: 0; }
.figures dt { font-size: 0.9rem; line-height: 1.2; color: var(--ink-soft); }
.figures dd { margin: 2px 0 0; font-size: 2.1rem; font-weight: 600; line-height: 1; }

.dist { width: 100%; margin: 8px 0 12px; border-collapse: collapse; }
.dist th { width: 5.5em; padding: 3px 10px 3px 0; text-align: left; font-size: 0.95rem; font-weight: 400; white-space: nowrap; }
.dist td { padding: 3px 0; }
.bar {
  display: block;
  min-width: 1.8em;
  width: var(--w, 0%);
  padding: 3px 6px;
  background: var(--ink);
  color: var(--paper);
  font: 600 0.75rem/1 "IBM Plex Mono", ui-monospace, monospace;
  text-align: right;
}
.dist .today { margin-left: 6px; font-size: 0.8rem; font-style: italic; color: var(--accent); }
.bar.is-zero { background: transparent; color: var(--ink-soft); text-align: left; padding-left: 0; }
.fineprint { font-size: 0.85rem; color: var(--ink-soft); }

.noscript { max-width: 33rem; margin: 20px auto; padding: 0 16px; }

/* ---- Text pages ----------------------------------------------------------- */

.text-page .article { padding-top: 6px; }
.article h1 { margin: 18px 0 6px; font-size: 2rem; font-weight: 600; line-height: 1.1; }
.article h2 { margin: 26px 0 4px; font-size: 1.2rem; font-weight: 600; }
.article p, .article li { max-width: 34em; }
.article ul { padding-left: 1.1em; }
.article .standfirst { margin-top: 4px; font-size: 1.2rem; font-style: italic; color: var(--ink-soft); }

/* ---- Larger screens --------------------------------------------------------- */

@media (min-width: 600px) {
  :root { --t: 50px; --gap: 6px; }
  .page { padding: 0 24px; }
  .wordmark { font-size: 2.2rem; }
  .masthead { padding-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
