/* Interactive companion page for "Disparate privacy risks from medical AI".
   Builds on the tokens in styles.css; only chart colours are added here. */

/* ------------------------------------------------------------ chart tokens */
:root {
  --under:     #2a78d6;   /* validated blue: underrepresented / selected dataset */
  --over:      #e34948;   /* validated red: overrepresented */
  --context:   #c9ccd1;   /* unselected series */
  --grid:      #eeede9;
  --axis:      #cfcdc6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --under:   #3987e5;
    --over:    #e66767;
    --context: #3b4047;
    --grid:    #1f2226;
    --axis:    #33373d;
  }
}
:root[data-theme="dark"] {
  --under:   #3987e5;
  --over:    #e66767;
  --context: #3b4047;
  --grid:    #1f2226;
  --axis:    #33373d;
}

/* ---------------------------------------------------------------- layout */
.story-head { padding-top: 1.5rem; }
.kicker {
  margin: 0 0 .75rem;
  font-size: .8rem;
  letter-spacing: .06em;
  color: var(--faint);
}
.story-head h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 5.5vw, 2.9rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 1.25rem;
}
.story-head .lede { max-width: 44rem; }
.byline { font-size: .85rem; color: var(--muted); }
.byline a { color: var(--accent); border-bottom-color: transparent; }
.byline a:hover { border-bottom-color: var(--accent); }

.story > section { margin-top: 3.5rem; padding-top: 3.5rem; border-top: 1px solid var(--rule); }
.story > section > p { max-width: 44rem; }
.step {
  margin: 0 0 .5rem;
  font-size: .78rem;
  font-weight: 500;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--faint);
}
h2.finding {
  font-family: var(--serif);
  font-size: clamp(1.4rem, 3.4vw, 1.8rem);
  line-height: 1.25;
  margin: 0 0 1rem;
  max-width: 40rem;
  text-transform: none;
  letter-spacing: -0.01em;
  color: var(--text);
}
.muted { color: var(--faint); font-weight: 400; }

/* -------------------------------------------------------------- controls */
.controls { margin: 1.75rem 0 1.25rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  font: inherit;
  font-size: .8rem;
  padding: .3rem .75rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.chip:hover { color: var(--text); border-color: var(--faint); }
.chip[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
.chip small { color: var(--faint); margin-left: .35rem; font-size: .72rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 1.25rem;
}
.stat { background: var(--surface); padding: 1rem 1.1rem; }
.stat p { margin: 0; }
.stat-label { font-size: .78rem; color: var(--muted); }
.stat-value { font-size: 1.9rem; font-weight: 500; line-height: 1.2; margin: .2rem 0 !important; letter-spacing: -0.02em; }
.stat-note { font-size: .78rem; color: var(--faint); }
.stat-accent .stat-value { color: var(--text); }
.stat-accent { box-shadow: inset 3px 0 0 var(--under); }

.threshold {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  font-size: .85rem;
  margin-bottom: .5rem;
}
.threshold input { flex: 1 1 12rem; accent-color: var(--under); }
.threshold output { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 3.2rem; }

/* ------------------------------------------------------------ infographic */
/* The figure is drawn for a white page, so it keeps a white card in dark mode too. */
.infographic {
  margin: 1.5rem 0;
  max-width: 44rem;
}
.infographic img {
  display: block;
  width: 100%;
  height: auto;
  padding: 1rem 1.25rem;
  background: #ffffff;
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.infographic figcaption { font-size: .82rem; color: var(--muted); margin-top: .6rem; line-height: 1.55; }

/* ----------------------------------------------------------------- charts */
.viz { margin: 0 0 1rem; }
.viz-plot { position: relative; width: 100%; touch-action: pan-y; }
.viz-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz figcaption { font-size: .82rem; color: var(--muted); margin-top: .75rem; max-width: 44rem; line-height: 1.55; }

.grid line { stroke: var(--grid); stroke-width: 1; }
.axis line, .axis path { stroke: var(--axis); stroke-width: 1; }
.axis text, .tick text { fill: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis-title { fill: var(--muted); font-size: 11.5px; }
.annot { fill: var(--muted); font-size: 11px; }

.series { fill: none; stroke: var(--context); stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; }
.series.on { stroke: var(--under); stroke-width: 2.25; }
.series-label { fill: var(--faint); font-size: 11px; }
.series-label.on { fill: var(--text); font-weight: 600; }
.threshold-line { stroke: var(--text); stroke-width: 1; opacity: .55; }
.threshold-dot { fill: var(--under); stroke: var(--surface); stroke-width: 2; }
.agg-marker { fill: var(--muted); }
.crosshair { stroke: var(--faint); stroke-width: 1; }

.pt { stroke: var(--surface); stroke-width: 1.5; transition: opacity .15s ease; }
.pt.over { fill: var(--over); }
.pt.under { fill: var(--under); }
.pt.ns { fill: var(--surface); stroke-width: 1.5; }
.pt.ns.over { stroke: var(--over); }
.pt.ns.under { stroke: var(--under); }
.pt.dim { opacity: .22; }
.pt.hot { stroke: var(--text); stroke-width: 2; }
.ref-line { stroke: var(--faint); stroke-width: 1; }
.region { fill: var(--faint); font-size: 11px; letter-spacing: .04em; }

/* ------------------------------------------------------------------ legend */
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; font-size: .8rem; color: var(--muted); margin-bottom: .75rem; }
.legend span { display: inline-flex; align-items: center; gap: .45rem; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.key.over { background: var(--over); }
.key.under { background: var(--under); }
.key.neutral { background: var(--muted); }
.key.hollow { border: 1.5px solid var(--muted); }
.key.ring { border: 1.5px solid var(--muted); background: var(--surface); }

/* ---------------------------------------------------------- group panels */
.panels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: .9rem 1rem 1rem;
}
.panel h3 { margin: 0; font-size: .9rem; font-weight: 600; }
.panel .sig { margin: .1rem 0 .7rem; font-size: .75rem; color: var(--faint); }
.panel.ns .rows { opacity: .6; }
.row {
  display: grid;
  grid-template-columns: minmax(5.5rem, 34%) 1fr 3.6rem;
  align-items: center;
  gap: .6rem;
  padding: .28rem 0;
  font-size: .8rem;
  border-radius: 4px;
  cursor: default;
}
.row:hover, .row:focus-visible { background: var(--accent-bg); outline: none; }
.row-label { color: var(--text); line-height: 1.3; }
.row-delta { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.row-delta.ns { font-weight: 400; color: var(--muted); }
.track { position: relative; height: 16px; }
.track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--grid); }
.track .bar { position: absolute; top: calc(50% - 1px); height: 2px; border-radius: 1px; }
.track .bar.over { background: var(--over); }
.track .bar.under { background: var(--under); }
.track .m { position: absolute; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; }
.track .m.train { border: 1.5px solid var(--muted); background: var(--surface); }
.track .m.tail { box-shadow: 0 0 0 2px var(--surface); }
.track .m.tail.over { background: var(--over); }
.track .m.tail.under { background: var(--under); }
.scale-row { padding: .1rem 0 0; cursor: default; }
.scale-row:hover { background: none; }
.scale { display: flex; justify-content: space-between; font-size: .68rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------------- tooltip */
.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  min-width: 11rem;
  max-width: 17rem;
  padding: .55rem .7rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .12);
  font-size: .78rem;
  line-height: 1.45;
}
.tooltip .tt-title { font-weight: 600; margin-bottom: .25rem; }
.tooltip .tt-sub { color: var(--muted); }
.tooltip .tt-row { display: flex; align-items: center; gap: .5rem; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; min-width: 4.2rem; }
.tooltip .tt-row span { color: var(--muted); }
.tooltip .tt-row.on span { color: var(--text); }
.tooltip .lk { width: 12px; height: 2px; background: var(--context); flex: none; }
.tooltip .tt-row.on .lk { background: var(--under); }

/* ------------------------------------------------------------- table view */
.table-view { margin-top: .75rem; font-size: .82rem; }
.table-view summary { cursor: pointer; color: var(--muted); width: max-content; }
.table-view summary:hover { color: var(--text); }
.table-wrap { overflow-x: auto; margin-top: .75rem; }
.table-wrap table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.table-wrap th, .table-wrap td { text-align: right; padding: .35rem .6rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.table-wrap th:first-child, .table-wrap td:first-child,
.table-wrap th:nth-child(2), .table-wrap td:nth-child(2) { text-align: left; }
.table-wrap th { font-weight: 500; color: var(--muted); }

.method p { font-size: .88rem; color: var(--muted); }

@media (max-width: 600px) {
  .stat-value { font-size: 1.6rem; }
  .row { grid-template-columns: minmax(4.5rem, 32%) 1fr 3.2rem; }
}

@media (forced-colors: active) {
  .series.on, .threshold-dot, .pt { forced-color-adjust: none; }
}
