/* Relaxation Dynamics Lab. Layout: title, experiment chips, the update rule and the transport bar; then oscilloscope and energy traces beside the phase portrait and forces; then the coefficient rack and state matrix. Everything stacks on narrow screens. */
:root {
  color-scheme: dark;
  --bg: #080c14;
  --panel: #0e1420;
  --panel-2: #141c2c;
  --line: #1c2638;
  --line-2: #2a374f;
  --fg: #e2e8f0;
  --muted: #8b97ad;
  --dim: #56627a;
  --phosphor: #4ade80;
  --cyan: #22d3ee;
  --amber: #f59e0b;
  --magenta: #e879f9;
  --lime: #a3e635;
  --red: #f87171;
  --c-feas: #f87171;
  --c-pref: #60a5fa;
  --c-mom: #fbbf24;
  --c-bin: #c084fc;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.lbl { font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 5px 9px; min-height: 32px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--phosphor); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.icon { padding: 5px 8px; }
.btn.primary { background: rgba(74,222,128,.12); border-color: rgba(74,222,128,.5); color: var(--phosphor); }
.btn.toggle[aria-pressed="true"] { border-color: var(--amber); color: var(--amber); background: rgba(245,158,11,.1); }

.experiments { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--phosphor); }
.chip.on { border-color: var(--phosphor); color: var(--phosphor); background: rgba(74,222,128,.08); }

.eq { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font: italic 500 15px/1.6 var(--display); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.eq b { font-weight: 600; }
.eq sub, .eq sup { font-size: .7em; }
.c-feas { color: var(--c-feas); } .c-pref { color: var(--c-pref); } .c-mom { color: var(--c-mom); } .c-bin { color: var(--c-bin); }
.note { margin: 0; font-size: 13.5px; color: #c4cddc; max-width: 125ch; }
.note b { color: var(--fg); }

.transport { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px; display: grid; gap: 8px; }
.tr-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.hz { display: grid; gap: 0; min-width: 130px; }
.hz span { font: 500 10.5px var(--mono); color: var(--muted); letter-spacing: .04em; }
.hz output { color: var(--amber); }
.tread { font: 500 13px var(--mono); font-variant-numeric: tabular-nums; min-width: 92px; }
.tread b { color: var(--phosphor); }
.spacer { flex: 1; }
.badge { display: inline-flex; align-items: center; gap: 8px; font: 700 11.5px/1 var(--mono); letter-spacing: .06em; padding: 7px 11px; border-radius: 4px; border: 1px solid var(--line-2); background: var(--panel-2); }
.badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.run { color: #bae6fd; } .badge.run i { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.badge.ok { color: #86efac; border-color: rgba(74,222,128,.5); background: rgba(74,222,128,.08); } .badge.ok i { background: var(--phosphor); box-shadow: 0 0 8px var(--phosphor); }
.badge.bad { color: #fca5a5; border-color: rgba(248,113,113,.55); background: rgba(248,113,113,.1); } .badge.bad i { background: var(--red); box-shadow: 0 0 8px var(--red); }
.badge.warn { color: #fcd34d; border-color: rgba(245,158,11,.5); background: rgba(245,158,11,.08); } .badge.warn i { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.badge.creep { color: #d8b4fe; border-color: rgba(192,132,252,.5); } .badge.creep i { background: var(--c-bin); }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--amber); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--amber); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--amber); border: 2px solid var(--bg); }
#scrub::-webkit-slider-thumb { background: var(--phosphor); box-shadow: 0 0 0 1px var(--phosphor), 0 0 8px var(--phosphor); }
#scrub::-moz-range-thumb { background: var(--phosphor); }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
.scope-col, .side { display: grid; gap: 12px; min-width: 0; }
.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font: 11.5px var(--mono); color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
canvas { display: block; width: 100%; }
#cvScope { height: 330px; }
#cvEnergy { height: 140px; }
#cvPhase { height: 300px; }
.scope canvas { border-radius: 6px; }
.pp-ctl { display: flex; flex-wrap: wrap; gap: 6px; }
.pp-ctl select { min-height: 28px; padding: 3px 6px; font-size: 12px; }
.cap { margin: 0; font: 11.5px/1.45 var(--mono); color: var(--dim); }

.forces { display: grid; gap: 7px; }
.frow { display: grid; grid-template-columns: 112px minmax(0, 1fr) 70px; gap: 8px; align-items: center; font: 12px var(--mono); }
.frow .nm { color: var(--muted); }
.frow .bar { height: 8px; border-radius: 4px; background: var(--panel-2); overflow: hidden; }
.frow .bar b { display: block; height: 100%; border-radius: 4px; }
.frow .v { text-align: right; font-variant-numeric: tabular-nums; }
.fsum { font: 11.5px/1.5 var(--mono); color: var(--muted); border-top: 1px dashed var(--line-2); padding-top: 6px; }
.fsum b { color: var(--fg); font-weight: 500; }

.lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.dials { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.dial { display: grid; gap: 4px; justify-items: center; text-align: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 8px 10px; position: relative; }
.dial svg { width: 100%; max-width: 120px; height: auto; }
.dial .nm { font: 11px var(--sans); color: var(--muted); }
.dial .row { display: flex; align-items: center; gap: 6px; width: 100%; }
.dial input[type=number] { width: 64px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 5px; font: 500 12px var(--mono); color: var(--amber); text-align: right; }
.dial .tag { position: absolute; top: 6px; right: 6px; font: 700 9.5px var(--mono); letter-spacing: .04em; color: var(--c-bin); border: 1px solid rgba(192,132,252,.5); border-radius: 3px; padding: 1px 4px; }
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 32px; height: 18px; border-radius: 9px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch input:checked + i { background: var(--c-bin); }
.switch input:checked + i::after { transform: translateX(14px); }
.switch:has(input:focus-visible) { outline: 2px solid var(--cyan); outline-offset: 2px; border-radius: 4px; }
.sched-strip { display: flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; font: 11px/1.35 var(--mono); position: relative; min-height: 46px; }
.sched-strip.off { opacity: .45; }
.sched-strip .ph { padding: 5px 7px; border-right: 1px solid var(--line-2); min-width: 0; overflow: hidden; }
.sched-strip .ph:last-of-type { border-right: 0; }
.sched-strip .ph b { display: block; color: var(--fg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-strip .ph span { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sched-strip .cur { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--phosphor); box-shadow: 0 0 6px var(--phosphor); pointer-events: none; }

.table-wrap { overflow-x: auto; }
table.mx { width: 100%; border-collapse: collapse; font: 12px var(--mono); font-variant-numeric: tabular-nums; min-width: 560px; }
.mx th, .mx td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.mx th { font-weight: 500; font-size: 10.5px; letter-spacing: .04em; color: var(--muted); }
.mx th:first-child, .mx td:first-child { text-align: left; }
.mx td:first-child i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 7px; vertical-align: -1px; }
.mx td.s { color: var(--fg); font-weight: 700; }
.mx .neg { color: #fca5a5; } .mx .pos { color: #86efac; }
.small { font-size: 12px; color: var(--muted); margin: 0; }

@media (max-width: 1100px) {
  .main, .lower { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 620px) {
  h1 { font-size: 20px; }
  .dials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #cvScope { height: 260px; }
  .eq { font-size: 13.5px; }
  .controls, .controls select { width: 100%; }
  .frow { grid-template-columns: 96px minmax(0, 1fr) 62px; }
}
.pg-embedded .top > div:first-child { display: none; }
.pg-embedded .top { justify-content: flex-start; }
@media (prefers-reduced-motion: reduce) { .btn, .chip, .switch i, .switch i::after { transition: none; } }
