:root {
  --ink: #0a0a0a;
  --paper: #ececec;
  --dim: #8a8a8a;
  --faint: #3a3a3a;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --type: "Courier Prime", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

/* Nothing on the page is meant to scroll sideways. clip, unlike hidden, keeps
   the sticky top bar working. */
html { overflow-x: clip; }

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--type);
  -webkit-font-smoothing: antialiased;
}

/* A spotlight from above: a soft beam, a pool of light where the question
   sits, and dark edges. The beam sways very slowly. */
.spotlight {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  background: radial-gradient(ellipse 80% 70% at 50% 45%, transparent 35%, rgba(0, 0, 0, 0.75) 100%);
}

.spotlight::before {
  content: "";
  position: absolute;
  inset: -10% -50% 0;
  transform-origin: 50% 0;
  /* 0deg points up, so a beam centred on 180deg points straight down. */
  background: conic-gradient(
    from 160deg at 50% 0,
    transparent 0deg,
    rgba(255, 255, 255, 0.045) 10deg,
    rgba(255, 255, 255, 0.075) 20deg,
    rgba(255, 255, 255, 0.045) 30deg,
    transparent 40deg
  );
  -webkit-mask-image: linear-gradient(to bottom, #000 5%, rgba(0, 0, 0, 0.6) 55%, transparent 95%);
  mask-image: linear-gradient(to bottom, #000 5%, rgba(0, 0, 0, 0.6) 55%, transparent 95%);
  filter: blur(10px);
  animation: sway 18s ease-in-out infinite alternate;
}

.spotlight::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 40% 32% at 50% 58%, rgba(255, 255, 255, 0.07), transparent 70%);
}

@keyframes sway {
  from { transform: rotate(-2.5deg); }
  to { transform: rotate(2.5deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spotlight::before { animation: none; }
}

/* Film grain. The texture is twice the screen so it can jitter without
   showing an edge; the frame clips it, or mobile browsers widen the page
   to fit it and let it scroll sideways. */
.grain {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.grain::before {
  content: "";
  position: absolute;
  inset: -50%;
  opacity: 0.09;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 0.6s steps(3) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-3%, 2%); }
  66% { transform: translate(2%, -3%); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .grain::before { animation: none; }
}

.top, .stage, .credits { position: relative; z-index: 2; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 24px clamp(16px, 5vw, 48px);
  border-bottom: 1px solid var(--faint);
}

.mark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.mark em { font-weight: 500; text-transform: none; letter-spacing: 0; }

.top-right { display: flex; align-items: baseline; gap: 24px; }

.score { color: var(--dim); font-size: 0.95rem; font-variant-numeric: tabular-nums; }

.link-btn {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--paper);
  font: inherit;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--paper);
  cursor: pointer;
}

.link-btn:hover { color: #fff; border-color: #fff; }

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 4px;
}

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: clamp(24px, 6vh, 72px) clamp(16px, 5vw, 48px);
}

.case { width: 100%; max-width: 760px; min-width: 0; }

/* During play the page is one screen tall. fitCase() (shared.js) lowers --fit
   from 1 until the case fits its stage; type shrinks more gently than spacing.
   Only if it still doesn't fit does the stage scroll. */
.case { --fit: 1; --fit-text: calc(0.5 + var(--fit) / 2); }

body[data-mode="solo"],
body[data-mode="versus"] { height: 100dvh; }

body[data-mode="solo"] .stage,
body[data-mode="versus"] .stage {
  min-height: 0;
  overflow-y: auto;
  padding-block: clamp(16px, 4vh, 48px);
}

.case-meta {
  margin: 0 0 calc(20px * var(--fit));
  color: var(--dim);
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.question {
  margin: 0 0 calc(36px * var(--fit));
  font-family: var(--serif);
  font-weight: 500;
  font-size: calc(clamp(1.6rem, 4.2vw, 2.5rem) * var(--fit));
  line-height: 1.25;
  text-wrap: balance;
}

.choices {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: calc(12px * var(--fit));
}

.choice {
  width: 100%;
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: calc(16px * var(--fit)) 20px;
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--faint);
  font: inherit;
  font-size: calc(1.05rem * var(--fit-text));
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms, background-color 120ms, color 120ms;
}

.choice .key { color: var(--dim); min-width: 1ch; }

.choice:hover:not(:disabled) { border-color: var(--paper); }

.choice:disabled { cursor: default; }

.choice.is-correct {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.choice.is-correct .key { color: var(--ink); }

.choice.is-wrong {
  color: var(--dim);
  text-decoration: line-through;
  border-color: var(--dim);
}

.choice.is-other { color: var(--faint); border-color: #1e1e1e; }
.choice.is-other .key { color: var(--faint); }

.after {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: calc(16px * var(--fit));
  margin-top: calc(28px * var(--fit));
}

.after[hidden] { display: none; }

.finding { flex: 1 1 320px; }

.explain {
  margin: 10px 0 0;
  max-width: 60ch;
  color: #b4b4b4;
  font-size: calc(0.95rem * var(--fit-text));
  line-height: 1.6;
}

.explain[hidden] { display: none; }

.verdict {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: calc(1.25rem * var(--fit-text));
}

.next {
  padding: calc(14px * var(--fit)) 28px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--paper);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
}

.next:hover { background: #fff; }

.credits {
  padding: 20px clamp(16px, 5vw, 48px) 28px;
  color: #5a5a5a;
  font-size: 0.75rem;
  line-height: 1.6;
}

.credits a { color: inherit; }

/* The sources are credited on the home page; play keeps the whole screen. */
body:not([data-mode="home"]) .credits { display: none; }

/* Panels: categories and history */

.panel {
  width: min(820px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 0 0 auto;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-left: 1px solid var(--faint);
  font-family: var(--type);
  overflow-y: auto;
}

.panel::backdrop { background: rgba(0, 0, 0, 0.75); }

.panel-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 24px clamp(16px, 4vw, 36px) 16px;
  background: var(--ink);
  border-bottom: 1px solid var(--faint);
}

.panel-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.6rem;
}

.panel-summary {
  margin: 0;
  padding: 16px clamp(16px, 4vw, 36px) 0;
  color: var(--dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 8px clamp(16px, 4vw, 36px) 40px;
}

.panel-bar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-right: clamp(16px, 4vw, 36px);
}

.panel-actions { display: flex; gap: 20px; }

.link-btn.small { font-size: 0.8rem; }

.cat-list {
  list-style: none;
  margin: 0;
  padding: 12px clamp(16px, 4vw, 36px) 40px;
}

.cat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid #1e1e1e;
  cursor: pointer;
}

.cat input {
  appearance: none;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid var(--dim);
  background: transparent;
  cursor: pointer;
}

.cat input:checked {
  background: var(--paper);
  border-color: var(--paper);
  box-shadow: inset 0 0 0 3px var(--ink);
}

.cat input:focus-visible { outline: 2px solid var(--paper); outline-offset: 3px; }

.cat-name {
  flex: 1;
  font-family: var(--serif);
  font-size: 1.2rem;
}

.cat input:not(:checked) ~ .cat-name { color: var(--dim); }

.cat-count {
  color: var(--dim);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  /* Keep the bar in reach while scrolling. Translucent so the grain still
     shows through; z-index lifts it over the stage it slides past. */
  .top {
    flex-wrap: wrap;
    row-gap: 8px;
    padding-block: 14px;
    position: sticky;
    top: 0;
    z-index: 3;
    background: rgba(10, 10, 10, 0.92);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  .top-right { gap: 14px; }
  /* Small enough to keep the bar on one row, leaving the height to the case. */
  .mark { font-size: 1.15rem; }
  .top .link-btn, .score { font-size: 0.8rem; letter-spacing: 0.08em; }
  .case-meta { font-size: 0.75rem; letter-spacing: 0.12em; }
}

.entry {
  padding: 20px 0;
  border-bottom: 1px solid #1e1e1e;
}

.entry-meta {
  margin: 0 0 8px;
  color: var(--dim);
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.entry-q {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.35;
}

.entry dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 0.95rem;
}

.entry dt { color: var(--dim); }
.entry dd { margin: 0; }

.entry-x {
  margin: 12px 0 0;
  color: #9a9a9a;
  font-size: 0.9rem;
  line-height: 1.6;
}
.entry.wrong .yours { text-decoration: line-through; color: var(--dim); }
.entry .mark-ok, .entry .mark-x { margin-left: 8px; }

.empty { color: var(--dim); padding: 24px 0; }

/* ---------- Shared ---------- */

[hidden] { display: none !important; }

.mark a { color: inherit; text-decoration: none; }

body:not([data-mode="solo"]) .solo-only { display: none; }

.ghost {
  padding: 14px 24px;
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--paper);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
}

.ghost:hover { background: rgba(255, 255, 255, 0.06); }

.next:disabled,
.ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.choice .label { flex: 1; }

/* Typed answers (solo) */
.typed {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(12px * var(--fit)) 16px;
}

.typed[hidden] { display: none; }

.typed input {
  flex: 1 1 240px;
  min-width: 0;
  padding: calc(16px * var(--fit)) 20px;
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--faint);
  border-radius: 0;
  font: inherit;
  /* 16px or more, or iOS zooms in on focus */
  font-size: max(16px, calc(1.05rem * var(--fit-text)));
}

.typed input:focus { outline: none; border-color: var(--paper); }
.typed input:disabled { opacity: 1; -webkit-text-fill-color: currentColor; }

.typed input.is-correct {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.typed input.is-wrong {
  color: var(--dim);
  text-decoration: line-through;
  border-color: var(--dim);
}

/* What the other players typed, shown at the reveal (multiplayer) */
.guesses {
  list-style: none;
  margin: calc(16px * var(--fit)) 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
  font-size: calc(0.95rem * var(--fit-text));
}

.guesses[hidden] { display: none; }
.guess { display: flex; gap: 12px; }
.guess-name { min-width: 8ch; color: var(--dim); }
.guess.is-wrong .guess-text { color: var(--dim); text-decoration: line-through; }
.guess.is-missing .guess-text { color: var(--faint); font-style: italic; }

.choice.is-picked {
  border-color: var(--paper);
  box-shadow: inset 0 0 0 1px var(--paper);
}

/* ---------- Home ---------- */

.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.mode {
  display: grid;
  gap: 10px;
  padding: 28px 24px;
  border: 1px solid var(--faint);
  color: var(--paper);
  text-decoration: none;
  transition: border-color 120ms, background-color 120ms;
}

.mode:hover { border-color: var(--paper); background: rgba(255, 255, 255, 0.03); }

.mode-name {
  font-family: var(--serif);
  font-size: 1.6rem;
}

.mode-desc { color: var(--dim); font-size: 0.95rem; line-height: 1.5; }

/* ---------- Multiplayer: entry & lobby ---------- */

.vs-form { display: grid; gap: 24px; }

.field { display: grid; gap: 8px; }

.field-label {
  color: var(--dim);
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.field input,
.share input {
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  color: var(--paper);
  border: 1px solid var(--faint);
  border-radius: 0;
  font: inherit;
  font-size: 1.05rem;
}

.field input:focus,
.share input:focus { outline: none; border-color: var(--paper); }

.code-field { width: 9ch; }
.code-field input { letter-spacing: 0.3em; text-transform: uppercase; }

.vs-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 16px;
}

.vs-or { color: var(--dim); padding-bottom: 16px; }

.vs-error { min-height: 1.5em; margin: 20px 0 0; font-family: var(--serif); font-style: italic; }

.room-code {
  margin: 0 0 20px;
  font-family: var(--serif);
  font-size: clamp(3rem, 12vw, 5rem);
  letter-spacing: 0.2em;
}

.share { display: flex; gap: 16px; align-items: baseline; margin-bottom: 32px; }
.share input { flex: 1; min-width: 0; font-size: 0.9rem; color: var(--dim); }

.vs-players { list-style: none; margin: 0 0 28px; padding: 0; border-top: 1px solid #1e1e1e; }

.vs-player {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid #1e1e1e;
}

.vs-player-name { font-family: var(--serif); font-size: 1.25rem; }
.vs-player-tags { color: var(--dim); font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; }
.vs-player.empty { color: var(--dim); font-style: italic; }

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 28px;
  padding: 0;
}

.chip {
  padding: 8px 14px;
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--faint);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.chip.is-on { background: var(--paper); color: var(--ink); border-color: var(--paper); }

.vs-wait, .vs-status { min-height: 1.5em; margin: calc(24px * var(--fit)) 0; color: var(--dim); }

/* ---------- Multiplayer: match ---------- */

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: calc(20px * var(--fit));
}

.vs-score { display: grid; gap: 4px; }
.vs-score:last-child { text-align: right; }
.vs-score-name { color: var(--dim); font-size: 0.85rem; letter-spacing: 0.08em; }
.vs-score.is-you .vs-score-name { color: var(--paper); }
.vs-answered { color: var(--dim); }

.vs-score-points {
  font-family: var(--serif);
  font-size: calc(2rem * var(--fit-text));
  font-variant-numeric: tabular-nums;
}

.standings { margin: 8px 0 36px; }
.standings .vs-player { align-items: baseline; color: var(--dim); }
.standings .vs-player.is-you { color: var(--paper); }
.standings .vs-player-name { white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.vs-standing-points { font-family: var(--serif); font-size: 1.5rem; font-variant-numeric: tabular-nums; }

.timer { display: grid; gap: 8px; margin-bottom: calc(28px * var(--fit)); }
.timer-clock { min-height: 1.2em; color: var(--dim); font-size: 0.85rem; text-align: right; font-variant-numeric: tabular-nums; }
.timer-track { height: 2px; background: #1e1e1e; overflow: hidden; }

.timer-bar {
  height: 100%;
  background: var(--paper);
  transform-origin: left;
  transform: scaleX(0);
}

.timer-bar.is-low { animation: flicker 0.5s steps(2) infinite; }

@keyframes flicker {
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .timer-bar.is-low { animation: none; }
}

#vs-reveal { margin-top: calc(28px * var(--fit)); }

.pick-tag {
  margin-left: auto;
  padding-left: 12px;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
}

/* ---------- Settings ---------- */

.segments {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0 0 24px;
  padding: 0;
}

.segment {
  min-width: 64px;
  padding: 10px 16px;
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--faint);
  margin-left: -1px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.segments li:first-child .segment { margin-left: 0; }
.segment:hover:not(.is-on) { color: var(--paper); }

.segment.is-on {
  position: relative;
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
}

.setting .case-meta { margin-bottom: 12px; }

.vs-settings { margin: 0 0 28px; color: var(--dim); line-height: 1.6; }

.panel-section { padding: 16px clamp(16px, 4vw, 36px) 0; }
.panel-section .panel-summary { padding: 0 0 12px; }
.panel-section .segments { margin-bottom: 8px; }
.panel-note { margin: 4px 0 8px; color: var(--dim); font-size: 0.85rem; line-height: 1.5; }

#solo-case .timer { margin-bottom: 24px; }
#solo-summary .explain { margin: 0 0 32px; font-size: 1.05rem; }

/* "All" toggles every category */
.cat-all .cat-name { font-style: italic; }

/* Some but not all ticked: a short dash */
.cat input:indeterminate {
  border-color: var(--paper);
  background: linear-gradient(var(--paper), var(--paper)) center / 8px 2px no-repeat;
}

.chip-all { font-style: italic; }
