:root {
  --bg: #111d29; --panel: #1b2a38; --panel-line: #3d4d5c; --ink: #f3e8cf; --muted: #b9c6cf; --gold: #d5ae70; --gold-soft: #dfbd81;
  --card: #2c2340; --card-line: #6d5a92; --good: #1f4f78; --good-line: #7fb2dc; --wolf: #6b1f24; --wolf-line: #e07a6f;
  --scope: #f2c86b; --ok: #5fae6e; --bad: #c8483f; --assist: #d9b34a; --start: #d9d4c7; --none: #2b3140;
  --dock: 132px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: radial-gradient(ellipse at top, #1d2c40 0%, var(--bg) 60%) fixed, var(--bg); color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  padding-bottom: calc(var(--dock) + env(safe-area-inset-bottom)); }
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #8bcbd8; outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; max-width: 640px; margin: 0 auto; padding: 14px 16px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; letter-spacing: .03em; min-width: 0; }
.brand img { border-radius: 9px; flex: none; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex: none; }
.ghost { background: transparent; border: 1px solid #536170; border-radius: 999px; color: #c8ced2; min-height: 40px; min-width: 40px; padding: 6px 14px; }
.loading { text-align: center; color: var(--muted); padding: 60px 16px; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px 20px; }
.case { text-align: center; padding: 8px 0 12px; }
.case h1 { margin: 0; font-size: 26px; letter-spacing: .02em; color: var(--gold-soft); }
.case-meta { margin: 2px 0 8px; color: var(--muted); display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.tier { color: var(--gold); }
.archive { background: #253441; border: 1px solid #55636b; border-radius: 10px; padding: 8px 12px; font-size: 13px; color: #c2cbd0; }
.archive a { color: var(--gold-soft); }
.status { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; font-size: 14px; color: #dfe4e8; }
.lives { color: #e86b62; letter-spacing: 2px; font-size: 16px; }
.clock-wrap { font-variant-numeric: tabular-nums; }

/* The whole board fits one screen: width follows the rows that must stay visible. */
.board { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; margin: 4px auto 0;
  width: min(100%, calc(var(--cols) * 118px), max(250px, calc((100svh - 360px) * var(--cols) / var(--rows) * 0.66))); }
.card { container-type: inline-size; position: relative; aspect-ratio: 108 / 156; border-radius: 10px; border: 2px solid var(--card-line); background: linear-gradient(180deg, #3a2d55, var(--card));
  padding: 0; overflow: hidden; display: flex; flex-direction: column; align-items: stretch; text-align: center; color: var(--ink);
  transition: transform .12s ease, box-shadow .2s ease; -webkit-tap-highlight-color: transparent; }
.card:active { transform: scale(.97); }
.card img { width: 100%; flex: 1 1 auto; min-height: 0; object-fit: cover; object-position: top; display: block; }
.card .name { font-weight: 700; font-size: 13px; line-height: 1.25; padding: 2px 3px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: #0006; }
.card .job { font-size: 11px; color: #d3c7e8; padding: 0 3px 3px; background: #0006; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .coord { position: absolute; top: 3px; left: 4px; font-size: 10px; color: #ffffffb0; text-shadow: 0 1px 2px #000; z-index: 1; }
.card .badge { position: absolute; top: 3px; right: 3px; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 999px; z-index: 1; }
.card.good { border-color: var(--good-line); background: linear-gradient(180deg, #2c618f, var(--good)); }
.card.good img { flex: 0 0 34%; filter: saturate(.8); }
.card.good .badge { background: #cfe6f7; color: #13324b; }
.card .quote { flex: 1 1 auto; min-height: 0; font-size: 11px; line-height: 1.3; padding: 3px 4px; overflow: hidden; color: #f4f8fb; background: #0b2238aa;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; text-align: left; }
.card.wolf { border-color: var(--wolf-line); background: linear-gradient(180deg, #8a2a31, var(--wolf)); }
.card.wolf img { filter: grayscale(.5) sepia(.6) hue-rotate(-30deg) saturate(1.6) brightness(.8); }
.card.wolf .badge { background: #f6c2bd; color: #4a1015; }
.card.missed::after { content: "✕"; position: absolute; bottom: 30px; right: 4px; font-size: 14px; font-weight: 700; color: #ffb3ab; text-shadow: 0 1px 3px #000; }
.card.scoped { box-shadow: 0 0 0 3px var(--scope), 0 0 14px #f2c86b88; }
.card.source { box-shadow: 0 0 0 3px #fff, 0 0 16px #ffffff88; }
.card .mark { display: none; }
.board[data-size="dense"] { gap: 4px; }
.board[data-size="dense"] .card { border-radius: 7px; border-width: 1.5px; }
/* Narrow cards keep the face readable; testimony moves to the focus bar and list. */
@container (max-width: 92px) {
  .name { font-size: 11px !important; }
  .job { font-size: 9px !important; }
  .quote { display: none !important; }
  .coord, .badge { font-size: 9px !important; }
  .mark { display: block !important; position: absolute; bottom: 30px; left: 4px; font-size: 18px; line-height: 1; color: #cfe6f7; text-shadow: 0 1px 3px #000; }
}
body[data-mode="good"] .card:not(.good):not(.wolf) { border-color: var(--good-line); }
body[data-mode="wolf"] .card:not(.good):not(.wolf) { border-color: var(--wolf-line); }

.clues { margin-top: 18px; background: var(--panel); border: 1px solid var(--panel-line); border-radius: 14px; padding: 12px 12px 6px; }
.clues h2 { margin: 0; font-size: 16px; color: var(--gold-soft); }
.hint { margin: 2px 0 8px; color: var(--muted); font-size: 12px; }
#clue-list { list-style: none; margin: 0; padding: 0; }
.clue { width: 100%; text-align: left; background: #ffffff08; border: 1px solid transparent; border-radius: 10px; padding: 8px 10px; margin-bottom: 6px; display: grid; gap: 2px; }
.clue strong { font-size: 12px; color: var(--gold); font-weight: 600; }
.clue.active { border-color: var(--scope); background: #f2c86b14; }

.dock { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: linear-gradient(180deg, #111d2900, #0b131c 30%); padding: 14px 16px calc(12px + env(safe-area-inset-bottom)); }
.focus { margin: 0 auto 8px; max-width: 520px; min-height: 2.6em; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 14px; line-height: 1.3; color: #e8edf2; background: #1b2a38ee; border: 1px solid var(--panel-line); border-radius: 12px; padding: 6px 12px; }
.focus strong { color: var(--gold); font-weight: 600; margin-right: 6px; white-space: nowrap; }
.focus.clue { border-color: var(--scope); }
.modes { display: grid; grid-template-columns: 1fr 1fr; max-width: 420px; margin: 0 auto; border-radius: 999px; overflow: hidden; border: 2px solid #c9a464; box-shadow: 0 8px 24px #0008; }
.mode { min-height: 52px; border: 0; font-size: 17px; font-weight: 700; letter-spacing: .04em; color: #e9eef5; }
.mode.good { background: #1e3f61; }
.mode.wolf { background: #5a1b20; }
.mode.good[aria-pressed="true"] { background: #2f72b0; box-shadow: inset 0 0 0 3px #cfe6f7; }
.mode.wolf[aria-pressed="true"] { background: #b0323a; box-shadow: inset 0 0 0 3px #f6c2bd; }
.pulse { animation: pulse .5s ease; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.toast { position: fixed; left: 50%; bottom: calc(var(--dock) + 14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6; max-width: min(92vw, 520px);
  background: #22303d; border: 1px solid #55636b; border-radius: 12px; padding: 10px 14px; font-size: 14px; box-shadow: 0 10px 30px #000a; text-align: center; }
.toast[data-tone="bad"] { border-color: var(--bad); }
.toast[data-tone="wolf"] { border-color: var(--wolf-line); }
.toast[data-tone="good"] { border-color: var(--good-line); }

.overlay { position: fixed; inset: 0; z-index: 10; background: #050a10cc; display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.sheet { width: min(100%, 420px); background: linear-gradient(180deg, #1f2f40, #152230); border: 1px solid #c9a464; border-radius: 18px; padding: 22px 20px; text-align: center; box-shadow: 0 30px 60px #000c; }
.sheet h2 { margin: 4px 0 12px; color: var(--gold-soft); font-size: 22px; line-height: 1.35; }
.rules { white-space: pre-line; text-align: left; color: #dfe4e8; margin: 0 0 18px; }
.primary, .secondary { display: block; width: 100%; min-height: 50px; border-radius: 12px; font-weight: 700; margin-top: 10px; text-decoration: none; line-height: 50px; }
.primary { background: var(--gold-soft); color: #182331; border: 0; }
.secondary { background: transparent; color: var(--ink); border: 1px solid #8a7652; line-height: 48px; }
.text { background: none; border: 0; color: var(--muted); margin-top: 8px; min-height: 40px; text-decoration: underline; text-underline-offset: 3px; }
.result-case { margin: 0; color: var(--muted); font-size: 13px; }
#result[data-outcome="failed"] h2 { color: #f0a090; }
.stats { display: flex; justify-content: center; gap: 36px; margin: 6px 0 14px; }
.stats div { display: grid; }
.stats strong { font-size: 30px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--muted); }
.result-grid { display: grid; grid-template-columns: repeat(var(--cols), 18px); gap: 4px; justify-content: center; margin: 0 auto 8px; }
.result-grid i { width: 18px; height: 18px; border-radius: 4px; display: block; }
.result-grid .ok { background: var(--ok); } .result-grid .wrong { background: var(--bad); } .result-grid .assist { background: var(--assist); }
.result-grid .start { background: var(--start); } .result-grid .none { background: var(--none); }
.streak { color: var(--gold); min-height: 1.4em; margin: 4px 0; }
.rate { margin: 6px 0 4px; }
.rate p { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.rate div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rate button { min-height: 42px; border-radius: 10px; border: 1px solid #55636b; background: #ffffff0d; color: var(--ink); font-weight: 600; }
.rate-thanks { color: var(--gold); font-size: 13px; margin: 6px 0; }
.app-link { display: block; margin-top: 14px; color: var(--gold-soft); font-size: 14px; }
.countdown { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

@media (max-width: 380px) {
  .case h1 { font-size: 22px; }
  .card .name { font-size: 12px; }
  .card .quote { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) { .card, .pulse { transition: none; animation: none; } }
