/* =============== ESCAPEMENTS II — engineering-lab dark theme =============== */

:root {
  --bg: #14171b;
  --panel: #1a1f25;
  --panel2: #171c21;
  --line: #2a323c;
  --txt: #d7dee7;
  --dim: #8b98a8;
  --recoil: #ff8a5c;
  --deadbeat: #4da3ff;
  --gravity: #35d0a0;
  --lock: #ffb648;
  --warn: #ff6259;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--txt);
  font: 13px/1.55 "Segoe UI", system-ui, -apple-system, sans-serif;
  display: grid;
  grid-template-columns: 214px 1fr 350px;
  grid-template-rows: 52px 1fr;
  grid-template-areas: "top top top" "left stage right";
}

/* ------------------------------- fatal ---------------------------------- */
#fatal {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: var(--bg); color: var(--txt);
  align-items: center; justify-content: center; text-align: center; padding: 40px;
}
#fatal.show { display: flex; }
#fatal code { color: var(--lock); font-family: var(--mono); }

/* ------------------------------- topbar --------------------------------- */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 18px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 14px; z-index: 20;
}
#brand h1 { font-size: 15px; letter-spacing: 3px; font-weight: 600; white-space: nowrap; }
#brand span {
  font-size: 10px; color: var(--dim); letter-spacing: 0.8px;
  text-transform: uppercase; white-space: nowrap;
}
#chaptabs { flex: 1; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
#chaptabs::-webkit-scrollbar { display: none; }
#chaptabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); font: 600 10.5px/1 inherit; letter-spacing: 1px;
  padding: 10px 9px 8px; cursor: pointer; white-space: nowrap;
}
#chaptabs button:hover { color: var(--txt); }
#chaptabs button.on { color: var(--txt); border-bottom-color: var(--deadbeat); }
#chaptabs button .n { color: var(--deadbeat); margin-right: 5px; font-family: var(--mono); }
#topright button {
  width: 28px; height: 28px; border-radius: 50%;
  background: none; border: 1px solid var(--line); color: var(--dim);
  cursor: pointer; font-size: 13px;
}
#topright button:hover { color: var(--txt); border-color: var(--dim); }

/* -------------------------------- rails --------------------------------- */
aside {
  background: var(--panel); overflow-y: auto; scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
aside::-webkit-scrollbar { width: 8px; }
aside::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

#leftrail { grid-area: left; border-right: 1px solid var(--line); }
#rightrail { grid-area: right; border-left: 1px solid var(--line); }

aside section { padding: 12px 12px 14px; border-bottom: 1px solid var(--line); }

aside h3 {
  font: 600 10px/1 inherit; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--dim); margin-bottom: 9px;
  display: flex; justify-content: space-between; align-items: baseline;
}
aside h3.sub { margin-top: 14px; }
aside h3 em {
  font-style: normal; color: var(--txt); font-family: var(--mono);
  font-size: 11px; letter-spacing: 0;
}
p.note { font-size: 10.5px; color: var(--dim); line-height: 1.45; margin-top: 6px; }

/* buttons */
.btncol, .btnrow { display: flex; gap: 4px; }
.btncol { flex-direction: column; }
.btnrow { flex-wrap: wrap; margin-top: 5px; }
.btnrow.tight { margin-top: 0; }

aside button, #chNav button {
  flex: 1; background: var(--panel2); border: 1px solid var(--line);
  color: var(--dim); font: 600 10px/1 inherit; letter-spacing: 0.9px;
  padding: 8px 6px; cursor: pointer; border-radius: 3px; white-space: nowrap;
}
aside button:hover, #chNav button:hover { color: var(--txt); border-color: #3b4753; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--lock);
  outline-offset: 2px;
}
aside button.on { color: #0e1116; background: var(--deadbeat); border-color: var(--deadbeat); }
aside button:disabled { opacity: 0.35; cursor: default; }
aside button em {
  font-style: normal; font-family: var(--mono); opacity: 0.55; margin-left: 5px;
}

#mechbtns button[data-mech="recoil"].on { background: var(--recoil); border-color: var(--recoil); }
#mechbtns button[data-mech="deadbeat"].on { background: var(--deadbeat); border-color: var(--deadbeat); }
#mechbtns button[data-mech="gravity"].on { background: var(--gravity); border-color: var(--gravity); }

.figline {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 8px; font-size: 10.5px; color: var(--dim);
}
.figline em { font-style: normal; font-family: var(--mono); color: var(--lock); }

input[type=range] {
  width: 100%; height: 3px; -webkit-appearance: none; appearance: none;
  background: var(--line); border-radius: 2px; outline: none; margin: 3px 0 2px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--txt); cursor: pointer; border: 2px solid var(--panel);
}
input[type=range]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: var(--txt);
  cursor: pointer; border: 2px solid var(--panel);
}

/* -------------------------------- stage --------------------------------- */
#stage {
  grid-area: stage; position: relative; overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 18%, #212832 0%, #12151a 62%, #0d1014 100%);
}
#stage canvas { display: block; width: 100%; height: 100%; }

.model-callouts {
  position: absolute; inset: 0; z-index: 3; overflow: hidden;
  pointer-events: none;
}
.model-callout {
  position: absolute; transform: translate(-50%, calc(-100% - 13px));
  max-width: 190px; padding: 5px 7px;
  color: #eef4fb; background: rgba(10,13,17,0.90);
  border: 1px solid currentColor; border-radius: 3px;
  font: 600 10px/1.25 var(--mono); letter-spacing: 0.25px;
  text-align: center; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.model-callout::after {
  content: ""; position: absolute; left: 50%; top: 100%;
  width: 1px; height: 13px; background: currentColor;
}
.model-callout.lock { color: var(--lock); }
.model-callout.lift { color: var(--deadbeat); }
.model-callout.impulse { color: var(--gravity); }
.model-callout.recoil { color: var(--warn); }

#actionhud {
  position: absolute; z-index: 4; left: 18px; top: 16px;
  width: min(430px, calc(100% - 36px));
  padding: 10px 12px 9px;
  background: rgba(14,17,22,0.84);
  border: 1px solid rgba(139,152,168,0.28);
  border-radius: 4px;
  backdrop-filter: blur(5px);
  pointer-events: none;
}
.actionlabel {
  color: var(--dim); font: 600 9px/1 var(--mono);
  letter-spacing: 1.3px; margin-bottom: 7px;
}
#actionflow {
  color: var(--txt); font: 600 12px/1.45 var(--mono);
  letter-spacing: 0.15px;
}
#actionflow .part { color: #fff; }
#actionflow .arrow { color: var(--lock); padding: 0 4px; }
#actiondetail { color: var(--dim); font-size: 10.5px; margin-top: 4px; }
.actionlegend { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 7px; }
.actionlegend .lg {
  color: var(--dim); font: 9px/1 var(--mono);
}
.actionlegend .lg::before {
  content: ""; display: inline-block; width: 6px; height: 6px;
  margin-right: 4px; border-radius: 50%; vertical-align: 1px;
}
.actionlegend .lock::before { background: var(--lock); }
.actionlegend .train::before { background: var(--deadbeat); }
.actionlegend .impulse::before { background: var(--gravity); }
.actionlegend .recoil::before { background: var(--warn); }

#partkey {
  display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 8px;
  padding-top: 7px; border-top: 1px solid rgba(139,152,168,0.18);
}
#partkey .pk { color: #aab5c2; font: 600 8.5px/1.25 var(--mono); }
#partkey .pk::before {
  content: ""; display: inline-block; width: 9px; height: 3px;
  margin-right: 4px; vertical-align: 2px; background: currentColor;
}
#partkey .brass { color: #c9a253; }
#partkey .steel { color: #e4e9ef; }
#partkey .arm { color: #4da3ff; }
#partkey .pend { color: #aeb8c4; }
#partkey .contact { color: var(--lock); }

#cyclehud {
  position: absolute; z-index: 4; right: 18px; top: 16px; width: 286px;
  padding: 10px 10px 9px; pointer-events: none;
  background: rgba(14,17,22,0.88);
  border: 1px solid rgba(139,152,168,0.28); border-radius: 4px;
  backdrop-filter: blur(5px);
}
.cycle-title {
  color: var(--dim); font: 600 9px/1 var(--mono);
  letter-spacing: 1.3px; margin: 0 2px 7px;
}
.cycle-step {
  position: relative; display: grid; grid-template-columns: 22px 1fr;
  column-gap: 7px; min-height: 38px; padding: 5px 6px;
  border: 1px solid transparent; border-radius: 3px;
  opacity: 0.34; transition: opacity 0.12s, background 0.12s;
}
.cycle-step + .cycle-step::before {
  content: "↓"; position: absolute; left: 13px; top: -9px;
  color: #596574; font: 10px/1 var(--mono);
}
.cycle-n {
  grid-row: 1 / 3; align-self: center; width: 20px; height: 20px;
  display: grid; place-items: center; border: 1px solid currentColor;
  border-radius: 50%; font: 600 10px/1 var(--mono);
}
.cycle-step strong {
  align-self: end; color: #e8eef6; font: 600 10px/1.25 var(--mono);
  letter-spacing: 0.15px;
}
.cycle-step small { color: var(--dim); font-size: 9px; line-height: 1.25; }
.cycle-step.active { opacity: 1; background: rgba(255,255,255,0.055); }
.cycle-step.active.lock { color: var(--lock); border-color: rgba(255,182,72,0.52); }
.cycle-step.active.lift { color: var(--deadbeat); border-color: rgba(77,163,255,0.52); }
.cycle-step.active.impulse { color: var(--gravity); border-color: rgba(53,208,160,0.52); }
.cycle-step.active.recoil { color: var(--warn); border-color: rgba(255,98,89,0.52); }

#bigmsg {
  position: absolute; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: rgba(20,23,27,0.9); border: 1px solid var(--warn);
  color: var(--warn); padding: 8px 16px; border-radius: 3px;
  font: 600 11px/1 var(--mono); letter-spacing: 0.6px;
  opacity: 0; transition: opacity 0.25s; pointer-events: none; white-space: nowrap;
}
#bigmsg.show { opacity: 1; }

/* ------------------------------ read-outs ------------------------------- */
.rogrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ro { background: var(--panel2); border: 1px solid var(--line); border-radius: 3px; padding: 7px 9px; }
.rolabel {
  font: 600 9px/1 inherit; letter-spacing: 1.2px; color: var(--dim); margin-bottom: 4px;
}
.roval { font: 600 17px/1 var(--mono); color: var(--txt); }
.roval small { font-size: 10px; color: var(--dim); margin-left: 3px; font-weight: 400; }
.roval.accent { color: var(--lock); }
.roval.mode { font-size: 13px; letter-spacing: 1px; padding-top: 3px; }
.roval.mode.locked { color: var(--lock); }
.roval.mode.impulse { color: var(--gravity); }
.roval.mode.recoil { color: var(--warn); }
.roval.mode.drop { color: var(--dim); }
.roval.mode.stopped { color: var(--warn); }

.rowide {
  display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px;
  font-size: 10.5px; align-items: center;
}
.rowide.dim { color: var(--dim); }
.rowide b { color: var(--txt); font-weight: 600; }
.mono { font-family: var(--mono); }

canvas.trace {
  width: 100%; height: 58px; margin-top: 9px; display: block;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 3px;
}
canvas.chart {
  width: 100%; height: 172px; display: block; margin-top: 8px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 3px;
}
canvas.chart.short { height: 116px; }

/* ------------------------------- article -------------------------------- */
#article h2 { font-size: 14.5px; font-weight: 600; margin-bottom: 8px; line-height: 1.35; }
#chBody p { margin-bottom: 9px; font-size: 12.5px; color: #c2cbd6; }
#chBody ol, #chBody ul { margin: 0 0 9px 17px; font-size: 12.5px; color: #c2cbd6; }
#chBody li { margin-bottom: 5px; }
#chBody b { color: var(--txt); }
#chBody code { font-family: var(--mono); font-size: 11.5px; color: var(--lock); }
#chBody p.hint {
  border-left: 2px solid var(--deadbeat); padding-left: 9px;
  color: var(--dim); font-size: 11.5px;
}
#chBody figure {
  margin: 0 0 10px; background: #f4f1ea; border-radius: 3px; padding: 8px;
}
#chBody figure img { width: 100%; display: block; mix-blend-mode: multiply; }
#chBody figcaption {
  font-size: 10px; color: #5a544a; padding-top: 5px; line-height: 1.4;
}
#chNav { display: flex; gap: 5px; margin-top: 10px; }

/* -------------------------------- modal --------------------------------- */
#helpmodal {
  position: fixed; inset: 0; z-index: 40; display: flex;
  align-items: center; justify-content: center; background: rgba(8,10,13,0.78);
  padding: 30px;
}
#helpmodal.hidden { display: none; }
#helpcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
  padding: 22px 24px; max-width: 640px; max-height: 86vh; overflow-y: auto;
}
#helpcard h2 {
  font: 600 11px/1 inherit; letter-spacing: 1.4px; text-transform: uppercase;
  color: var(--dim); margin: 16px 0 8px;
}
#helpcard h2:first-child { margin-top: 0; }
#helpcard table { width: 100%; border-collapse: collapse; font-size: 12px; }
#helpcard td { padding: 3px 0; }
#helpcard td:last-child { text-align: right; font-family: var(--mono); color: var(--dim); }
#helpcard p { font-size: 12px; color: #b9c3cf; margin-bottom: 8px; }
#helpcard code { font-family: var(--mono); font-size: 11.5px; color: var(--lock); }
#helpcard em { color: var(--txt); font-style: italic; }
#btnCloseHelp {
  margin-top: 16px; background: var(--panel2); border: 1px solid var(--line);
  color: var(--dim); font: 600 10px/1 inherit; letter-spacing: 1px;
  padding: 9px 18px; cursor: pointer; border-radius: 3px;
}
#btnCloseHelp:hover { color: var(--txt); }

@media (max-width: 1180px) {
  body { grid-template-columns: 190px 1fr 300px; }
  #cyclehud { top: auto; bottom: 12px; }
}

@media (max-width: 800px) {
  html, body { height: auto; min-height: 100%; overflow: auto; }
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 52px minmax(420px, 62vh) auto auto;
    grid-template-areas: "top" "stage" "left" "right";
  }
  #topbar { position: sticky; top: 0; }
  #brand span { display: none; }
  #leftrail, #rightrail {
    border: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }
  #bigmsg { max-width: calc(100vw - 24px); white-space: normal; text-align: center; }
  #actionhud { left: 10px; top: 10px; width: calc(100% - 20px); }
  #actionflow { font-size: 10px; overflow-wrap: anywhere; }
  #actiondetail { font-size: 9.5px; }
  #partkey .pk { font-size: 7.5px; }
  #cyclehud {
    left: 10px; right: auto; top: auto; bottom: 10px;
    width: calc(100% - 20px); padding: 8px;
  }
  #cyclesteps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; }
  .cycle-step {
    display: block; min-width: 0; min-height: 56px; padding: 5px 2px; text-align: center;
  }
  .cycle-step + .cycle-step::before { content: "→"; left: -5px; top: 23px; }
  .cycle-n { margin: 0 auto 4px; }
  .cycle-step small { display: none; }
  .cycle-step strong { display: block; font-size: 7px; overflow-wrap: anywhere; }
}

@media (max-width: 520px) {
  #topbar { gap: 8px; padding: 0 8px; }
  #brand h1 { font-size: 12px; letter-spacing: 1.5px; }
  #chaptabs button { padding-inline: 7px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* Back to the Parastrate dashboard (parastrate.com hosts these lessons). */
#homelink {
  pointer-events: auto; flex: none; white-space: nowrap;
  font-size: 10.5px; letter-spacing: 0.06em; text-decoration: none;
  color: #9aa7b4; padding: 4px 9px; border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 3px;
}
#homelink:hover { color: #fff; border-color: rgba(255, 255, 255, 0.4); }
