/* Interactive companion page for "Memorisation bias in medical AI".
   Builds on styles.css and privacy-risk.css (story layout, chips, stats, charts, tooltip). */

/* ------------------------------------------------------------ chart tokens */
:root {
  --record: #eb6834;   /* validated orange: record-level DP */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --record: #d95926; }
}
:root[data-theme="dark"] { --record: #d95926; }

/* ------------------------------------------------------------------ layout */
.infographic.wide { max-width: none; }
.infographic.wide img { padding: .75rem 1rem; }

.method-steps {
  display: grid;
  gap: .75rem;
  max-width: 44rem;
  margin: 1.25rem 0 1.75rem;
  padding-left: 1.25rem;
}
.method-steps li { padding-left: .25rem; }
.method-steps li::marker { color: var(--faint); font-variant-numeric: tabular-nums; }

.data-table { border-collapse: collapse; width: 100%; font-size: .84rem; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { text-align: right; padding: .45rem .6rem; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child,
.data-table th:nth-child(2), .data-table td:nth-child(2),
.data-table th:nth-child(3), .data-table td:nth-child(3) { text-align: left; }
.data-table th { font-weight: 500; color: var(--muted); }
.data-table td:first-child { font-weight: 600; }

h3.sub { font-size: .95rem; font-weight: 600; margin: 2.25rem 0 .25rem; }
.sub-note { font-size: .84rem; color: var(--muted); max-width: 44rem; }

.es-readout { font-size: .85rem; color: var(--muted); margin: 0 0 1rem; max-width: 44rem; min-height: 2.6em; }

.stats.compact { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }

.controls.stacked { display: grid; gap: .75rem; }
.controls.stacked > * { min-width: 0; }

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 2px;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
}
.segmented button {
  font: inherit;
  font-size: .8rem;
  padding: .3rem .85rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

/* ---------------------------------------------------------- legend keys */
.key.line { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--under); }
.key.line.muted-line { border-top-color: var(--muted); }
.key.line.dashed { border-top: 2px dashed var(--faint); }
.key.bar { width: 12px; height: 8px; border-radius: 2px; }
.key.bar.under { background: var(--over); }
.key.bar.over { background: var(--under); }
.key.bar.faint { background: var(--context); }
.key.dot.record { background: var(--record); }
.key.dot.patient { background: var(--under); }

/* ------------------------------------------------------------- chart marks */
.series.hist { stroke: var(--muted); stroke-width: 1.5; }
.series.random { stroke: var(--faint); stroke-width: 1.5; stroke-dasharray: 4 3; }
.series.record { stroke: var(--record); stroke-width: 2; }
.series.patient { stroke: var(--under); stroke-width: 2; }
.dot-record { fill: var(--record); stroke: var(--surface); stroke-width: 2; }
.dot-patient { fill: var(--under); stroke: var(--surface); stroke-width: 2; }
.err { stroke-width: 1.5; }
.err.record { stroke: var(--record); }
.err.patient { stroke: var(--under); }
.col { fill: var(--under); }
.col:hover { opacity: .8; }
.col-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.zero-band { fill: var(--grid); }

.panel-title { font-size: .8rem; color: var(--muted); margin: 0 0 .35rem; }
.dp-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr)); gap: 1.25rem; }

/* ---------------------------------------------------------- example cards */
.examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.example {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: .4rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}
.example p { margin: 0; }
.example .ex-kind { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); }
.example .ex-value { font-size: 1.6rem; font-weight: 500; letter-spacing: -0.02em; line-height: 1.15; }
.example .ex-value small { font-size: .8rem; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-left: .25rem; }
.example .ex-text { font-size: .82rem; color: var(--muted); line-height: 1.5; }
.ex-track { position: relative; height: 8px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.ex-track i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--under); border-radius: 0 4px 4px 0; }
.ex-scale { display: flex; justify-content: space-between; font-size: .68rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------- horizontal bars */
.aside-block { margin-top: 1rem; }
.hbars { display: grid; gap: .5rem; max-width: 36rem; margin-top: .9rem; }
.hbar { display: grid; grid-template-columns: 9.5rem 1fr 7.5rem; align-items: center; gap: .75rem; font-size: .82rem; }
.hbar .hb-track { position: relative; height: 10px; }
.hbar .hb-track::before { content: ""; position: absolute; inset: 4px 0 auto; border-top: 1px solid var(--grid); }
.hbar .hb-track i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--under); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .hb-value { text-align: right; font-variant-numeric: tabular-nums; }
.hbar .hb-value small { color: var(--faint); }

/* -------------------------------------------------------- diagnostic chart */
.diag { display: grid; gap: 0; font-size: .8rem; }
.diag-head, .diag-row {
  display: grid;
  grid-template-columns: minmax(8rem, 26%) 1fr 1fr;
  gap: 1rem;
  align-items: center;
}
.diag-head { color: var(--muted); font-size: .76rem; padding-bottom: .35rem; border-bottom: 1px solid var(--rule); }
.diag-head span:not(:first-child) { text-align: center; }
.diag-row { padding: .22rem .35rem; margin: 0 -.35rem; border-radius: 4px; cursor: pointer; }
.diag-row:hover, .diag-row:focus-visible { background: var(--accent-bg); outline: none; }
.diag-row[aria-pressed="true"] { background: var(--accent-bg); box-shadow: inset 2px 0 0 var(--accent); }
.diag-name { color: var(--text); line-height: 1.3; }
.diag-name small { color: var(--faint); margin-left: .3rem; font-variant-numeric: tabular-nums; }
.diag-cell { position: relative; height: 18px; }
.diag-cell::before { content: ""; position: absolute; top: 0; bottom: 0; left: var(--zero); border-left: 1px solid var(--axis); }
.diag-cell .b { position: absolute; top: 5px; height: 8px; }
.diag-cell .b.neg { background: var(--over); border-radius: 3px 0 0 3px; }
.diag-cell .b.pos { background: var(--under); border-radius: 0 3px 3px 0; }
.diag-cell .b.ns { background: var(--context); }
.diag-cell .v { position: absolute; top: 1px; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.diag-axis { display: grid; grid-template-columns: minmax(8rem, 26%) 1fr 1fr; gap: 1rem; margin-top: .3rem; font-size: .68rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.diag-axis .ax { position: relative; height: 1em; }
.diag-axis .ax span { position: absolute; transform: translateX(-50%); }

/* ------------------------------------------------------------- icon array */
.icon-compare {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0 .5rem;
  padding: 1.1rem 1.2rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.icon-compare h3 { margin: 0; font-size: .95rem; font-weight: 600; }
.icon-compare .ic-note { margin: 0; font-size: .8rem; color: var(--muted); }
.ic-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 1.25rem; }
.ic-group p { margin: 0 0 .5rem; font-size: .82rem; color: var(--muted); }
.ic-group p b { color: var(--text); font-size: 1.35rem; font-weight: 500; margin-right: .3rem; }
.ic-grid { display: grid; grid-template-columns: repeat(20, 1fr); gap: 3px; max-width: 18rem; }
.ic-grid i { aspect-ratio: 1; border-radius: 50%; background: var(--grid); }
.ic-grid i.on { background: var(--under); }
.ic-grid i.diff { background: none; box-shadow: inset 0 0 0 1.5px var(--over); }

@media (max-width: 600px) {
  .diag-head, .diag-row, .diag-axis { grid-template-columns: minmax(6.5rem, 30%) 1fr 1fr; gap: .6rem; }
  .hbar { grid-template-columns: 7rem 1fr 6.5rem; }
  .example .ex-value { font-size: 1.4rem; }
}
