:root {
  --hull:      #0A0D12;
  --panel:     #141922;
  --panel-2:   #1C232E;
  --bezel:     #2B3442;
  --bezel-lt:  #3A4657;
  --text:      #DCE4EC;
  --text-dim:  #7C8797;
  --led-on:    #3BDE84;
  --led-off:   #3A4552;
  --led-stale: #F2B84B;
  --led-mild:  #5EA3E0;
  --pos:       #3BDE84;
  --neg:       #E2604F;
  --zero:      #8A94A3;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse 900px 500px at 50% -10%, rgba(59,222,132,0.05), transparent 60%),
    var(--hull);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 900px; margin: 0 auto; padding: 16px 20px 60px; }

/* ---- top bar: title + tiny nav ---- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 10px 18px;
  border-bottom: 1px solid var(--bezel);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 19px;
  margin: 0;
  flex-shrink: 0;
}

.mainnav { display: flex; gap: 4px; flex-wrap: wrap; }
.navtab {
  font-family: var(--sans); font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--bezel); border-radius: 4px;
  padding: 6px 11px; cursor: pointer;
}
.navtab .navsub { color: inherit; opacity: .7; font-size: 10.5px; }
.navtab[aria-selected="true"] { color: var(--hull); background: var(--led-on); border-color: var(--led-on); font-weight: 600; }
.navtab:not([aria-selected="true"]):hover { color: var(--text); border-color: var(--bezel-lt); }

/* ---- readout dashboard ---- */

.dash {
  background: var(--panel);
  border: 1px solid var(--bezel);
  border-radius: 6px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1.3fr;
  gap: 14px;
  margin-bottom: 16px;
}

.stat { text-align: left; }
.stat-label {
  font-size: 10.5px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.stat-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat-value.pos { color: var(--pos); }
.stat-value.neg { color: var(--neg); }
.stat-value.zero { color: var(--zero); }

.stat.grand .stat-value {
  font-size: 30px;
  text-shadow: 0 0 18px currentColor;
}
.stat.grand .stat-sub { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* ---- settings view ---- */

.settings-sec .settings-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.settings-sec .settings-row label { font-size: 13px; color: var(--text-dim); }
.settings-sec input[type="number"] {
  width: 56px; background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  color: var(--text); font-family: var(--mono); font-size: 13px; padding: 4px 6px;
}
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; border-top: 1px solid var(--bezel); padding-top: 14px; }
.settings-sec button.action {
  font-family: var(--sans); font-size: 12.5px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  padding: 6px 11px; cursor: pointer;
}
.settings-sec button.action:hover { border-color: var(--bezel-lt); }
.settings-sec button.danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.settings-sec button.danger:hover { background: rgba(226,96,79,0.1); }

.settings-cats { border-top: 1px solid var(--bezel); padding-top: 14px; margin-top: 10px; }
.settings-cats h4 { font-family: var(--serif); font-size: 13.5px; margin: 0 0 10px; font-weight: 600; color: var(--text-dim); }
.catrow { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.catrow .catTitle { flex: 0 0 160px; }
.catrow .catObjective { flex: 1 1 auto; }
.settings-cats input[type="text"] {
  background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  color: var(--text); font-family: var(--sans); font-size: 13px; padding: 5px 8px;
}
.addCategoryForm { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.addCategoryForm input#addCategoryTitle { flex: 0 0 160px; }
.addCategoryForm input#addCategoryObjective { flex: 1 1 auto; }

.settings-signals { border-top: 1px solid var(--bezel); padding-top: 14px; margin-top: 14px; }
.settings-signals h4 { font-family: var(--serif); font-size: 13.5px; margin: 0 0 8px; font-weight: 600; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.plannedTag {
  font-family: var(--sans); font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-dim); border: 1px solid var(--bezel-lt); border-radius: 3px; padding: 1px 6px;
}
.plannedNote { font-size: 12px; color: var(--text-dim); line-height: 1.6; margin: 0 0 10px; max-width: 60ch; }
.plannedNote a { color: var(--led-mild); }
.settings-signals input[type="text"] {
  background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  color: var(--text); font-family: var(--sans); font-size: 13px; padding: 5px 8px; width: 220px;
}
.settings-signals input:disabled, .settings-signals label:has(input:disabled) { opacity: .55; cursor: not-allowed; }

/* ---- sections ---- */

.sec { margin-bottom: 36px; }
.sechead {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  border-bottom: 2px solid var(--bezel-lt);
  padding-bottom: 6px; margin-bottom: 4px;
}
.sechead h2 { font-family: var(--serif); font-size: 18px; font-weight: 600; margin: 0; }
.secount { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.objective {
  font-family: var(--serif); font-style: italic; font-size: 13.5px; color: var(--text-dim);
  padding: 9px 0 13px; border-bottom: 1px solid var(--bezel); margin-bottom: 2px;
}

/* ---- milestone rows ---- */

.mrow { display: grid; grid-template-columns: 1fr 120px; gap: 14px; align-items: start; padding: 10px 0; border-bottom: 1px solid var(--bezel); }
.mrow:last-child { border-bottom: none; }
.mrow .rlabel { font-weight: 500; }
.rtag { display: inline-block; font-size: 10px; color: var(--led-stale); border: 1px solid var(--led-stale); border-radius: 2px; padding: 0 5px; margin-left: 6px; vertical-align: 1.5px; }
.rnote { color: var(--text-dim); font-size: 12.5px; margin-top: 2px; }
.mcheck { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.mcheck .delbtn { margin-top: 2px; }
.mbox { appearance: none; -webkit-appearance: none; width: 20px; height: 20px; border: 1.5px solid var(--bezel-lt); border-radius: 3px; background: var(--panel-2); cursor: pointer; position: relative; }
.mbox:checked { background: var(--led-on); border-color: var(--led-on); }
.mbox:checked::after { content: ""; position: absolute; left: 5px; top: 1px; width: 6px; height: 11px; border: solid var(--hull); border-width: 0 2.5px 2.5px 0; transform: rotate(42deg); }
.mbox:focus-visible { outline: 2px solid var(--led-on); outline-offset: 2px; }
.mstamp { font-size: 10px; color: var(--led-on); font-family: var(--mono); white-space: nowrap; }

/* ---- domain groups (switchboard) ---- */

.domain { margin-bottom: 26px; }
.domainhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 3px; }
.domainhead h3 { font-family: var(--serif); font-size: 15.5px; font-weight: 600; margin: 0; color: var(--text); }
.domainsub { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.domainobj { font-size: 12.5px; color: var(--text-dim); font-style: italic; margin-bottom: 8px; }

/* ---- switch rows ---- */

.srow {
  background: var(--panel);
  border: 1px solid var(--bezel);
  border-radius: 5px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.srow.editing { border-color: var(--bezel-lt); }
.srow-top { display: flex; align-items: flex-start; gap: 12px; }
.srow-label { flex: 1; min-width: 0; }
.srow-label .name { font-weight: 500; }
.notes-ro { color: var(--text-dim); font-size: 12.5px; margin-top: 4px; line-height: 1.5; }
.srow-controls { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }

.modeBtn {
  font-family: var(--sans); font-size: 11.5px; color: var(--text-dim);
  background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 4px;
  padding: 4px 9px; cursor: pointer; flex-shrink: 0;
}
.modeBtn:hover { color: var(--text); border-color: var(--bezel-lt); }
.srow.editing .modeBtn { color: var(--text); border-color: var(--led-mild); }

.leds { display: flex; align-items: center; gap: 6px; }
.led { width: 9px; height: 9px; border-radius: 50%; background: var(--led-off); display: inline-block; }
.led.good { background: var(--led-on); box-shadow: 0 0 7px var(--led-on); }
.led.bad { background: var(--neg); box-shadow: 0 0 7px var(--neg); }
.led.mild { background: var(--led-mild); box-shadow: 0 0 5px var(--led-mild); }
.led.neutral { background: var(--led-off); }
.led.stale { background: var(--led-stale); box-shadow: 0 0 7px var(--led-stale); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .led.stale, .rx-led.stale { animation: none; opacity: 0.9; } }

.lever {
  width: 44px; height: 23px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--bezel);
  position: relative; padding: 0; cursor: pointer; flex-shrink: 0;
}
.lever .thumb {
  position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%;
  background: var(--text-dim); transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}
.lever[aria-checked="true"] .thumb { transform: translateX(21px); }
.lever:focus-visible { outline: 2px solid var(--led-on); outline-offset: 2px; }

/* tone: read from the switch's CURRENT value, not from on/off itself —
   good (on+positive) is the only tone that reads "on" as green. */
.lever.tone-good[aria-checked="true"] { background: rgba(59,222,132,0.13); border-color: var(--led-on); }
.lever.tone-good[aria-checked="true"] .thumb { background: var(--led-on); box-shadow: 0 0 7px var(--led-on); }
.lever.tone-bad { border-color: var(--neg); }
.lever.tone-bad[aria-checked="true"] { background: rgba(226,96,79,0.13); }
.lever.tone-bad .thumb { background: var(--neg); }
.lever.tone-bad[aria-checked="true"] .thumb { box-shadow: 0 0 7px var(--neg); }
.lever.tone-mild .thumb { background: var(--led-mild); }
.lever.tone-neutral .thumb { background: var(--text-dim); }

.delbtn {
  background: transparent; border: none; color: var(--text-dim); font-size: 15px;
  cursor: pointer; padding: 2px 4px; line-height: 1; flex-shrink: 0;
}
.delbtn:hover { color: var(--neg); }

.notesArea {
  width: 100%; margin-top: 4px; background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 4px;
  color: var(--text); font-family: var(--sans); font-size: 12.5px; padding: 8px; resize: vertical; min-height: 44px;
}

/* ---- Edit Module panel ---- */

.srow-edit { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--bezel); }
.editGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.editField { display: block; font-size: 10.5px; color: var(--text-dim); }
.editFieldLabel { display: block; margin-bottom: 3px; }
.editField input[type="number"] {
  width: 100%; background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  color: var(--text); font-family: var(--mono); font-size: 12.5px; padding: 5px 6px; text-align: center;
}
.editNotes { margin-bottom: 10px; }
.editActions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.signalBtn {
  font-family: var(--sans); font-size: 12px; color: var(--text-dim);
  background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 4px;
  padding: 5px 10px; cursor: pointer;
}
.signalBtn:hover { color: var(--text); border-color: var(--led-mild); }
.delbtn-edit {
  font-family: var(--sans); font-size: 12px; color: var(--neg); background: transparent;
  border: 1px solid var(--neg); border-radius: 4px; padding: 5px 10px; cursor: pointer; margin-left: auto;
}
.delbtn-edit:hover { background: rgba(226,96,79,0.1); }

.signalPanel {
  margin-top: 10px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 4px;
}
.signalTitle { font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.signalBody { font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ---- add switch ---- */

.addWrap { margin-top: 6px; }
.addToggleBtn {
  font-family: var(--sans); font-size: 13px; color: var(--text-dim);
  background: var(--panel); border: 1px dashed var(--bezel-lt); border-radius: 5px;
  padding: 10px 14px; cursor: pointer; width: 100%; text-align: left;
}
.addToggleBtn:hover { color: var(--text); border-color: var(--led-on); }
.addForm {
  background: var(--panel); border: 1px solid var(--bezel); border-radius: 5px; padding: 14px;
  display: grid; gap: 10px; margin-top: 8px;
}
.addForm label { font-size: 11.5px; color: var(--text-dim); display: block; margin-bottom: 3px; }
.addForm input[type="text"], .addForm select, .addForm textarea {
  width: 100%; background: var(--panel-2); border: 1px solid var(--bezel); border-radius: 3px;
  color: var(--text); font-family: var(--sans); font-size: 13px; padding: 7px 9px;
}
.addForm textarea { min-height: 44px; resize: vertical; }
.addRow2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.addCheckWrap { display: flex; align-items: flex-end; }
.addCheckWrap label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text); margin-bottom: 0; }
.addForm .go {
  justify-self: start; font-family: var(--sans); font-size: 13px; color: var(--hull);
  background: var(--led-on); border: none; border-radius: 3px; padding: 8px 16px; cursor: pointer; font-weight: 600;
}

/* ---- reactor view: the visual is central and self-contained ---- */

.reactor-visual {
  position: relative;
  width: min(94vw, 82vh, 800px);
  margin: 4px auto 8px;
  display: flex; align-items: center; justify-content: center;
}
.reactor-svg-wrap { width: 100%; }
.reactor-svg-el { width: 100%; height: auto; display: block; overflow: visible; }

.fsBtn {
  position: absolute; top: 4px; right: 4px; z-index: 1;
  font-family: var(--sans); font-size: 11.5px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--bezel); border-radius: 4px;
  padding: 5px 9px; cursor: pointer;
}
.fsBtn:hover { color: var(--text); border-color: var(--bezel-lt); }

.reactor-visual:fullscreen,
.reactor-visual:-webkit-full-screen {
  width: 100vw; max-width: none; margin: 0;
  background: var(--hull); height: 100vh; padding: 20px;
}
.reactor-visual:fullscreen .reactor-svg-wrap,
.reactor-visual:-webkit-full-screen .reactor-svg-wrap {
  width: auto; height: 92vh; max-height: 92vh;
}
.reactor-visual:fullscreen .reactor-svg-el,
.reactor-visual:-webkit-full-screen .reactor-svg-el {
  width: auto; height: 100%; max-width: 92vw;
}

.reactor-below { max-width: 640px; margin: 0 auto; }

.rx-bezel { fill: none; stroke: var(--bezel); stroke-dasharray: 2 7; }

/* outer bezel doubles as the momentum ring — a very slow spin, direction
   and color set by RX.computeRingSpeed; duration is set inline per render
   since it scales continuously with speed. */
.rx-outer-ring { transform-origin: 320px 320px; stroke-width: 1.5; }
.rx-outer-ring.ring-pos { stroke: var(--led-on); animation-name: rx-ring-spin; animation-timing-function: linear; animation-iteration-count: infinite; }
.rx-outer-ring.ring-neg { stroke: var(--neg); animation-name: rx-ring-spin; animation-timing-function: linear; animation-iteration-count: infinite; }
.rx-outer-ring.ring-neutral { stroke: var(--led-stale); animation: rx-ring-blink 3.2s ease-in-out infinite; }
@keyframes rx-ring-spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes rx-ring-blink { 0%, 100% { opacity: .3; } 50% { opacity: .9; } }
@media (prefers-reduced-motion: reduce) { .rx-outer-ring { animation: none !important; } }
.rx-slice { stroke-width: 1.5; cursor: pointer; transition: opacity .15s ease, stroke-width .15s ease; opacity: .5; }
.rx-slice.on { opacity: 1; }
.rx-slice:hover, .rx-slice:focus-visible { stroke-width: 3; outline: none; }
.rx-domain-arc { fill: none; stroke-linecap: round; opacity: .85; }

/* tone-based, same rule as the console lever/LED: color reads the switch's
   current value, not just whether it's on or off. */
.rx-led { fill: var(--led-off); }
.rx-led.good { fill: var(--led-on); filter: drop-shadow(0 0 4px var(--led-on)); }
.rx-led.bad { fill: var(--neg); filter: drop-shadow(0 0 4px var(--neg)); }
.rx-led.mild { fill: var(--led-mild); filter: drop-shadow(0 0 3px var(--led-mild)); }
.rx-led.neutral { fill: var(--led-off); }
.rx-led.stale { fill: var(--led-stale); filter: drop-shadow(0 0 4px var(--led-stale)); animation: pulse 1.6s ease-in-out infinite; }

.rx-mled { fill: var(--neg); cursor: pointer; filter: drop-shadow(0 0 3px rgba(226,96,79,.5)); transition: fill .15s ease; }
.rx-mled.on { fill: var(--led-on); filter: drop-shadow(0 0 5px var(--led-on)); }
.rx-mled:hover, .rx-mled:focus-visible { outline: none; stroke: var(--text); stroke-width: 1.5; }

.rx-core-value { font-family: var(--mono); font-weight: 700; text-anchor: middle; }
.rx-core-value.pos { fill: var(--pos); }
.rx-core-value.neg { fill: var(--neg); }
.rx-core-value.zero { fill: var(--zero); }
.rx-core-caption { font-family: var(--sans); text-anchor: middle; letter-spacing: .06em; }

.reactor-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 4px 0 8px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.legend-title { color: var(--text); }
.legend-val { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.legend-val.pos { color: var(--pos); }
.legend-val.neg { color: var(--neg); }
.legend-val.zero { color: var(--zero); }
.reactor-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; line-height: 1.6; }

footer {
  margin-top: 44px; padding-top: 16px; border-top: 1px solid var(--bezel);
  color: var(--text-dim); font-size: 12px; line-height: 1.6;
}
footer b { color: var(--text); }

@media (max-width: 640px) {
  .wrap { padding: 14px 14px 50px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .dash { grid-template-columns: 1fr; }
  .srow-top { flex-wrap: wrap; }
  .srow-controls { width: 100%; justify-content: space-between; margin-top: 8px; }
  .addRow2 { grid-template-columns: 1fr; }
  .editGrid { grid-template-columns: 1fr 1fr; }
}
