/* Axis - one stylesheet, no build step.
   Dark by default because coloured points on a dark field are easier to tell
   apart; light theme is a variable swap. Every interactive target is at least
   44px on a touch screen, which is why controls look chunkier than they would
   in a mouse-only app. */

:root {
  color-scheme: dark;
  --bg:          #0b0e14;
  --bg-alt:      #0f131c;
  --surface:     #141924;
  --surface-2:   #1a2030;
  --line:        #262d3d;
  --line-strong: #38415a;
  --ink:         #e8eaf0;
  --ink-muted:   #8d95a9;
  --ink-dim:     #626b80;
  --accent:      #5b8cff;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --danger:      #e5484d;
  --warn:        #f59e0b;
  --ok:          #10b981;
  --self:        #3b82f6;
  --proxy:       #f59e0b;
  --llm:         #a855f7;
  --radius:      12px;
  --radius-lg:   18px;
  --shadow:      0 10px 40px rgba(0, 0, 0, 0.45);
  --tap:         44px;
  --header-h:    58px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg:          #f6f7fa;
  --bg-alt:      #ffffff;
  --surface:     #ffffff;
  --surface-2:   #f1f3f8;
  --line:        #e2e6ef;
  --line-strong: #c6cddd;
  --ink:         #131722;
  --ink-muted:   #5c6479;
  --ink-dim:     #858da1;
  --accent-soft: rgba(91, 140, 255, 0.12);
  --shadow:      0 10px 34px rgba(20, 26, 45, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 0.75em; }
a  { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- App shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.topbar-spacer { flex: 1; }
.topbar-title {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
  color: var(--ink-muted);
}

main { flex: 1; width: 100%; }
.page { max-width: 1180px; margin: 0 auto; padding: 20px 16px 64px; }
.page-wide { max-width: none; padding: 0; }
.page-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .grow { flex: 1; min-width: 220px; }
.page-sub { color: var(--ink-muted); font-size: 0.92rem; margin: 4px 0 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-weight: 560;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, transform 0.06s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover:not(:disabled) { background: var(--line); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 85%, white); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 50%, transparent); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-small { min-height: 30px; padding: 0 9px; font-size: 0.82rem; border-radius: 8px; }
.btn-wide { width: 100%; }
.icon { flex: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- Inputs ---------- */
input[type="text"], input[type="email"], input[type="number"], textarea, select {
  width: 100%;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-alt);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
}
textarea { min-height: 76px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--ink-dim); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d95a9' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 16px;
  padding-right: 32px;
}
input[type="color"] {
  width: 38px; height: 38px; padding: 2px;
  border-radius: 9px; border: 1px solid var(--line-strong);
  background: var(--bg-alt); cursor: pointer;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 0.8rem; font-weight: 600; color: var(--ink-muted); letter-spacing: 0.01em; }
.field-hint { font-size: 0.76rem; color: var(--ink-dim); line-height: 1.4; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > * { flex: 1; min-width: 150px; }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.seg {
  flex: 1;
  min-width: fit-content;
  min-height: 32px;
  padding: 0 11px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 560;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, color 0.14s;
}
.seg:hover { color: var(--ink); }
.seg-active { background: var(--surface-2); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.segmented-small .seg { min-height: 26px; font-size: 0.78rem; padding: 0 8px; }

/* ---------- Toggle ---------- */
.toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; min-height: 32px; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: relative; flex: none;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 0.16s;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.16s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-label { font-size: 0.87rem; color: var(--ink); }

/* ---------- Slider ---------- */
.slider { display: flex; flex-direction: column; gap: 3px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.slider-label { font-size: 0.8rem; font-weight: 600; color: var(--ink-muted); }
.slider-value { font-size: 0.8rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.slider-input {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; background: transparent; cursor: pointer; margin: 0;
}
.slider-input::-webkit-slider-runnable-track { height: 5px; border-radius: 999px; background: var(--line-strong); }
.slider-input::-moz-range-track { height: 5px; border-radius: 999px; background: var(--line-strong); }
.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -7.5px;
  border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg); box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.slider-input::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h3 { flex: 1; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }

.quiz-card {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 15px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  text-align: left;
  font: inherit;
  color: inherit;
}
.quiz-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.quiz-card h3 { font-size: 1.02rem; }
.quiz-card-desc {
  color: var(--ink-muted); font-size: 0.86rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.quiz-card-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.78rem; color: var(--ink-dim); margin-top: auto; }

.trait-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.trait-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.trait-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 0.78rem; font-weight: 560; white-space: nowrap;
}

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 650; letter-spacing: 0.02em;
  border: 1px solid var(--line-strong); color: var(--ink-muted);
}
.pill-self  { color: var(--self);  border-color: color-mix(in srgb, var(--self) 45%, transparent);  background: color-mix(in srgb, var(--self) 12%, transparent); }
.pill-proxy { color: var(--proxy); border-color: color-mix(in srgb, var(--proxy) 45%, transparent); background: color-mix(in srgb, var(--proxy) 12%, transparent); }
.pill-llm   { color: var(--llm);   border-color: color-mix(in srgb, var(--llm) 45%, transparent);   background: color-mix(in srgb, var(--llm) 12%, transparent); }
.pill-ok    { color: var(--ok);    border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.pill-warn  { color: var(--warn);  border-color: color-mix(in srgb, var(--warn) 45%, transparent); }

.empty { text-align: center; padding: 48px 20px; color: var(--ink-muted); }
.empty h3 { margin-bottom: 6px; color: var(--ink); }
.muted { color: var(--ink-muted); }
.dim { color: var(--ink-dim); }
.small { font-size: 0.82rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.85em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Overlays ---------- */
#toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); z-index: 90; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast { padding: 11px 18px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 0.88rem; font-weight: 540; max-width: 88vw; }
.toast-error { border-color: var(--danger); color: var(--danger); }
.toast-success { border-color: var(--ok); color: var(--ok); }

.scrim {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(4, 6, 12, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; transition: opacity 0.18s;
}
.scrim.open { opacity: 1; }
.panel {
  width: 100%; max-width: 460px; max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transform: translateY(10px); transition: transform 0.2s;
}
.scrim.open .panel { transform: none; }
.panel-wide { max-width: 720px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 15px 15px 11px; border-bottom: 1px solid var(--line); }
.panel-head h2 { flex: 1; font-size: 1.05rem; }
.panel-body { padding: 15px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.panel-foot { display: flex; gap: 9px; justify-content: flex-end; padding: 12px 15px; border-top: 1px solid var(--line); }
.dialog-text { color: var(--ink-muted); margin: 0; }

/* ---------- Graph workspace ---------- */
/* The shell owns the viewport height so the canvas can take whatever the header
   and controls leave behind, on a phone as well as a desktop. */
.results-shell { display: flex; flex-direction: column; height: calc(100dvh - var(--header-h)); }
.results-head { padding: 12px 16px 0; margin-bottom: 10px; flex: none; }
.workspace { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.graph-stage {
  position: relative;
  flex: 1;
  min-height: 260px;
  background:
    radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--surface) 70%, transparent), transparent 68%),
    var(--bg);
  overflow: hidden;
}
.graph-stage canvas {
  display: block;
  touch-action: none;   /* the canvas owns pan and pinch; the page must not steal them */
  cursor: grab;
}
.graph-stage canvas:active { cursor: grabbing; }

.graph-tools {
  position: absolute; top: 10px; right: 10px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 5;
}
.graph-tools .icon-btn {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  width: var(--tap); height: var(--tap);
}
.graph-legend {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; gap: 12px; flex-wrap: wrap;
  padding: 7px 11px; border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 0.75rem; color: var(--ink-muted);
  z-index: 5; max-width: calc(100% - 76px);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-mark { width: 11px; height: 11px; flex: none; border: 1.6px solid currentColor; }
.legend-mark.self { border-radius: 50%; background: currentColor; }
.legend-mark.proxy { border-radius: 2px; }
.legend-mark.llm { transform: rotate(45deg); border-radius: 2px; }
.graph-hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 0.74rem; color: var(--ink-dim); pointer-events: none;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  padding: 3px 9px; border-radius: 8px; white-space: nowrap;
}

/* Controls: a docked sidebar with a mouse, a drag-up sheet with a thumb. */
.controls {
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  max-height: 52dvh;
}
.controls-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.controls-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px; display: flex; flex-direction: column; gap: 14px; }
.control-group { display: flex; flex-direction: column; gap: 9px; }
.control-group > h4 {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--ink-dim); margin: 0;
}
.control-note { font-size: 0.76rem; color: var(--ink-dim); line-height: 1.45; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 4px 12px; }

.tabbar { display: flex; gap: 2px; padding: 3px; background: var(--bg-alt); border-radius: 11px; border: 1px solid var(--line); }
.tabbar button {
  flex: 1; min-height: 34px; border: none; border-radius: 8px;
  background: transparent; color: var(--ink-muted);
  font: inherit; font-size: 0.85rem; font-weight: 570; cursor: pointer;
}
.tabbar button.active { background: var(--surface-2); color: var(--ink); }

/* Respondent list */
.people-list { display: flex; flex-direction: column; gap: 2px; }
.person {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px; border-radius: 10px;
  cursor: pointer; border: 1px solid transparent;
  background: transparent; text-align: left; font: inherit; color: inherit;
  min-height: 46px; width: 100%;
}
.person:hover { background: var(--surface-2); }
.person.selected { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.person-mark { width: 12px; height: 12px; flex: none; border: 2px solid currentColor; }
.person-mark.self { border-radius: 50%; background: currentColor; }
.person-mark.proxy { border-radius: 2px; }
.person-mark.llm { transform: rotate(45deg); border-radius: 2px; }
.person-body { flex: 1; min-width: 0; }
.person-name { font-size: 0.88rem; font-weight: 570; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub { font-size: 0.74rem; color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Score bars in the detail sheet */
.score-row { display: grid; grid-template-columns: minmax(72px, 30%) 1fr auto; align-items: center; gap: 9px; padding: 4px 0; }
.score-name { font-size: 0.83rem; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; position: relative; }
.score-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.score-value { font-size: 0.78rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

/* ---------- Builder ---------- */
.builder-layout { display: flex; flex-direction: column; gap: 16px; }
.builder-preview { position: sticky; top: calc(var(--header-h) + 8px); }
.preview-stage {
  position: relative;
  height: 300px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  overflow: hidden;
  background: var(--bg-alt);
}

.item-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-alt);
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.item-head { display: flex; align-items: center; gap: 8px; }
.item-index {
  width: 24px; height: 24px; flex: none;
  border-radius: 7px; background: var(--surface-2);
  display: grid; place-items: center;
  font-size: 0.75rem; font-weight: 700; color: var(--ink-muted);
}
.drag-handle { cursor: grab; color: var(--ink-dim); touch-action: none; }
.drag-handle:active { cursor: grabbing; }
.item-card.dragging { opacity: 0.4; }
.item-card.drop-target { border-color: var(--accent); }

.effect-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.effect-name { flex: 1; font-size: 0.82rem; display: flex; align-items: center; gap: 6px; min-width: 0; }
.effect-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.effect-input { width: 74px; flex: none; }
.effect-quick { display: flex; gap: 3px; }
.effect-quick button {
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--line); background: var(--bg);
  color: var(--ink-muted); font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.effect-quick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.corr-grid { display: flex; flex-direction: column; gap: 10px; }
.corr-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.corr-pair { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; min-width: 0; }
.corr-pair span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.corr-angle { font-size: 0.74rem; color: var(--ink-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }

.issue { display: flex; gap: 8px; align-items: flex-start; font-size: 0.82rem; padding: 7px 10px; border-radius: 9px; }
.issue-error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.issue-warn  { background: color-mix(in srgb, var(--warn) 12%, transparent);   color: var(--warn); }

/* ---------- Take flow ---------- */
.take-shell { max-width: 640px; margin: 0 auto; padding: 20px 16px 120px; }
.progress { height: 4px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-bottom: 20px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }

.question-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; margin-bottom: 14px; }
.question-prompt { font-size: 1.02rem; font-weight: 600; margin-bottom: 14px; line-height: 1.4; }
.option-list { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex; align-items: center; gap: 11px;
  min-height: var(--tap);
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--bg-alt);
  cursor: pointer;
  font-size: 0.93rem;
  transition: border-color 0.14s, background 0.14s;
  text-align: left; width: 100%; color: inherit; font-family: inherit;
}
.option:hover { border-color: var(--line-strong); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option-mark {
  width: 20px; height: 20px; flex: none;
  border-radius: 50%; border: 2px solid var(--line-strong);
  display: grid; place-items: center;
}
.option.multi .option-mark { border-radius: 6px; }
.option.selected .option-mark { border-color: var(--accent); background: var(--accent); color: #fff; }
.option.selected .option-mark svg { display: block; }
.option-mark svg { display: none; width: 12px; height: 12px; }

.scale-row { display: flex; gap: 6px; }
.scale-btn {
  flex: 1; min-height: var(--tap); min-width: 40px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: var(--bg-alt);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}
.scale-btn:hover { border-color: var(--line-strong); }
.scale-btn.selected { border-color: var(--accent); background: var(--accent); color: #fff; }
.scale-ends { display: flex; justify-content: space-between; gap: 10px; margin-top: 7px; font-size: 0.76rem; color: var(--ink-dim); }

.allocate-row { display: grid; grid-template-columns: minmax(70px, 26%) 1fr auto; align-items: center; gap: 10px; padding: 5px 0; }
.allocate-remaining { font-size: 0.84rem; color: var(--ink-muted); margin-bottom: 10px; }
.allocate-remaining strong { color: var(--ink); font-variant-numeric: tabular-nums; }

.take-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 11px 16px calc(11px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center;
}
.take-footer .grow { flex: 1; }

.mode-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--bg-alt);
  cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
  transition: border-color 0.14s, background 0.14s;
}
.mode-card:hover { border-color: var(--line-strong); }
.mode-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.mode-icon { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; }
.mode-body { flex: 1; min-width: 0; }
.mode-title { font-weight: 620; font-size: 0.93rem; }
.mode-desc { font-size: 0.8rem; color: var(--ink-muted); line-height: 1.4; }

.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; font-size: 0.75rem; font-weight: 700; color: var(--ink-muted); flex: none; }

.spinner {
  width: 17px; height: 17px; flex: none;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 44px; color: var(--ink-muted); }

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
  .page { padding: 26px 24px 64px; }
  .workspace { flex-direction: row; }
  .graph-stage { flex: 1; }
  .controls {
    width: 340px; flex: none;
    border-top: none; border-left: 1px solid var(--line);
    max-height: none; height: 100%;
  }
  .builder-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; align-items: start; gap: 22px; }
  .preview-stage { height: 340px; }
  .graph-hint { display: block; }
}
@media (max-width: 899px) {
  .graph-hint { display: none; }
  /* On a phone the graph is the point of the page, so the header shrinks to a
     title and its actions, and the control sheet gives back some height. */
  .results-head { padding: 10px 14px 0; margin-bottom: 6px; gap: 8px; }
  .results-head h1 { font-size: 1.12rem; }
  .results-head .page-sub { display: none; }
  .results-head .grow { min-width: 0; flex: 1 1 auto; }
  .results-head .btn { min-height: 34px; padding: 0 11px; font-size: 0.84rem; }
  .controls { max-height: 44dvh; }
  .graph-stage { min-height: 200px; }
  .scrim { align-items: flex-end; padding: 0; }
  .panel {
    max-width: none; width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    max-height: 88dvh;
    transform: translateY(100%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .scrim.open .panel { transform: none; }
  .panel-foot { position: sticky; bottom: 0; background: var(--surface); }
  .topbar-title { max-width: 32vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
