/* DailyHub: a newspaper puzzle page. Two editions, picked in Settings:
   - "night" (default): black paper, white ink, orange for stamps, highlights and the "Hub" box.
   - "paper": cream newsprint, black ink, red stamps and a yellow highlighter.
   --orange is the accent colour in both (it's red in the paper edition).
   Headlines and names in a serif; everything else (text, labels, scores) in a clean sans. */
:root {
  --paper: #0b0b0b;
  --paper-2: #171717;
  --ink: #f5f5f5;
  --ink-soft: #d6d6d6;
  --muted: #a0a0a0;
  --rule: #343434;
  --orange: #ff9000;
  --on-orange: #000000;
  --marker: rgb(255 144 0 / .22);
  --display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="paper"] {
  --paper: #f3ede0;
  --paper-2: #faf6ec;
  --ink: #1a1814;
  --ink-soft: #3a352c;
  --muted: #6e6656;
  --rule: #cfc4ad;
  --orange: #b4301f;
  --on-orange: #faf6ec;
  --marker: rgb(245 214 70 / .7);
  color-scheme: light;
}
:root[data-theme="paper"] .pastebox { box-shadow: 0 -8px 18px rgb(26 24 20 / .12); }
:root[data-theme="paper"] .grid td.best,
:root[data-theme="paper"] .grid td.best small { color: var(--ink); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
main { max-width: 560px; margin: 0 auto; padding: 0 16px; }
button, input, textarea { font: inherit; color: inherit; }
b { font-weight: 600; }
[hidden] { display: none !important; }

/* labels: uppercase sans, big enough to read */
.section-head h2, .board-card h3,
.seg button, .tabs button, .preview-label, .game a.play {
  font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em;
}

/* ---------- masthead ---------- */
.masthead {
  max-width: 560px; margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 16px 0;
}
.mast-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-bottom: 12px; border-bottom: 3px solid var(--ink);
}
.logo {
  margin: 0; display: flex; align-items: center; gap: 5px;
  font: 900 29px/1 var(--display); letter-spacing: -.01em;
}
.logo b {
  font-weight: 900; color: var(--on-orange); background: var(--orange);
  padding: 2px 7px 4px; border-radius: 6px;
}
.mast-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.theme-toggle {
  flex: none; position: relative; width: 66px; height: 36px; padding: 0; cursor: pointer;
  border: 1.5px solid var(--rule); background: var(--paper-2); border-radius: 999px;
  display: flex; align-items: center; justify-content: space-between;
}
.theme-toggle .knob {
  position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--orange); transition: transform .2s;
  transform: translateX(30px); /* dark theme: knob on the moon (right) */
}
:root[data-theme="paper"] .theme-toggle .knob { transform: translateX(0); } /* light: on the sun */
.theme-toggle svg {
  position: relative; z-index: 1; width: 28px; height: 16px; margin: 0 3px;
  fill: none; stroke: var(--muted); stroke-width: 2.2; stroke-linecap: round; transition: stroke .2s, fill .2s;
}
.theme-toggle .sun circle { fill: var(--muted); stroke: none; }
.theme-toggle .moon path { fill: var(--muted); stroke: none; }
/* the icon under the knob is drawn in the knob's text colour */
:root:not([data-theme="paper"]) .theme-toggle .moon path,
:root[data-theme="paper"] .theme-toggle .sun circle { fill: var(--on-orange); }
:root[data-theme="paper"] .theme-toggle .sun { stroke: var(--on-orange); }
.profile {
  display: flex; align-items: center; gap: 7px; min-width: 0; max-width: 170px;
  border: 1.5px solid var(--rule); background: none; cursor: pointer;
  padding: 6px 10px 6px 6px; border-radius: 999px;
  font: 600 15px var(--sans); color: var(--ink);
}
.profile svg {
  flex: none; width: 22px; height: 22px; padding: 3px; border-radius: 50%;
  background: var(--orange); fill: var(--on-orange); stroke: none;
}
.profile svg path { fill: var(--on-orange); }
.profile span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dateline .me-streak { margin-left: 10px; font-weight: 700; color: var(--orange); }
.dateline {
  font: 500 14px/1 var(--sans); color: var(--muted); text-align: center;
  padding: 9px 0; border-bottom: 1px solid var(--rule);
}

/* ---------- welcome card (new users) ---------- */
.welcome {
  margin: 16px 0 4px; padding: 16px; background: var(--paper-2);
  border: 1.5px solid var(--ink); border-left: 5px solid var(--orange);
}
.welcome h2 { margin: 0 0 6px; font: 900 22px/1.2 var(--display); }
.welcome p { margin: 0 0 10px; font-size: 15px; color: var(--ink-soft); }
.welcome ol { margin: 0 0 14px; padding-left: 20px; font-size: 15px; line-height: 1.45; }
.welcome li { margin: 5px 0; }
.welcome li::marker { color: var(--orange); font-weight: 800; }
.welcome .btn { width: 100%; }
dialog .intro { margin: -6px 0 16px; font: 15px/1.45 var(--sans); color: var(--ink-soft); }

/* ---------- section headings ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 20px 0 8px; border-bottom: 1px solid var(--ink); padding-bottom: 5px;
}
.section-head h2 { margin: 0; font-size: 14px; font-weight: 800; }
.tally { font: 500 14px var(--sans); color: var(--muted); }
.tally b { color: var(--orange); font-weight: 700; }

/* progress: one box per game, filled orange when solved */
.ticks { display: flex; gap: 5px; margin: 10px 0 16px; }
.ticks i { flex: 1; height: 10px; border: 1.5px solid var(--ink-soft); }
.ticks i.on { background: var(--orange); border-color: var(--orange); }

/* ---------- play controls ---------- */
.hint { color: var(--muted); font-size: 14px; margin: 12px 2px; }

/* ---------- the paste box: fixed just above the tab bar on the Play tab ---------- */
.pastebox {
  position: fixed; left: 0; right: 0; bottom: var(--tabs-h, 52px); z-index: 45;
  padding: 10px 16px; background: var(--paper);
  box-shadow: 0 -8px 18px rgb(0 0 0 / .35);   /* lifts it off the list scrolling underneath */
}
.pastebox textarea {
  display: block; width: 100%; max-width: 528px; margin: 0 auto; resize: none; outline: none;
  padding: 12px 14px; border: 3px solid var(--orange); background: var(--paper-2);
  font: 600 15px/1.45 var(--sans); color: var(--ink);
}
/* faded hint text, so it reads as an empty box to paste into, not as real text */
.pastebox textarea::placeholder { color: var(--muted); opacity: .55; font-weight: 500; font-style: italic; }
.pastebox textarea:focus { background: var(--paper); }
/* room for the paste box under the last game */
body[data-tab="play"] { padding-bottom: calc(var(--tabs-h, 52px) + 110px); }

/* ---------- the puzzle index ---------- */
.games { list-style: none; padding: 0; margin: 6px 0 16px; }
.game {
  display: flex; align-items: center; gap: 8px;
  padding: 13px 0; border-bottom: 1px dotted var(--rule);
}

.game .em { font-size: 21px; width: 26px; text-align: center; }
.game .info { flex: 1; min-width: 0; }
.game .name { font: 700 19px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game .score { font: 500 14px/1.4 var(--sans); color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.game.done .score { color: var(--ink-soft); }
.game .pts { color: var(--orange); font-weight: 700; }
.stamp {
  display: inline-block; margin-left: 8px; padding: 1px 6px; vertical-align: 3px;
  font: 800 10px/1.3 var(--sans); letter-spacing: .1em; color: var(--orange);
  border: 1.5px solid var(--orange); transform: rotate(-4deg);
}
/* each unplayed game: Play opens it */
.game a.play {
  flex: none; white-space: nowrap; cursor: pointer; text-decoration: none;
  font: 800 13px var(--sans); letter-spacing: .06em; text-transform: uppercase;
  padding: 8px 11px; border: 1.5px solid var(--ink); background: none; color: var(--ink);
}
.game a.play:active { opacity: .8; }
.stamp.best { color: var(--on-orange); background: var(--orange); }
.game .x {
  border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px;
}
.game.flash { animation: flash 1.2s; }
@keyframes flash { 0% { background: var(--marker); } 100% { background: transparent; } }

/* ---------- segmented switch ---------- */
.seg { display: flex; gap: 20px; margin: 4px 0 14px; }
.seg button {
  border: 0; background: none; padding: 5px 0; cursor: pointer; color: var(--muted);
  font-size: 14px; font-weight: 700; border-bottom: 2px solid transparent;
}
.seg button.on { color: var(--ink); border-bottom-color: var(--orange); }

/* ---------- buttons (flat) ---------- */
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.btn {
  flex: 1; min-width: 120px; cursor: pointer;
  border: 1.5px solid var(--ink); background: none; color: var(--ink);
  padding: 12px; font: 700 17px/1.2 var(--display);
}
.btn.primary { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.btn:active { opacity: .85; }
.board-row .btn:first-child { flex: 0 0 auto; min-width: 0; padding: 12px 18px; }
.board-row .btn:last-child { white-space: nowrap; }
.copy-row { margin-top: 0; }
/* the main action on Copy Results: the accent colour, with the WhatsApp logo */
.btn.wa {
  display: flex; align-items: center; justify-content: center; gap: 9px; text-decoration: none;
  background: var(--orange); border-color: var(--orange); color: var(--on-orange);
  padding: 14px; font-size: 18px; font-weight: 900;
}
.btn.wa svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
.btn.wa:active { opacity: .85; }
.btn.wa.disabled { opacity: .45; }

/* ---------- results preview: a clipped slip of paper ---------- */
.preview-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 6px 0; }
.summary {
  background: var(--paper-2); border: 1px dashed var(--muted);
  padding: 12px 14px; margin: 0 0 12px;
  white-space: pre-wrap; word-break: break-word;
  font: 14px/1.45 var(--sans);
  /* Preview scrolls inside its own box so the page itself never needs to. */
  max-height: 38vh; overflow-y: auto;
}

/* ---------- leaderboard ---------- */
.board-card { margin: 20px 0 8px; }
.board-card h3 {
  margin: 0 0 6px; padding-bottom: 5px; border-bottom: 1px solid var(--ink);
  font-size: 14px; font-weight: 800;
}
.board-card table { width: 100%; border-collapse: collapse; }
.standings td { padding: 10px 0; border-bottom: 1px dotted var(--rule); vertical-align: baseline; }
.standings td.r { width: 42px; font: italic 900 24px var(--display); color: var(--muted); }
.standings tr:first-child td.r { color: var(--orange); }
.standings td.n { font: 700 21px var(--display); }
.standings td.v { text-align: right; font: 700 17px var(--sans); white-space: nowrap; font-variant-numeric: tabular-nums; }
.standings .wins { display: block; font: 500 12px var(--sans); color: var(--muted); }
.standings tr.me td.n .nm::after { content: " (you)"; font: 500 14px var(--sans); color: var(--orange); }

.board-status { margin: 10px 0 0; min-height: 0; font: 13px var(--sans); color: var(--muted); }
.board-status:empty { display: none; }

/* yesterday's winner, above today's standings */
.champ {
  margin: 16px 0 0; padding: 10px 12px; background: var(--paper-2);
  border-left: 4px solid var(--orange); font: 15px/1.4 var(--sans); color: var(--ink-soft);
}
.champ b { color: var(--ink); font-weight: 700; }
.standings .streak { margin-left: 8px; font: 700 13px var(--sans); color: var(--orange); white-space: nowrap; }
.pb { font-weight: 700; color: var(--orange); white-space: nowrap; }

/* how many of today's games each person has played */
.standings .progress {
  display: flex; align-items: center; gap: 7px; margin-top: 4px;
  font: 500 12.5px var(--sans); color: var(--muted);
}
.mini-ticks { display: inline-flex; gap: 2px; }
.mini-ticks i { width: 7px; height: 7px; border: 1px solid var(--muted); }
.mini-ticks i.on { background: var(--orange); border-color: var(--orange); }
.waiting { margin: 10px 0 0; font: 14px/1.45 var(--sans); color: var(--muted); }
.waiting b { color: var(--ink-soft); font-weight: 600; }

/* game picker: one chip per game (greyed out if nobody has played it), plus the full grid */
.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; cursor: pointer; white-space: nowrap;
  border: 1.5px solid var(--rule); background: none; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 999px; font: 600 14px var(--sans);
}
.chip.on { background: var(--orange); border-color: var(--orange); color: var(--on-orange); }
.chip:disabled { opacity: .35; cursor: default; }

/* one game's ranking: rank, name + score, a 0–100 points bar, points */
.game-rank { list-style: none; margin: 0; padding: 0; }
.game-rank li {
  display: grid; grid-template-columns: 30px 1fr 70px 34px; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px dotted var(--rule);
}
.game-rank .r { font: italic 900 20px var(--display); color: var(--muted); }
.game-rank li.best .r { color: var(--orange); }
.game-rank .who { min-width: 0; }
.game-rank .who b { display: block; font: 700 18px/1.2 var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-rank .lbl { display: block; font: 500 14px var(--sans); color: var(--ink-soft); margin-top: 2px; font-variant-numeric: tabular-nums; }
.game-rank li.best .lbl { color: var(--orange); font-weight: 700; }
.game-rank .bar { height: 8px; background: var(--paper-2); border: 1px solid var(--rule); }
.game-rank .bar i { display: block; height: 100%; background: var(--orange); }
.game-rank .pts { text-align: right; font: 800 16px var(--sans); font-variant-numeric: tabular-nums; }
.game-rank li.me .who b::after { content: " (you)"; font: 500 13px var(--sans); color: var(--orange); }

.grid-scroll { overflow-x: auto; }
.board-card table.grid { width: auto; min-width: 100%; }
.grid th, .grid td {
  padding: 9px 10px; white-space: nowrap; text-align: center;
  border-bottom: 1px dotted var(--rule); font: 500 14px/1.3 var(--sans); font-variant-numeric: tabular-nums;
}
.grid thead th { font: 700 17px var(--display); border-bottom: 1px solid var(--ink); padding-top: 4px; }
.grid thead th.me { color: var(--orange); }
.grid th.g {
  position: sticky; left: 0; z-index: 1; background: var(--paper);
  text-align: left; padding-left: 0; font: 600 15px var(--sans);
}
.grid td small { display: block; font-size: 12px; color: var(--muted); }
/* highlighter stroke on each game's best score */
.grid td.best {
  font-weight: 700; color: var(--orange);
  background: linear-gradient(100deg, transparent 4%, var(--marker) 6%, var(--marker) 94%, transparent 96%);
}
.grid td.best small { color: var(--orange); }
.grid td.none { color: var(--rule); }
.grid tr.total th, .grid tr.total td { border-top: 3px double var(--ink); border-bottom: 0; font-weight: 700; }
.grid tr.total th.g { font: 700 17px var(--display); }

.scoring { font-size: 15px; margin: 14px 0 20px; color: var(--ink-soft); }
.scoring summary { cursor: pointer; color: var(--muted); font-family: var(--sans); font-size: 14px; }
.scoring ul { padding-left: 18px; margin: 6px 0 0; }
.scoring li { margin: 5px 0; }
.empty { color: var(--muted); text-align: center; padding: 36px 0; }

/* ---------- bottom tabs ---------- */
/* z-index keeps scrolled content (incl. the sticky scoresheet column) underneath the bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; background: var(--paper); border-top: 3px double var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1; border: 0; background: none; cursor: pointer;
  padding: 16px 0 15px; color: var(--muted); font-size: 12.5px; font-weight: 700;
  position: relative;
}
.tabs button.on { color: var(--ink); }
.tabs button.on::after {
  content: ""; position: absolute; left: 50%; bottom: 9px; width: 26px; height: 3px;
  background: var(--orange); transform: translateX(-50%);
}
/* the centre tab is the main button: an orange block, level with the other two */
.tabs { align-items: center; }
.tabs button.main-tab {
  flex: 1.4; align-self: stretch; margin: 6px 4px; padding: 0 6px;
  background: var(--orange); color: var(--on-orange);
  font-size: 12.5px; font-weight: 900; line-height: 1.15;
}
.tabs button.main-tab.on { outline: 2px solid var(--ink); outline-offset: -5px; }
.tabs button.main-tab.on::after { display: none; }

/* ---------- name dialog ---------- */
dialog {
  border: 1.5px solid var(--ink); padding: 0; width: min(420px, calc(100% - 32px));
  background: var(--paper); color: var(--ink);
}
dialog::backdrop { background: rgb(0 0 0 / .7); }
dialog form { padding: 20px; }
dialog h2 { margin: 0 0 14px; font: 900 28px/1.1 var(--display); }
dialog label {
  display: block; margin-bottom: 12px; font: 700 12px var(--sans);
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
dialog .name-hint { margin: -4px 0 0; font: 14px/1.45 var(--sans); color: var(--muted); }
dialog input::placeholder { color: var(--rule); }
dialog .theme-pick { margin: 18px 0 6px; }
dialog .theme-pick .seg { margin: 6px 0 0; }
dialog input:not([type]), dialog input[type=text] {
  display: block; width: 100%; margin-top: 6px; padding: 8px 0;
  border: 0; border-bottom: 2px solid var(--orange); background: none;
  font: 700 24px var(--display); letter-spacing: 0; text-transform: none; color: var(--ink);
  outline: none;
}

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h, 52px) + 140px); z-index: 150; /* clear of the tab bar and the paste box */
  transform: translateX(-50%) translateY(16px); opacity: 0; pointer-events: none;
  background: var(--orange); color: var(--on-orange); padding: 10px 16px;
  font: 600 14px/1.4 var(--sans); transition: .25s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
