/* Cold Opens — "tonight's listings".
   Dark: a late-night broadcast (warm black, cream ink, the amber of an on-air lamp).
   Light: the printed TV guide (newsprint, black ink, listings red).
   Type: Instrument Serif for titles (the voice of the shows), IBM Plex Mono for codes and labels
   (the voice of the listing), IBM Plex Sans for interface text. All self-hosted (OFL).
   Every colour pair here is contrast-tested in tests/unit/theme.test.js. */

@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/instrument-serif-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/instrument-serif-latin-400-italic.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans';
  font-style: normal;
  font-weight: 100 700;
  font-display: swap;
  src: url('../fonts/ibm-plex-sans-latin-wght-normal.woff2') format('woff2-variations');
}

:root {
  color-scheme: dark;
  --bg: #12100e;
  --raise: #1c1916;
  --ink: #f2ece3;
  --muted: #a99f92;
  --faint: #3a342e;
  --rule: #2b2621;
  --accent: #e9b75c;
  --good: #9fc98a;
  --warm: #e9b75c;
  --glow: rgba(233, 183, 92, 0.07);

  --serif: 'Instrument Serif', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --measure: 34rem;
  --gutter: clamp(1rem, 5vw, 1.75rem);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3eee5;
    --raise: #ebe4d7;
    --ink: #1b1712;
    --muted: #625a4f;
    --faint: #c9bfae;
    --rule: #d8cfbf;
    --accent: #a33a26;
    --good: #3f6b2c;
    --warm: #8a5a12;
    --glow: rgba(163, 58, 38, 0);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.5 var(--sans);
  font-feature-settings: 'kern';
  -webkit-font-smoothing: antialiased;
}

/* A single soft pool of light at the top of the page, like the glow of a screen in a dark room. */
body::before {
  content: '';
  position: fixed;
  inset: 0 0 auto;
  height: 60vh;
  background: radial-gradient(60% 100% at 50% 0%, var(--glow), transparent 70%);
  pointer-events: none;
  z-index: -1;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 6px;
  z-index: 10;
}
.skip:focus {
  top: 1rem;
}

/* ----------------------------------------------------------------- top bar */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: max(1rem, env(safe-area-inset-top)) var(--gutter) 0.5rem;
}

.wordmark {
  font: italic 400 1.5rem/1 var(--serif);
  letter-spacing: 0.005em;
  text-decoration: none;
}

.bar-actions {
  display: flex;
  gap: 0.25rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 160ms var(--ease),
    background 160ms var(--ease);
}
.icon-btn:hover {
  color: var(--ink);
  background: var(--raise);
}
.icon-btn svg {
  width: 1.375rem;
  height: 1.375rem;
}

/* ----------------------------------------------------------------- main column */

main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.25rem var(--gutter) 2.5rem;
}

.meta {
  margin: 0 0 1.25rem;
  font: 500 0.75rem/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ----------------------------------------------------------------- the listing */

.listing {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}

.ep {
  display: grid;
  grid-template-columns: 4.75rem 1fr;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.6rem 0 0.55rem;
  border-bottom: 1px solid var(--rule);
}

.ep-code {
  font: 500 0.8125rem/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.ep-title {
  font: 400 clamp(1.35rem, 5.6vw, 1.75rem) / 1.12 var(--serif);
  letter-spacing: -0.005em;
  overflow-wrap: anywhere;
}

/* Facts that arrive late (premiere and network, lead character) read as a listing's small print. */
.ep--fact .ep-code {
  color: var(--muted);
}
.ep--fact .ep-title {
  font: italic 400 clamp(1.15rem, 4.6vw, 1.4rem) / 1.2 var(--serif);
}

/* Clues still to come: present but unreadable, so the length of the evening is visible. */
.ep--locked .ep-code {
  color: var(--faint);
}
.ep--locked .ep-code::before {
  content: attr(data-code);
}
.ep--locked .ep-title {
  height: 0.55em;
  margin-top: 0.3em;
  width: var(--w, 60%);
  border-radius: 2px;
  background: var(--raise);
  font-size: clamp(1.35rem, 5.6vw, 1.75rem);
}

/* A newly revealed clue tunes in: a quick, quiet settle rather than a flourish. */
.ep--new .ep-title,
.ep--new .ep-code {
  animation: tune-in 520ms var(--ease) both;
}
.ep--new .ep-code {
  animation-delay: 60ms;
}
@keyframes tune-in {
  0% {
    opacity: 0;
    transform: translateY(0.35rem);
    filter: blur(3px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

/* ----------------------------------------------------------------- status + guess */

.status {
  margin: 0;
  color: var(--muted);
}
.status:empty {
  display: none;
}
.status .btn {
  display: flex;
  width: fit-content;
  margin-top: 0.75rem;
}

/* The desk: errors, then the result once the game ends (before the guesses that led to it),
   then the guess box and history. */
.desk {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  margin-top: 1.5rem;
}
.result {
  order: -1;
}

.combo {
  position: relative;
}

.combo input {
  width: 100%;
  height: 3.5rem;
  padding: 0 3.75rem 0 1.1rem;
  border: 1px solid var(--faint);
  border-radius: 12px;
  background: var(--raise);
  color: var(--ink);
  font: 400 1.0625rem/1 var(--sans);
  transition: border-color 160ms var(--ease);
}
.combo input::placeholder {
  color: var(--muted);
}
.combo input:focus {
  outline: none;
  border-color: var(--accent);
}
.combo input:disabled {
  opacity: 0.6;
}

.guess-go {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: grid;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
.guess-go:disabled {
  opacity: 0.35;
  cursor: default;
}
.guess-go svg {
  width: 1.25rem;
  height: 1.25rem;
}

.options {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.4rem);
  z-index: 5;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  border: 1px solid var(--faint);
  border-radius: 12px;
  background: var(--raise);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  max-height: min(22rem, 50vh);
  overflow-y: auto;
}
.options li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
}
.options li[aria-selected='true'] {
  background: var(--bg);
}
.opt-year {
  font: 400 0.8125rem/1 var(--mono);
  color: var(--muted);
}

.guess-count {
  margin: 0.6rem 0 0;
  font: 400 0.8125rem/1.4 var(--mono);
  color: var(--muted);
}

.guesses {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}
/* One line per guess, newest first: name and year on the left, the verdicts on the right. */
.guess {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 0.75rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--rule);
}
.guess--latest .guess-name {
  color: var(--accent);
}
.guess-head {
  min-width: 0;
}
.guess-name {
  font-weight: 500;
}
.guess-year {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.8125rem;
  margin-left: 0.4rem;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.chip {
  font: 400 0.6875rem/1 var(--mono);
  letter-spacing: 0.02em;
  padding: 0.3rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--faint);
  color: var(--muted);
  white-space: nowrap;
}
.chip--good {
  border-color: var(--good);
  color: var(--good);
}

/* ----------------------------------------------------------------- result */

.result {
  padding-top: 0.5rem;
}
.result-kicker {
  margin: 0;
  font: 500 0.75rem/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.result-title {
  margin: 0.5rem 0 0.35rem;
  font: italic 400 clamp(2.4rem, 11vw, 3.4rem) / 1 var(--serif);
  letter-spacing: -0.01em;
}
.result-sub {
  margin: 0;
  color: var(--muted);
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
  align-items: center;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 3rem;
  padding: 0 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font: 500 0.9375rem/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
}
.btn svg {
  width: 1.1rem;
  height: 1.1rem;
}
.btn--quiet {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--faint);
}
.countdown {
  margin: 1.25rem 0 0;
  font: 400 0.8125rem/1.4 var(--mono);
  color: var(--muted);
}
.source {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ----------------------------------------------------------------- footer */

.foot {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.25rem var(--gutter) max(2rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
  font-size: 0.875rem;
  color: var(--muted);
}
.foot p {
  margin: 0.25rem 0;
}

/* ----------------------------------------------------------------- dialogs */

.sheet {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1.5rem 1.5rem 1.75rem;
  border: 1px solid var(--faint);
  border-radius: 16px;
  background: var(--bg);
  color: var(--ink);
}
.sheet::backdrop {
  background: rgba(10, 8, 6, 0.65);
}
.sheet[open] {
  animation: sheet-in 260ms var(--ease);
}
@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -0.5rem -0.75rem 0.5rem 0;
}
.sheet h2 {
  margin: 0;
  font: italic 400 1.9rem/1.1 var(--serif);
}
.rules {
  padding-left: 1.2rem;
}
.rules li {
  margin: 0.5rem 0;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1rem 0;
}
.stat-row div {
  text-align: center;
}
.stat-row dt {
  font: 400 0.6875rem/1.3 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-row dd {
  margin: 0 0 0.25rem;
  font: 400 2rem/1 var(--serif);
}
.dist-title {
  margin: 1rem 0 0.5rem;
  font: 500 0.75rem/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.dist {
  list-style: none;
  margin: 0;
  padding: 0;
}
.dist li {
  display: grid;
  grid-template-columns: 1.25rem 1fr;
  gap: 0.6rem;
  align-items: center;
  margin: 0.3rem 0;
  font: 400 0.8125rem/1 var(--mono);
}
.dist .bar-fill {
  display: block;
  min-width: 1.75rem;
  padding: 0.3rem 0.45rem;
  border-radius: 4px;
  background: var(--raise);
  text-align: right;
}
.dist .is-today .bar-fill {
  background: var(--accent);
  color: var(--bg);
}
.next {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

/* Author display rules must never beat the hidden attribute. */
[hidden] {
  display: none !important;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9375rem;
  white-space: pre-line;
  z-index: 20;
}

/* ----------------------------------------------------------------- about page */

.prose h1 {
  margin: 0.5rem 0 1rem;
  font: italic 400 clamp(2.4rem, 10vw, 3.2rem) / 1.05 var(--serif);
}
.prose h2 {
  margin: 2rem 0 0.5rem;
  font: 500 0.75rem/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.prose p,
.prose li {
  color: var(--ink);
}

/* ----------------------------------------------------------------- wide screens */

/* Two columns: the listing on the left stays put (sticky) while guesses and the result fill the
   right, so clues and feedback are both in view without scrolling. */
@media (min-width: 60rem) {
  .bar,
  main,
  .foot {
    max-width: calc(64rem + 2 * var(--gutter));
  }
  main {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    gap: 3.5rem;
    align-items: start;
  }
  .board {
    position: sticky;
    top: 1.25rem;
  }
  .desk {
    margin-top: 0;
    padding-top: 2.6rem; /* lines the guess box up with the first clue */
  }
  .result {
    padding-top: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Back to the other games at ringanybells.xyz: one quiet line above the bar, on every page. The
   link is relative, so it reaches the hub's home from /<game>/ and /<game>/about alike. */
.hub {
  box-sizing: border-box;
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: max(0.5rem, env(safe-area-inset-top)) var(--gutter) 0;
  font: 500 0.75rem/1 var(--mono);
  letter-spacing: 0.04em;
}
.hub a {
  display: inline-block;
  padding: 0.4rem 0;
  color: var(--muted);
  text-decoration: none;
}
.hub a:hover {
  color: var(--ink);
}
.hub + .bar {
  padding-top: 0.25rem;
}
