/* ── PAGE-SCOPED TOKENS ──────────────────────────────────────────── */
:root {
  --primary:       #1e3a8a;
  --accent-green:  #047857;
  --accent-amber:  #b45309;
  --accent-red:    #dc2626;
  --text-main:     #0f172a;
  --text-muted:    #475569;
  --bg-card:       #ffffff;
  --bg-subtle:     #f8fafc;
  --chart-stroke:  #2563eb;
  --chart-fill:    rgba(37,99,235,0.08);
  --chart-grid:    #e2e8f0;
  --border:        #e2e8f0;
  --radius:        12px;
  --radius-sm:     8px;
}
[data-theme="dark"] {
  --primary:       #60a5fa;
  --accent-green:  #34d399;
  --accent-amber:  #fbbf24;
  --accent-red:    #f87171;
  --text-main:     #f8fafc;
  --text-muted:    #cbd5e1;
  --bg-card:       #1e293b;
  --bg-subtle:     #0f172a;
  --chart-stroke:  #60a5fa;
  --chart-fill:    rgba(96,165,250,0.15);
  --chart-grid:    #334155;
  --border:        #334155;
}

body { font-family: 'Inter', system-ui, -apple-system, sans-serif; color: var(--text-main); line-height: 1.5; }

/* ── CARDS ───────────────────────────────────────────────────────── */
.block-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.card-title {
  font-size: 1.4rem;
  font-weight: 800; margin: 0 0 18px;
  color: var(--primary); display: flex; align-items: center; gap: 8px;
}

/* ── HERO STATS ──────────────────────────────────────────────────── */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 20px;
}
@media (min-width: 560px) { .hero-grid { grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); } }

.stat-hero-box {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat-hero-label {
  font-size: 0.72rem; color: var(--text-muted);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  display: block;
  margin-bottom: 5px;
}
.stat-hero-value {
  font-size: 2rem; font-weight: 900; line-height: 1.1; display: block;
  color: var(--text-main);
}
.stat-hero-value.c-primary { color: var(--primary); }
.stat-hero-value.c-green   { color: var(--accent-green); }
.stat-hero-sub { font-size: 0.78rem; color: var(--text-muted);
  margin-top: 2px; display: block; }

/* ── BADGE ROW ───────────────────────────────────────────────────── */
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 13px; border-radius: 20px;
  font-size: 0.82rem; font-weight: 700;
}
.badge-meaning  { background: rgba(4,120,87,.08);  color: var(--accent-green); border: 1px solid rgba(4,120,87,.2);  }
.badge-origin   { background: rgba(30,58,138,.07); color: var(--primary); border: 1px solid rgba(30,58,138,.18); }
.badge-theme    { background: rgba(0,0,0,.03);      color: var(--text-muted);   border: 1px solid var(--border); }
.badge-audio    {
  background: var(--bg-card); color: var(--primary); border: 1px solid var(--border);
  cursor: pointer; font-family: inherit;
  transition: background .15s;
}
.badge-audio:hover { background: rgba(30,58,138,.07); }

/* ── TREND INDICATORS ────────────────────────────────────────────── */
.trend-up   { color: var(--accent-green) !important; font-weight: 800; }
.trend-down { color: var(--accent-red)   !important; font-weight: 800; }
.trend-flat { color: var(--text-muted)   !important; font-weight: 700; }

/* ── STAT GRIDS ──────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 10px;
}
@media (min-width: 540px) { .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); } }

.stat-box {
  border: 1px solid var(--border); padding: 13px 14px;
  border-radius: var(--radius-sm); background: var(--bg-subtle);
}
.stat-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 4px; }
.stat-value { font-size: 1.3rem; font-weight: 900; display: block; color: var(--text-main); }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); display: block; margin-top: 2px; }

/* ── CHART ───────────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--bg-subtle); border-radius: var(--radius-sm);
  padding: 14px 10px 6px; margin-top: 16px;
  border: 1px solid var(--border);
}
.chart-labels {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--text-muted);
  font-weight: 600;
  padding: 6px 4px 0;
}

/* ── DECADE CHIPS ────────────────────────────────────────────────── */
.decade-row { display: flex; flex-wrap: wrap; gap: 8px; }
.decade-chip {
  padding: 6px 13px; background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: 20px; font-size: 0.85rem;
}
.decade-chip .d-yr { color: var(--text-muted); font-weight: 500; }
.decade-chip .d-v  { font-weight: 800; color: var(--text-main); }

/* ── ETYMOLOGY ───────────────────────────────────────────────────── */
.etym-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px,1fr));
  gap: 10px; margin-bottom: 16px;
}
.etym-box {
  padding: 13px 15px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg-subtle);
}
.etym-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 4px; }
.etym-value { font-size: 1.05rem; font-weight: 800; color: var(--text-main); display: block; }
.etym-body {
  border-left: 4px solid var(--accent-green);
  padding: 14px 16px; background: rgba(4,120,87,.03);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1rem;
  line-height: 1.75; color: var(--text-main);
}
.confidence-row {
  margin-top: 12px; font-size: 0.8rem;
  color: var(--text-muted); display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.conf-high   { color: var(--accent-green); font-weight: 700; }
.conf-medium { color: var(--accent-amber); font-weight: 700; }
.conf-low    { color: var(--accent-red);   font-weight: 700; }

/* ── STATE TABLE — BUG FIX: last column bleed & truncation ───────── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: block;
}
.state-table {
  width: 100%;
  min-width: 600px; 
  border-collapse: collapse;
  font-size: 0.88rem;
}
.state-table th,
.state-table td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; 
  text-align: left;
}
.state-table thead th {
  background: var(--bg-subtle); font-size: 0.72rem;
  font-weight: 800; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted);
  position: sticky; top: 0; z-index: 2;
}
.state-table tbody tr:hover { background: var(--bg-subtle); }
.state-table tbody tr:last-child td { border-bottom: none; }

/* scrollable max-height */
.table-scroll-inner {
  max-height: 360px; overflow-y: auto; display: block; width: 100%;
}

/* ── SIBLING / SIMILAR TAG CHIPS ─────────────────────────────────── */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 13px; border-radius: 20px; font-size: 0.88rem;
  font-weight: 600; text-decoration: none; display: inline-block;
  border: 1px solid var(--border);
  color: var(--text-main);
  background: var(--bg-subtle); transition: border-color .15s, background .15s;
}
.chip:hover  { border-color: var(--primary); background: rgba(30,58,138,.06); color: var(--primary); }
.chip-ghost  { opacity: .55; cursor: default; pointer-events: none; }
.chip-green  { background: rgba(4,120,87,.06); color: var(--accent-green); border-color: rgba(4,120,87,.2); }
.chip-blue   { background: rgba(30,58,138,.06); color: var(--primary); border-color: rgba(30,58,138,.18); }

/* ── SIBLING COLUMNS ─────────────────────────────────────────────── */
.sibling-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px,1fr));
  gap: 14px;
}
.sibling-col {
  border: 1px solid var(--border); padding: 16px;
  border-radius: var(--radius-sm); background: var(--bg-subtle);
}
.sibling-hdr {
  font-weight: 800; display: block; margin-bottom: 12px;
  font-size: 0.95rem; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}

/* ── BROWSE HUB ──────────────────────────────────────────────────── */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px,1fr));
  gap: 10px;
}
.hub-link {
  padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--primary); font-weight: 600; font-size: 0.9rem;
  text-decoration: none;
  background: var(--bg-subtle); display: block;
  transition: background .15s, border-color .15s;
}
.hub-link:hover { background: rgba(30,58,138,.06); border-color: var(--primary); }

/* ── CADENCE TOOL ────────────────────────────────────────────────── */
.cadence-input {
  width: 100%; max-width: 440px; padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem; background: var(--bg-card); color: var(--text-main);
  font-family: inherit; transition: border-color .15s;
}
.cadence-input:focus { outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,.12); }
.cadence-output {
  display: none; margin-top: 14px; padding: 14px 16px;
  background: rgba(30,58,138,.04);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem; line-height: 1.6;
}

/* ── NARRATIVE BLOCK ─────────────────────────────────────────────── */
.narr-block {
  border-left: 4px solid var(--primary); padding: 14px 18px;
  font-size: 1.05rem; line-height: 1.7;
  color: var(--text-main);
  background: rgba(30,58,138,.03); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.summary-banner {
  margin-top: 18px; padding: 14px 18px;
  background: rgba(37,99,235,.05);
  border-left: 4px solid var(--chart-stroke);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 1rem; line-height: 1.65;
}

/* ── RESPONSIVE ──────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .block-card    { padding: 16px 14px; }
  .stat-hero-value { font-size: 1.6rem; }
  .card-title    { font-size: 1.2rem; }
  h1.profile-title { font-size: 2.2rem !important; }
}