:root {
  --bg: #eef0f4;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #5d6475;
  --line: #d9dde5;
  --navy: #1d2173;
  --navy-2: #2b318f;
  --accent: #f07d2a;
  --blue: #3b57c4;
  --ok: #2e9e3a;
  --warn: #b25b00;
  --bad: #c0392b;
  --field: #f7f8fb;
  --radius: 8px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.4 var(--font); }
[hidden] { display: none !important; }
h2 { font-size: 15px; margin: 0; letter-spacing: .01em; }
h3 { font-size: 14px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; }
.right { text-align: right; }

/* ------------------------------------------------------------------ buttons, inputs */
.btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 6px;
       padding: 6px 12px; cursor: pointer; }
.btn:hover { border-color: #aab1c0; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--navy-2); }
.btn.primary:disabled { background: #9aa0c4; border-color: #9aa0c4; cursor: default; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: inherit; }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
.btn.wide { width: 100%; margin-top: 10px; padding: 9px; }
input, select { font: inherit; color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; }
select { padding: 3px 4px; }
label.inline { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--muted); }
.link { color: #dfe3ff; text-decoration: none; }
.link:hover { text-decoration: underline; }

/* ------------------------------------------------------------------ sign in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px;
          background: linear-gradient(160deg, #141861 0%, #2b318f 55%, #3b57c4 100%); }
.signin-card { width: min(360px, 100%); padding: 26px; display: flex; flex-direction: column; gap: 6px; }
.signin-card .brand { color: var(--navy); font-size: 19px; }
.signin-card input { padding: 8px; }
.signin-card .btn { margin-top: 10px; padding: 9px; }
.error { color: var(--bad); min-height: 1.2em; margin: 4px 0 0; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { width: 22px; height: 22px; border-radius: 50%; position: relative;
              background: radial-gradient(circle at 35% 35%, #ffc83a, #f07d2a 60%, #a8206d); }
.brand-mark::after { content: ""; position: absolute; left: 9px; top: -6px; width: 4px; height: 12px; background: #c9cdf5; border-radius: 2px; }

/* ------------------------------------------------------------------ frame */
.top { display: flex; align-items: center; gap: 14px; padding: 9px 18px; background: var(--navy); color: #fff; }
.top .btn.ghost { color: #dfe3ff; }
.who { color: #c9cdf5; font-size: 13px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; background: #e6e9f2; color: var(--muted); }
.top .pill { background: rgba(255,255,255,.12); color: #dfe3ff; }
.pill.running { background: #fff1e5; color: var(--warn); }
.pill.queued { background: #eef0ff; color: var(--blue); }
.pill.done { background: #e7f6e9; color: var(--ok); }
.pill.stopped { background: #f4ecdf; color: var(--warn); }
.pill.failed { background: #fbe6e3; color: var(--bad); }

.layout { display: grid; gap: 14px; padding: 14px; grid-template-columns: 360px minmax(0, 1fr);
          grid-template-areas: "setup result" "setup tools" "setup compare" "setup runs"; grid-template-rows: auto auto auto 1fr; align-items: start; max-width: 1600px; margin: 0 auto; }
.setup { grid-area: setup; display: flex; flex-direction: column; gap: 14px; }
.result { grid-area: result; min-height: 420px; }
.runs { grid-area: runs; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "setup" "result" "tools" "compare" "runs"; padding: 10px; }
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
        box-shadow: 0 1px 2px rgba(20, 24, 60, .05); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

/* ------------------------------------------------------------------ segmented control */
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.seg button { flex: 1; font: inherit; font-size: 13px; border: 0; background: #fff; padding: 6px 4px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-checked="true"] { background: var(--navy); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------------ fields */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; margin-bottom: 8px; }
.sv { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sv > label, .choice > label { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sv-box { display: flex; }
.sv-box input { flex: 1; min-width: 0; border-radius: 5px 0 0 5px; font-variant-numeric: tabular-nums; }
.sv-arrows { display: flex; flex-direction: column; }
.sv-arrows button { flex: 1; border: 1px solid var(--line); border-left: 0; background: #fff; font-size: 7px; line-height: 1; padding: 0 5px; cursor: pointer; color: var(--muted); }
.sv-arrows button:first-child { border-radius: 0 5px 0 0; border-bottom: 0; }
.sv-arrows button:last-child { border-radius: 0 0 5px 0; }
.sv.bad input { border-color: var(--bad); background: #fff4f2; }
.choice { display: flex; flex-direction: column; gap: 2px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; padding-top: 14px; }
.readouts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: 12.5px;
            background: #f6f7fb; border-radius: 6px; padding: 7px 10px; }
.readouts dt { color: var(--muted); }
.readouts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.problems { margin: 6px 0 0; padding: 0; list-style: none; }
.problems li { font-size: 12.5px; color: var(--bad); background: #fdf0ee; border-radius: 5px; padding: 6px 8px; margin-top: 4px; }
.message { font-size: 13px; color: var(--muted); min-height: 1.3em; margin: 0 4px; }
.message.bad { color: var(--bad); }

/* ------------------------------------------------------------------ result */
.run-title { margin: -4px 0 8px; font-size: 13px; }
.progress { position: relative; height: 20px; background: #eef0f6; border-radius: 99px; overflow: hidden; margin-bottom: 10px; }
.progress .bar { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--blue), var(--navy)); transition: width .4s; }
.progress span { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 20px; color: #fff; mix-blend-mode: difference; }
.downloads { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.downloads a { text-decoration: none; }
.panes { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; }
/* rows of images that fill the width: 1, 2 or 3 per row (4 as 2 x 2, 5 as 3 + 2, 6 as 3 x 2) */
.panes[data-count="1"] { grid-template-columns: minmax(0, 1fr); }
.panes[data-count="2"], .panes[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panes[data-count="3"], .panes[data-count="5"], .panes[data-count="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .panes[data-count] { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
}
.pane { border: 1px solid var(--line); border-radius: 7px; padding: 8px; background: #fafbfd; min-width: 0; }
.pane-bar { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; align-items: center; }
.pane-bar select { font-size: 12px; }
.pane-img { display: flex; gap: 6px; align-items: stretch; min-height: 76px; }
.img-wrap { flex: 1 1 0; min-width: 0; align-self: flex-start; position: relative; aspect-ratio: 1; background: #111; border-radius: 3px; overflow: hidden; cursor: crosshair; }
.img-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.cross { position: absolute; width: 11px; height: 11px; margin: -6px 0 0 -6px; border: 2.5px solid #00e5ff; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 1px rgba(255,255,255,.85); }
.scanmark { position: absolute; left: 0; width: 0; height: 0; margin-top: -6px; border-top: 6px solid transparent; border-bottom: 6px solid transparent;
  border-left: 9px solid #ff2a2a; filter: drop-shadow(0 0 1px #fff); pointer-events: none; }
.small-label { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.small-label select { font-size: 12px; }
.cbar-box { flex: none; width: 14px; position: relative; }
.cbar { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 2px; }
.pane-img > * { min-height: 0; }
.cbar-labels { flex: none; contain: size; width: 56px; display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; font-variant-numeric: tabular-nums; min-width: 52px; }
.cbar-labels .unit { color: var(--muted); }
.pane-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 4px; min-height: 1.3em; }
.scope { width: 100%; height: 70px; display: block; margin-top: 4px; background: #14161d; border-radius: 3px; }
.plot-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 4px; }
canvas.plot { width: 100%; height: 280px; display: block; }
canvas.plot.tall { height: 420px; }
.ffm { margin-top: 6px; border-top: 1px solid var(--line); }

/* ------------------------------------------------------------------ runs */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); padding: 6px; }
td { border-bottom: 1px solid #eef0f4; padding: 6px; vertical-align: middle; }
tr.current td { background: #f3f5ff; }
td .btn + .btn { margin-left: 4px; }
td.right { white-space: nowrap; }

/* ------------------------------------------------------------------ parameters dialog */
.dialog { border: 0; border-radius: 10px; padding: 16px; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
          box-shadow: 0 20px 60px rgba(10, 14, 50, .35); }
.dialog::backdrop { background: rgba(14, 18, 50, .45); }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button { font: inherit; font-size: 13px; border: 0; background: none; padding: 6px 10px; cursor: pointer; color: var(--muted);
               border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
.param-body { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 14px; max-height: 58vh; overflow: auto; padding: 2px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }

.tools { grid-area: tools; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.tune-fields { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card-head { flex-wrap: wrap; }
.law-table { margin-top: 8px; font-size: 12.5px; }
.law-table td, .law-table th { padding: 4px 6px; }
.scope { height: 92px; }
.carried { font-size: 11.5px; color: var(--warn); }

.compare { grid-area: compare; }
.sweep-axis { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.sweep-axis .choice.wide, .sweep-axis .wide { grid-column: 1 / -1; }
.row-btns { display: flex; gap: 8px; align-items: center; }
.compare-table { font-size: 12.5px; }
.compare-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.compare-table td.best { font-weight: 700; }
.grid-cell { text-align: center; font-variant-numeric: tabular-nums; cursor: pointer; }
.api-steps li { margin: 8px 0; }
pre.key { background: #fff8e6; border: 1px solid #f0d58a; padding: 8px; border-radius: 6px; user-select: all; word-break: break-all; white-space: pre-wrap; }
pre.example { background: #14161d; color: #e8eaf0; padding: 12px; border-radius: 6px; font-size: 12px; overflow-x: auto; }

/* ------------------------------------------------------------------ sweep, tip, favourites */
.sv.swept input { background: #fff3cf; border-color: #e0a100; }
.sv.swept label::after { content: " · swept"; color: #b07800; font-weight: 600; }
.sweep-kind { margin-bottom: 8px; }
.tip-plots { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 14px; }
.tip-plots canvas.plot { height: 250px; }
.plot-title { font-size: 13px; margin: 0 0 2px; font-weight: 600; }
@media (max-width: 900px) { .tip-plots { grid-template-columns: minmax(0, 1fr); } }
.fav-save { display: flex; gap: 6px; margin-bottom: 8px; }
.fav-save input { flex: 1 1 auto; min-width: 0; }
.fav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.fav-list li { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fafbfd; }
.fav-list .fav-text { flex: 1 1 auto; min-width: 0; }
.fav-list .fav-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.fav-list .fav-sub { font-size: 11.5px; color: var(--muted); }
.fav-empty { font-size: 12px; color: var(--muted); }
