:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-track: #cde2fb;
  --series-2: #eb6834;
  --negative: #e34948;
  --good: #0ca30c;
  --good-text: #006300;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-track: #1c3a5e;
    --series-2: #d95926;
    --negative: #e66767;
    --good-text: #0ca30c;
    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #262624;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-track: #1c3a5e;
  --series-2: #d95926;
  --negative: #e66767;
  --good-text: #0ca30c;
  --accent: #3987e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 22px; }
h3 { font-size: 15px; margin-bottom: 12px; }
h4 { font-size: 13px; margin-top: 18px; }

.muted { color: var(--text-secondary); margin: 2px 0 0; }
.small { font-size: 13px; }
.card > .muted.small { margin: -4px 0 12px; }
.card > #model-note { margin-top: 12px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.controls { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }

.control { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.control input[type="range"] { width: 130px; accent-color: var(--accent); }
.control output { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; min-width: 32px; }
.toggle input { accent-color: var(--accent); }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
}
button.ghost { padding: 6px 12px; font-size: 13px; }
button.ghost:hover { background: var(--surface-2); }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 20px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}
.column { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-head { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.card-head h3 { margin-bottom: 0; }

/* ---------- question ---------- */

.question-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.eyebrow { margin: 0 0 2px; font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-secondary); }
.qid { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }
.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
}
.tag.focus { outline: 1px solid var(--text-secondary); color: var(--text-primary); }

.prediction { margin: 16px 0 8px; }
.prediction-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--text-secondary); }
.prediction-label strong { font-size: 28px; color: var(--text-primary); font-weight: 600; }

.meter { position: relative; height: 10px; border-radius: 5px; background: var(--series-1-track); margin-top: 6px; }
.meter-fill { height: 100%; border-radius: 5px; background: var(--series-1); width: 0; transition: width 300ms ease; }
.meter-target { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text-primary); border-radius: 1px; }

.reason { font-size: 13px; color: var(--text-secondary); margin: 10px 0 0; }

.note {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 14px 0;
}

.choices { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.choices.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice {
  position: relative;
  padding: 16px 8px;
  font-size: 20px;
  font-weight: 600;
  min-height: 64px;
}
.choice:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-2); }
.choice:disabled { cursor: wait; opacity: 0.6; }
.choice .key-badge {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--good-text);
}

/* ---------- feedback ---------- */

.feedback {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px;
  font-size: 14px;
}
.feedback .icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 700;
  font-size: 14px;
}
.feedback.good .icon { background: var(--good); }
.feedback.bad .icon { background: var(--critical); }
.feedback strong { display: block; }
.feedback p { margin: 0; color: var(--text-secondary); }

/* ---------- stat tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.tile .label { font-size: 12px; color: var(--text-secondary); }
.tile .value { font-size: 22px; font-weight: 600; }
.tile .sub { font-size: 12px; color: var(--text-muted); }

/* ---------- charts ---------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .empty { color: var(--text-muted); font-size: 13px; padding: 28px 0; text-align: center; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; color: var(--text-secondary); }
.key { display: inline-block; margin-left: 8px; }
.key:first-child { margin-left: 0; }
.key-line { width: 16px; height: 2px; background: var(--series-1); border-radius: 1px; }
.key-bar { width: 12px; height: 10px; background: var(--series-1); border-radius: 0 3px 3px 0; }
.key-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-2); }
.key-target { width: 2px; height: 12px; background: var(--text-primary); }

.parts { display: flex; flex-direction: column; gap: 4px; }
.part-row {
  display: grid;
  grid-template-columns: 178px minmax(0, 1fr) 76px;
  gap: 10px;
  align-items: center;
  padding: 5px 0;
  border-radius: 6px;
}
.part-row:hover { background: var(--surface-2); }
.part-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-name span { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.part-track { position: relative; height: 14px; }
.part-track::before { content: ""; position: absolute; left: 0; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.part-bar { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; transition: width 300ms ease; }
.part-dot {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: var(--series-2);
  box-shadow: 0 0 0 2px var(--surface);
}
.part-target { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text-primary); }
.part-value { font-size: 12px; color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }

.weak-tags { display: flex; flex-direction: column; gap: 8px; }
.weak-row { display: grid; grid-template-columns: 70px minmax(0, 1fr) 84px; gap: 10px; align-items: center; font-size: 13px; }
.weak-meter { height: 8px; border-radius: 4px; background: var(--series-1-track); overflow: hidden; }
.weak-meter div { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.weak-row .count { color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }

.coefs { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.coef-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) 52px; gap: 10px; align-items: center; font-size: 12px; }
.coef-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
.coef-track { position: relative; height: 12px; }
.coef-track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.coef-bar { position: absolute; top: 0; height: 100%; }
.coef-bar.pos { left: 50%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.coef-bar.neg { right: 50%; background: var(--negative); border-radius: 4px 0 0 4px; }
.coef-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-secondary); }

/* ---------- table ---------- */

details { margin-top: 10px; font-size: 13px; }
summary { cursor: pointer; color: var(--text-secondary); }
.table-wrap { overflow-x: auto; margin-top: 8px; max-height: 280px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; background: var(--surface); }

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 10;
  pointer-events: none;
  max-width: 260px;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
}
.tooltip b { font-weight: 600; }

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .topbar { padding: 14px 16px; }
}

@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Labels get their own line so they are not truncated on phones */
  .part-row,
  .coef-row {
    grid-template-columns: minmax(0, 1fr) 76px;
    grid-template-areas: "name name" "track value";
    row-gap: 2px;
  }
  .part-name, .coef-name { grid-area: name; }
  .part-track, .coef-track { grid-area: track; }
  .part-value, .coef-value { grid-area: value; }
  .choices { gap: 8px; }
}
