/* ──────────────────────────────────────────────────────────
   App layout & components (theme-agnostic — uses tokens).
   ────────────────────────────────────────────────────────── */

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Top bar ────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}
.brand .mark {
  width: 1.65rem;
  height: 1.65rem;
}
.brand .name {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: var(--track-display);
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand .name b {
  color: var(--accent);
  font-weight: inherit;
}
.brand .sub {
  display: none;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin-left: var(--space-3);
  padding-left: var(--space-3);
  border-left: 1px solid var(--rule);
}
@media (min-width: 740px) {
  .brand .sub {
    display: inline-block;
  }
}

.topbar .grow {
  flex: 1;
}

.topbar .search {
  flex: 1 1 280px;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.4em 0.8em;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  transition: border-color var(--duration);
}
.topbar .search:focus-within {
  border-color: var(--accent);
}
.topbar .search input {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  min-width: 0;
}
.topbar .search input::placeholder {
  color: var(--ink-faint);
}
.topbar .search .icon {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.theme-switch select,
.icon-btn {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 0.4em 0.55em;
  font-size: 0.85rem;
  font-family: var(--font-mono);
}
.icon-btn {
  width: 2.1rem;
  height: 2.1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ─── Hero ───────────────────────────────────────────────── */
.hero {
  padding: var(--space-6) var(--space-4) var(--space-5);
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}
.hero .eyebrow {
  margin-bottom: var(--space-2);
}
.hero h1 {
  margin: 0 0 var(--space-3) 0;
  font-size: var(--text-3xl);
  line-height: var(--leading-display);
  letter-spacing: var(--track-display);
}
.hero p.lede {
  font-size: var(--text-lg);
  color: var(--ink-mute);
  max-width: 60ch;
  margin: 0 0 var(--space-4) 0;
}
.hero .stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--ink-mute);
}
.hero .stats b {
  display: block;
  font-size: var(--text-xl);
  color: var(--ink);
  font-weight: 700;
  font-feature-settings: 'tnum';
}

/* ─── Filter bar ─────────────────────────────────────────── */
.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.filterbar .label {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-right: var(--space-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  border: 1px solid var(--rule);
  background: var(--paper-2);
  color: var(--ink-mute);
  padding: 0.3em 0.7em;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  transition: border-color var(--duration), color var(--duration), background var(--duration);
}
.chip:hover {
  border-color: var(--accent);
  color: var(--ink);
}
.chip[aria-pressed='true'] {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
}
.chip .count {
  opacity: 0.55;
  font-feature-settings: 'tnum';
}
.chip[aria-pressed='true'] .count {
  opacity: 0.75;
}

.filterbar .clear {
  margin-left: auto;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}
.filterbar .clear:hover {
  color: var(--accent);
}

/* ─── Card grid ──────────────────────────────────────────── */
.grid {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-4) var(--space-8);
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}

.card {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  transition: transform var(--duration) var(--ease), box-shadow var(--duration);
  position: relative;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
}
.card .cover {
  aspect-ratio: 4 / 5;
  background: var(--paper-3);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  position: relative;
}
.card .cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: contrast(1.05);
}
.card .meta {
  padding: var(--space-3) var(--space-3) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  flex: 1;
}
.card .row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.card .agency-badge {
  font-weight: 600;
  color: var(--accent);
}
.card .credibility {
  margin-left: auto;
}
.card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  line-height: 1.25;
  letter-spacing: var(--track-display);
  font-weight: 600;
  color: var(--ink);
}
.card .excerpt {
  font-size: 0.92rem;
  color: var(--ink-mute);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Credibility dots */
.cred-dot {
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  margin-right: 0.4em;
  vertical-align: middle;
  background: currentColor;
}
.cred-LOW {
  color: var(--ink-faint);
}
.cred-MEDIUM {
  color: var(--warn);
}
.cred-HIGH {
  color: var(--good);
}
.cred-VERY_HIGH {
  color: var(--accent);
}
.cred-MIXED {
  color: var(--accent-2);
}

.empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

/* ─── Detail view ─────────────────────────────────────────── */
.detail {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.detail-hd {
  padding: var(--space-4);
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: none;
}
.detail-hd .crumbs {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.detail-hd .crumbs a {
  color: var(--ink-mute);
}
.detail-hd h1 {
  margin: 0;
  font-size: var(--text-xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--track-display);
  font-family: var(--font-display);
  font-weight: 700;
}
.detail-hd .tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-mute);
}
.detail-hd .tag {
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.2em 0.6em;
  background: var(--paper-2);
}
.detail-hd .tag b {
  color: var(--ink);
  font-weight: 500;
}

/* Header row (title + share) */
.detail-hd .hd-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-3);
}
.detail-hd .hd-row h1 {
  flex: 1;
  min-width: 0;
}

/* Share row */
.share-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  align-items: center;
  font-family: var(--font-mono);
}
.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.45em 0.7em;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  color: var(--ink-mute);
  border-radius: var(--radius);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-decoration: none;
  text-transform: uppercase;
  transition: border-color var(--duration), color var(--duration), background var(--duration);
}
.share-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}
.share-btn svg {
  fill: currentColor;
  flex-shrink: 0;
}

/* Heading anchors in analysis pane */
.analysis-body h2,
.analysis-body h3 {
  position: relative;
  scroll-margin-top: 80px;
}
.analysis-body .hash-anchor {
  position: absolute;
  left: -1.2em;
  color: var(--ink-faint);
  font-weight: 400;
  text-decoration: none;
  opacity: 0;
  transition: opacity var(--duration), color var(--duration);
  font-family: var(--font-mono);
}
.analysis-body h2:hover .hash-anchor,
.analysis-body h3:hover .hash-anchor,
.analysis-body .hash-anchor:focus {
  opacity: 1;
}
.analysis-body .hash-anchor:hover {
  color: var(--accent);
}
@media (max-width: 760px) {
  .analysis-body .hash-anchor {
    position: static;
    margin-right: 0.4em;
    opacity: 0.4;
  }
}

/* Tabs (mobile) */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 60px;
  z-index: 10;
  background: color-mix(in oklab, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.tabs button {
  flex: 1;
  padding: 0.85em 0.6em;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 2px solid transparent;
  transition: color var(--duration), border-color var(--duration);
}
.tabs button[aria-selected='true'] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
@media (min-width: 1100px) {
  .tabs {
    display: none;
  }
}

/* Pane container — mobile: stacked, only active visible. desktop: 3-col. */
.panes {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--paper);
}
@media (min-width: 1100px) {
  .panes {
    flex-direction: row;
    gap: 1px;
    background: var(--rule);
  }
  .pane {
    flex: 1;
    min-width: 0;
    overflow: auto;
  }
  .pane[data-pane='document'] {
    flex: 1.4;
  }
  .pane[data-pane='analysis'] {
    flex: 1.2;
  }
  .pane[data-pane='whispers'] {
    flex: 1;
  }
}

/* Mobile: only active pane visible */
@media (max-width: 1099px) {
  .pane {
    display: none;
  }
  .pane.active {
    display: flex;
  }
}

.pane-hd {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--paper-2);
}
.pane-hd .badge {
  margin-left: auto;
  color: var(--accent);
}

.pane-body {
  padding: var(--space-5) var(--space-4);
  overflow-y: auto;
  flex: 1;
}

/* Document pane — PDF.js iframe or image */
.pdf-frame,
.image-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--paper-2);
}
.image-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  overflow: auto;
}
.image-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: var(--shadow);
}

.pdf-fallback {
  padding: var(--space-5);
  text-align: center;
  color: var(--ink-mute);
}
.pdf-fallback .openlink {
  display: inline-block;
  margin-top: var(--space-3);
  padding: 0.5em 1em;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Analysis pane — markdown content */
.analysis-body {
  font-family: var(--font-body);
  max-width: 64ch;
  font-size: var(--text-base);
  line-height: var(--leading-body);
}
.analysis-body h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin: 1.8em 0 0.6em;
  letter-spacing: var(--track-display);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3em;
  color: var(--ink);
}
.analysis-body h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 1.4em 0 0.4em;
  color: var(--ink);
}
.analysis-body h2:first-child,
.analysis-body h3:first-child {
  margin-top: 0;
}
.analysis-body p {
  margin: 0 0 1em;
}
.analysis-body strong {
  color: var(--ink);
  font-weight: 600;
}
.analysis-body em {
  color: var(--ink-mute);
}
.analysis-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--paper-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  border: 1px solid var(--rule);
}
.analysis-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9em;
  font-family: var(--font-mono);
}
.analysis-body th,
.analysis-body td {
  border: 1px solid var(--rule);
  padding: 0.4em 0.6em;
  text-align: left;
  vertical-align: top;
}
.analysis-body th {
  background: var(--paper-2);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.analysis-body ul,
.analysis-body ol {
  padding-left: 1.4em;
  margin: 0.6em 0 1em;
}
.analysis-body li {
  margin: 0.3em 0;
}
.analysis-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 1em 0;
  padding: 0.3em 1em;
  color: var(--ink-mute);
  background: var(--paper-2);
}
.analysis-body hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}

/* Whispers pane — ITALIC pull-quote at top of body */
.whispers-body {
  font-family: var(--font-body);
  max-width: 60ch;
  font-size: var(--text-base);
  line-height: var(--leading-body);
}
.whispers-body em:first-child,
.whispers-body p:first-child em {
  font-size: 1.15em;
  color: var(--accent);
  display: block;
  margin-bottom: 1.2em;
  line-height: 1.4;
}
.whispers-body p {
  margin: 0 0 1em;
}
.whispers-empty {
  font-family: var(--font-mono);
  color: var(--ink-mute);
  text-align: center;
  padding: var(--space-6) var(--space-4);
}
.whispers-empty .symbol {
  font-size: 2.5rem;
  color: var(--ink-faint);
  margin-bottom: var(--space-3);
}

/* About / footer */
.footer {
  border-top: 1px solid var(--rule);
  padding: var(--space-5) var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}
.footer a {
  color: var(--ink-mute);
}
.footer a:hover {
  color: var(--accent);
}

/* ─── SSR shell (pre-hydration content for SEO + first-paint) ── */
.ssr-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-4) var(--space-6);
  width: 100%;
}
.ssr-shell .eyebrow {
  margin-bottom: var(--space-2);
}
.ssr-shell h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-3xl);
  line-height: var(--leading-display);
  letter-spacing: var(--track-display);
  margin: 0 0 var(--space-3);
}
.ssr-shell .lede {
  font-size: var(--text-lg);
  color: var(--ink-mute);
  max-width: 60ch;
  margin: 0 0 var(--space-5);
}
.ssr-loading {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: var(--space-6);
  display: flex;
  align-items: center;
  gap: 0.6em;
}
.ssr-loading .spinner {
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ─── Modal (access code prompt) ──────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in oklab, var(--paper) 70%, #000);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 1rem;
  animation: backdrop-in 180ms var(--ease) both;
}
@keyframes backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.modal {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 2rem 1.7rem 1.6rem;
  max-width: 460px;
  width: 100%;
  box-shadow: var(--shadow);
  animation: modal-in 220ms var(--ease) both;
}
[data-theme='alien-tech'] .modal {
  background:
    linear-gradient(160deg, rgba(122, 249, 255, 0.04), transparent 60%),
    var(--paper-2);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(122, 249, 255, 0.08);
}
[data-theme='redaction'] .modal {
  border-radius: 2px;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.modal-x {
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}
.modal-x:hover {
  color: var(--accent);
  background: var(--paper-3);
}
.modal h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: var(--track-display);
  color: var(--ink);
}
.modal-input {
  width: 100%;
  padding: 0.7em 0.85em;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 1rem;
  letter-spacing: 0.08em;
  color: var(--ink);
  transition: border-color var(--duration);
}
.modal-input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 25%, transparent);
}
.modal-btn {
  padding: 0.6em 1.1em;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-mute);
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}
.modal-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--ink);
}
.modal-btn-primary {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--accent);
  font-weight: 600;
}
.modal-btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
}
.modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Search hints highlight in cards */
mark.hit {
  background: color-mix(in oklab, var(--accent) 30%, transparent);
  color: var(--ink);
  padding: 0 0.1em;
  border-radius: 2px;
}
