:root {
  --bg: #0e0e11;
  --surface: #16161a;
  --surface-2: #1d1d22;
  --border: #26262c;
  --border-strong: #35353d;
  --text: #ececef;
  --muted: #8b8b95;
  --faint: #5c5c66;
  --accent: #d9a95b;
  --accent-ink: #1a1304;
  --ok: #5fb57c;
  --ok-bg: rgba(95, 181, 124, .14);
  --bad: #c96a6a;
  --bad-bg: rgba(201, 106, 106, .12);
  --hint: #d9a95b;
  --hint-bg: rgba(217, 169, 91, .13);
  --radius: 14px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-ui); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.app { max-width: 540px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }

.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 18px 0 14px; border-bottom: 1px solid var(--border); }
.top-group { display: flex; gap: 2px; }
.top-group.right { justify-content: flex-end; }
.wordmark { margin: 0; text-align: center; font-family: var(--font-display); font-weight: 600; font-size: 28px; letter-spacing: -.01em; line-height: 1; }
.wordmark span { background: linear-gradient(180deg, #f3e3c3, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wordmark small { display: block; margin-top: 6px; font-family: var(--font-ui); font-weight: 500; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; background: transparent; border: 1px solid transparent; border-radius: 10px; color: var(--muted); transition: color .15s, background .15s, border-color .15s; }
.icon-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.banner a { color: inherit; font-weight: 600; }
.banner { margin: 14px 0 0; padding: 10px 14px; border: 1px dashed var(--accent); border-radius: 10px; color: var(--accent); font-size: 13px; text-align: center; }

main { padding-top: 22px; }

.cover-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.cover-frame { position: relative; width: min(100%, 300px); aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--surface); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 20px 50px -20px rgba(0,0,0,.8), 0 0 0 1px var(--border); }
.cover-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; opacity: 0; transition: opacity .35s ease; }
.cover-frame img.ready { opacity: 1; }
.cover-frame img.smooth { image-rendering: auto; }
.cover-skeleton { position: absolute; inset: 0; background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; }
.cover-skeleton.off { display: none; }
@keyframes shimmer { to { background-position: -200% 0; } }
.cover-frame.pop { animation: pop .45s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { 0% { transform: scale(.985); } 100% { transform: scale(1); } }

.lives { display: flex; gap: 8px; }
.lives i { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); transition: background .2s, transform .2s; }
.lives i.on { background: var(--accent); box-shadow: 0 0 10px rgba(217,169,91,.45); }
.lives i.lost { background: var(--bad); opacity: .55; }
.lives i.won { background: var(--ok); }

.search { position: relative; margin-top: 22px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; padding: 6px 6px 6px 12px; transition: border-color .15s, box-shadow .15s; }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(217,169,91,.15); }
.search-icon { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; flex: none; }
.search-box input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 8px 0; font-size: 16px; }
.search-box input::placeholder { color: var(--faint); }
.guess-btn { flex: none; padding: 9px 16px; border-radius: 9px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 14px; transition: opacity .15s, transform .1s; }
.guess-btn:disabled { opacity: .35; cursor: not-allowed; }
.guess-btn:not(:disabled):active { transform: translateY(1px); }
.results { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; margin: 0; padding: 6px; list-style: none; max-height: 320px; overflow: auto; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 24px 50px -16px rgba(0,0,0,.9); }
.results li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.results li:hover, .results li[aria-selected="true"] { background: rgba(255,255,255,.06); }
.results li.used { opacity: .4; cursor: not-allowed; }
.results .r-title { font-weight: 500; }
.results .r-title mark { background: none; color: var(--accent); }
.results .r-author { color: var(--muted); font-size: 13px; }
.results .r-year { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.results .empty { color: var(--muted); padding: 10px; font-size: 14px; cursor: default; }

.guesses { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.guess { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; animation: rise .3s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.guess.correct { border-color: rgba(95,181,124,.5); background: linear-gradient(180deg, rgba(95,181,124,.08), var(--surface)); }
.guess-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.guess-title { font-family: var(--font-display); font-size: 17px; font-weight: 500; }
.guess-n { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; border: 1px solid var(--border-strong); color: var(--muted); background: transparent; line-height: 1.2; }
.chip i { font-style: normal; font-size: 10px; }
.chip.ok { color: var(--ok); border-color: rgba(95,181,124,.4); background: var(--ok-bg); }
.chip.bad { color: var(--bad); border-color: rgba(201,106,106,.35); background: var(--bad-bg); }
.chip.hint { color: var(--hint); border-color: rgba(217,169,91,.4); background: var(--hint-bg); }
.chip.label { color: var(--faint); border-style: dashed; }
.chip-group { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sep { width: 1px; height: 16px; background: var(--border-strong); margin: 0 2px; }

.reveal { margin-top: 26px; text-align: center; animation: rise .4s ease both; }
.verdict { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.verdict.win { color: var(--ok); }
.verdict.lose { color: var(--bad); }
.book-title { margin: 8px 0 4px; font-family: var(--font-display); font-weight: 600; font-size: 28px; line-height: 1.15; letter-spacing: -.01em; }
.book-meta { margin: 0; color: var(--muted); font-size: 15px; }
.community { margin: 10px 0 0; color: var(--faint); font-size: 13px; min-height: 1em; }
.actions { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }
.btn { padding: 10px 18px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; font-size: 14px; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.synopsis { margin: 22px auto 0; text-align: left; color: #c9c9d0; font-size: 15px; line-height: 1.6; max-width: 60ch; }
.synopsis p { margin: 0 0 1em; }
.synopsis.clamped { position: relative; max-height: 9.6em; overflow: hidden; }
.synopsis.clamped::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4em; background: linear-gradient(transparent, var(--bg)); }
.synopsis-more { display: block; margin: 6px auto 0; background: none; border: 0; color: var(--accent); font-weight: 500; font-size: 14px; }
.next { margin-top: 24px; color: var(--muted); font-size: 14px; }
.next strong { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }

.finished { margin: 10px 0 0; padding: 28px 20px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.finished h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.finished p { margin: 0; color: var(--muted); }

.foot { margin-top: 40px; text-align: center; color: var(--faint); font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.foot a { color: var(--muted); text-decoration: none; }
.foot a:hover { color: var(--text); }

/* about page */
.page { padding-top: 26px; }
.page h2 { font-family: var(--font-display); font-weight: 600; font-size: 24px; margin: 34px 0 10px; letter-spacing: -.01em; scroll-margin-top: 20px; }
.page h2:first-of-type { margin-top: 10px; }
.page p, .page li { color: #c9c9d0; font-size: 15px; line-height: 1.6; }
.page ul { padding-left: 20px; }
.page .lede { font-size: 17px; color: var(--text); }
.page .back { display: inline-block; margin-top: 30px; }
.page code { font-size: 13px; background: var(--surface-2); padding: 1px 6px; border-radius: 5px; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(5,5,8,.7); backdrop-filter: blur(6px); animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal-card { position: relative; width: 100%; max-width: 440px; max-height: 90dvh; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; padding: 24px 22px; box-shadow: 0 40px 80px -30px rgba(0,0,0,.9); animation: rise .2s ease; }
.modal-card h2 { margin: 0 0 12px; font-family: var(--font-display); font-weight: 600; font-size: 24px; }
.modal-card h3 { margin: 22px 0 10px; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.modal-card p { color: #c9c9d0; line-height: 1.55; font-size: 15px; }
.modal-card .close { position: absolute; top: 12px; right: 12px; }
.help-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 9px; color: #c9c9d0; font-size: 14px; line-height: 1.45; }
.help-list li { display: flex; gap: 10px; align-items: center; }
.help-list .chip { flex: none; }
.help-list b { color: var(--ok); }
.arrow, .chip i { font-style: normal; font-family: var(--font-ui); font-size: 10px; line-height: 1; display: inline-block; vertical-align: 1px; }
.help-list .arrow { color: var(--hint); font-size: 11px; }
#modal-help p { margin: 8px 0; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { text-align: center; background: var(--surface-2); border-radius: 12px; padding: 12px 4px; }
.stat b { display: block; font-family: var(--font-display); font-weight: 600; font-size: 26px; line-height: 1; }
.stat span { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.dist { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.dist-row .k { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.dist-row .bar { height: 20px; min-width: 22px; display: flex; align-items: center; justify-content: flex-end; padding: 0 7px; border-radius: 5px; background: var(--border-strong); font-size: 12px; font-weight: 600; color: var(--text); }
.dist-row .bar.hl { background: var(--accent); color: var(--accent-ink); }
.dist-row .bar.fail { background: var(--bad-bg); color: var(--bad); border: 1px solid rgba(201,106,106,.35); }
.recent { margin-top: 18px; color: var(--muted); font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); opacity: 0; background: #f0f0f3; color: #121216; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 420px), (max-height: 600px) {
  .wordmark { font-size: 24px; }
  .modal-card { padding: 18px 16px; border-radius: 14px; }
  .modal-card h2 { font-size: 20px; margin-bottom: 8px; }
  .modal-card p { font-size: 14px; line-height: 1.45; }
  .help-list { font-size: 13.5px; gap: 8px; margin: 10px 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .guess-title { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* past games */
.archive-intro { margin-top: 0; }
.archive-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 50dvh; overflow: auto; }
.archive-list li a { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; background: var(--surface-2); border: 1px solid transparent; }
.archive-list li a:hover { border-color: var(--border-strong); }
.archive-list li.current a { border-color: var(--accent); }
.archive-list .a-no { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.archive-list .a-date { color: var(--muted); font-size: 13px; margin-left: 8px; }
.archive-list .empty { color: var(--muted); font-size: 14px; padding: 8px 0; }
.chip.won { color: var(--ok); border-color: rgba(95,181,124,.4); background: var(--ok-bg); }
.chip.lost { color: var(--bad); border-color: rgba(201,106,106,.35); background: var(--bad-bg); }
.chip.progress { color: var(--hint); border-color: rgba(217,169,91,.4); background: var(--hint-bg); }
.next a { color: var(--accent); text-decoration: none; }
