:root {
  color-scheme: dark;
  --bg: #070915;
  --panel: rgba(16, 20, 39, 0.88);
  --panel-solid: #101427;
  --line: rgba(170, 185, 220, 0.16);
  --grid: rgba(174, 194, 225, 0.11);
  --text: #f4f7fb;
  --muted: #98a3ba;
  --quiet: #657089;
  --frontier: #6ce5c8;
  --frontier-soft: rgba(108, 229, 200, 0.2);
  --accent: #ffbd5d;
  --dot: #8ca0c6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 70% -20%, rgba(46, 68, 119, 0.32), transparent 38%),
    radial-gradient(circle at 0% 100%, rgba(28, 95, 85, 0.14), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select, input { font: inherit; }
button, select { color: inherit; }

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 540px;
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) 34px;
  isolation: isolate;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 9, 21, 0.72);
  backdrop-filter: blur(18px);
  z-index: 5;
}

.brand-block, .brand, .header-actions, .status { display: flex; align-items: center; }
.brand-block { gap: 20px; min-width: 0; }
.brand { gap: 10px; color: var(--text); text-decoration: none; font-size: 1rem; letter-spacing: -0.02em; white-space: nowrap; }
.brand strong { font-weight: 720; }
.brand-mark { width: 29px; height: 29px; border-radius: 8px; background: #13182d; }
.brand-mark path { fill: none; stroke: var(--frontier); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark circle { fill: var(--accent); }

.status { gap: 7px; color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--frontier); box-shadow: 0 0 12px var(--frontier); }
.header-actions { gap: 6px; }

.icon-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover, .icon-button:focus-visible { color: var(--text); border-color: var(--line); background: rgba(255,255,255,0.04); outline: none; }
.icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }

.chart-shell { position: relative; min-height: 0; padding: 20px 24px 88px; display: flex; flex-direction: column; }
.chart-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; padding: 0 7px 12px 54px; }
.eyebrow { margin: 0 0 5px; color: var(--frontier); font: 600 0.68rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 0.14em; }
h1 { margin: 0; font-size: clamp(1.65rem, 3vw, 3.25rem); line-height: 0.98; letter-spacing: -0.055em; font-weight: 680; }
.chart-summary { width: min(36vw, 460px); margin: 0 0 3px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

.plot-wrap { position: relative; flex: 1; min-height: 0; border-top: 1px solid var(--line); }
#chart { display: block; width: 100%; height: 100%; overflow: visible; }
.axis-label { position: absolute; color: var(--quiet); font-size: 0.72rem; letter-spacing: 0.03em; pointer-events: none; }
.axis-y { left: 0; top: 50%; transform: translate(-37%, -50%) rotate(-90deg); }
.axis-x { left: 50%; bottom: -19px; transform: translateX(-50%); }

.grid-line { stroke: var(--grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.axis-tick { fill: var(--quiet); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.model-dot { fill: var(--dot); opacity: 0.48; stroke: #070915; stroke-width: 1.5; vector-effect: non-scaling-stroke; transition: opacity 160ms ease, r 160ms ease; }
.model-dot.open { fill: var(--bg); stroke: var(--dot); opacity: 0.75; }
.model-dot:hover, .model-dot.focused { opacity: 1; }
.frontier-area { fill: url(#frontier-fill); opacity: 0.42; pointer-events: none; }
.frontier-line { fill: none; stroke: var(--frontier); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 7px rgba(108,229,200,.35)); vector-effect: non-scaling-stroke; pointer-events: none; }
.frontier-dot { fill: var(--frontier); stroke: #070915; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; }
.frontier-dot.open { fill: #070915; stroke: var(--frontier); stroke-width: 2.4; }
.highlight-dot { fill: var(--accent); stroke: #070915; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: pointer; filter: drop-shadow(0 0 6px rgba(255,189,93,.38)); }
.highlight-dot.open { fill: #070915; stroke: var(--accent); stroke-width: 2.4; }
.leader { stroke: rgba(108,229,200,.62); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.frontier-label { fill: var(--text); font-size: 11px; font-weight: 650; paint-order: stroke; stroke: var(--bg); stroke-width: 5px; stroke-linejoin: round; cursor: grab; touch-action: none; user-select: none; }
.frontier-label:hover, .frontier-label:focus-visible { fill: var(--accent); outline: none; }
.dragging-label, .dragging-label .frontier-label { cursor: grabbing; }
.frontier-label-sub { fill: var(--muted); font-size: 9.5px; font-weight: 500; }
.threshold-line { stroke-width: 2; stroke-dasharray: 7 5; vector-effect: non-scaling-stroke; cursor: grab; opacity: .9; pointer-events: stroke; }
.threshold-line:hover, .threshold-line:focus-visible { stroke-width: 4; opacity: 1; outline: none; }
.threshold-hit-area { stroke: transparent; stroke-width: 16; vector-effect: non-scaling-stroke; cursor: grab; pointer-events: stroke; }
.dragging-threshold, .dragging-threshold .threshold-line { cursor: grabbing; }
.threshold-label { font-size: 10px; font-weight: 700; paint-order: stroke; stroke: var(--bg); stroke-width: 5px; stroke-linejoin: round; pointer-events: none; }

.tooltip {
  position: fixed;
  z-index: 20;
  width: max-content;
  max-width: min(320px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid rgba(162, 179, 216, 0.24);
  border-radius: 11px;
  background: rgba(12, 15, 30, 0.96);
  box-shadow: 0 16px 44px rgba(0,0,0,.36);
  pointer-events: none;
  backdrop-filter: blur(12px);
}
.tooltip strong { display: block; margin-bottom: 5px; font-size: 0.9rem; }
.tooltip p { margin: 3px 0 0; color: var(--muted); font-size: 0.77rem; line-height: 1.4; }
.tooltip .value { color: var(--frontier); font-weight: 650; }

.control-dock {
  position: absolute;
  left: 50%;
  bottom: 43px;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 5px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 6px;
  border: 1px solid rgba(163, 180, 216, 0.2);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 16px 48px rgba(0,0,0,.38);
  backdrop-filter: blur(18px);
}

.select-control, .switch-control { min-height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 12px; border-radius: 9px; color: var(--muted); font-size: 0.79rem; white-space: nowrap; }
.select-control { gap: 6px; }
.select-control > span { color: var(--quiet); font-size: 0.7rem; text-transform: uppercase; letter-spacing: .08em; }
select { max-width: 190px; border: 0; background: transparent; font-weight: 620; outline: none; cursor: pointer; }
.segment { display: flex; gap: 2px; padding: 3px; border-radius: 9px; background: rgba(0,0,0,.24); }
.segment button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 0.79rem; cursor: pointer; }
.segment button.active { background: #28304a; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.switch-control { cursor: pointer; }
.switch-control input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 31px; height: 18px; flex: 0 0 auto; border-radius: 99px; background: #343a50; transition: background 140ms ease; }
.switch i { position: absolute; width: 12px; height: 12px; left: 3px; top: 3px; border-radius: 50%; background: #aeb7ca; transition: transform 140ms ease, background 140ms ease; }
input:checked + .switch { background: rgba(108,229,200,.28); }
input:checked + .switch i { transform: translateX(13px); background: var(--frontier); }
.switch-control:focus-within { outline: 2px solid rgba(108,229,200,.7); outline-offset: 1px; }

.help-panel {
  position: absolute;
  right: 24px;
  top: 18px;
  z-index: 8;
  width: min(390px, calc(100% - 48px));
  padding: 22px 24px 20px;
  border: 1px solid rgba(163,180,216,.22);
  border-radius: 15px;
  background: rgba(13,17,33,.97);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.customize-panel {
  position: absolute;
  right: 24px;
  top: 18px;
  z-index: 9;
  width: min(420px, calc(100% - 48px));
  max-height: calc(100% - 36px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid rgba(163,180,216,.22);
  border-radius: 15px;
  background: rgba(13,17,33,.98);
  box-shadow: 0 20px 60px rgba(0,0,0,.48);
  backdrop-filter: blur(18px);
}
.panel-heading, .section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 1.25rem; letter-spacing: -.025em; }
.panel-close { margin: -9px -8px 0 0; border: 0; background: none; color: var(--muted); font-size: 1.55rem; cursor: pointer; }
.customize-section { margin-top: 19px; padding-top: 17px; border-top: 1px solid var(--line); }
.customize-section h3 { margin: 0; font-size: .86rem; }
.customize-section p { margin: 4px 0 0; color: var(--quiet); font-size: .7rem; line-height: 1.35; }
.range-controls { display: grid; gap: 13px; margin-top: 13px; }
.range-control { min-width: 0; margin: 0; padding: 0; border: 0; }
.range-control legend { float: left; color: var(--muted); font-size: .72rem; font-weight: 620; }
.range-values { display: flex; justify-content: flex-end; gap: 6px; color: var(--quiet); font: .66rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.range-values output { color: var(--text); }
.range-pair { --range-low: 0%; --range-high: 100%; position: relative; height: 24px; margin-top: 3px; }
.range-track { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 99px; background: linear-gradient(to right, #343a50 0 var(--range-low), var(--frontier) var(--range-low) var(--range-high), #343a50 var(--range-high) 100%); }
.range-pair input[type="range"] { appearance: none; position: absolute; inset: 0; width: 100%; height: 24px; margin: 0; background: transparent; pointer-events: none; }
.range-pair input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: transparent; }
.range-pair input[type="range"]::-webkit-slider-thumb { appearance: none; width: 16px; height: 16px; margin-top: -6px; border: 2px solid var(--panel-solid); border-radius: 50%; background: var(--frontier); box-shadow: 0 0 0 1px rgba(108,229,200,.5); pointer-events: auto; cursor: grab; }
.range-pair input[type="range"]::-moz-range-track { height: 4px; background: transparent; }
.range-pair input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 2px solid var(--panel-solid); border-radius: 50%; background: var(--frontier); box-shadow: 0 0 0 1px rgba(108,229,200,.5); pointer-events: auto; cursor: grab; }
.range-pair input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-pair input[type="range"]:focus-visible::-moz-range-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
.threshold-actions { display: flex; gap: 5px; }
.mini-button, .text-button { border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.04); color: var(--muted); cursor: pointer; }
.mini-button { height: 29px; display: flex; align-items: center; gap: 5px; padding: 0 8px; font-size: .68rem; }
.mini-button:hover, .mini-button:focus-visible, .text-button:hover, .text-button:focus-visible { color: var(--text); border-color: rgba(108,229,200,.42); outline: none; }
.mini-button i { display: block; width: 11px; height: 11px; }
.vertical-icon { border-left: 2px dashed var(--accent); }
.horizontal-icon { border-top: 2px dashed var(--accent); transform: translateY(4px); }
.threshold-list { display: grid; gap: 7px; margin-top: 12px; }
.threshold-item { display: grid; grid-template-columns: 28px minmax(0,1fr) 26px; align-items: center; gap: 8px; padding: 7px; border-radius: 9px; background: rgba(255,255,255,.035); }
.threshold-item input[type="color"] { width: 28px; height: 28px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: transparent; cursor: pointer; }
.threshold-details { min-width: 0; }
.threshold-details > input { width: 100%; padding: 0; border: 0; background: transparent; color: var(--text); font-size: .77rem; font-weight: 620; outline: none; }
.threshold-details > span { display: flex; gap: 8px; margin-top: 3px; color: var(--quiet); font: .64rem ui-monospace, SFMono-Regular, Menlo, monospace; }
.threshold-details output { color: var(--muted); }
.remove-button { width: 26px; height: 26px; border: 0; border-radius: 7px; background: transparent; color: var(--quiet); font-size: 1.1rem; cursor: pointer; }
.remove-button:hover, .remove-button:focus-visible { background: rgba(240,120,143,.12); color: #f0788f; outline: none; }
.panel-empty { padding: 12px 2px; }
.model-section { min-height: 0; }
.text-button { padding: 4px 8px; font-size: .68rem; }
.settings-actions { display: flex; gap: 7px; margin-top: 11px; }
.import-status { min-height: 1em; }
.import-status.error { color: #f0788f; }
.model-search { height: 35px; display: flex; align-items: center; gap: 7px; margin-top: 11px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(0,0,0,.18); }
.model-search:focus-within { border-color: rgba(108,229,200,.48); }
.model-search svg { width: 15px; fill: none; stroke: var(--quiet); stroke-width: 1.8; }
.model-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font-size: .75rem; }
.model-list { max-height: min(31vh, 265px); overflow: auto; display: grid; gap: 2px; margin-top: 7px; padding-right: 3px; scrollbar-color: #39415c transparent; }
.model-option { display: grid; grid-template-columns: 16px minmax(0,1fr); column-gap: 8px; align-items: center; padding: 7px 8px; border-radius: 7px; cursor: pointer; }
.model-option:hover { background: rgba(255,255,255,.045); }
.model-option input { position: absolute; opacity: 0; }
.checkmark { grid-row: 1; width: 15px; height: 15px; display: grid; place-items: center; border: 1px solid #46506d; border-radius: 4px; }
.model-option input:checked + .checkmark { border-color: var(--accent); background: var(--accent); }
.model-option input:checked + .checkmark::after { content: '✓'; color: #251a06; font-size: 11px; font-weight: 900; }
.model-option input:focus-visible + .checkmark { outline: 2px solid rgba(108,229,200,.75); outline-offset: 2px; }
.model-option-text { grid-column: 2; min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 9px; }
.model-option-text strong { overflow: hidden; color: #dce3f1; font-size: .72rem; font-weight: 580; text-overflow: ellipsis; white-space: nowrap; }
.model-option-text small { flex: 0 0 auto; color: var(--quiet); font-size: .61rem; }
.help-panel h2 { margin: 4px 0 10px; font-size: 1.25rem; letter-spacing: -.025em; }
.help-panel p:not(.eyebrow) { color: var(--muted); font-size: .88rem; line-height: 1.55; }
.help-close { position: absolute; right: 11px; top: 8px; border: 0; background: none; color: var(--muted); font-size: 1.55rem; cursor: pointer; }
.help-key { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .78rem; }
.sample-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--dot); border: 1px solid var(--dot); }
.sample-dot.hollow { margin-left: 8px; background: var(--panel-solid); }
.empty-state { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.source-note { padding: 0 24px; display: flex; align-items: center; justify-content: space-between; color: var(--quiet); font-size: .68rem; border-top: 1px solid var(--line); }
.source-note a { color: #8593b0; text-underline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 780px) {
  body { overflow: auto; }
  .app-shell { min-height: 720px; }
  .topbar { padding: 0 14px; }
  .status, .wide-label { display: none; }
  .icon-button { width: 38px; justify-content: center; padding: 0; }
  .chart-shell { padding: 16px 12px 148px; }
  .chart-heading { padding: 0 4px 10px 38px; align-items: flex-start; }
  .chart-summary { display: none; }
  h1 { font-size: 1.65rem; }
  .control-dock { bottom: 42px; flex-wrap: wrap; justify-content: center; width: calc(100% - 24px); }
  .select-control { flex: 1 1 100%; justify-content: center; }
  .segment { flex: 1 1 auto; }
  .segment button { flex: 1; }
  .switch-control { padding: 0 8px; }
  .axis-y { left: -9px; }
  .source-note { padding: 0 12px; }
  .source-note span:last-child { display: none; }
  .customize-panel { right: 12px; top: 10px; width: calc(100% - 24px); max-height: calc(100% - 20px); padding: 16px; }
}

@media (max-width: 430px) {
  .switch-control { font-size: .72rem; }
  .control-dock { gap: 2px; padding: 5px; }
  .plot-wrap { min-height: 390px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
