:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #1b1a17;
  --ink-soft: #6b665d;
  --line: #e4e0d8;
  --line-strong: #cfc9bd;
  --accent: #d93a26;
  --green: #3a9d5d;
  --yellow: #e2b33a;
  --grey: #9a958b;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Space Grotesk", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161513; --surface: #1f1e1b; --ink: #eeebe4; --ink-soft: #a29d92;
    --line: #2e2c28; --line-strong: #45423c; --grey: #5a564f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1f1e1b; --ink: #eeebe4; --ink-soft: #a29d92;
  --line: #2e2c28; --line-strong: #45423c; --grey: #5a564f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* ---------- Header ---------- */
.masthead { padding-top: 14px; }
.masthead-top {
  display: grid; grid-template-columns: 36px 1fr 36px; align-items: center;
  padding-bottom: 10px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: transparent;
  display: grid; place-items: center; font-weight: 700; font-size: 15px; color: var(--ink-soft);
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink); }
.logo {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(32px, 7vw, 48px);
  line-height: 1;
  letter-spacing: -.02em;
  text-align: center;
  margin: 0;
}
.edition {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 6px 0 10px;
  font-size: 12px; color: var(--ink-soft);
}
.edition-date { text-align: center; }
#next-edition, #edition-no { font-family: var(--mono); font-size: 11.5px; }
#next-edition { text-align: right; }

.headline {
  font-family: var(--serif); font-weight: 600;
  font-size: clamp(19px, 4vw, 24px); line-height: 1.2;
  text-align: center; margin: 20px auto 14px; max-width: 36ch;
  text-wrap: balance;
}
.headline em { color: var(--accent); font-style: normal; display: block; font-weight: 600; }

/* ---------- Slots / tiles ---------- */
.slots-bar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 10px 0 12px;
  border-bottom: 1px solid var(--line);
}
.attempts {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; color: var(--ink-soft); margin-bottom: 8px;
}
.pips { display: flex; gap: 5px; }
.pip { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.pip.used { background: var(--ink); }

.slots, .row {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px;
}
.tile {
  position: relative;
  min-height: 70px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 20px 6px 6px;
  display: flex; flex-direction: column; justify-content: flex-end;
  text-align: left; width: 100%;
  font-size: 11.5px; line-height: 1.15; font-weight: 500;
  overflow: hidden;
}
.tile .n {
  position: absolute; top: 4px; left: 6px;
  font-family: var(--serif); font-weight: 700; font-size: 15px; line-height: 1; color: var(--ink-soft);
}
.tile .t {
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.tile.empty { border-style: dashed; background: transparent; }
.tile.filled { border-color: var(--ink); }
.tile.filled:hover { background: var(--line); }
.tile.filled::after {
  content: "×"; position: absolute; top: 2px; right: 6px; font-size: 14px; color: var(--ink-soft);
}
.tile.g, .tile.y, .tile.x { color: #fff; border-color: transparent; }
.tile.g .n, .tile.y .n, .tile.x .n { color: inherit; opacity: .8; }
.tile.g { background: var(--green); }
.tile.y { background: var(--yellow); color: #231b06; }
.tile.x { background: var(--grey); }
.tile.locked { cursor: default; }
.tile.locked::after { content: "✓"; color: #fff; }

.row.reveal .tile {
  animation: flip .5s ease both;
  animation-delay: calc(var(--i) * 180ms);
}
@keyframes flip {
  0%   { transform: rotateX(0); background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
  49%  { transform: rotateX(90deg); background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

.submit {
  display: block; width: 100%; margin-top: 10px;
  padding: 11px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 16px;
  transition: opacity .15s;
}
.submit:hover:not(:disabled) { opacity: .9; }
.submit:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; }

/* ---------- History ---------- */
.history { display: grid; gap: 6px; margin-bottom: 6px; }
.history .row .tile { min-height: 52px; padding-top: 6px; }
.history .row .tile .n { display: none; }

/* ---------- Pool ---------- */
.pool-label { font-size: 12px; color: var(--ink-soft); margin: 14px 0 10px; }
.pool {
  list-style: none; margin: 0 0 32px; padding: 0;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
}
@media (min-width: 640px) { .pool { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 880px) { .pool { grid-template-columns: repeat(4, 1fr); } }

.card {
  position: relative; width: 100%; height: 100%;
  display: flex; flex-direction: column; text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); padding: 0; overflow: hidden;
  transition: border-color .15s, opacity .2s;
}
.card:hover:not(:disabled) { border-color: var(--ink-soft); }
.card .img {
  aspect-ratio: 16 / 10; width: 100%;
  background: var(--line) center / cover no-repeat;
}
.card .img.noimg {
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 700; font-size: 44px; color: var(--ink-soft);
}
.card .body { padding: 8px 10px 10px; }
.card .title {
  font-family: var(--serif); font-weight: 600; font-size: 15.5px; line-height: 1.15;
  overflow-wrap: anywhere;
}
.card .desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; line-height: 1.25; }
.card .badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px;
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%;
}
.card .tag {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
}
.card.st-y .tag { background: var(--yellow); color: #231b06; }
.card.st-g .tag { background: var(--green); color: #fff; }
.card.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card.st-x { opacity: .35; }
.card.st-x .img { filter: grayscale(1); }
.card.st-x .title { text-decoration: line-through; }
.card:disabled { cursor: not-allowed; }
.card.st-g { opacity: .55; }

/* ---------- Result ---------- */
.result { margin: 18px 0 40px; }
.verdict { text-align: center; margin: 8px 0 16px; }
.verdict .kicker { font-size: 12px; color: var(--ink-soft); }
.verdict h2 {
  font-family: var(--serif); font-weight: 700; font-size: clamp(28px, 6vw, 40px);
  line-height: 1.05; margin: 4px 0 6px; letter-spacing: -.01em;
}
.verdict p { margin: 0; color: var(--ink-soft); }
.actions { display: flex; gap: 10px; justify-content: center; margin: 16px 0 26px; flex-wrap: wrap; }
.cta {
  padding: 10px 20px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
}
.cta.alt { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.cta:hover { opacity: .9; }

.board-title {
  font-family: var(--serif); font-weight: 600; font-size: 19px;
  border-bottom: 1px solid var(--line-strong);
  padding: 8px 0; margin: 0;
}
.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid; grid-template-columns: 26px 40px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px 4px; border-bottom: 1px solid var(--line);
}
.board li.cut { border-bottom: 1px solid var(--line-strong); }
.board .rk { font-family: var(--serif); font-weight: 700; font-size: 17px; text-align: right; color: var(--ink-soft); }
.board li.top5 .rk { color: var(--ink); }
.board .th {
  width: 40px; height: 40px; border-radius: 6px;
  background: var(--line) center / cover no-repeat;
}
.board .nm { min-width: 0; }
.board .nm a { font-weight: 600; text-decoration: none; }
.board .nm a:hover { text-decoration: underline; }
.board .nm small { display: block; color: var(--ink-soft); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board .bar { height: 3px; border-radius: 2px; background: var(--line-strong); margin-top: 5px; }
.board li.top5 .bar { background: var(--accent); }
.board .vw { font-family: var(--mono); font-size: 12.5px; text-align: right; color: var(--ink-soft); }
.board .mine { display: inline-block; width: 9px; height: 9px; margin-left: 6px; border-radius: 2px; vertical-align: middle; }
.board .mine.g { background: var(--green); }
.board .mine.y { background: var(--yellow); }

/* ---------- Modals ---------- */
.modal {
  border: 0; border-radius: 12px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
  max-width: min(420px, calc(100vw - 32px)); padding: 22px 22px 18px;
}
.modal::backdrop { background: rgba(20, 18, 15, .4); }
.modal h2 { font-family: var(--serif); font-weight: 700; font-size: 24px; margin: 0 0 10px; line-height: 1.1; }
.modal .close {
  position: absolute; top: 8px; right: 12px; border: 0; background: none; font-size: 24px; line-height: 1; color: var(--ink-soft);
}
.modal .small { font-size: 13px; color: var(--ink-soft); }
.modal .cta { width: 100%; margin-top: 6px; }
.legend { display: grid; gap: 10px; margin: 14px 0; }
.legend > div { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; font-size: 14px; }
.chip { width: 22px; height: 22px; border-radius: 5px; }
.chip.g { background: var(--green); } .chip.y { background: var(--yellow); } .chip.x { background: var(--grey); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 4px; margin-bottom: 18px; }
.stat-grid b { display: block; font-family: var(--serif); font-weight: 700; font-size: 28px; line-height: 1.1; }
.stat-grid span { font-size: 11px; color: var(--ink-soft); }
.dist { display: grid; gap: 5px; }
.dist div { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: center; font-family: var(--mono); font-size: 13px; }
.dist i {
  display: block; background: var(--grey); color: #fff; font-style: normal; border-radius: 3px;
  text-align: right; padding: 2px 6px; min-width: 24px;
}
.dist i.cur { background: var(--green); }

/* ---------- Misc ---------- */
.toast {
  position: fixed; left: 50%; top: 16px; transform: translate(-50%, -150%);
  background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  transition: transform .25s; z-index: 50; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }
.footer { font-size: 12px; color: var(--ink-soft); padding-top: 16px; padding-bottom: 32px; border-top: 1px solid var(--line); }

@media (max-width: 420px) {
  .edition { font-size: 11px; }
  .tile { font-size: 10.5px; min-height: 66px; }
  .card .title { font-size: 14.5px; }
}
@media (prefers-reduced-motion: reduce) {
  .row.reveal .tile { animation: none; }
  * { transition: none !important; }
}

/* ---------- Footer links & content pages ---------- */
.footer p { margin: 6px 0 0; }
.footer-links a { font-weight: 500; color: var(--ink); text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }

.page-header {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding-top: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.logo-link {
  font-family: var(--serif); font-weight: 700; font-size: 26px; letter-spacing: -.02em; text-decoration: none;
}
.back { font-size: 14px; color: var(--ink-soft); text-decoration: none; }
.back:hover { color: var(--ink); }

.prose { max-width: 680px; padding-bottom: 40px; line-height: 1.6; }
.prose h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(30px, 6vw, 40px); line-height: 1.1; margin: 28px 0 10px; }
.prose h2 { font-family: var(--serif); font-weight: 600; font-size: 21px; margin: 30px 0 6px; }
.prose p, .prose li { color: var(--ink); }
.prose ul { padding-left: 20px; }
.prose li { margin-bottom: 6px; }
.prose a { color: var(--accent); text-underline-offset: 2px; }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--line); padding: 1px 5px; border-radius: 4px; }
.prose .note { font-size: 14px; color: var(--ink-soft); }
.prose .summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 16px; margin: 18px 0; }
.sw { padding: 0 6px; border-radius: 4px; color: #fff; font-weight: 600; white-space: nowrap; }
.sw.g { background: var(--green); } .sw.y { background: var(--yellow); color: #231b06; } .sw.x { background: var(--grey); }
