/* ==========================================================================
   gossip-rag trace viewer — "Calm Console" design language
   Tokens below are reused verbatim from the companion portfolio site this
   project pairs with. Quiet, restrained, instrument-panel aesthetic:
   thin hairlines, muted semantic color, no gradients/glow/bounce.
   ========================================================================== */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --bg: #fafafa; --bg-2: #f4f5f7; --surface: #ffffff; --surface-2: #f5f5f5;
  --border: #ebebeb; --border-strong: #e0e0e0; --line: #f0f0f0;
  --text: #111111; --text-2: #404040; --text-3: #737373; --text-4: #a3a3a3;
  --accent: #2563eb; --accent-hover: #1d4ed8; --accent-subtle: #dbeafe; --accent-ghost: rgba(37,99,235,0.08);
  --green: #16a34a; --green-subtle: #f0fdf4;
  --amber: #b45309; --amber-subtle: #fef8ec;
  --red: #dc2626; --red-subtle: #fef2f2;
  --radius: 5px; --radius-sm: 3px; --radius-lg: 9px;
  --shadow-sm: 0 1px 2px rgba(17,17,17,0.04), 0 2px 6px rgba(17,17,17,0.05);

  /* spacing scale — not part of the shared token set, defined locally for
     internal rhythm/consistency across this app's own layout */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;

  --t-fast: 150ms ease-out;
  --t-med: 220ms ease-out;
}

html[data-theme="dark"] {
  --bg: #0c0d10; --bg-2: #0e0f13; --surface: #15161b; --surface-2: #1a1c22;
  --border: #262932; --border-strong: #333743; --line: #20232b;
  --text: #f2f3f5; --text-2: #c3c7d0; --text-3: #9297a3; --text-4: #666b77;
  --accent: #6191ff; --accent-hover: #83a8ff; --accent-subtle: rgba(97,145,255,0.16); --accent-ghost: rgba(97,145,255,0.1);
  --green: #4ade80; --green-subtle: rgba(74,222,128,0.12);
  --amber: #fbbf24; --amber-subtle: rgba(251,191,36,0.12);
  --red: #f87171; --red-subtle: rgba(248,113,113,0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
}

/* Respect prefers-color-scheme by default when the user hasn't overridden
   via the toggle (inline boot script sets data-theme before first paint;
   this block only matters if JS is unavailable). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d10; --bg-2: #0e0f13; --surface: #15161b; --surface-2: #1a1c22;
    --border: #262932; --border-strong: #333743; --line: #20232b;
    --text: #f2f3f5; --text-2: #c3c7d0; --text-3: #9297a3; --text-4: #666b77;
    --accent: #6191ff; --accent-hover: #83a8ff; --accent-subtle: rgba(97,145,255,0.16); --accent-ghost: rgba(97,145,255,0.1);
    --green: #4ade80; --green-subtle: rgba(74,222,128,0.12);
    --amber: #fbbf24; --amber-subtle: rgba(251,191,36,0.12);
    --red: #f87171; --red-subtle: rgba(248,113,113,0.12);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  }
}

/* ==========================================================================
   Reset + base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--t-med), color var(--t-med);
}
h1, h2, h3, p, ol, ul { margin: 0; }
button, select, input { font-family: inherit; color: inherit; }
button { cursor: pointer; }

/* The `hidden` attribute must always win over component display classes —
   without this, any ".foo[hidden]" element where .foo sets its own
   `display` ties the UA [hidden] rule on specificity and (being
   author-origin) beats it, silently un-hiding the element. */
[hidden] { display: none !important; }
svg { display: block; }

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

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: baseline; gap: var(--space-2); }
.topbar__mark { color: var(--accent); flex-shrink: 0; align-self: center; }
.topbar__name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--text);
}
.topbar__tagline {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-4);
}

.topbar__controls { display: flex; align-items: center; gap: var(--space-3); min-width: 0; flex-shrink: 1; }

.scenario-picker { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.scenario-picker__label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
  flex-shrink: 0;
}
.scenario-picker__select {
  appearance: none; -webkit-appearance: none;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23737373' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 26px 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  width: 100%;
  min-width: 0;
  max-width: 280px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: border-color var(--t-fast);
}
@media (max-width: 640px) {
  .scenario-picker__select { max-width: 150px; }
  .topbar__tagline { display: none; }
}
.scenario-picker__select:hover { border-color: var(--text-4); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--text-4); color: var(--text); }
.icon-btn svg { width: 15px; height: 15px; }

.icon-moon { display: none; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: block; }

/* ==========================================================================
   Error banner
   ========================================================================== */

.error-banner {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: var(--space-4) var(--space-6) 0;
  padding: var(--space-3) var(--space-4);
  background: var(--red-subtle);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
.error-banner[hidden] { display: none; }
.error-banner strong { font-weight: 700; }

/* ==========================================================================
   Layout
   ========================================================================== */

.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--space-6);
  max-width: 1440px;
  margin: 0 auto;
  padding: var(--space-6);
  align-items: start;
}

.col-main { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
.col-side { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: var(--space-4); }
}

/* ==========================================================================
   Stats bar
   ========================================================================== */

.statsbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.statsbar__meta { min-width: 0; max-width: 620px; }
.statsbar__title {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.statsbar__desc {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
}
.statsbar__claim {
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-3);
}
.statsbar__claim b { color: var(--text-2); font-weight: 500; }
.statsbar__claim .truth { color: var(--green); }
.statsbar__claim .corrupted { color: var(--red); }
.statsbar__caption {
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--text-4);
}

.statsbar__readout { display: flex; align-items: flex-end; gap: var(--space-6); flex-shrink: 0; }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat__label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-4);
}
.stat__value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  font-feature-settings: "tnum";
}
.stat--big { align-items: flex-start; }
.stat__value--display {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 34px;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
}
.stat--big .stat__row { display: flex; align-items: baseline; gap: var(--space-2); }

.trend {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  font-feature-settings: "tnum";
}
.trend--up { color: var(--green); }
.trend--down { color: var(--red); }
.trend--neutral { color: var(--text-4); }

/* ==========================================================================
   Bracket-frame motif — small L-shaped "scan target" corner ticks.
   Used deliberately in exactly two places (graph panel + detail panel) —
   not sprinkled everywhere.
   ========================================================================== */

.bracket-frame {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.bf-corner { position: absolute; width: 14px; height: 14px; pointer-events: none; }
.bf-corner--tl { top: -1px; left: -1px; border-top: 1.5px solid var(--border-strong); border-left: 1.5px solid var(--border-strong); border-top-left-radius: 4px; }
.bf-corner--tr { top: -1px; right: -1px; border-top: 1.5px solid var(--border-strong); border-right: 1.5px solid var(--border-strong); border-top-right-radius: 4px; }
.bf-corner--bl { bottom: -1px; left: -1px; border-bottom: 1.5px solid var(--border-strong); border-left: 1.5px solid var(--border-strong); border-bottom-left-radius: 4px; }
.bf-corner--br { bottom: -1px; right: -1px; border-bottom: 1.5px solid var(--border-strong); border-right: 1.5px solid var(--border-strong); border-bottom-right-radius: 4px; }

/* ==========================================================================
   Graph panel
   ========================================================================== */

.graph-panel { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }

.graph-panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.graph-panel__label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--text-4);
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--text-3);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.chip-btn:hover { border-color: var(--text-4); color: var(--text-2); }
.chip-btn[aria-pressed="true"] {
  background: var(--accent-ghost);
  border-color: var(--accent);
  color: var(--accent);
}

.graph-panel__canvas-wrap {
  position: relative;
  width: 100%;
  height: 480px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
#graphCanvas { display: block; width: 100%; height: 100%; }

@media (max-width: 960px) {
  .graph-panel__canvas-wrap { height: 380px; }
}

.graph-panel__loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--text-4);
  background: var(--surface);
  animation: softPulse 1.4s ease-in-out infinite;
}
.graph-panel__loading[hidden] { display: none; }

@keyframes softPulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* legend */
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); padding: 0 2px; }
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-3);
}
.legend__dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend__dot--green { background: var(--green); }
.legend__dot--red { background: var(--red); }
.legend__dot--gray { background: var(--text-4); }
.legend__note { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--text-4); }

/* ==========================================================================
   Transport (playback controls)
   ========================================================================== */

.transport { display: flex; align-items: center; gap: var(--space-3); padding-top: var(--space-2); border-top: 1px solid var(--line); }

.transport__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}
.transport__btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-4); }
.transport__btn:active:not(:disabled) { transform: scale(0.94); }
.transport__btn:disabled { opacity: 0.35; cursor: default; }
.transport__btn svg { width: 14px; height: 14px; }

.transport__btn--primary {
  width: 38px; height: 38px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.transport__btn--primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.transport__scrub {
  flex: 1;
  min-width: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border-strong);
  border-radius: 2px;
  outline-offset: 6px;
}
.transport__scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--t-fast);
}
.transport__scrub::-webkit-slider-thumb:hover { transform: scale(1.15); }
.transport__scrub::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.transport__scrub::-moz-range-track { height: 3px; background: var(--border-strong); border-radius: 2px; }

.transport__roundlabel {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  min-width: 52px;
  text-align: right;
  font-feature-settings: "tnum";
}

/* ==========================================================================
   Cards (round log / detail panel shared chrome)
   ========================================================================== */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--line);
}
.card__label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-4);
}

/* ==========================================================================
   Round log
   ========================================================================== */

.round-log__list { list-style: none; padding: var(--space-2) var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); max-height: 220px; overflow-y: auto; }
.round-log__item { display: flex; flex-direction: column; gap: 2px; }
.round-log__edge {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}
.round-log__outcome { font-size: 12px; color: var(--text-3); line-height: 1.5; }
.round-log__empty { padding: var(--space-2) var(--space-4) var(--space-4); font-family: var(--font-mono); font-size: 11.5px; color: var(--text-4); }

/* ==========================================================================
   Detail panel
   ========================================================================== */

.detail-panel { display: flex; flex-direction: column; }
.detail-panel__body { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }

.detail-empty {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-4);
  padding: var(--space-2) 0 var(--space-4);
}

.detail-id-row { display: flex; align-items: center; justify-content: space-between; }
.detail-id { font-family: var(--font-mono); font-weight: 700; font-size: 20px; color: var(--text); }
.detail-role { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em; color: var(--text-4); text-transform: uppercase; }

.detail-value-block { display: flex; flex-direction: column; gap: 6px; }
.detail-label { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-4); }
.badge {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
}
.badge--green { background: var(--green-subtle); color: var(--green); }
.badge--red { background: var(--red-subtle); color: var(--red); }
.badge--gray { background: var(--surface-2); color: var(--text-4); }

.meter-row { display: flex; flex-direction: column; gap: 6px; }
.meter-row__top { display: flex; align-items: baseline; justify-content: space-between; }
.meter-row__value { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); font-feature-settings: "tnum"; }
.meter { height: 5px; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.meter__fill { height: 100%; background: var(--accent); border-radius: var(--radius-sm); transition: width var(--t-med), background var(--t-med); }

.provenance-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 1.5px solid var(--line);
  padding-left: var(--space-3);
}
.provenance-list li {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
}
.provenance-list .idx {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
  flex-shrink: 0;
  min-width: 16px;
}

.detail-docs { display: flex; flex-direction: column; gap: 4px; }
.detail-docs__item { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-3); }

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 var(--space-6) var(--space-8);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-4);
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

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