:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #e3e7ee;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e6efff;
  --good: #1a7f37;
  --bad: #c62828;
  --warn: #9a6700;
  --chip: #eef1f5;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1318;
    --panel: #171c23;
    --text: #e4e8ee;
    --muted: #9aa4b2;
    --line: #2a313b;
    --accent: #5b9dff;
    --accent-ink: #0b1220;
    --accent-soft: #1c2a40;
    --good: #4ac26b;
    --bad: #ff6b6b;
    --warn: #d4a72c;
    --chip: #222933;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 8px; color: var(--muted); }
h3 { font-size: 15px; margin: 12px 0 6px; }
.hint { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
.muted { color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 16px; }
.brand img { height: 34px; width: auto; }
.brand small { font-weight: 400; color: var(--muted); }
.links { margin-left: auto; display: flex; gap: 14px; }
.links a { text-decoration: none; }
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.status.loading .dot { animation: pulse 1s ease-in-out infinite; }
.status.ready .dot { background: var(--good); }
.status.error .dot { background: var(--bad); }
.status.busy .dot { background: var(--accent); animation: pulse .7s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* layout */
.layout {
  display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 16px; padding: 16px 20px 40px; max-width: 1600px; margin: 0 auto;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-inline: 16px; }
  .links { margin-left: 0; }
}
.setup { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel, .results { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel { padding: 12px 14px; }
.results { padding: 0 16px 16px; min-width: 0; }

/* form controls */
label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
input, select, button { font: inherit; color: var(--text); }
input[type=number], input[type=search], input[type=text], select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=search] { width: 100%; margin-bottom: 8px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1 1 140px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.span2 { grid-column: span 2; }
.pair { display: flex; gap: 4px; }
.pair select { flex: 0 0 76px; }
.pair input { flex: 1 1 auto; width: 60px; }
button { cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); padding: 6px 10px; }
button:disabled { cursor: not-allowed; opacity: .55; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary.busy { position: relative; color: transparent; }
button.primary.busy::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent-ink); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
button.ghost { background: transparent; }
button.small { padding: 2px 7px; font-size: 12px; }
#compute { padding: 10px; font-size: 15px; }

/* element picker */
.elements { display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; overflow-y: auto; padding: 2px; }
.el { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.el button { border: 0; border-radius: 0; padding: 3px 7px; background: var(--chip); font-size: 12.5px; }
.el button + button { border-left: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.el button.on { background: var(--accent); color: var(--accent-ink); }
.el button:disabled { opacity: 1; cursor: default; }
.components { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.comp { display: grid; grid-template-columns: 1fr 120px 24px; gap: 6px; align-items: center; }
.comp .name { font-weight: 600; }
.comp .name small { font-weight: 400; color: var(--muted); margin-left: 4px; }
.comp input { width: 100%; }
.comp button { padding: 0; border: 0; background: none; color: var(--muted); font-size: 16px; }
.subhead { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; margin: 10px 0 4px; }

/* phases */
.phases { max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.phase { display: grid; grid-template-columns: 18px 1fr 92px; gap: 6px; align-items: center; padding: 2px 0; }
.phase .pname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phase .pname small { color: var(--muted); margin-left: 5px; }
.phase input[type=number] { width: 100%; padding: 2px 5px; }
.phase input[type=number]:disabled { opacity: .35; }
.phase-group { font-size: 11.5px; text-transform: uppercase; color: var(--muted); margin: 6px 0 2px; display: flex; justify-content: space-between; }
.fixed-row { display: grid; grid-template-columns: 1fr 90px 24px; gap: 6px; margin-bottom: 4px; }
.fixed-row button { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 0; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; margin: 0 -16px 12px; padding: 0 12px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 12px 12px 10px; white-space: nowrap; color: var(--muted); font-weight: 500; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.alert { padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); white-space: pre-wrap; }
.alert.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.empty { padding: 30px 10px; max-width: 680px; }
.empty h3 { font-size: 18px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 8px; }
.card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.card .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.card .v { font-size: 18px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.card .v.small { font-size: 14px; }
.card.good .v { color: var(--good); }
.card.bad .v { color: var(--bad); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 1150px) { .split { grid-template-columns: minmax(0, 1fr); } }
.chart { min-height: 340px; width: 100%; overflow: hidden; }
.chart.tall { min-height: 440px; }
.chart.square { height: min(72vh, 680px); }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--panel); font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
tr.present td:first-child { font-weight: 600; }
td.pos { color: var(--bad); }
td.zero { color: var(--good); }
#notes { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
details { margin-top: 10px; }
details pre { overflow-x: auto; background: var(--bg); padding: 10px; border-radius: 8px; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; margin-bottom: 10px; }
.controls input[type=number] { width: 84px; }
.progress { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.progress div { flex: 1; height: 6px; border-radius: 3px; background: var(--line); position: relative; overflow: hidden; }
.progress div::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--p, 0%); background: var(--accent); transition: width .15s; }
.progress span { font-size: 12.5px; color: var(--muted); min-width: 120px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.code-wrap { position: relative; }
.code-wrap button { position: absolute; top: 8px; right: 8px; }
.code-wrap pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow-x: auto; }
