:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #475569;
  --accent: #0d9488;
  --accent-deep: #0f766e;
  --violet: #6366f1;
  --warn: #b45309;
  --below: #dc2626;
  --border: #cbd5e1;
  --focus: #2563eb;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  overflow-x: clip;
}

html {
  overflow-x: clip;
}

header {
  background: linear-gradient(135deg, #0f766e 0%, #6366f1 100%);
  color: #fff;
  padding: 1.5rem 1.25rem 1rem;
}

header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
  font-weight: 650;
}

header p {
  margin: 0;
  max-width: 52rem;
  opacity: 0.95;
  font-size: 0.95rem;
}

nav[aria-label="Sections"] {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}

nav button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}

nav button[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent-deep);
  color: #fff;
}

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

main {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
  box-sizing: border-box;
}

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  max-width: 100%;
  overflow-x: clip;
}

.panel.active {
  display: block;
}

.panel h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  background: #f8fafc;
}

.stat .label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat .value {
  font-size: 1.25rem;
  font-weight: 650;
}

.stat .source {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

th {
  background: #f1f5f9;
}

.table-scroll th,
.bar-chart-plot th {
  position: static;
  top: auto;
}

tr.below-chance {
  background: #fef2f2;
}

tr.below-chance td:first-child {
  font-weight: 600;
  color: var(--below);
}

.chart-wrap {
  margin: 1rem 0;
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.table-scroll:focus-visible,
.bar-chart-plot:focus-visible,
.chart-wrap:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.fold-chart-block {
  min-width: min(100%, 520px);
}

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

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
}

.swatch.chance {
  background: #94a3b8;
}

.swatch.csp {
  background: var(--accent);
}

.swatch.nn {
  background: var(--violet);
}

.chart-plot-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  min-width: 0;
  --chart-label-space: 1.15rem;
}

.y-axis {
  position: relative;
  width: 2.75rem;
  flex-shrink: 0;
  height: 180px;
  margin-top: var(--chart-label-space);
  border-right: 1px solid var(--border);
  overflow: visible;
}

.y-tick {
  position: absolute;
  right: 0.35rem;
  transform: translateY(-50%);
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1;
}

.y-tick.tick-zero {
  transform: translateY(-100%);
}

.y-tick span {
  display: block;
  text-align: right;
}

.bar-plot-area {
  flex: 1;
  min-width: 0;
}

.bar-chart-plot {
  overflow-x: auto;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--chart-label-space);
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  min-width: min(100%, 520px);
  overflow: visible;
}

.bar-group-plot {
  flex: 1 1 72px;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bar-group-plot .bars {
  display: flex;
  justify-content: center;
  gap: 4px;
  align-items: flex-end;
  width: 100%;
  height: 180px;
  border-bottom: 1px solid var(--border);
}

.bar-caption {
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.bar {
  width: 16px;
  border-radius: 4px 4px 0 0;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.bar-value {
  position: absolute;
  top: -1.1rem;
  font-size: 0.62rem;
  color: var(--muted);
  white-space: nowrap;
  transform: rotate(-45deg);
  transform-origin: bottom center;
  pointer-events: none;
}

.bar.csp {
  background: var(--accent);
}

.bar.chance {
  background: #94a3b8;
}

.bar.nn {
  background: var(--violet);
}

.ci-note {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

.note {
  border-left: 4px solid var(--accent);
  padding: 0.75rem 1rem;
  background: #ecfdf5;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.note.warn {
  border-color: var(--warn);
  background: #fffbeb;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.controls label {
  font-size: 0.88rem;
  color: var(--muted);
}

.controls select,
.controls input {
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.5rem, 1fr));
  gap: 0.35rem;
  font-size: 0.75rem;
  font-family: ui-monospace, monospace;
}

footer {
  max-width: 1100px;
  margin: 1rem auto 2rem;
  padding: 0 1.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  header h1 {
    font-size: 1.25rem;
  }
}
