:root {
  --paper: #f6f1e7;
  --paper-2: #ece5d6;
  --desk: #ddd3bf;
  --sheet-shadow: 0 0 0 1px rgb(0 0 0 / 0.04), 0 10px 40px rgb(60 45 20 / 0.18);
  --ink: #1a1a1a;
  --ink-soft: #5b5650;
  --rule: #1a1a1a;
  --rule-soft: #cfc6b4;
  --redact: #1a1a1a;
  --accent: #c0392b;
  --fast: #2e8b57;
  --slow: #d4a017;
  --miss: #c0392b;
  --empty: #ddd5c4;
  --serif: "Georgia", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161513;
    --paper-2: #211f1c;
    --desk: #0b0a09;
    --sheet-shadow: 0 0 0 1px rgb(255 255 255 / 0.02), 0 10px 40px rgb(0 0 0 / 0.6);
    --ink: #ece6da;
    --ink-soft: #a39d92;
    --rule: #ece6da;
    --rule-soft: #3a3632;
    --redact: #ece6da;
    --accent: #e0604f;
    --fast: #3fa66b;
    --slow: #d9a92a;
    --miss: #d0503f;
    --empty: #34312c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

[hidden] { display: none !important; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sheet ----------
   The game sits on a sheet of newsprint; on wide screens the space either
   side of it is a darker "desk", with a rule and shadow marking the edge. */

.sheet { background: var(--paper); min-height: 100vh; }

@media (min-width: 700px) {
  body { background: var(--desk); }
  .sheet {
    max-width: 680px;
    margin: 0 auto;
    padding: 0 4px;
    border-left: 1px solid var(--rule-soft);
    border-right: 1px solid var(--rule-soft);
    box-shadow: var(--sheet-shadow);
  }
}

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

.masthead {
  display: grid;
  grid-template-columns: 80px 1fr 80px;
  align-items: center;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 10px;
  border-bottom: 3px double var(--rule);
}

.masthead-title { text-align: center; }

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
}

.dateline {
  margin: 6px 0 0;
  font-family: var(--serif);
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-soft);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--rule-soft);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  font: 700 1rem var(--serif);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--paper-2); }
.masthead-actions { display: flex; gap: 8px; justify-self: end; }

.account-btn { overflow: hidden; padding: 0; font-family: var(--sans); font-size: 0.9rem; }
.account-btn img, .account-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- Page ---------- */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.kicker {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.sample-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  border: 1px dashed var(--ink-soft);
  border-radius: 4px;
  padding: 2px 6px;
}

.redacted-sample {
  background: var(--redact);
  color: var(--paper);
  padding: 0 4px;
  border-radius: 1px;
}

.btn {
  padding: 12px 16px;
  font: 600 0.95rem var(--sans);
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid var(--ink);
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-primary:not(:disabled):hover { opacity: 0.88; }
.btn-ghost:not(:disabled):hover { background: var(--paper-2); }
.btn-big { width: 100%; padding: 16px; font-size: 1.05rem; }

.loading {
  margin: 48px 0;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  animation: ink-in 0.4s ease-out;
}

/* ---------- Edition picker ---------- */

.editions {
  display: flex;
  gap: 6px;
  margin: -6px -16px 18px;
  padding: 0 16px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.editions::-webkit-scrollbar { display: none; }

.edition {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--rule-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
}
.edition:hover { border-color: var(--ink); color: var(--ink); }
.edition[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.stats-edition { font-family: var(--sans); font-size: 0.8rem; font-weight: 600; color: var(--ink-soft); }
h3 .stats-edition { font-size: inherit; letter-spacing: inherit; text-transform: none; }
h3 .stats-edition:not(:empty)::before { content: "· "; }

.account-stats {
  margin: 4px 0 20px;
  padding-top: 4px;
  border-top: 1px solid var(--rule-soft);
}

/* ---------- Intro ---------- */

.intro { text-align: center; padding-top: 12px; }

.intro-title {
  margin: 6px 0 10px;
  font-family: var(--serif);
  font-size: 1.9rem;
}

.intro-rules {
  list-style: none;
  margin: 20px auto 28px;
  padding: 0;
  max-width: 340px;
  text-align: left;
  font-family: var(--serif);
  font-size: 1.05rem;
}
.intro-rules li {
  padding: 10px 0;
  border-top: 1px solid var(--rule-soft);
}
.intro-rules li:last-child { border-bottom: 1px solid var(--rule-soft); }

/* ---------- Round ---------- */

.play-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.score-chip {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.timer {
  height: 8px;
  margin-top: 12px;
  background: var(--empty);
  border-radius: 4px;
  overflow: hidden;
}
.timer-fill {
  height: 100%;
  background: var(--ink);
  transform-origin: left;
}
.timer-fill.low { background: var(--miss); }

.timer-text {
  margin: 6px 0 0;
  text-align: right;
  font-size: 0.85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.headline-card {
  margin: 14px 0 18px;
  padding: 18px 0 20px;
  border-top: 3px double var(--rule);
  border-bottom: 1px solid var(--rule);
}

.headline-source {
  margin: 0 0 6px;
  min-height: 1em;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.headline {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  line-height: 1.4;
}

.headline-hint {
  margin: 14px 0 0;
  font-family: var(--serif);
  font-size: 0.95rem;
  color: var(--ink-soft);
  animation: ink-in 0.4s ease-out;
}
.headline-hint .slot { font-size: 0.85em; }

/* The blank: one box per letter. */
.slot {
  display: inline-flex;
  gap: 2px;
  vertical-align: -0.12em;
  white-space: nowrap;
}
.cell {
  display: inline-grid;
  place-items: center;
  width: 0.85em;
  height: 1.1em;
  font-family: var(--sans);
  font-size: 0.85em;
  font-weight: 700;
  background: var(--redact);
  color: var(--paper);
  border-radius: 2px;
}
.cell.hint { color: var(--ink-soft); background: var(--empty); }
.cell.filled { background: var(--paper-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }

.answer {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
}
.answer-correct { color: var(--fast); }
.answer-missed { color: var(--miss); }

@keyframes ink-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Guess form ---------- */

.guess-form { display: grid; gap: 10px; }

.guess-form input {
  width: 100%;
  padding: 14px;
  font: 1.05rem var(--sans);
  color: var(--ink);
  background: var(--paper-2);
  border: 2px solid var(--rule-soft);
  border-radius: 8px;
  outline: none;
}
.guess-form input:focus { border-color: var(--ink); }
.shake { animation: shake 0.35s; }

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

.guess-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
}

.tried {
  min-height: 1.2em;
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.round-result { text-align: center; }
.round-verdict {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 700;
}
.round-verdict.good { color: var(--fast); }

/* ---------- Squares ---------- */

.sq {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--empty);
}
.sq-fast { background: var(--fast); }
.sq-slow { background: var(--slow); }
.sq-miss { background: var(--miss); }

/* ---------- Summary ---------- */

.summary { text-align: center; }

.final-score {
  margin: 4px 0 8px;
  font-family: var(--serif);
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.final-score small { font-size: 1.1rem; color: var(--ink-soft); }

.final-squares {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 18px;
}

.result-line {
  margin: -6px auto 18px;
  max-width: 40ch;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink-soft);
}
.result-line:empty { display: none; }

.fine-print { font-size: 0.8rem; color: var(--ink-soft); }

.signin-nudge { margin: 14px 0 0; font-size: 0.9rem; color: var(--ink-soft); }
.link-btn {
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

/* Google's sign-in button: white, the multicolour G, dark text. */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 18px 0 6px;
  padding: 12px 16px;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid #747775;
  border-radius: 8px;
  font: 600 0.95rem var(--sans);
  text-decoration: none;
}
.google-btn:hover { background: #f2f2f2; }

.account-card { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.account-card strong { display: block; }
.account-card span { font-size: 0.85rem; color: var(--ink-soft); }
.account-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--paper-2);
  font: 700 1.2rem var(--serif);
}

.result-actions .btn { min-width: 200px; }

.next-puzzle {
  margin: 14px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
#countdown { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--ink); }

.section-title {
  margin: 36px 0 0;
  padding: 12px 0 10px;
  border-top: 3px double var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--serif);
  font-size: 1.35rem;
  text-align: left;
}

.stories {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

.story {
  padding: 16px 0 18px;
  border-bottom: 1px solid var(--rule-soft);
}

.story-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.story-meta .sq { width: 12px; height: 12px; border-radius: 3px; }

.story h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 1.2rem;
  line-height: 1.35;
}
.story .answer { text-decoration-thickness: 2px; text-underline-offset: 3px; }

.story-summary {
  margin: 0 0 8px;
  font-family: var(--serif);
  color: var(--ink-soft);
}

.story-link {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.story-link:hover { text-decoration: underline; }

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

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 12px; font-family: var(--serif); }
dialog h3 { margin: 20px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; }
dialog ul { padding-left: 20px; }
dialog li { margin-bottom: 6px; }

.dialog-close { position: absolute; top: 8px; right: 8px; margin: 0; }
.dialog-close button {
  width: 32px; height: 32px;
  border: none; background: transparent;
  color: var(--ink); font-size: 1.5rem; cursor: pointer;
}

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 0.85rem; }
.legend .sq { width: 14px; height: 14px; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
}
.stats-row strong { display: block; font-family: var(--serif); font-size: 1.6rem; }
.stats-row span { font-size: 0.72rem; color: var(--ink-soft); }

.distribution { display: grid; gap: 4px; font-size: 0.85rem; color: var(--ink-soft); }
.dist-row { display: grid; grid-template-columns: 36px 1fr; gap: 8px; align-items: center; color: var(--ink); }
.dist-bar {
  padding: 2px 6px;
  text-align: right;
  font-weight: 700;
  font-size: 0.8rem;
  background: var(--ink-soft);
  color: var(--paper);
}
.dist-bar.today { background: var(--fast); color: #fff; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 10;
}
