:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #17202e;
  --muted: #5d6878;
  --line: #d9dee6;
  --accent: #2563c9;
  --accent-soft: #e6eefb;
  --bad: #b42318;
  --warn-bg: #fff4e5;
  --info-bg: #eef3fb;
  --grid: #e7eaef;
  --band: rgba(34, 160, 90, 0.10);
  --c0: #2563c9;
  --c1: #e07a10;
  --c2: #1f9d55;
  --c3: #c8323c;
  --c4: #7c4dcc;
  --c5: #6b7280;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --panel: #1a2029;
    --text: #e6e9ef;
    --muted: #9aa4b2;
    --line: #2e3644;
    --accent: #6ea0ff;
    --accent-soft: #1f2b40;
    --bad: #ff7b72;
    --warn-bg: #3a2a12;
    --info-bg: #1c2636;
    --grid: #262d39;
    --band: rgba(60, 200, 120, 0.12);
    --c0: #6ea0ff;
    --c1: #f5a052;
    --c2: #4cc38a;
    --c3: #ff7b72;
    --c4: #b393ff;
    --c5: #9aa4b2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bad { color: var(--bad); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.icon.big { width: 40px; height: 40px; }

button, select, input {
  font: inherit;
  color: inherit;
}
button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.small { padding: 2px 7px; font-size: 12px; }
select, input[type="number"], input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 6px;
  min-width: 0;
}
input[type="number"] { text-align: right; width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions select { max-width: 260px; }

.layout { flex: 1; display: flex; min-height: 0; }
.steps {
  width: 200px; flex: none; background: var(--panel); border-right: 1px solid var(--line);
  padding: 12px 8px;
}
.steps ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.steps button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  border: none; background: transparent; padding: 8px 10px; border-radius: 6px;
}
.steps button[aria-current="step"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.steps button:hover:not(:disabled) { background: var(--accent-soft); }

main { flex: 1; min-width: 0; padding: 16px 20px 24px; }
.loading {
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  padding: 64px 16px 40px; max-width: 520px; margin: 0 auto;
}
.splash-icon { width: 96px; height: 96px; border-radius: 22px; box-shadow: 0 6px 24px rgba(13, 21, 39, 0.25); }
.splash-name { font-size: 22px; font-weight: 600; }
.splash-status { display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 12px; }
.page-head h1 { font-size: 20px; margin: 2px 0 4px; }
.help { margin: 0; color: var(--muted); max-width: 900px; }

.columns { display: grid; grid-template-columns: minmax(300px, 440px) minmax(0, 1fr); gap: 20px; align-items: start; }
.columns.wide-inputs { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 10px; }
.form { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(150px, 230px); gap: 7px 10px; align-items: center; }
.form label { color: var(--text); }
.field { display: flex; align-items: center; gap: 6px; }
.field .unit { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 2.5em; }
.field select { width: 100%; }
.check { display: flex; gap: 6px; align-items: center; grid-column: 1 / -1; }
.hint { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-top: -3px; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.choice {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); text-align: center; font-size: 13px;
}
.choice .icon { width: 32px; height: 32px; }
.choice[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.elements { width: 100%; min-width: 580px; border-collapse: collapse; font-size: 13px; }
.elements td:nth-child(2) { min-width: 90px; }
.elements td:nth-child(n+3):nth-child(-n+6) { min-width: 64px; }
.elements th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px; border-bottom: 1px solid var(--line); }
.elements td { padding: 3px 4px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.elements input { width: 100%; }
.elements td.kind { white-space: nowrap; }
.elements td.ops { white-space: nowrap; text-align: right; }
.elements tr.crystal td { background: var(--accent-soft); }
.table-scroll { overflow-x: auto; }
.add-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.outputs { min-width: 0; }
.busy { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.info { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; }
.info:empty { display: none; }
.info p { margin: 3px 0; }
.rows { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.rows td { padding: 5px 12px; border-bottom: 1px solid var(--grid); }
.rows > tbody > tr:last-child > td { border-bottom: none; }
.rows > tbody > tr > td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
/* What sets each result: shown on hover, keyboard focus or tap */
.rows tr.has-tip { cursor: help; }
.rows tr.has-tip > td:first-child { position: relative; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.rows tr.has-tip:hover > td, .rows tr.has-tip:focus-visible > td, .rows tr.has-tip.open > td { background: var(--accent-soft); }
.rows tr.has-tip:focus-visible { outline: none; }
.result-tip { display: none; position: absolute; z-index: 20; left: 8px; top: calc(100% + 2px); width: min(360px, 80vw); white-space: normal;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); font-size: 12px; line-height: 1.35; text-decoration: none; cursor: auto; }
.rows tr.has-tip:hover .result-tip, .rows tr.has-tip:focus-visible .result-tip, .rows tr.has-tip.open .result-tip { display: block; }
.result-tip.up { top: auto; bottom: calc(100% + 2px); }
.result-tip p { margin: 0 0 6px; }
.result-tip table { border-collapse: collapse; width: 100%; }
.result-tip td { padding: 1px 0; border: none; background: none !important; text-align: left; }
.result-tip td + td { padding-left: 12px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.result-tip tr.tip-step td { color: var(--muted); font-style: italic; padding-top: 4px; }
.note { border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.note.warn { background: var(--warn-bg); }
.note.info { background: var(--info-bg); }
.error { color: var(--bad); white-space: pre-wrap; }

.plots { display: grid; gap: 12px; }
.plot { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.plot-title { font-weight: 600; font-size: 13px; margin: 0 0 2px 4px; }
.plot-message { color: var(--muted); padding: 40px 10px; text-align: center; }
.plot .grid line { stroke: var(--grid); }
.plot .frame { fill: none; stroke: var(--line); }
.plot .axis text { fill: var(--muted); font-size: 11px; }
.plot .axis text.label { fill: var(--text); font-size: 12px; }
.plot .line { fill: none; stroke-width: 1.8; }
.plot .ref { stroke: var(--muted); stroke-width: 1; }
.plot .dot.hollow { fill: var(--panel); stroke-width: 1.5; }
.plot .ref-label { fill: var(--muted); font-size: 10px; }
.plot .band { fill: var(--band); }
.plot .cross { stroke: var(--muted); stroke-width: 0.8; }
.plot .c0 { stroke: var(--c0); fill: var(--c0); } .plot .line.c0 { fill: none; }
.plot .c1 { stroke: var(--c1); fill: var(--c1); } .plot .line.c1 { fill: none; }
.plot .c2 { stroke: var(--c2); fill: var(--c2); } .plot .line.c2 { fill: none; }
.plot .c3 { stroke: var(--c3); fill: var(--c3); } .plot .line.c3 { fill: none; }
.plot .c4 { stroke: var(--c4); fill: var(--c4); } .plot .line.c4 { fill: none; }
.plot .c5 { stroke: var(--c5); fill: var(--c5); } .plot .line.c5 { fill: none; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 2px 4px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend line { stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; white-space: pre; font-size: 11px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 4px 7px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12); font-variant-numeric: tabular-nums;
}

.nav { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.statusbar { padding: 5px 16px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); min-height: 26px; }
.statusbar.bad { color: var(--bad); }

@media (max-width: 960px) {
  .columns, .columns.wide-inputs { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .steps { width: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 6px 8px; overflow-x: auto; }
  .steps ol { flex-direction: row; }
  .steps button { white-space: nowrap; padding: 6px 8px; }
  main { padding: 12px 16px 20px; }
  .form { grid-template-columns: minmax(0, 1fr) minmax(110px, 160px); }
}

/* Results: plot a result against one of its inputs */
.sweep .hint { margin-top: 8px; }
.sweep-buttons { display: flex; gap: 8px; margin-top: 10px; }
.sweep-plot { border-color: var(--accent); }
.sweep-plot .note { margin: 6px 0 0; }
