:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #121212;
  --muted: #6b6b6b;
  --line: #d7d7d2;
  --accent: #2a6df4;
  --accent-soft: #d8e5ff;
  --warn: #c0392b;
  --good: #1f9254;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* A class with display: set on it beats the browser's own [hidden] rule, so
   anything marked hidden stays visible. Settle it once, here. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: -0.02em; font-size: 18px; }
.brand a { color: inherit; }
.topbar nav { display: flex; align-items: center; gap: 16px; font-size: 14px; }
.topbar nav a { color: var(--ink); }
.topbar .who { color: var(--muted); }
.topbar .cta {
  background: var(--ink); color: #fff; padding: 6px 12px; border-radius: 999px;
}
.topbar .cta:hover { text-decoration: none; opacity: .85; }

.wrap { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }
.wrap.narrow { max-width: 520px; }

.puzzle-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin-bottom: 18px;
}
.puzzle-head h1 { margin: 0; font-size: 30px; letter-spacing: -0.03em; }
.date { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

.timer-box {
  display: flex; align-items: center; gap: 8px;
  font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 700;
}
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font-size: 12px;
}
body.paused .grid { filter: blur(6px); pointer-events: none; }

/* ---------- layout ---------- */

.board { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 28px; align-items: start; }
.board-lower { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 36px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.panel h2, .clues-col h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

/* ---------- grid ---------- */

.grid {
  display: grid;
  /* Rows must be declared too. Without this the rows are content-sized, so a
     row containing letters grows taller than the empty ones. */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 2px; background: var(--ink); border: 3px solid var(--ink);
  border-radius: 4px; aspect-ratio: 1 / 1; width: 100%;
}
.cell {
  position: relative; background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; user-select: none;
}
.cell.block { background: var(--ink); cursor: default; }
.cell .num {
  position: absolute; top: 2px; left: 4px;
  font-size: 11px; font-weight: 700; color: var(--muted); line-height: 1;
}
.cell .letter {
  font-size: clamp(20px, 6vw, 34px); font-weight: 700; text-transform: uppercase;
  line-height: 1;
}
.cell.inword { background: var(--accent-soft); }
.cell.active { background: #ffd84d; }
.cell.wrong .letter { color: var(--warn); text-decoration: line-through; }
.cell.revealed .letter { color: var(--accent); }
.grid.solved { border-color: var(--good); background: var(--good); }

.current-clue {
  /* fixed height: a two-line clue must not shove the buttons down the page */
  margin-top: 12px; padding: 10px 14px; height: 58px;
  display: flex; align-items: center; overflow: hidden;
  background: var(--accent-soft); border-radius: var(--radius); font-weight: 600;
}

.tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tool {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 7px 12px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.tool:hover { border-color: var(--ink); }
.tool.warn { color: var(--warn); }
.tool:disabled { opacity: .4; cursor: default; }

.hint { color: var(--muted); font-size: 12.5px; margin-top: 12px; }

/* ---------- clues ---------- */

.clues-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.clue-list { list-style: none; margin: 0; padding: 0; }
.clue-list li {
  display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px;
  cursor: pointer; font-size: 14.5px; line-height: 1.35;
}
.clue-list li b { min-width: 16px; text-align: right; color: var(--muted); }
.clue-list li:hover { background: #ececea; }
.clue-list li.active { background: var(--accent-soft); }

/* ---------- leaderboard / archive ---------- */

.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14.5px;
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard .rank { width: 22px; color: var(--muted); }
.leaderboard .name { flex: 1; }
.leaderboard .t { font-variant-numeric: tabular-nums; font-weight: 700; }

.archive { list-style: none; margin: 0; padding: 0; font-size: 14.5px; }
.archive li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.archive li:last-child { border-bottom: 0; }

/* ---------- forms / stats ---------- */

.form { display: grid; gap: 14px; margin: 18px 0; }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.form input {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 16px; background: var(--panel); color: var(--ink);
}
.btn {
  display: inline-block; border: 0; background: var(--ink); color: #fff;
  padding: 11px 18px; border-radius: 999px; font-size: 15px; cursor: pointer; text-align: center;
}
.btn:hover { opacity: .87; text-decoration: none; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.error { background: #fdecea; color: var(--warn); padding: 10px 12px; border-radius: 8px; }
.muted { color: var(--muted); }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 20px 0 30px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; text-align: center; font-size: 12px; color: var(--muted);
}
.stat .n { display: block; font-size: 24px; font-weight: 800; color: var(--ink); font-variant-numeric: tabular-nums; }

.times { width: 100%; border-collapse: collapse; font-size: 15px; }
.times th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.times td, .times th { padding: 7px 0; border-bottom: 1px solid var(--line); }

/* ---------- modal ---------- */

.modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel); border-radius: 14px; padding: 28px; max-width: 380px;
  width: 100%; text-align: center;
}
.modal-card h2 { margin: 0 0 6px; }
.big-time { font-size: 44px; font-weight: 800; margin: 6px 0; font-variant-numeric: tabular-nums; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 0 20px 40px; }

/* off-screen input that summons the mobile keyboard */
.mobile-input { position: fixed; opacity: 0; pointer-events: none; top: -100px; left: -100px; width: 1px; height: 1px; }

@media (max-width: 860px) {
  .board { grid-template-columns: 1fr; }
  .board-lower { grid-template-columns: 1fr; }
  .grid { max-width: 420px; margin: 0 auto; }
  .clues-col { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .clues-col { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

.grid.failed {
  display: block; background: #fdecea; border-color: #f0c8c2; aspect-ratio: auto;
}
.grid-error { margin: 0; padding: 22px; color: var(--warn); font-size: 14.5px; line-height: 1.5; }

.flash {
  background: #e6f5ec; border: 1px solid #b9e0c9; color: #14603a;
  padding: 11px 14px; border-radius: var(--radius); margin: 0 0 16px;
}

.flash.bad { background: #fdecea; border-color: #f0c8c2; color: var(--warn); }

/* ---------- games hub ---------- */

.game-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; margin-top: 20px; }
.game-card {
  display: flex; align-items: center; gap: 14px; padding: 16px 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink);
}
.game-card:hover { border-color: var(--ink); text-decoration: none; }
.game-card.done { border-color: var(--good); }
.game-icon {
  width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px;
}
.game-card.done .game-icon { background: var(--good); }
.game-body { display: grid; gap: 2px; flex: 1; min-width: 0; }
.game-body .muted { font-size: 13px; line-height: 1.35; }
.game-state { font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.game-card.done .game-state { color: var(--good); }

/* ---------- shared game page ---------- */

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.blurb { color: var(--muted); margin: -6px 0 18px; }
.board-area {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; min-height: 180px;
}
.board-area.solved { border-color: var(--good); }
.board-area.failed { background: #fdecea; border-color: #f0c8c2; color: var(--warn); }

/* ladder - one square per letter, coloured against the rung above */
.ladder { display: grid; gap: 8px; justify-content: center; }
.lrow { display: grid; grid-auto-flow: column; gap: 6px; }
.lbox {
  width: 52px; height: 52px; border: 2px solid var(--line); border-radius: 8px;
  background: #fff; display: flex; align-items: center; justify-content: center;
  font: 800 24px/1 ui-monospace, Menlo, Consolas, monospace; text-transform: uppercase;
}
.lrow.fixed .lbox { background: var(--ink); border-color: var(--ink); color: #fff; }
.lbox.ok  { background: #e4f5ea; border-color: var(--good); }
.lbox.bad { background: #fdecea; border-color: var(--warn); }
.lbox.ok input  { color: var(--good); }
.lbox.bad input { color: var(--warn); }
.lin {
  width: 100%; height: 100%; border: 0; background: transparent; text-align: center;
  font: inherit; color: var(--ink); padding: 0;
}
.lin:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); border-radius: 6px; }

/* cryptogram */
.cipher { display: flex; flex-wrap: wrap; gap: 16px; }
.cw { display: flex; gap: 3px; }
.cc { display: grid; gap: 2px; justify-items: center; cursor: pointer; }
.cc .plain {
  display: block; width: 26px; height: 30px; line-height: 30px; text-align: center;
  border-bottom: 2px solid var(--line); font-size: 18px; font-weight: 800;
}
.cc .ciph { font-size: 11px; color: var(--muted); font-style: normal; letter-spacing: .08em; }
.cc.given .plain { color: var(--muted); border-bottom-color: var(--muted); }
.cc.sel .plain { background: #ffd84d; border-bottom-color: var(--ink); }
.cc.dupe .plain { color: var(--warn); }

/* mini six */
.sixgrid {
  display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  width: min(100%, 360px); aspect-ratio: 1/1; border: 3px solid var(--ink); border-radius: 4px;
}
.sixcell {
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
}
.sixcell.br { border-right: 3px solid var(--ink); }
.sixcell.bb { border-bottom: 3px solid var(--ink); }
.sixcell.given { background: #f2f2ef; }
.sixinput {
  width: 100%; height: 100%; border: 0; text-align: center; background: transparent;
  font-size: 22px; font-weight: 700; color: var(--accent); font-family: inherit;
}
.sixinput:focus { outline: none; background: var(--accent-soft); }

/* foursomes */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  padding: 18px 6px; border-radius: 8px; border: 1px solid var(--line); background: #f2f2ef;
  font-weight: 700; font-size: 13px; cursor: pointer; text-transform: uppercase; color: var(--ink);
}
.tile:hover { border-color: var(--ink); }
.tile.picked { background: var(--ink); color: #fff; }
.found-groups { display: grid; gap: 8px; margin-bottom: 12px; }
.found-row { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 14px; }

/* logic grid */
.clues-block { margin: 0 0 18px; padding-left: 18px; list-style: decimal; }
.clues-block li { cursor: default; padding: 3px 0; }
.clues-block li:hover { background: transparent; }
.logic-table { border-collapse: collapse; width: 100%; }
.logic-table th, .logic-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.logic-table th { font-size: 13px; color: var(--muted); }
.logic-table select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 14px; }
.logic-table select.dupe { border-color: var(--warn); color: var(--warn); }

@media (max-width: 860px) {
  .game-layout { grid-template-columns: 1fr; }
}


/* the link */
.links { display: grid; gap: 10px; }
.linkrow {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfbfa;
}
.linkrow.right { border-color: var(--good); background: #f2faf5; }
.linkrow.wrong { border-color: var(--warn); background: #fdf2f0; }
.linkwords { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.chip {
  background: var(--ink); color: #fff; border-radius: 6px; padding: 6px 10px;
  font-size: 13px; font-weight: 700; letter-spacing: .04em;
}
.linkarrow { color: var(--muted); font-size: 18px; }
.linkin {
  width: 150px; padding: 9px 10px; border: 2px solid var(--line); border-radius: 8px;
  font: 700 15px/1 inherit; text-transform: uppercase; letter-spacing: .06em;
  background: #fff; color: var(--ink);
}
.linkin:focus { outline: none; border-color: var(--accent); background: var(--accent-soft); }
.linkrow.right .linkin { border-color: var(--good); color: var(--good); }
.linkrow.wrong .linkin { border-color: var(--warn); color: var(--warn); }
.linkhint {
  width: 30px; height: 30px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); cursor: pointer; font-weight: 700;
}
.linkhint:hover { border-color: var(--ink); color: var(--ink); }
.linkrow.hinted .linkhint { opacity: .35; }

@media (max-width: 520px) {
  .linkin { width: 100%; }
  .linkarrow { display: none; }
}

/* ---------- landing page teasers ---------- */

.lede { font-size: 15.5px; margin: -6px 0 22px; }

.teaser-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.teaser-card {
  display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: var(--ink); transition: border-color .12s, transform .12s;
}
.teaser-card:hover {
  border-color: var(--ink); text-decoration: none; transform: translateY(-2px);
}
.teaser-card.done { border-color: var(--good); }

.teaser-art {
  display: block; background: #f4f4f1; border-radius: 8px; padding: 8px;
}
.teaser-card.done .teaser-art { background: #eef7f1; }
.teaser { display: block; width: 100%; height: auto; }

.teaser-text { display: grid; gap: 3px; }
.teaser-text b { font-size: 16.5px; letter-spacing: -0.01em; }
.teaser-text .muted { font-size: 13px; line-height: 1.4; }

.teaser-foot { margin-top: auto; }
.play-badge, .done-badge {
  display: inline-block; font-size: 12.5px; font-weight: 700;
  padding: 5px 12px; border-radius: 999px;
}
.play-badge { background: var(--ink); color: #fff; }
.done-badge { background: #e4f5ea; color: var(--good); }

/* the case */
.case-brief { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.case-fact {
  flex: 1; min-width: 150px; background: var(--ink); color: #fff;
  border-radius: var(--radius); padding: 12px 14px;
}
.case-fact span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; opacity: .65; }
.case-fact b { font-size: 16px; }

.case-clues { margin: 0 0 20px; padding-left: 20px; }
.case-clues li { padding: 4px 0; font-size: 15px; line-height: 1.45; }

.suspects { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.suspect {
  display: grid; justify-items: center; gap: 8px; padding: 16px 10px;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel);
  cursor: pointer; font: inherit; color: var(--ink); text-align: center;
}
.suspect:hover:not(:disabled) { border-color: var(--ink); }
.face {
  width: 46px; height: 46px; border-radius: 50%; background: #ececea; color: var(--ink);
  display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 800;
}
.sname { font-weight: 700; font-size: 14px; }
.verdict { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); min-height: 14px; }

.suspect.picked { border-color: var(--accent); background: var(--accent-soft); }
.suspect.picked .face { background: var(--accent); color: #fff; }
.suspect.cleared { opacity: .45; }
.suspect.cleared .sname { text-decoration: line-through; }
.suspect.cleared .verdict { color: var(--warn); }
.suspect.guilty { border-color: var(--good); background: #eef7f1; opacity: 1; }
.suspect.guilty .face { background: var(--good); color: #fff; }
.suspect.guilty .verdict { color: var(--good); font-weight: 700; }
.suspect.missed { border-color: var(--warn); background: #fdf2f0; opacity: 1; }
.suspect.missed .face { background: var(--warn); color: #fff; }
.suspect.missed .verdict { color: var(--warn); font-weight: 700; }
