/* ============================================================================
   BulkTranscripts design system — warm bone canvas, hairline grid

   Structure comes from 1px rules dividing content into cells, not from floating
   cards with shadows. Shadows are near-absent by design: on a light canvas they
   read as dirt rather than depth.

   Colour is contrast-led:
     brand  #5b3fd9 — white text 6.65:1, on canvas 6.00:1
     ink    #16181d — 16.03:1 on canvas
     ink-2  #5a5f6b — 5.77:1
   Data series use the palette's LIGHT column (#2a78d6 blue, #eb6834 orange);
   the dark-mode steps were validated against a dark surface and would fail here.
   ========================================================================== */

:root {
  /* surfaces — warm bone canvas, cells sit a shade lighter than the page */
  --bg: #f4f1ea;
  --surface-1: #fbf9f5;
  --surface-2: #f0ece2;
  --surface-3: #e7e2d5;

  /* ink */
  --ink: #0a0f2c;
  --ink-2: #545a70;
  --ink-3: #828799;

  /* lines — the hairline grid is the structure, so it must stay quiet */
  --line: #e0dbd0;
  --line-2: #cfc9bb;

  /* brand — sampled from the logo so UI and mark cannot drift apart */
  --brand: #6054f0;          /* brand violet · white text 5.22:1 */
  --brand-ink: #4a41e0;      /* darker step for links on the bone canvas */
  --brand-wash: rgba(96, 84, 240, 0.10);
  --navy: #040a2d;           /* logo navy, used as the ink base */

  /* data series — the palette's LIGHT column (dark steps would vanish here) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-wash: rgba(42, 120, 214, 0.11);

  /* status — reserved, never used as a series color */
  --good: #0ca30c;
  --good-ink: #067a06;
  --warning: #b57500;
  --critical: #d03b3b;
  --critical-ink: #b02c2c;

  /* geometry */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  --shadow-1: 0 1px 2px rgba(26, 24, 18, 0.05);
  --shadow-2: 0 10px 28px -14px rgba(26, 24, 18, 0.18);
  --shadow-3: 0 20px 48px -20px rgba(26, 24, 18, 0.26);

  /* motion — built-in easings are too weak; these have the punch */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background:
    radial-gradient(1100px 520px at 78% -200px, rgba(96, 84, 240, 0.05), transparent 62%),
    radial-gradient(820px 440px at 12% -160px, rgba(235, 104, 52, 0.04), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--ink-2); }

::selection { background: rgba(42, 120, 214, 0.22); }

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

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, 0.86);
  backdrop-filter: blur(12px) saturate(140%);
}

.brand { display: flex; align-items: center; gap: 10px; }
/* Brand lockup — the supplied logo, used as-is so it never drifts from the asset. */
.brand-lockup { display: block; height: 26px; width: auto; }
.brand-mark { display: grid; place-items: center; flex-shrink: 0; }
.brand-mark img { display: block; height: 26px; width: auto; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand-tag {
  color: var(--ink-3);
  font-size: 12px;
  padding-left: 12px;
  margin-left: 2px;
  border-left: 1px solid var(--line-2);
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  border: 0;
  color: var(--ink-3);
  padding: 7px 16px;
  border-radius: var(--r-pill);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--ink); color: var(--surface-1); }
.pill {
  background: var(--surface-2);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.tab.active .pill { background: rgba(255,255,255,0.22); color: var(--surface-1); }

main { max-width: 1060px; margin: 0 auto; padding: 36px 24px 90px; }

/* ---------------------------------------------------------------- hero + form */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-pill);
  padding: 5px 14px 5px 11px;
  font-size: 12px;
  font-weight: 550;
  color: var(--ink-2);
}
.eyebrow-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.16);
}

.hero h1 {
  font-size: 34px;
  line-height: 1.2;
  letter-spacing: -0.03em;
  font-weight: 700;
  margin: 14px 0 12px;
}
.hero .sub {
  color: var(--ink-2);
  max-width: 620px;
  margin: 0 0 26px;
  font-size: 15px;
}
.hero .sub strong { color: var(--ink); font-weight: 600; }

.url-row { display: flex; gap: 10px; }
.url-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 4px 12px 4px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.url-box:focus-within {
  border-color: var(--series-1);
  box-shadow: 0 0 0 4px var(--series-1-wash);
}
.url-icon { color: var(--ink-3); flex-shrink: 0; transition: color 180ms ease; }
.url-box:focus-within .url-icon { color: var(--series-1); }
.clear-btn {
  background: transparent;
  border: 0;
  color: var(--ink-3);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  transition: color 140ms ease, background 140ms ease;
}
.clear-btn:hover { color: var(--ink); background: var(--surface-3); }
.url-box input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--ink);
  font-size: 15px;
  padding: 13px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.url-box input::placeholder { color: var(--ink-3); font-family: Inter, system-ui, sans-serif; }

.chip {
  background: var(--surface-3);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
.chip.video { background: rgba(42, 120, 214, 0.12); color: #1f66b8; }
.chip.playlist { background: rgba(12, 163, 12, 0.10); color: var(--good-ink); }
.chip.channel { background: rgba(235, 104, 52, 0.13); color: #b8471c; }

button.primary {
  background: var(--brand);
  border: 0;
  color: #fff;
  font-weight: 650;
  font-size: 15px;
  font-family: inherit;
  border-radius: var(--r-md);
  padding: 0 24px;
  cursor: pointer;
  box-shadow: none;
  transition: filter 160ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  button.primary:hover { filter: brightness(1.08); }
}
button.primary:active { transform: scale(0.97); }
button.primary:disabled { filter: grayscale(0.7) brightness(0.8); cursor: wait; box-shadow: none; }
button.primary:disabled:active { transform: none; }

/* every pressable surface answers the press */
.icon-btn:active,
.export-actions button:active,
.drawer-actions button:active,
.modal-actions button:active,
.recent-chip:active { transform: scale(0.97); }

.options {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 16px 2px 0;
  color: var(--ink-3);
  font-size: 13px;
  flex-wrap: wrap;
}
.options label { display: flex; align-items: center; gap: 8px; }
select {
  background: var(--surface-1);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 6px 9px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
select:hover { border-color: var(--ink-3); }
input[type="checkbox"] { accent-color: var(--brand); width: 15px; height: 15px; cursor: pointer; }
.check { cursor: pointer; }

/* ---------------------------------------------------------------- recent + intro */
.recent-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.recent-label {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.recent-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .recent-chip:hover { border-color: var(--line-2); color: var(--ink); }
}
.recent-chip .rc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-chip .rc-count { color: var(--ink-3); font-variant-numeric: tabular-nums; }

.intro-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 12px;
  margin-top: 34px;
}
.intro-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 20px;
  opacity: 0;
  transform: translateY(8px);
  animation: rise-in 420ms var(--ease-out) forwards;
}
.intro-card:nth-child(1) { animation-delay: 40ms; }
.intro-card:nth-child(2) { animation-delay: 100ms; }
.intro-card:nth-child(3) { animation-delay: 160ms; }
@keyframes rise-in { to { opacity: 1; transform: translateY(0); } }
.intro-card .ic-icon {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--series-1-wash);
  color: #1f66b8;
  font-size: 13px;
  margin-bottom: 11px;
}
.intro-card h3 { margin: 0 0 5px; font-size: 14px; font-weight: 650; }
.intro-card p { margin: 0; font-size: 13px; color: var(--ink-3); line-height: 1.5; }

/* ---------------------------------------------------------------- run panel */
.run-panel {
  margin-top: 32px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-2);
}
.run-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.run-head h2 { margin: 0 0 3px; font-size: 17px; letter-spacing: -0.015em; }
.run-head p { margin: 0; font-size: 13px; }
.run-stats { display: flex; gap: 7px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.stat::before { content: ""; width: 7px; height: 7px; border-radius: 50%; }
.stat.ok { background: rgba(12, 163, 12, 0.11); color: var(--good-ink); }
.stat.ok::before { background: var(--good); }
.stat.cached { background: rgba(42, 120, 214, 0.11); color: #1f66b8; }
.stat.cached::before { background: var(--series-1); }
.stat.err { background: rgba(208, 59, 59, 0.10); color: var(--critical-ink); }
.stat.err::before { background: var(--critical); }

.progress-track {
  height: 5px;
  background: var(--surface-3);
  border-radius: var(--r-pill);
  margin: 16px 0 6px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--series-1);
  border-radius: var(--r-pill);
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------------------------------------------------------------- export bar */
.export-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 16px;
  margin: 16px 0 4px;
  font-size: 13px;
  color: var(--ink-3);
}
.export-controls { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.export-controls label { display: flex; align-items: center; gap: 8px; }
.export-actions { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.export-actions button {
  border: 1px solid var(--line-2);
  background: var(--surface-1);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.export-actions button:hover { border-color: var(--series-1); background: var(--surface-3); }
.export-actions button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  padding: 8px 16px;
  box-shadow: none;
}

/* ---------------------------------------------------------------- video rows */
.video-list { list-style: none; margin: 6px 0 0; padding: 0; }
.video-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px 10px;
  border-radius: var(--r-sm);
  border-bottom: 1px solid var(--line);
  transition: background 0.12s;
}
.video-row:last-child { border-bottom: 0; }
.video-row:hover { background: var(--surface-2); }
.video-row .status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.ok { background: var(--good); }
.status-dot.cached { background: var(--series-1); }
.status-dot.error { background: var(--critical); }
.status-dot.pending { background: var(--line-2); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.video-row .v-main { flex: 1; min-width: 0; }
.video-row .v-title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: color 0.12s;
}
.video-row .v-title:hover { color: #1f66b8; }
.video-row .v-meta {
  color: var(--ink-3);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.video-row .v-meta .err-text { color: var(--critical-ink); }
.v-skeleton {
  display: inline-block;
  height: 11px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.v-actions { display: flex; gap: 6px; flex-shrink: 0; opacity: 0; transition: opacity 0.15s; }
.video-row:hover .v-actions,
.video-row:focus-within .v-actions { opacity: 1; }
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  border-radius: var(--r-sm);
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.icon-btn:hover { color: var(--ink); border-color: var(--series-1); }
.video-row input[type="checkbox"] { flex-shrink: 0; }

/* ---------------------------------------------------------------- dashboard */
.dash-head { margin-bottom: 22px; }
.dash-head h1 { margin: 0 0 3px; font-size: 23px; letter-spacing: -0.02em; }
.dash-head p { margin: 0; font-size: 14px; }

/* hero figure — exactly one per view, same sans, proportional figures */
.hero-figure {
  background: linear-gradient(150deg, var(--surface-1), var(--surface-2));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 28px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-2);
}
.hero-figure .hf-label {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}
.hero-figure .hf-value {
  font-size: 54px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.035em;
  margin: 8px 0 6px;
}
.hero-figure .hf-sub { color: var(--ink-2); font-size: 14px; margin: 0; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(172px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px 18px;
  transition: border-color 0.15s, transform 0.15s;
}
.stat-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.stat-card .sc-label {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.stat-card .sc-value {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.025em;
  margin-top: 5px;
  line-height: 1.15;
}
.stat-card .sc-hint { color: var(--ink-3); font-size: 12px; margin-top: 1px; }

.dash-grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 14px; margin-bottom: 14px; }
.dash-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  margin-bottom: 14px;
}
.dash-grid .dash-card { margin-bottom: 0; }
.dash-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.dash-card h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.dash-card .card-sub { color: var(--ink-3); font-size: 12px; margin: 0 0 16px; }
.link-btn {
  background: none;
  border: 0;
  color: var(--ink-3);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--ink); }

/* horizontal bars: one hue (single series), 4px rounded data-end, square baseline */
.channel-bars { display: grid; gap: 11px; }
.channel-bar {
  display: grid;
  grid-template-columns: 132px 1fr 30px;
  align-items: center;
  gap: 12px;
  cursor: default;
}
.cb-label {
  font-size: 13px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cb-track { height: 10px; background: var(--surface-3); border-radius: 2px; }
.cb-fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
  min-width: 3px;
  transition: filter 0.12s;
}
.channel-bar:hover .cb-fill { filter: brightness(1.18); }
.channel-bar:hover .cb-label { color: var(--ink); }
.cb-count {
  font-size: 12px;
  color: var(--ink-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* stacked part-to-whole bar: 2px surface gap between segments, never a border */
.split-track { display: flex; gap: 2px; height: 12px; margin-bottom: 14px; }
.split-seg { height: 100%; }
.split-seg.manual { background: var(--series-1); border-radius: 2px 0 0 2px; }
.split-seg.auto { background: var(--series-2); border-radius: 0 2px 2px 0; }
.split-seg:only-child { border-radius: 2px; }

.legend { display: grid; gap: 8px; font-size: 13px; }
.legend-row { display: flex; align-items: center; gap: 9px; color: var(--ink-2); }
.legend-row .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.swatch.s1 { background: var(--series-1); }
.swatch.s2 { background: var(--series-2); }
.legend-row .lg-value {
  margin-left: auto;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lang-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.lang-pill {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 12px;
  font-size: 12px;
  color: var(--ink-2);
}

/* word cloud — gist only; the ranked bars are the accurate read of the same data.
   Size AND one-hue lightness both step with frequency, so magnitude survives
   even when the layout scrambles order. */
.word-cloud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 14px;
  padding: 14px 6px 6px;
  text-align: center;
}
.word-cloud .wc-term {
  line-height: 1.15;
  font-weight: 650;
  letter-spacing: -0.02em;
  cursor: default;
  transition: color 0.12s;
}
.word-cloud .wc-term:hover { color: var(--ink) !important; }

/* tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  color: var(--ink-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 650;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.text-col { font-variant-numeric: normal; }
.run-source { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.num-ok { color: var(--good-ink); font-weight: 650; }
.num-err { color: var(--critical-ink); font-weight: 650; }

/* chart tooltip */
.viz-tip {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  background: var(--ink);
  color: var(--surface-1);
  border: 1px solid var(--ink);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: var(--shadow-3);
  max-width: 260px;
}
.viz-tip .tip-title { font-weight: 650; margin-bottom: 3px; }
.viz-tip .tip-row { color: #b9bcc4; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- library */
.library-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.library-head h1 { margin: 0 0 3px; font-size: 23px; letter-spacing: -0.02em; }
#library-search {
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  color: var(--ink);
  border-radius: var(--r-md);
  padding: 11px 16px;
  font-size: 14px;
  font-family: inherit;
  width: 320px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#library-search:focus { border-color: var(--series-1); box-shadow: 0 0 0 4px var(--series-1-wash); }
.empty {
  color: var(--ink-3);
  text-align: center;
  padding: 52px 20px;
  border: 1px dashed var(--line-2);
  border-radius: var(--r-md);
}

.sel-count { margin-right: auto; font-variant-numeric: tabular-nums; }
.export-actions button.danger { color: var(--critical-ink); }
.export-actions button.danger:hover { border-color: var(--critical); background: rgba(208, 59, 59, 0.08); }
.export-actions button:disabled { opacity: 0.45; cursor: not-allowed; }
.export-actions button:disabled:active { transform: none; }

/* library groups */
.lib-group {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: 12px;
  overflow: hidden;
}
.lib-group-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  transition: background 140ms ease;
}
.lib-group-head:hover { background: var(--surface-2); }
.lib-group-head .caret {
  color: var(--ink-3);
  font-size: 10px;
  transition: transform 200ms var(--ease-out);
  flex-shrink: 0;
}
.lib-group[data-open="true"] .caret { transform: rotate(90deg); }
.lg-title { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg-meta { color: var(--ink-3); font-size: 12px; white-space: nowrap; }
.lg-main { flex: 1; min-width: 0; }
.lg-actions { display: flex; gap: 6px; flex-shrink: 0; }
.lib-group .video-list { padding: 0 16px 10px; border-top: 1px solid var(--line); }
.lib-group[data-open="false"] .video-list { display: none; }

/* ---------------------------------------------------------------- credits */
.top-right { display: flex; align-items: center; gap: 12px; }

.credits-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, transform 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .credits-badge:hover { border-color: var(--series-1); color: var(--ink); }
}
.credits-badge:active { transform: scale(0.97); }
.credits-badge .cb-count { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.credits-badge.low { border-color: var(--critical); }
.credits-badge.low .cb-count { color: var(--critical-ink); }

.paywall-note { color: var(--ink-3); font-size: 12px; line-height: 1.55; margin: 0 0 18px; }
#paywall .cta { display: block; text-align: center; margin-bottom: 20px; }
.redeem-row { border-top: 1px solid var(--line); padding-top: 16px; }
.redeem-row label { display: block; color: var(--ink-3); font-size: 12px; margin-bottom: 8px; }
.redeem-input { display: flex; gap: 8px; }
.redeem-input input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line-2);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-family: ui-monospace, Menlo, monospace;
  outline: none;
}
.redeem-input input:focus { border-color: var(--series-1); }
.redeem-input button {
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms var(--ease-out);
}
.redeem-input button:hover { border-color: var(--series-1); }
.redeem-input button:active { transform: scale(0.97); }

/* ---------------------------------------------------------------- confirm modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 20, 0.32);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  z-index: 90;
  animation: fade 140ms ease-out;
  padding: 20px;
}
.modal-card {
  width: min(420px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-3);
  /* modals are not anchored to a trigger — they scale from center */
  transform-origin: center;
  animation: modal-in 200ms var(--ease-out);
}
@keyframes modal-in { from { opacity: 0; transform: scale(0.96); } }
.modal-card h2 { margin: 0 0 8px; font-size: 17px; letter-spacing: -0.015em; }
.modal-card p { margin: 0 0 20px; font-size: 13px; line-height: 1.55; }
.modal-actions { display: flex; gap: 9px; justify-content: flex-end; }
.modal-actions button {
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 160ms var(--ease-out);
}
.modal-actions button:hover { background: var(--surface-3); }
.modal-actions button.danger-solid {
  background: var(--critical);
  border-color: var(--critical);
  color: #fff;
}
.modal-actions button.danger-solid:hover { filter: brightness(1.1); background: var(--critical); }

/* ---------------------------------------------------------------- drawer */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(30, 27, 20, 0.34);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-end;
  z-index: 60;
  animation: fade 0.16s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.drawer-card {
  width: min(660px, 94vw);
  background: var(--surface-1);
  border-left: 1px solid var(--line-2);
  padding: 24px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: slide 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slide { from { transform: translateX(28px); opacity: 0.4; } }
.drawer-head { display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.drawer-head h2 { margin: 0 0 4px; font-size: 17px; line-height: 1.35; letter-spacing: -0.015em; }
.drawer-head p { margin: 0; font-size: 12px; }
.drawer-actions { display: flex; gap: 10px; align-items: center; margin: 16px 0; }
.drawer-actions button {
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.drawer-actions button:hover { border-color: var(--series-1); }
.drawer-actions a { color: #1f66b8; font-size: 13px; text-decoration: none; margin-left: auto; }
.drawer-actions a:hover { text-decoration: underline; }
#drawer-text {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.75;
  color: var(--ink-2);
  margin: 0;
}

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  border: 1px solid var(--ink);
  color: var(--surface-1);
  border-radius: var(--r-pill);
  padding: 11px 22px;
  font-size: 13px;
  font-weight: 600;
  z-index: 70;
  box-shadow: var(--shadow-3);
  animation: rise 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  main { padding: 26px 16px 70px; }
  .topbar { padding: 12px 16px; }
  .brand-tag { display: none; }
  .hero h1 { font-size: 26px; }
  .url-row { flex-direction: column; }
  button.primary { padding: 13px 22px; }
  .channel-bar { grid-template-columns: 92px 1fr 28px; }
  .hero-figure .hf-value { font-size: 42px; }
  #library-search { width: 100%; }
  .export-actions { margin-left: 0; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ---------------------------------------------------------------- cell grid
   The structural motif: content sits in cells separated by 1px rules, so the
   page reads as one typeset sheet rather than a scatter of floating cards.
   Borders are drawn with a wrapper ring + per-cell right/bottom rules, which
   keeps every internal line exactly 1px with no doubling. */
.cellgrid {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-1);
}
.cellgrid > .cell {
  padding: 26px 28px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.cellgrid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cellgrid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cellgrid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.cellgrid.cols-2 > .cell:nth-child(2n) { border-right: 0; }
.cellgrid.cols-3 > .cell:nth-child(3n) { border-right: 0; }
.cellgrid.cols-4 > .cell:nth-child(4n) { border-right: 0; }
.cell.span-2 { grid-column: span 2; }
.cell.span-3 { grid-column: span 3; }
.cell.span-full { grid-column: 1 / -1; border-right: 0; }

.cell h3 {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.012em;
}
.cell p { margin: 0; color: var(--ink-2); font-size: 13px; line-height: 1.65; }
.cell-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  color: var(--brand-ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.cell-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* centred section head, the editorial rhythm */
.sec-head { text-align: center; max-width: 60ch; margin: 0 auto 26px; }
.sec-head h2 {
  font-size: clamp(21px, 2.6vw, 28px);
  letter-spacing: -0.028em;
  font-weight: 650;
  margin: 0 0 8px;
  line-height: 1.22;
}
.sec-head p { margin: 0; color: var(--ink-2); font-size: 15px; line-height: 1.6; }

/* monoline illustration frame — thin strokes, no fills, generous air */
.illus {
  display: grid;
  place-items: center;
  min-height: 118px;
  margin-top: 18px;
  color: var(--ink-3);
}
.illus svg { width: 100%; max-width: 210px; height: auto; }
.illus .accent { stroke: var(--brand); }
.illus .fill-accent { fill: var(--brand); }

@media (max-width: 860px) {
  .cellgrid.cols-3, .cellgrid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .cellgrid.cols-3 > .cell:nth-child(3n),
  .cellgrid.cols-4 > .cell:nth-child(4n) { border-right: 1px solid var(--line); }
  .cellgrid.cols-3 > .cell:nth-child(2n),
  .cellgrid.cols-4 > .cell:nth-child(2n) { border-right: 0; }
}
@media (max-width: 620px) {
  .cellgrid, .cellgrid.cols-2, .cellgrid.cols-3, .cellgrid.cols-4 { grid-template-columns: 1fr; }
  .cellgrid > .cell { border-right: 0 !important; }
  .cell.span-2, .cell.span-3 { grid-column: span 1; }
}

/* an <ol> used as a cell grid must not draw native markers beside the badges */
ol.cellgrid, ul.cellgrid { list-style: none; margin: 0; padding: 0; }
ol.cellgrid > li, ul.cellgrid > li { list-style: none; }

/* the brand lockup is a link on every page — keep it looking like a mark, not a link */
a.brand { text-decoration: none; color: inherit; }
a.brand:hover .brand-lockup { opacity: 0.82; }
.brand-lockup { transition: opacity 160ms ease; }

/* ---------------------------------------------------------------- mobile nav
   Five nav items plus the lockup cannot share one row on a phone: the pill
   overflowed the viewport and "How it works" wrapped to three lines. Below
   760px the bar becomes two rows — brand + primary CTA, then the section
   links on their own scrollable line. */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 10px;
    padding: 10px 16px;
  }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand-lockup { height: 22px; }

  .tabs {
    order: 3;
    flex: 1 0 100%;
    background: transparent;
    border: 0;
    padding: 0;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    padding: 6px 12px;
    white-space: nowrap;      /* never wrap a label mid-phrase */
    flex: 0 0 auto;
    border-radius: var(--r-sm);
  }
  /* Only the landing nav's CTA floats up beside the logo. The app's tabs are a
     segmented control built from <button>, so they must stay grouped — an
     earlier rule matched both and tore "Extract" out of the group. */
  .tabs a.tab.active {
    position: absolute;
    top: 10px;
    right: 16px;
    border-radius: var(--r-pill);
    padding: 7px 15px;
  }

  /* app view: the tab group is the primary control, keep it on its own row */
  .top-right { flex: 1 0 100%; order: 3; justify-content: flex-start; }
  .top-right .tabs { flex: 1 1 auto; background: var(--surface-1); border: 1px solid var(--line); padding: 3px; }
  .top-right .tabs .tab { border-radius: var(--r-pill); }
  .credits-badge { position: absolute; top: 10px; right: 16px; }
}

@media (max-width: 400px) {
  .brand-lockup { height: 20px; }
  .tab { font-size: 12px; padding: 6px 10px; }
}
