:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --border: #e2e1dc;
  --text: #1d1c1a;
  --muted: #6b6862;
  --accent: #b8562f;
  --accent-soft: #fdf0e9;
  --term-underline: #d9a68d;
  /* The transcript highlight carries its own colours: it sits on body text and
     has to be findable at a glance, so it runs darker than the soft
     --term-underline used for badge and toggle borders. */
  --term-mark: #a8471f;
  --term-mark-bg: #f7e3d6;
  --term-mark-bg-hover: #f0c9b1;
  --active: #fff6ec;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.07);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17161a;
    --surface: #1f1e23;
    --surface-2: #27262c;
    --border: #35333b;
    --text: #eceaf0;
    --muted: #9d99a6;
    --accent: #f0906a;
    --accent-soft: #33241e;
    --term-underline: #8a5843;
    --term-mark: #ff9e77;
    --term-mark-bg: #45291d;
    --term-mark-bg-hover: #5c3826;
    --active: #2a2119;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 40;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.02em;
  text-decoration: none;
  font-size: 17px;
}

.brand span {
  color: var(--accent);
}

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: 20px;
  font-size: 14px;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-header nav a:hover,
.site-header nav a[aria-current="page"] {
  color: var(--text);
}

/* ---------- index ---------- */

.page-intro {
  padding: 56px 0 32px;
  max-width: 640px;
}

.page-intro h1 {
  font-size: 34px;
  line-height: 1.2;
  letter-spacing: -0.025em;
  margin: 0 0 12px;
}

.page-intro p {
  color: var(--muted);
  margin: 0;
}

.category {
  padding-bottom: 40px;
}

.category:last-of-type {
  padding-bottom: 64px;
}

.category-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border, rgba(128, 128, 128, 0.2));
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-title .count {
  font-weight: 400;
  letter-spacing: 0;
  opacity: 0.6;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.video-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.video-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.video-card .thumb {
  aspect-ratio: 16 / 9;
  background: var(--surface-2) center / cover no-repeat;
  border-bottom: 1px solid var(--border);
}

.video-card .body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.video-card h2 {
  font-size: 16px;
  margin: 0;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.video-card .meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  color: var(--muted);
  margin-bottom: 64px;
}

.empty-state code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 4px;
  color: var(--text);
}

.badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--term-underline);
}

/* ---------- video page ---------- */

.video-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
  padding: 28px 0 80px;
}

@media (max-width: 1000px) {
  .video-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }
}

.stage {
  position: sticky;
  top: 80px;
}

@media (max-width: 1000px) {
  .stage {
    position: static;
  }
}

.player-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.player-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.no-player {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 24px;
}

.no-player p {
  margin: 0;
  color: #9d99a6;
  font-size: 14px;
  text-align: center;
  max-width: 42ch;
}

.no-player code {
  font-family: var(--mono);
  font-size: 13px;
  color: #eceaf0;
}

.video-title {
  font-size: 24px;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 20px 0 8px;
}

.video-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.video-meta a {
  color: var(--muted);
}

.video-description {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 20px;
}

.notice {
  border: 1px solid var(--term-underline);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 20px;
}

/* term chips under the player */

.terms-panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.term-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  padding: 0 2px 2px 0;
  margin: 0;
  /* Capped so a video with a hundred terms cannot push the player out of
     the sticky column and off the screen. */
  max-height: 168px;
  overflow-y: auto;
}

.term-chips button {
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 3px 10px;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.term-chips button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.term-chips .count {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- transcript ---------- */

.transcript-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.transcript-head h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0;
  font-weight: 600;
}

.toggle {
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  margin-left: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 99px;
  padding: 3px 10px;
}

.toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--term-underline);
  background: var(--accent-soft);
}

.transcript {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

@media (max-width: 1000px) {
  .transcript {
    max-height: none;
  }
}

.line {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 10px;
  padding: 7px 8px;
  border-radius: 7px;
  margin: 0;
  scroll-margin-top: 12px;
}

.line.is-active {
  background: var(--active);
}

.line .ts {
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 3px 0 0;
  cursor: pointer;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.line .ts:hover {
  color: var(--accent);
  text-decoration: underline;
}

.line.is-active .ts {
  color: var(--accent);
}

.term {
  background: var(--term-mark-bg);
  color: var(--term-mark);
  border-bottom: 2px solid var(--term-mark);
  cursor: help;
  border-radius: 2px;
  padding: 0 2px;
}

.term:hover,
.term:focus-visible,
.term.is-open {
  background: var(--term-mark-bg-hover);
  outline: none;
}

.term.is-flash {
  animation: flash 1.2s ease-out;
}

@keyframes flash {
  from {
    background: var(--accent);
    color: var(--surface);
  }
}

body.hide-terms .term {
  border-bottom-color: transparent;
  background: none;
  color: inherit;
  cursor: text;
  pointer-events: none;
}

/* ---------- definition popover ---------- */

.popover {
  position: absolute;
  z-index: 100;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0;
  visibility: hidden;
  transform: translateY(3px);
  transition: opacity 0.12s, transform 0.12s, visibility 0.12s;
}

.popover.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.popover .pop-term {
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.popover .pop-category {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.popover .pop-def {
  color: var(--text);
  margin: 0;
}

.popover .pop-links {
  margin-top: 8px;
  font-size: 13px;
  display: flex;
  gap: 12px;
}

.popover .pop-links a {
  color: var(--accent);
  text-decoration: none;
}

.popover .pop-links a:hover {
  text-decoration: underline;
}

/* ---------- glossary ---------- */

.glossary-section {
  padding-bottom: 40px;
}

.glossary-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin: 0 0 16px;
}

.glossary-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin: 0;
}

.glossary-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.glossary-item dt {
  font-weight: 650;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.glossary-item .count {
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

.glossary-item dd {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.glossary-item .aliases {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 0 40px;
  font-size: 13px;
  color: var(--muted);
}
