:root {
  --bg: #f1f6fb;
  --ink: #16324b;
  --muted: #4f6f8b;
  --panel: #ffffff;
  --line: #d7e4f0;
  --panel-shadow: rgba(22, 50, 75, 0.08);
  --table-head: #f8fbff;
  --table-row-alt: #fbfdff;
  --input-bg: #ffffff;
  --hero-a: #0f3a62;
  --hero-b: #1c5f96;
  --hero-c: #20818b;
  --brand: #1f6fb2;
  --brand-dark: #154f82;
  --teal: #1f8f85;
  --amber: #bd7d00;
  --danger: #b6404d;
}

* {
  box-sizing: border-box;
}

body.theme-dark {
  --bg: #0b1725;
  --ink: #d8e7f5;
  --muted: #9bb3ca;
  --panel: #132537;
  --line: #2a4157;
  --panel-shadow: rgba(0, 0, 0, 0.35);
  --table-head: #162b3f;
  --table-row-alt: #112335;
  --input-bg: #0f1f30;
  --hero-a: #061726;
  --hero-b: #0a3a5b;
  --hero-c: #1f6a73;
  --brand: #67b2ff;
  --brand-dark: #9fd1ff;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: 'IBM Plex Sans', sans-serif;
  background:
    radial-gradient(circle at 7% 0%, color-mix(in oklab, var(--brand) 16%, transparent) 0, transparent 34%),
    radial-gradient(circle at 100% 8%, color-mix(in oklab, var(--teal) 18%, transparent) 0, transparent 30%),
    linear-gradient(180deg, color-mix(in oklab, var(--bg) 92%, #ffffff) 0%, var(--bg) 75%);
}

.page {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.15rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(320px, 1fr);
  gap: 1rem;
  padding: 1.3rem;
  border-radius: 22px;
  color: #f7fbff;
  background: linear-gradient(120deg, var(--hero-a), var(--hero-b) 52%, var(--hero-c));
  box-shadow: 0 16px 32px rgba(15, 58, 98, 0.24);
}

.hero-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
}

.kicker {
  margin: 0 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  opacity: 0.9;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: 'Source Serif 4', serif;
}

h1 {
  font-size: clamp(1.45rem, 2.45vw, 2.45rem);
  line-height: 1.12;
}

.subtitle {
  margin: 0.55rem 0 0;
  color: #dbefff;
  max-width: 72ch;
}

.theme-btn {
  min-height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.16);
  color: #f4f9ff;
  padding: 0.35rem 0.82rem;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.scope-pill {
  display: inline-block;
  margin: 0.58rem 0 0;
  padding: 0.38rem 0.72rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.17);
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: #eef7ff;
  font-size: 0.83rem;
}

.citation {
  margin: 0.72rem 0 0;
  font-size: 0.84rem;
  line-height: 1.4;
  color: #e5f2ff;
}

.citation a {
  color: #ffffff;
  font-weight: 700;
}

.hero-stats {
  display: grid;
  gap: 0.58rem;
  align-content: start;
}

.stat-card {
  min-height: 74px;
  border-radius: 14px;
  padding: 0.64rem 0.78rem;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: grid;
  align-content: center;
}

.stat-value {
  font-size: 1.34rem;
  font-weight: 700;
}

.stat-label {
  margin-top: 0.08rem;
  color: #ebf4ff;
  font-size: 0.8rem;
}

.accent-intra {
  border-color: rgba(95, 255, 221, 0.44);
}

.accent-post {
  border-color: rgba(166, 219, 255, 0.42);
}

.accent-pre {
  border-color: rgba(255, 225, 167, 0.5);
}

.context-card {
  background: rgba(8, 25, 40, 0.32);
}

.panel {
  margin-top: 0.95rem;
  padding: 1rem;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 9px 20px var(--panel-shadow);
}

.top-tabs {
  margin-top: 0.95rem;
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.26rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel) 90%, #ffffff);
  box-shadow: 0 8px 18px var(--panel-shadow);
}

.top-tab {
  border: 1px solid transparent;
  border-radius: 999px;
  min-height: 38px;
  padding: 0.38rem 0.95rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.top-tab:hover {
  color: var(--ink);
}

.top-tab.is-active {
  color: #ffffff;
  background: linear-gradient(120deg, var(--hero-a), var(--hero-b) 62%, var(--hero-c));
  box-shadow: 0 8px 16px rgba(15, 58, 98, 0.24);
}

.tab-analysis-only {
  display: none;
}

body[data-active-tab='analysis'] .tab-analysis-only {
  display: block;
}

.panel h2 {
  font-size: 1.28rem;
  margin-bottom: 0.58rem;
}

.intro-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.62rem;
}

.secondary-btn {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel) 92%, #ffffff);
  color: var(--ink);
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}

.secondary-btn:hover {
  border-color: color-mix(in oklab, var(--brand) 40%, var(--line));
  background: color-mix(in oklab, var(--panel) 86%, #ffffff);
}

#reset-filters {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 90;
  box-shadow: 0 8px 20px var(--panel-shadow);
}

.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.58rem;
}

.filter-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.filter-field,
label {
  display: grid;
  gap: 0.22rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.filter-label {
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select {
  min-height: 44px;
  width: 100%;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  padding: 0.54rem 0.62rem;
  font: inherit;
  color: var(--ink);
}

input:focus,
select:focus,
.secondary-btn:focus {
  outline: 3px solid rgba(31, 111, 178, 0.24);
  outline-offset: 2px;
}

.filter-popover {
  position: relative;
}

.popover-trigger {
  list-style: none;
  min-height: 44px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  padding: 0.54rem 0.72rem;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popover-trigger::-webkit-details-marker {
  display: none;
}

.popover-trigger::after {
  content: '▾';
  font-size: 0.8rem;
  color: var(--muted);
}

.filter-popover[open] .popover-trigger {
  border-color: #9dbdd8;
  box-shadow: 0 0 0 3px rgba(31, 111, 178, 0.14);
}

.filter-popover[open] .popover-trigger::after {
  content: '▴';
}

.popover-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 260px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 10px 24px var(--panel-shadow);
  padding: 0.45rem;
  display: grid;
  gap: 0.2rem;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 8px;
  padding: 0.35rem 0.35rem;
  color: var(--ink);
  font-size: 0.9rem;
}

.filter-option:hover {
  background: color-mix(in oklab, var(--brand) 10%, transparent);
}

.filter-option input {
  min-height: auto;
  width: auto;
  margin: 0;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.chart-subtitle {
  margin: 0 0 0.5rem;
  color: #4a6782;
  font-size: 0.9rem;
}

.chart {
  min-height: 330px;
}

.chart-fallback {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-caption {
  margin: 0 0 0.62rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-filters-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.6rem;
  margin: 0.55rem 0 0.75rem;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  background: var(--panel);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.56rem 0.5rem;
  vertical-align: top;
  text-align: left;
}

th {
  color: var(--ink);
  font-weight: 700;
  background: var(--table-head);
}

tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

.rob-pill {
  display: inline-block;
  padding: 0.2rem 0.52rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.rob-low {
  color: #0f6d54;
  background: #daf3eb;
}

.rob-some {
  color: #7f5d00;
  background: #fff2ce;
}

.rob-high {
  color: #8d2633;
  background: #fde4e9;
}

.study-name {
  font-weight: 700;
}

.study-link {
  font-weight: 700;
  color: var(--brand-dark);
  text-decoration: none;
}

.study-link:hover {
  color: var(--brand);
  text-decoration: underline;
}

.app-footer {
  margin: 1rem 0 0.4rem;
  padding: 0.8rem 0.95rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: color-mix(in oklab, var(--panel) 90%, transparent);
  color: var(--muted);
  font-size: 0.84rem;
}

.app-footer p {
  margin: 0;
}

.source-line {
  margin-top: 0.35rem !important;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.source-link {
  display: inline-flex;
  align-items: center;
  color: var(--ink);
}

.source-link:hover {
  color: #1f6fb2;
}

.github-icon {
  width: 1rem;
  height: 1rem;
}

.app-footer a {
  color: var(--brand-dark);
  font-weight: 600;
  text-decoration: none;
}

.app-footer a:hover {
  color: var(--brand);
  text-decoration: underline;
}

.meta-analysis-panel {
  position: relative;
}

.meta-note,
.meta-coverage-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.meta-coverage-note {
  margin-top: 0.38rem;
}

.meta-forest-wrap {
  margin-top: 0.68rem;
  overflow-x: auto;
}

.meta-forest-grid {
  display: grid;
  grid-template-columns: 198px 132px 132px 300px 170px 170px;
  align-items: stretch;
  grid-auto-rows: minmax(44px, auto);
  min-width: 1102px;
  border-top: 1px solid var(--line);
}

.meta-cell {
  padding: 0.24rem 0.4rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.79rem;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  height: 100%;
  min-height: 44px;
  box-sizing: border-box;
}

.meta-cell-head {
  font-size: 0.76rem;
  font-weight: 700;
  background: color-mix(in oklab, var(--table-head) 85%, var(--panel));
  color: var(--ink);
  white-space: pre-line;
  min-height: 68px;
  align-items: flex-end;
  padding-top: 0.34rem;
  padding-bottom: 0.5rem;
}

.meta-study-col {
  font-weight: 500;
}

.meta-count-col {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meta-plot-head {
  padding: 0.34rem 0 0.5rem;
  display: flex;
  align-items: flex-end;
}

.meta-favours {
  display: flex;
  justify-content: space-between;
  gap: 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.15;
  width: 100%;
}

.meta-favours span {
  flex: 1 1 50%;
}

.meta-favours span:last-child {
  text-align: right;
}

.meta-plot-cell {
  padding: 0.22rem 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  height: 100%;
  min-height: 44px;
  box-sizing: border-box;
}

.meta-plot-svg,
.meta-axis-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.meta-plot-svg {
  min-height: 34px;
}

.meta-axis-svg {
  height: 56px;
}

.meta-row-pooled {
  background: color-mix(in oklab, var(--table-head) 82%, var(--panel));
  font-style: italic;
  font-weight: 700;
}

.meta-axis-spacer {
  border-bottom: none;
  background: transparent;
}

.meta-axis-cell {
  padding: 0;
  border-bottom: none;
  display: flex;
  align-items: flex-end;
}

.meta-footnote-row {
  border-bottom: none;
  padding-top: 0.36rem;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 30px;
}

.meta-inspiration {
  text-align: right;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  justify-content: flex-end;
  grid-column: 5 / span 2;
}

.meta-inspiration-block {
  display: inline-block;
  text-align: left;
  line-height: 1.2;
}

.meta-inspiration-line1 {
  white-space: nowrap;
}

.meta-inspiration a {
  color: var(--brand-dark);
  font-style: italic;
  text-decoration: none;
}

.meta-inspiration a:hover {
  color: var(--brand);
  text-decoration: underline;
}

.meta-symbol-note {
  margin: 0.42rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
}

.meta-explainer {
  margin-top: 0.9rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.45rem;
}

.meta-explainer > summary {
  cursor: pointer;
  color: var(--brand-dark);
  font-weight: 700;
  list-style: none;
}

.meta-explainer > summary::-webkit-details-marker {
  display: none;
}

.meta-explainer > summary::before {
  content: '▸';
  margin-right: 0.35rem;
  color: var(--muted);
}

.meta-explainer[open] > summary::before {
  content: '▾';
}

.meta-explainer-body {
  margin-top: 0.62rem;
  font-size: 0.84rem;
  color: var(--ink);
  line-height: 1.45;
}

.meta-explainer-body p {
  margin: 0 0 0.58rem;
}

.meta-explainer-body pre {
  margin: 0.35rem 0 0.58rem;
  padding: 0.62rem 0.72rem;
  border-radius: 10px;
  background: color-mix(in oklab, var(--table-head) 86%, var(--panel));
  border: 1px solid var(--line);
  overflow-x: auto;
}

.meta-explainer-body code {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 0.82rem;
}

.meta-explainer-body ul {
  margin: 0 0 0.62rem;
  padding-left: 1.1rem;
}

.meta-explainer-body li {
  margin-bottom: 0.28rem;
}

.meta-explainer-body a {
  color: var(--brand-dark);
  font-weight: 600;
}

.meta-equation {
  overflow-x: auto;
}

@media (max-width: 1180px) {
  .hero {
    grid-template-columns: 1fr;
  }

  .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-filters-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .meta-forest-grid {
    grid-template-columns: 180px 122px 122px 282px 160px 160px;
  }
}

@media (max-width: 740px) {
  .chart-grid,
  .filters-grid {
    grid-template-columns: 1fr;
  }

  .table-filters-grid {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-topline {
    flex-direction: column;
    align-items: flex-start;
  }

  .top-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .top-tab {
    width: 100%;
  }
}
