:root {
  --bg: #ebe5d8;
  --panel: #fffdf8;
  --panel-strong: #f7f1e6;
  --ink: #15171a;
  --ink-2: #23262a;
  --border: #cfc5b6;
  --fg: #191b1f;
  --muted: #66707a;
  --accent: #256f5f;
  --hl: #ffe066;
  --chip: #eee7db;
  --chip-on: #2f6f5e;
  --good: #1f7a45;
  --ai: #9a5b00;
  --shadow: 0 18px 48px rgba(31, 26, 18, .16);
  --shadow-soft: 0 8px 24px rgba(31, 26, 18, .10);

  --tap: 44px;
  --pad-x: 14px;
  --gap: 10px;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

html, body {
  background:
    linear-gradient(180deg, #f3eee4 0%, var(--bg) 420px, #e5ddcf 100%);
  color: var(--fg);
  margin: 0;
  padding: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.synthesis-active {
  min-height: 100dvh;
  overflow: hidden;
}

/* ---------- Header (mobile-first) ---------- */

header {
  padding: 10px var(--pad-x) 8px;
  border-bottom: 1px solid rgba(255,255,255,.10);
  position: sticky;
  top: 0;
  background: rgba(21,23,26,.94);
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 8px 26px rgba(0,0,0,.18);
  z-index: 5;
  color: #f7f1e6;
  backdrop-filter: blur(18px);
}

body:not(.search-first):not(.synthesis-active) header {
  display: grid;
  grid-template-columns: 118px minmax(0, 760px) minmax(180px, 1fr);
  grid-template-areas:
    "brand search status"
    "brand filters status";
  align-items: center;
  gap: 8px 20px;
}

body:not(.search-first):not(.synthesis-active) h1.brand-mark {
  grid-area: brand;
  justify-self: start;
}

body:not(.search-first):not(.synthesis-active) h1.brand-mark img {
  width: 112px;
}

body:not(.search-first):not(.synthesis-active) .tagline {
  display: none;
}

body:not(.search-first):not(.synthesis-active) .search-row {
  grid-area: search;
  max-width: none;
}

body:not(.search-first):not(.synthesis-active) .filters {
  grid-area: filters;
  margin-top: 0;
}

body:not(.search-first):not(.synthesis-active) .status {
  grid-area: status;
  justify-self: end;
  max-width: 360px;
  text-align: right;
  justify-content: flex-end;
  margin-top: 0;
}

body.search-first header {
  min-height: 100dvh;
  border-bottom: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-top: 24px;
  padding-bottom: 24px;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), transparent 44%),
    linear-gradient(135deg, #111316 0%, #202226 46%, #16120d 100%);
  box-shadow: none;
}

body.search-first header::before,
body.search-first header::after {
  content: "";
  position: absolute;
  inset: -14%;
  z-index: -2;
  pointer-events: none;
}

body.search-first header::before {
  display: none;
}

body.search-first header::after {
  display: none;
}

.home-ambient {
  display: none;
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

body.search-first .home-ambient {
  display: none;
}

.home-signal {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(76vw, 880px);
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(47,111,94,.18), rgba(163,95,0,.12), transparent);
  transform-origin: left center;
  opacity: .25;
}
.signal-a { transform: translate3d(calc(-50% + 30px), calc(-50% + 16px), 0) rotate(-13deg); }
.signal-c { transform: translate3d(calc(-50% + 20px), calc(-50% - 26px), 0) rotate(13deg); }

body.synthesis-active header {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-8px);
}

body.search-first h1 {
  margin-bottom: 14px;
}

h1.brand-mark {
  display: inline-grid;
  place-items: center;
  letter-spacing: 0;
}

h1.brand-mark img {
  width: 140px;
  min-width: 0;
  height: auto;
  display: block;
  border-radius: 0;
  filter: drop-shadow(0 14px 28px rgba(0,0,0,.18));
  transform: none;
}

body.search-first h1.brand-mark img {
  width: min(54vw, 370px);
  min-width: 216px;
}

body.search-first h1.brand-mark {
  width: min(86vw, 520px);
  min-height: 260px;
  padding: 18px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.035)),
    radial-gradient(ellipse at 50% 42%, rgba(208,157,83,.16), transparent 54%),
    rgba(8,10,13,.42);
  box-shadow: 0 28px 90px rgba(0,0,0,.32), 0 1px 0 rgba(255,255,255,.12) inset;
}

body.search-first .tagline {
  font-size: 15px;
  margin-bottom: 20px;
  max-width: 520px;
  color: rgba(247,241,230,.76);
}

body.search-first .search-row {
  max-width: 680px;
  filter: drop-shadow(0 22px 42px rgba(0,0,0,.28));
}

body.search-first .status {
  max-width: 760px;
  justify-content: center;
}

body.search-first .filters {
  align-items: center;
}

body.search-first .filters > summary {
  align-self: center;
}

body.search-first .filters-body {
  text-align: left;
}

h1 { margin: 0; font-size: 18px; letter-spacing: .3px; display: inline-block; }
.tagline { margin: 2px 0 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
header .tagline { color: rgba(247,241,230,.68); }

.search-row { display: flex; gap: 6px; width: 100%; }

#q {
  flex: 1; min-width: 0;
  padding: 0 16px;
  height: var(--tap);
  background: rgba(255,253,248,.98); color: var(--fg);
  border: 1px solid rgba(255,255,255,.68); border-radius: 999px;
  font-size: 16px; /* WHY: <16px triggers iOS auto-zoom on focus */
  box-shadow: 0 1px 0 rgba(255,255,255,.9) inset, 0 10px 26px rgba(0,0,0,.10);
}
#q:focus { outline: 0; border-color: rgba(37,111,95,.72); box-shadow: 0 0 0 4px rgba(37,111,95,.16), 0 16px 38px rgba(0,0,0,.16); }
#q::-webkit-search-cancel-button,
#q::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
#q:disabled { opacity: .74; cursor: progress; }

/* ---------- Filters (TRI-126 disclosure markup) ---------- */

.filters { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }

.filters > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 999px;
  background: rgba(255,253,248,.10); color: rgba(247,241,230,.76); font-size: 12px;
  align-self: flex-start;
}
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary:hover { color: var(--fg); border-color: var(--accent); }
header .filters > summary:hover { color: #fff; border-color: rgba(255,255,255,.34); }
.filters .filters-label { font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.filters .filters-count {
  background: var(--chip-on); color: #fff; font-weight: 600;
  font-size: 11px; line-height: 1; padding: 2px 6px; border-radius: 999px;
  min-width: 16px; text-align: center;
}
.filters .filters-caret { font-size: 10px; transition: transform .15s; }
.filters[open] > summary .filters-caret { transform: rotate(180deg); }

.filters-body {
  display: flex; flex-direction: column; gap: 10px; margin-top: 8px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 8px;
  background: rgba(23,25,29,.92);
  box-shadow: 0 18px 44px rgba(0,0,0,.24);
}
.filters-group { display: flex; flex-direction: column; gap: 6px; }
.filters-group-label {
  color: var(--muted); font-size: 11px; letter-spacing: .5px; text-transform: uppercase;
}
.filters-more {
  align-self: flex-start; background: transparent; border: 0;
  color: var(--accent); cursor: pointer; padding: 2px 0; font-size: 12px;
}
.filters-more:hover { text-decoration: underline; }

/* ---------- Chips (mobile-first horizontal scroll, wrap on tablet+) ---------- */

.chip-row {
  display: flex; flex-wrap: nowrap; gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-row.tags { max-height: none; padding-right: 0; }
.chip-row.tags.expanded { max-height: none; }

.chip {
  background: rgba(255,253,248,.10); border: 1px solid rgba(255,255,255,.16); color: rgba(247,241,230,.86);
  padding: 6px 12px; min-height: 32px;
  border-radius: 999px; cursor: pointer;
  font-size: 13px; user-select: none;
  transition: background .12s;
  white-space: nowrap; flex-shrink: 0;
  display: inline-flex; align-items: center;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--chip-on); border-color: var(--chip-on); }
.chip .count { color: var(--muted); margin-left: 4px; font-size: 11px; }
.chip[aria-pressed="true"] .count { color: rgba(255,255,255,.7); }

/* ---------- Status (TRI-132 structured) ---------- */

.status {
  color: rgba(247,241,230,.62); margin: 8px 0 0; font-size: 12px;
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline;
}
.status #status-summary { color: rgba(247,241,230,.92); font-weight: 500; }
.status .status-filters {
  color: var(--muted); font-size: 11px;
  display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.status .filter-pill {
  background: var(--chip); border: 1px solid var(--border);
  color: var(--fg); padding: 1px 8px; border-radius: 999px; font-size: 11px;
}

/* ---------- Answer pane ---------- */

#answer-pane {
  width: min(1240px, calc(100% - (var(--pad-x) * 2)));
  margin: 18px auto 8px;
  padding: 16px 18px;
  border: 1px solid rgba(124,103,76,.20);
  border-radius: 8px;
  background: rgba(255,253,248,.92);
  box-shadow: var(--shadow-soft);
  scroll-margin-top: var(--header-h, 240px); /* WHY: TRI-123 — keep pane visible below sticky header */
}

body.synthesis-active #answer-pane {
  width: auto;
  margin: 0;
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  border-bottom: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), transparent),
    #15171a;
}

body.synthesis-active #answer-pane::before {
  display: none;
}

body.synthesis-active .answer-head {
  display: none;
}

body.synthesis-active #answer-body {
  position: relative;
  width: min(92vw, 640px);
}

.answer-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  color: var(--muted); font-size: 12px; flex-wrap: wrap;
}

.ai-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(154,91,0,.12); color: var(--ai);
  padding: 2px 8px; border-radius: 999px;
  font-weight: 600; letter-spacing: .3px; text-transform: uppercase; font-size: 10px;
}

#answer-body { font-size: 15px; line-height: 1.55; }
#answer-body strong { color: var(--fg); }
#answer-body em { color: var(--fg); }
#answer-body p { margin: 0 0 10px; }

.answer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

#answer-body .evidence {
  margin: 12px 0 0; padding: 10px 12px;
  background: var(--panel-strong);
  border: 1px solid rgba(124,103,76,.20); border-radius: 8px;
}
#answer-body .evidence-head {
  font-size: 11px; letter-spacing: .5px; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px;
}
#answer-body .evidence ul { margin: 0; padding: 0; list-style: none; }
#answer-body .evidence li {
  font-size: 13.5px; padding: 6px 0;
  border-bottom: 1px solid rgba(32,33,36,.06);
}
#answer-body .evidence li:last-child { border-bottom: 0; }
#answer-body .evidence q { color: var(--fg); font-style: italic; }
#answer-body .evidence q::before { content: "\201C"; }
#answer-body .evidence q::after { content: "\201D"; }
#answer-body .empty-evidence { color: var(--muted); font-style: italic; }

#answer-body details.context { margin-top: 10px; }
#answer-body details.context summary {
  color: var(--muted); cursor: pointer; font-size: 12px;
  user-select: none; padding: 6px 0;
}
#answer-body details.context summary:hover { color: var(--fg); }
#answer-body details.context .ctx-item {
  padding: 8px 10px; margin: 6px 0;
  border-left: 2px solid var(--accent);
  background: rgba(47,111,94,.05);
  border-radius: 0 6px 6px 0;
}
#answer-body details.context .ctx-title { font-weight: 600; font-size: 13px; }
#answer-body details.context .ctx-bullets {
  font-size: 12.5px; color: var(--muted); margin: 4px 0 0; padding-left: 18px;
}
#answer-body details.context .ctx-transcript {
  font-size: 12px; color: var(--muted); margin-top: 4px;
  max-height: 120px; overflow-y: auto;
  padding: 6px 8px; background: rgba(32,33,36,.05); border-radius: 4px;
}

/* ---------- Citation chips (TRI-124/133 button-based, accessible) ---------- */

.cite {
  display: inline-block;
  background: var(--accent); color: #fff;
  padding: 0 6px; border: 0; border-radius: 6px;
  font: inherit; font-size: 12px; font-weight: 600; line-height: 1.5;
  cursor: pointer; margin: 0 2px; vertical-align: 1px;
  min-width: 22px; text-align: center;
}
.cite:hover { background: #1f8aff; }
.cite:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.thinking { color: var(--muted); font-style: italic; }

.synthesis-loader {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  max-width: 760px;
  padding: 16px;
  border: 1px solid rgba(47,111,94,.22);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0,0,0,.26);
}

body.synthesis-active .synthesis-loader {
  max-width: none;
  padding: 20px;
  border-color: rgba(47,111,94,.28);
  background: rgba(255,253,248,.96);
  box-shadow: 0 32px 90px rgba(0,0,0,.38), 0 0 0 1px rgba(255,255,255,.7) inset;
  backdrop-filter: blur(16px);
  animation: modal-rise .32s ease-out both;
}

.loader-stage {
  display: grid;
  gap: 8px;
}

.scan-frame {
  position: relative;
  height: 58px;
  overflow: hidden;
  border: 1px solid rgba(47,111,94,.32);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(47,111,94,.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255,255,255,.6), rgba(222,216,204,.28));
  background-size: 14px 100%, 100% 100%;
}

.scan-line {
  position: absolute;
  inset: 0 auto 0 0;
  width: 28px;
  background: linear-gradient(90deg, transparent, rgba(47,111,94,.45), transparent);
  animation: scan-sweep 1.45s ease-in-out infinite;
}

.signal-row {
  position: relative;
  display: block;
  height: 6px;
  margin: 9px 10px;
  border-radius: 999px;
  background: rgba(32,33,36,.09);
  overflow: hidden;
}

.signal-row::after {
  content: "";
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  animation: signal-grow 1.2s ease-in-out infinite;
}
.signal-row:nth-child(3)::after { animation-delay: .16s; width: 58%; }
.signal-row:nth-child(4)::after { animation-delay: .32s; width: 35%; }

.loader-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.loader-copy strong { color: var(--fg); font-size: 16px; }
.loader-copy span { color: var(--muted); font-size: 13px; }
.loader-copy em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

@keyframes modal-rise {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes scan-sweep {
  0% { transform: translateX(-32px); opacity: .15; }
  18% { opacity: 1; }
  100% { transform: translateX(112px); opacity: .2; }
}

@keyframes signal-grow {
  0%, 100% { transform: translateX(-18%); opacity: .55; }
  50% { transform: translateX(98%); opacity: 1; }
}

.share-answer {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid rgba(47,111,94,.58);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(37,111,95,.22);
}
.share-answer:hover:not(:disabled) {
  border-color: #fff;
  transform: translateY(-1px);
}
.share-answer:disabled { opacity: .6; cursor: progress; }
.share-status { color: var(--muted); min-height: 18px; }

/* ---------- Cards grid (TRI-127 compact 2-col, cited/non-cited grouping) ---------- */

main {
  padding: 14px var(--pad-x) 56px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  max-width: 1240px;
  margin: 0 auto;
}

.results-section {
  grid-column: 1 / -1;
  display: flex; align-items: baseline; gap: 10px;
  padding: 10px 2px 6px;
  border-bottom: 1px solid rgba(124,103,76,.22);
  margin: 6px 0 4px;
}
.results-section .label {
  font-size: 11px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--fg); font-weight: 600;
}
.results-section .hint { font-size: 12px; color: var(--muted); }

.card {
  background: rgba(255,253,248,.96); border: 1px solid rgba(124,103,76,.22); border-radius: 8px;
  overflow: hidden;
  display: grid; grid-template-columns: 148px minmax(0, 1fr);
  box-shadow: 0 8px 24px rgba(31,26,18,.09);
  transition: border-color .15s, box-shadow .15s, opacity .15s;
}
.card:hover { border-color: rgba(37,111,95,.42); box-shadow: 0 14px 36px rgba(31,26,18,.14); }
.card.cite-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(47,111,94,.16);
}
.card.cite-context { opacity: .72; }
.card.cite-context:hover { opacity: 1; }
.card[aria-current="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent);
}
.card:focus { outline: none; }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.media-rail {
  min-width: 0;
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,0)),
    #25211c;
  border-right: 1px solid rgba(124,103,76,.28);
}

.thumb {
  position: relative; cursor: pointer;
  width: 100%; aspect-ratio: 16 / 9; background: #000;
  align-self: start; overflow: hidden; border-radius: 6px;
}
.thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb:hover .play-hint { opacity: 1; }
.thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb .dur {
  position: absolute; bottom: 4px; right: 4px;
  background: rgba(0,0,0,.7); color: #fff;
  font-size: 10px; padding: 1px 5px; border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.thumb .play-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: #fff; background: rgba(0,0,0,.45);
  opacity: 0; transition: opacity .15s;
}

.rail-meta {
  display: flex; flex-wrap: wrap; gap: 5px;
  align-content: flex-start;
}

.rail-meta .score,
.rail-meta .video-id,
.rail-meta .rail-duration,
.rail-meta .rail-more,
.rail-meta .t {
  max-width: 100%;
  min-width: 0;
  font-size: 10.5px; line-height: 1.2;
  padding: 3px 6px; border-radius: 999px;
}

.rail-meta .score {
  background: rgba(31,122,69,.14);
  color: #1c693d;
}

.video-id {
  color: #ffe9b2;
  background: rgba(0,0,0,.26);
  border: 1px solid rgba(255,233,178,.22);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.rail-meta .rail-duration {
  color: rgba(255,253,248,.76);
  background: rgba(255,255,255,.10);
}

.rail-meta .rail-more {
  color: rgba(255,253,248,.72);
  background: rgba(255,255,255,.08);
}

.body {
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  min-width: 0;
}
.title-row { display: flex; align-items: flex-start; gap: 6px; }
.cite-num {
  flex: none;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 1px 6px; border-radius: 4px;
  font-variant-numeric: tabular-nums; line-height: 1.4;
}
.title {
  margin: 0; font-weight: 600; font-size: 14px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.score { color: var(--good); font-variant-numeric: tabular-nums; font-weight: 600; }
.vote-pill {
  color: var(--accent);
  background: rgba(47,111,94,.08);
}
.upvote {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 44px;
  min-height: 32px;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}
.upvote:hover { border-color: var(--accent); color: var(--accent); }
.upvote[aria-pressed="true"] {
  background: rgba(47,111,94,.12);
  border-color: rgba(47,111,94,.35);
  color: var(--accent);
}

.bullets {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 3px;
}
.bullets li {
  font-size: 12.5px; line-height: 1.4; color: var(--muted);
  padding: 4px 8px; border-radius: 6px;
  background: var(--panel-strong);
  border-left: 2px solid transparent;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.bullets li.match {
  color: var(--fg);
  border-left-color: #d59b24;
  background: rgba(255,224,102,.14);
}
.bullets li.more {
  font-size: 11px; color: var(--muted); font-style: italic;
  background: transparent; padding: 2px 0;
}
.bullets li mark { background: var(--hl); color: #000; padding: 0 2px; border-radius: 3px; }

.rail-meta .t {
  font-size: 10px; color: rgba(255,253,248,.72);
  background: rgba(255,255,255,.08);
}
.rail-meta .t.active { color: #fff; background: var(--chip-on); }

/* Card horizontal layout collapses to a tighter thumb on very small phones */
@media (max-width: 480px) {
  .card { display: block; }
  .media-rail {
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .rail-meta {
    align-items: center;
  }
  .thumb { aspect-ratio: 16 / 9; }
  .share-answer { margin-left: 0; width: 100%; }
}

/* ---------- Player modal (TRI-137 context + controls) ---------- */

dialog#player {
  background: var(--panel); border: 1px solid rgba(124,103,76,.24); border-radius: 8px;
  padding: 0; width: min(960px, 96vw); max-height: calc(100dvh - 32px);
  color: var(--fg); overflow: hidden;
}
dialog#player:not([open]) { display: none; }
dialog#player[open] { display: flex; flex-direction: column; }
dialog#player::backdrop { background: rgba(0,0,0,.7); }
dialog#player video {
  width: 100%;
  max-height: min(52dvh, 520px);
  display: block;
  background: #000;
  flex: 0 0 auto;
}

.player-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid rgba(124,103,76,.24); background: var(--ink);
  color: #f7f1e6;
  flex: 0 0 auto;
}
.player-cite {
  background: var(--accent); color: #fff;
  padding: 2px 8px; border-radius: 6px;
  font-size: 12px; font-weight: 700;
  font-variant-numeric: tabular-nums; flex: 0 0 auto;
}
.player-cite.is-cited { box-shadow: 0 0 0 2px rgba(47,111,94,.25); }
.player-title {
  margin: 0; font-size: 16px; font-weight: 600; line-height: 1.3;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#closeplayer {
  background: transparent; color: var(--muted); border: 1px solid var(--border);
  width: 32px; height: 32px; border-radius: 8px;
  cursor: pointer; font-size: 20px; line-height: 1; padding: 0; flex: 0 0 auto;
}
#closeplayer:hover { color: var(--fg); border-color: var(--accent); }

.player-context {
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
  border-top: 1px solid rgba(124,103,76,.24);
  min-height: 0;
  overflow-y: auto;
  flex: 1 1 auto;
}
.player-meta {
  color: var(--muted); font-size: 12px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.player-meta .video-id {
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}
.player-meta .dot { opacity: .5; }

.player-bullets {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 4px;
}
.player-bullets li {
  font-size: 13.5px; padding: 6px 10px;
  border-radius: 8px;
  background: var(--panel-strong);
  border: 1px solid transparent;
}
.player-bullets li mark { background: var(--hl); color: #000; padding: 0 2px; border-radius: 3px; }

.player-transcript { font-size: 13px; }
.player-transcript summary {
  color: var(--muted); cursor: pointer; user-select: none;
  padding: 4px 0; font-size: 12px; letter-spacing: .3px; text-transform: uppercase;
}
.player-transcript summary:hover { color: var(--fg); }
.player-transcript-body {
  color: var(--muted); margin-top: 6px;
  max-height: 180px; overflow-y: auto;
  padding: 8px 10px;
  background: rgba(32,33,36,.05);
  border-radius: 6px; line-height: 1.55;
}
.player-transcript-body mark { background: var(--hl); color: #000; padding: 0 2px; border-radius: 3px; }

.player-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid rgba(124,103,76,.24);
  background: var(--panel-strong);
  flex: 0 0 auto;
}
.player-nav button {
  background: var(--chip); color: var(--fg); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  min-height: var(--tap);
}
.player-nav button:hover:not(:disabled) { border-color: var(--accent); }
.player-nav button:disabled { opacity: .4; cursor: not-allowed; }
.player-pos { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 48px 20px; }

/* ---------- Admin ---------- */

.admin-shell {
  display: block;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px var(--pad-x) 64px;
}
.admin-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.admin-top h1 { display: block; font-size: 26px; margin: 0; }
.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.admin-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.admin-panel h2 { margin: 0 0 12px; font-size: 18px; }
.admin-help {
  color: var(--muted);
  font-size: 12px;
  margin: -4px 0 12px;
}
.admin-search {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 12px;
}
.admin-form {
  display: grid;
  gap: 10px;
}
.admin-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
.admin-form input,
.admin-form textarea,
.admin-search input {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--fg);
  padding: 9px 10px;
  font: inherit;
}
.admin-form textarea { min-height: 80px; resize: vertical; }
.admin-form button,
.admin-link,
.admin-actions button,
.danger-button {
  min-height: var(--tap);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--chip);
  color: var(--fg);
  cursor: pointer;
  font-weight: 600;
}
.admin-form button { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.admin-actions button:last-child { background: var(--accent); border-color: var(--accent); color: #fff; }
.admin-link { display: inline-flex; align-items: center; text-decoration: none; }
.danger-button { color: #ffb4ad; }
.danger-button:hover { border-color: #ff7b72; }
.admin-status { color: var(--muted); min-height: 20px; }
.visibility-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}
.visibility-tag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--fg);
  font-size: 12px;
}
.visibility-tag input { accent-color: var(--accent); }
.visibility-tag small { color: var(--muted); font-size: 10px; }
.admin-list {
  display: grid;
  gap: 8px;
  max-height: 70vh;
  overflow: auto;
}
.admin-video {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
}
.admin-video-title { font-weight: 600; }
.admin-video-id {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  margin-bottom: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(210,153,34,.16);
  border: 1px solid rgba(210,153,34,.28);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
}
.admin-video-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.admin-video-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}
.admin-video-tags span {
  color: var(--muted);
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
}
.admin-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 8px;
}

@media (max-width: 520px) {
  .synthesis-loader {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 900px) {
  .admin-grid { grid-template-columns: 380px minmax(0, 1fr); align-items: start; }
}

/* ---------- Phone-only overrides ---------- */

@media (max-width: 600px) {
  body:not(.search-first):not(.synthesis-active) header {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "search"
      "filters"
      "status";
    gap: 8px;
  }
  body:not(.search-first):not(.synthesis-active) h1.brand-mark img { width: 96px; }
  body:not(.search-first):not(.synthesis-active) .status {
    justify-self: start;
    text-align: left;
    justify-content: flex-start;
  }
  dialog#player[open] { width: 96vw; max-height: 92vh; display: flex; flex-direction: column; }
  dialog#player video { max-height: 40vh; }
  .player-title { font-size: 14px; white-space: normal; }
  .player-context { padding: 10px 12px; overflow-y: auto; }
}

/* ---------- Tablet (≥600px) ---------- */

@media (min-width: 600px) {
  :root { --pad-x: 20px; }

  header { padding: 16px var(--pad-x) 12px; }
  h1 { font-size: 22px; }
  .tagline { font-size: 13px; margin-bottom: 12px; }

  .search-row { gap: 8px; max-width: 760px; }
  .chip-row { flex-wrap: wrap; overflow-x: visible; }
  .chip-row.tags { max-height: 64px; overflow-y: auto; padding-right: 6px; }
  .chip-row.tags.expanded { max-height: none; overflow-y: visible; }

  .filters { margin-top: 12px; max-width: 1200px; gap: 8px; }

  #answer-pane { padding: 16px var(--pad-x); }
  #answer-body { font-size: 16px; line-height: 1.6; max-width: none; }

  main {
    padding: 16px var(--pad-x) 60px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    width: 100%;
  }
}

/* ---------- Desktop (≥1024px) ---------- */

@media (min-width: 1024px) {
  :root { --pad-x: max(20px, 4vw); }

  header { padding: 24px var(--pad-x) 12px; }
  h1 { font-size: 26px; letter-spacing: .5px; margin-bottom: 4px; }
  .tagline { font-size: 14px; margin-bottom: 14px; }

  main {
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  }

  .card { grid-template-columns: 170px minmax(0, 1fr); }
}

@media (min-width: 1500px) {
  main {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  }
}
