/* ============================================================
   FOUNDATIONAL ML RESEARCHER SIM — ui.css
   Dark, monospace, terminal-adjacent. Palette fixed by SPEC §3/§5,
   deliberately identical to the DayTrader sim so the RoleSims
   family reads as one product.
   ============================================================ */

:root {
  --bg:      #0d1117;
  --panel:   #161b22;
  --panel2:  #1c222b;
  --panel3:  #11161d;
  --border:  #30363d;
  --border2: #21262d;
  --text:    #c9d1d9;
  --dim:     #8b949e;
  --green:   #3fb950;
  --red:     #f85149;
  --amber:   #d29922;
  --cyan:    #39c5cf;
  --violet:  #a371f7;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "DejaVu Sans Mono", "Liberation Mono", monospace;

  --gap: 8px;
  --pad: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "calt" 0;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#mls-root { height: 100%; width: 100%; position: relative; }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b333d; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3d4753; }

/* ---------- primitives ---------- */
.hidden { display: none !important; }
.dim { color: var(--dim); }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.flat { color: var(--text); }
.amber { color: var(--amber); }
.cyan { color: var(--cyan); }
.violet { color: var(--violet); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
b, strong { font-weight: 600; color: #e6edf3; }

.lbl {
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 500;
}

/* ---------- screens ---------- */
.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; flex-direction: column; }
.center-screen { align-items: center; }
.scrollwrap { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; width: 100%; }

/* ---------- panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.panel-hd {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1b2129, #171c24);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}
.panel-hd b { font-size: 11px; letter-spacing: 0.06em; }
.panel-bd {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px;
}
.panel-bd.nopad { padding: 0; overflow: hidden; }
.panel-bd.scroll { overflow: auto; }
.panel-ft { flex: 0 0 auto; border-top: 1px solid var(--border2); padding: 6px 10px; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--text);
  background: #1f262e;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { background: #29313b; border-color: #4a545f; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:focus-visible { outline: 1px solid var(--cyan); outline-offset: 1px; }
.btn.primary { background: #12331d; border-color: #2b6c39; color: #7ee495; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #174526; border-color: var(--green); }
.btn.danger { background: #331616; border-color: #6b2b2b; color: #ff9d97; }
.btn.danger:hover:not(:disabled) { background: #451c1c; border-color: var(--red); }
.btn.warn { background: #332a10; border-color: #6b5518; color: #e3b341; }
.btn.warn:hover:not(:disabled) { background: #45380f; border-color: var(--amber); }
.btn.ghost { background: transparent; border-color: var(--border2); color: var(--dim); }
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--border); background: #1a1f27; }
.btn.cyan { background: #10262b; border-color: #2c5f66; color: #7fe3ea; }
.btn.cyan:hover:not(:disabled) { background: #143138; border-color: var(--cyan); }
.btn.big { font-size: 13px; padding: 10px 20px; letter-spacing: 0.1em; }
.btn.wide { width: 100%; display: block; }
.btn.tiny { font-size: 10px; padding: 3px 6px; letter-spacing: .04em; }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.seg.wide { display: flex; width: 100%; }
.seg.wide .seg-b { flex: 1 1 0; text-align: center; }
.seg-b {
  font-family: var(--mono); font-size: 10.5px;
  background: #1a1f27; color: var(--dim);
  border: 0; border-right: 1px solid var(--border);
  padding: 5px 8px; cursor: pointer; white-space: nowrap;
}
.seg-b:last-child { border-right: 0; }
.seg-b:hover { color: var(--text); background: #232a34; }
.seg-b.is-on { background: #223b44; color: var(--cyan); font-weight: 600; }
.seg-b .sub { display: block; font-size: 8.5px; letter-spacing: .06em; opacity: .75; }

/* inputs */
input[type="text"], input[type="number"], textarea, select {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: #0b0f14;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 7px;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
input:focus, textarea:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 1px rgba(57,197,207,.25); }
input:disabled { opacity: .4; }
textarea { resize: none; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: #5b636d; }
input.bad, textarea.bad { border-color: #6b5518; background: #14120b; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; background: transparent;
  padding: 0; border: 0; height: 18px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px; background: #0b0f14; border: 1px solid var(--border); border-radius: 3px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; margin-top: -5px; border-radius: 3px;
  background: var(--cyan); border: 1px solid #0d1117; cursor: pointer;
}

/* ============================================================
   SCREEN 1 — BRIEF
   ============================================================ */
.sheet { width: 100%; max-width: 1300px; margin: 0 auto; padding: 20px 24px 34px; }
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: 0.2em; font-weight: 600; color: #e6edf3; }
.brand .sub { color: var(--dim); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.rule { height: 1px; background: var(--border); margin: 13px 0 16px; }

.blk { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 12px 14px; }
.blk + .blk { margin-top: 12px; }
.blk h3 {
  margin: 0 0 7px; font-size: 9.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--dim); font-weight: 600;
}
.blk p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.6; }
.blk p:last-child { margin-bottom: 0; }
.blk.headline p { font-size: 14px; line-height: 1.55; color: #e6edf3; }
.blk.ask { border-left: 2px solid var(--cyan); background: #12222a; }
.blk.ask p { color: #d6f2f5; }

.brief-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.stat .lbl { display: block; }
.stat .v { font-size: 15px; font-weight: 600; color: #e6edf3; }

.iv-cards { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 9px; }
.iv-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 11px; display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.iv-card .n { font-size: 12.5px; color: #e6edf3; font-weight: 600; line-height: 1.3; }
.iv-card .d { font-size: 11px; color: var(--dim); line-height: 1.5; flex: 1 1 auto; }
.iv-card .f { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tag {
  font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase;
  border: 1px solid var(--border); border-radius: 3px; padding: 1px 5px; color: var(--dim);
}
.tag.fam-architecture { border-color: #2c5f66; color: var(--cyan); }
.tag.fam-data { border-color: #2b6c39; color: var(--green); }
.tag.fam-optimization, .tag.fam-optimizer { border-color: #6b5518; color: var(--amber); }
.tag.fam-objective { border-color: #5a3a86; color: var(--violet); }
.tag.fam-systems, .tag.fam-infra { border-color: #4a545f; color: #adb6c0; }
.tag.cost-low { border-color: #2b6c39; color: var(--green); }
.tag.cost-medium, .tag.cost-med { border-color: #6b5518; color: var(--amber); }
.tag.cost-high { border-color: #6b2b2b; color: var(--red); }

.ev-list { margin: 0; padding: 0; list-style: none; }
.ev-list li { padding: 5px 0; border-bottom: 1px solid var(--border2); font-size: 12px; line-height: 1.55; }
.ev-list li:last-child { border-bottom: 0; }
.ev-list .src { color: var(--dim); font-size: 10.5px; display: block; margin-top: 2px; }

.foot-row { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; gap: 14px; }
.note { color: var(--dim); font-size: 11px; line-height: 1.5; }

/* ============================================================
   SCREEN 2 — LAB CONSOLE
   ============================================================ */
#scr-lab { padding: 8px 10px 10px; }

.lab-hdr {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  margin-bottom: var(--gap);
}
.hdr-l { min-width: 176px; }
.clock { font-size: 25px; font-weight: 600; letter-spacing: .04em; color: #e6edf3; line-height: 1.05; }
.clock-sub { font-size: 10px; color: var(--dim); letter-spacing: .09em; }
.clock-sub b { color: var(--cyan); font-weight: 600; }

.hdr-c { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ctl-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#l-status { font-size: 10.5px; letter-spacing: .03em; }
#l-status.is-warn { color: var(--amber); }
#l-status.is-alarm { color: var(--red); }

.hdr-r { display: flex; align-items: center; gap: 14px; }
.budget-wrap { min-width: 254px; }
.budget-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.budget-top .v { font-size: 15px; font-weight: 600; color: #e6edf3; }
.bar { height: 7px; background: #0b0f14; border: 1px solid var(--border2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar-fill { height: 100%; width: 0%; background: var(--cyan); transition: width .3s linear, background .2s; }
.bar-fill.hot { background: var(--amber); }
.bar-fill.max { background: var(--red); }
.hdr-kv { display: flex; flex-direction: column; gap: 1px; text-align: right; min-width: 132px; }
.hdr-kv > div { display: flex; justify-content: space-between; gap: 10px; font-size: 11px; }
.hdr-kv .v { font-weight: 600; color: #e6edf3; }

/* --- grid --- */
.lab-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 372px minmax(0, 1fr) 312px;
  grid-template-rows: minmax(0, 1fr) 246px;
  grid-template-areas:
    "design plots  feed"
    "design bottom feed";
  gap: var(--gap);
}
.a-design { grid-area: design; }
.a-plots  { grid-area: plots; display: grid; grid-template-columns: minmax(0,1fr) 318px; gap: var(--gap); min-height: 0; }
.plots-side { display: grid; grid-template-rows: minmax(0,1fr) 208px; gap: var(--gap); min-height: 0; }
.a-bottom { grid-area: bottom; display: grid; grid-template-columns: minmax(0,1fr); min-height: 0; }
.a-feed   { grid-area: feed; }

.plot-host { position: relative; background: var(--panel3); }
.plot-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.plot-err {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 18px; color: var(--red); font-size: 11.5px; line-height: 1.6;
  background: rgba(13,17,23,.92);
}
.plot-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px; color: #5b636d; font-size: 11.5px; line-height: 1.7;
  pointer-events: none;
}

/* --- experiment designer --- */
.a-design .panel-bd { padding: 7px 9px; overflow: hidden; }
.d-col { display: flex; flex-direction: column; min-height: 0; }
.d-fix { flex: 0 0 auto; }
.d-sec { margin-bottom: 5px; }
.d-sec:last-child { margin-bottom: 0; }
.d-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 3px; }

.iv-list { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-height: 68px; overflow-y: auto; padding-right: 2px; }
.iv-row {
  display: grid; grid-template-columns: 13px minmax(0,1fr) auto auto; gap: 7px; align-items: center;
  padding: 1px 7px; border: 1px solid var(--border2); border-radius: 4px;
  background: #12171e; cursor: pointer; user-select: none;
}
.iv-row:hover { border-color: var(--border); background: #171d25; }
.iv-row.is-on { border-color: #2b6c39; background: #13251a; }
.iv-box {
  width: 12px; height: 12px; border: 1px solid var(--border); border-radius: 2px;
  display: block; line-height: 10px; text-align: center; font-size: 9px; color: transparent;
}
.iv-row.is-on .iv-box { background: var(--green); border-color: var(--green); color: #0d1117; }
.iv-row .nm { font-size: 11px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iv-row.is-on .nm { color: #e6edf3; }
.iv-row .ev { font-size: 9.5px; color: #6b737d; letter-spacing: .04em; }
.iv-row .ev.has { color: var(--cyan); }

.seeds-row { display: grid; grid-template-columns: 52px 58px minmax(0,1fr); gap: 6px; align-items: center; }
.seeds-row > .lbl { line-height: 1.2; }
.seed-btns { display: flex; gap: 4px; }
.seed-btns .btn { flex: 1 1 0; text-align: center; padding: 4px 0; font-size: 10px; }
.seed-btns .btn.is-on { background: #223b44; border-color: #2c5f66; color: var(--cyan); font-weight: 600; }

/* --- THE pricing preview (the teaching moment) --- */
.prev {
  border: 1px solid #2c5f66; background: #0f1b21; border-radius: 5px; padding: 8px 9px;
}
.prev.is-bad { border-color: #6b2b2b; background: #1d1216; }
.prev-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 7px; }
.prev-grid .lbl { display: block; }
.prev-grid .v { font-size: 14px; font-weight: 600; color: #e6edf3; line-height: 1.2; }
.prev-grid .v.neg { color: var(--red); }
.prev-grid .v small {
  font-size: 9px; font-weight: 400; color: var(--dim); display: block; letter-spacing: .02em;
  line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sigma-hero { margin-top: 7px; padding-top: 7px; border-top: 1px solid #1e2b31; }
.sigma-line { display: flex; align-items: baseline; gap: 9px; }
.sigma-val { font-size: 27px; font-weight: 700; color: var(--cyan); line-height: 1; letter-spacing: -.01em; }
.sigma-val .u { font-size: 11px; color: var(--dim); font-weight: 500; letter-spacing: .06em; }
.sigma-cap { font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--dim); line-height: 1.3; }
.mde { font-size: 11.5px; line-height: 1.45; color: #d6dde5; margin-top: 5px; }
.mde b { color: var(--amber); font-weight: 700; }

.resbar {
  position: relative; height: 22px; margin-top: 8px;
  background: #0b0f14; border: 1px solid var(--border2); border-radius: 3px; overflow: hidden;
}
.resbar .noise {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: repeating-linear-gradient(135deg, rgba(248,81,73,.20) 0 5px, rgba(248,81,73,.08) 5px 10px);
  border-right: 1px dashed var(--red);
}
.resbar .pred { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--cyan); }
.resbar-cap { font-size: 9px; color: #6b737d; margin-top: 3px; letter-spacing: .02em; white-space: nowrap; }

.verdict {
  margin-top: 6px; padding: 5px 8px; border-radius: 4px; font-size: 10.5px; line-height: 1.4;
  border: 1px solid var(--border); background: #12171e; color: var(--dim);
}
.verdict b { display: block; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 1px; }
.verdict.good { border-color: #2b6c39; background: #12281a; color: #a6e9b6; }
.verdict.good b { color: #7ee495; }
.verdict.mid { border-color: #6b5518; background: #241f11; color: #e6cf95; }
.verdict.mid b { color: var(--amber); }
.verdict.bad { border-color: #6b2b2b; background: #2c1414; color: #ffc4bf; }
.verdict.bad b { color: var(--red); }

.ladder { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 4px; margin-top: 6px; }
.lad-b {
  font-family: var(--mono); cursor: pointer; text-align: center;
  background: #12171e; border: 1px solid var(--border2); border-radius: 3px;
  padding: 3px 2px; color: var(--text); font-size: 11px; line-height: 1.25;
}
.lad-b:hover { border-color: var(--cyan); background: #141c24; }
.lad-b.is-on { border-color: #2c5f66; background: #16262b; }
.lad-b .k { display: block; font-size: 8.5px; letter-spacing: .1em; color: var(--dim); }
.lad-b .s { color: var(--cyan); font-weight: 600; }
.lad-b .c { display: block; font-size: 8.5px; color: #6b737d; }

.fld { margin-bottom: 7px; }
.fld > .lbl { display: block; margin-bottom: 3px; }
.ci-row { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 5px; }
#d-hyp { height: 38px; font-size: 11.5px; }
.req { color: var(--amber); }
.ok { color: var(--green); }

.d-msg { margin-top: 6px; }
.msg-err {
  padding: 6px 8px; border-radius: 4px; background: #3a1717; border: 1px solid #6b2b2b;
  color: #ffb3ad; font-size: 11.5px; line-height: 1.45; white-space: normal;
}
.msg-ok {
  padding: 6px 8px; border-radius: 4px; background: #12281a; border: 1px solid #2b6c39;
  color: #8ff0a4; font-size: 11.5px; line-height: 1.45;
}
.msg-warn {
  padding: 6px 8px; border-radius: 4px; background: #241f11; border: 1px solid #6b5518;
  color: #e3b341; font-size: 11.5px; line-height: 1.45;
}

/* --- running jobs --- */
.job {
  border: 1px solid var(--border2); border-left: 2px solid var(--cyan);
  border-radius: 0 4px 4px 0; background: var(--panel2);
  padding: 6px 8px; margin-bottom: 6px;
}
.job-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.job-ttl { font-size: 11.5px; color: #e6edf3; min-width: 0; }
.job-meta { font-size: 9.5px; color: var(--dim); letter-spacing: .04em; white-space: nowrap; }
.prog { height: 6px; background: #0b0f14; border: 1px solid var(--border2); border-radius: 3px; overflow: hidden; margin: 5px 0 4px; }
.prog-fill { height: 100%; width: 0%; background: var(--cyan); transition: width .25s linear; }
.prog-fill.late { background: var(--amber); }
.job-ft { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.job-eta { font-size: 10.5px; color: var(--dim); }
.job-eta b { color: var(--text); }
.btn-x {
  font-family: var(--mono); font-size: 9.5px; line-height: 1; letter-spacing: .08em;
  background: #331616; border: 1px solid #6b2b2b; color: #ff9d97;
  border-radius: 3px; padding: 3px 6px; cursor: pointer;
}
.btn-x:hover { background: #4a1c1c; border-color: var(--red); }

.empty-note { color: #5b636d; font-size: 11px; padding: 12px 6px; text-align: center; line-height: 1.7; }

/* --- results table --- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 11px; }
table.tbl th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel); color: var(--dim); font-weight: 500;
  font-size: 9px; letter-spacing: .09em; text-transform: uppercase;
  text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.notrans { text-transform: none; font-size: 11px; }
table.tbl th.sortable:hover { color: var(--text); }
table.tbl th.is-sort { color: var(--cyan); }
table.tbl td { padding: 3px 6px; border-bottom: 1px solid #1b2028; white-space: nowrap; }
table.tbl td.r, table.tbl th.r { text-align: right; }
table.tbl tr:hover td { background: #1b212a; }
table.tbl td.wrapcell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 1px; }
tr.is-failed td { color: #7d858e; }
tr.is-failed td.reason { color: #ff9d97; font-style: italic; }
.pill {
  font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase;
  border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; color: var(--dim);
}
.pill.ok { border-color: #2b6c39; color: var(--green); }
.pill.fail { border-color: #6b2b2b; color: var(--red); }
.pill.zero { border-color: #6b5518; color: var(--amber); }

/* --- team feed --- */
.a-feed .panel-hd { background: linear-gradient(180deg, #1d2530, #171c24); }
.feed-bd { padding: 6px 8px; }
.msg {
  border-left: 2px solid var(--border);
  background: var(--panel2);
  border-radius: 0 4px 4px 0;
  padding: 6px 9px;
  margin-bottom: 6px;
  animation: msgIn .28s ease-out;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-who { font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; min-width: 0; }
.msg-role { font-size: 9px; color: var(--dim); letter-spacing: .1em; font-weight: 500; }
.msg-tm { font-size: 10px; color: #6b737d; white-space: nowrap; }
.msg-tx { font-size: 12px; line-height: 1.5; color: #d6dde5; white-space: pre-wrap; word-break: break-word; }

.msg.from-LEAD  { border-left-color: var(--cyan); }
.msg.from-LEAD  .msg-who { color: var(--cyan); }
.msg.from-OPS   { border-left-color: var(--amber); }
.msg.from-OPS   .msg-who { color: var(--amber); }
.msg.from-PEER  { border-left-color: var(--violet); }
.msg.from-PEER  .msg-who { color: #b98bff; }
.msg.from-RIVAL { border-left-color: #f0883e; background: #1f1811; }
.msg.from-RIVAL .msg-who { color: #f0883e; }
.msg.from-SYS   { border-left-color: #3d4753; background: #10151b; }
.msg.from-SYS   .msg-who { color: #6b737d; }
.msg.from-SYS   .msg-tx { color: var(--dim); font-size: 11px; }

.msg.tone-pressure { background: #1f2129; }
.msg.tone-warn { background: #241f11; border-left-color: var(--amber); }
.msg.tone-alarm { background: #2c1414; border-left-color: var(--red); }
.msg.tone-alarm .msg-who { color: var(--red); }
.msg.tone-praise { background: #14231a; }

/* ---------- toasts ---------- */
.toasts {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 6px; z-index: 60;
  pointer-events: none; align-items: center;
}
.toast {
  background: #1c222b; border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 4px; padding: 6px 14px; font-size: 11.5px; color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,.55); max-width: 620px;
  animation: toastIn .2s ease-out;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
.toast.info { border-left-color: var(--cyan); }

/* ============================================================
   SCREEN 3 — MODALS (gate / confirm)
   ============================================================ */
#modal-layer { position: fixed; inset: 0; z-index: 100; display: none; }
#modal-layer.active { display: block; }
.modal-bg {
  position: absolute; inset: 0; background: rgba(4,7,10,.80);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  width: 100%; max-width: 640px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0,0,0,.7);
  animation: modalIn .18s ease-out;
  max-height: 86vh; display: flex; flex-direction: column;
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-hd {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-hd h3 { margin: 0; font-size: 15px; letter-spacing: .1em; color: #e6edf3; font-weight: 600; }
.modal-bd { padding: 16px 18px; overflow: auto; }
.modal-bd p { margin: 0 0 10px; line-height: 1.6; }
.modal-ft { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal.gate { border-color: var(--cyan); }
.modal.gate .modal-hd { background: #10222a; }
.modal.gate .modal-hd h3 { color: var(--cyan); }
.modal.danger { border-color: #6b2b2b; }
.modal.danger .modal-hd h3 { color: var(--red); }
.gate-kicker { font-size: 9.5px; letter-spacing: .18em; text-transform: uppercase; color: var(--cyan); }
.gate-prompt { font-size: 15px; line-height: 1.6; color: #e6edf3; margin: 4px 0 14px; }
.gate-list { margin: 0; padding-left: 18px; color: var(--dim); font-size: 12px; line-height: 1.7; }
.gate-paused {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--amber);
  border: 1px solid #6b5518; border-radius: 3px; padding: 2px 7px;
}
.gate-clock { font-size: 11px; color: var(--dim); }

/* ============================================================
   SCREEN 4 — READOUT
   ============================================================ */
.ro-grid { display: grid; grid-template-columns: minmax(0, 1.32fr) minmax(0, 1fr); gap: 14px; }
.cap {
  display: inline-flex; align-items: baseline; gap: 8px;
  border: 1px solid var(--border); border-radius: 4px; padding: 3px 10px; background: var(--panel);
}
.cap .n { font-size: 17px; font-weight: 700; color: var(--green); }
.cap.is-full { border-color: #6b5518; background: #241f11; }
.cap.is-full .n { color: var(--amber); }

.ro-cards { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.ro-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 11px; cursor: pointer; user-select: none; min-width: 0;
  transition: border-color .12s, background .12s, opacity .12s;
}
.ro-card:hover { border-color: #4a545f; }
.ro-card.is-on { border-color: var(--green); background: #16301f; box-shadow: inset 0 0 0 1px rgba(63,185,80,.28); }
.ro-card .pick-mark { color: var(--green); font-weight: 700; }
.tag.picked { border-color: var(--green); color: var(--green); background: #12281a; }
.ro-card.is-blocked { opacity: .42; cursor: not-allowed; }
.ro-card.is-blocked:hover { border-color: var(--border); }
.ro-card .rc-hd { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ro-card .rc-n { font-size: 12.5px; font-weight: 600; color: #e6edf3; min-width: 0; }
.ro-card .rc-ev { margin-top: 5px; font-size: 11px; color: var(--dim); line-height: 1.5; }
.ro-card .rc-est { font-size: 13px; font-weight: 600; color: var(--text); }
.ro-card.untested { border-left: 3px solid var(--red); }
.ro-card.untested .rc-ev { color: #ff9d97; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-4px); } 40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}
.shake { animation: shake .32s ease-in-out; }

.conf-row { display: grid; grid-template-columns: minmax(0,1fr) 58px; gap: 10px; align-items: center; }
.conf-val { font-size: 19px; font-weight: 700; color: var(--cyan); text-align: right; }
#ro-rat { height: 132px; }

/* ============================================================
   SCREEN 5 — DEBRIEF
   ============================================================ */
.db-hero {
  display: grid; grid-template-columns: auto minmax(0,1fr); gap: 26px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 16px 22px; margin: 14px 0 14px;
}
.grade-wrap { text-align: center; min-width: 118px; }
.grade { font-size: 60px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.grade.g-A { color: var(--green); }
.grade.g-B { color: #7ee495; }
.grade.g-C { color: var(--amber); }
.grade.g-D { color: #ff9d97; }
.grade.g-F { color: var(--red); }
.db-kv { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px 14px; }
.db-kv .lbl { display: block; }
.db-kv .v { font-size: 16px; font-weight: 600; color: #e6edf3; }
.banner {
  border-radius: 5px; padding: 9px 12px; margin-bottom: 12px; font-size: 12.5px; line-height: 1.55;
  border: 1px solid #6b2b2b; background: #2c1414; color: #ffc4bf;
}
.banner b { color: #ff9d97; }
.banner.good { border-color: #2b6c39; background: #12281a; color: #a6e9b6; }
.banner.good b { color: #7ee495; }

.db-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 14px; }
.truth-host { height: 400px; position: relative; background: var(--panel3); border-radius: 4px; overflow: hidden; }
.truth-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tbl-wrap { max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 4px; }
.tbl-wrap table.tbl th { background: var(--panel2); }
.calib-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; margin-bottom: 10px; }
.verdict-tag { font-size: 9px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; }
#db-copyarea textarea { height: 190px; font-size: 10.5px; margin-top: 6px; }

/* ============================================================
   DIAGNOSTICS (defensive boot)
   ============================================================ */
.diag-wrap { padding: 40px 32px; max-width: 940px; margin: 0 auto; overflow: auto; height: 100%; }
.diag-wrap h1 { font-size: 18px; letter-spacing: .12em; color: var(--red); margin: 0 0 6px; }
.diag-tbl { width: 100%; border-collapse: collapse; margin: 18px 0; font-size: 12px; }
.diag-tbl th, .diag-tbl td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.diag-tbl th { color: var(--dim); font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; }
.diag-ok { color: var(--green); }
.diag-bad { color: var(--red); font-weight: 700; }
.diag-box {
  background: var(--panel); border: 1px solid var(--border); border-left: 2px solid var(--amber);
  border-radius: 4px; padding: 12px 14px; margin-top: 16px; font-size: 12px; line-height: 1.7;
}
.errbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: #3a1717; border-top: 1px solid var(--red); color: #ffb3ad;
  font-size: 11px; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px;
}

/* ---------- narrow / short safety ---------- */
@media (max-width: 1400px) {
  .lab-grid { grid-template-columns: 352px minmax(0,1fr) 306px; }
  .a-plots { grid-template-columns: minmax(0,1fr) 290px; }
  .a-bottom { grid-template-columns: 312px minmax(0,1fr); }
  .iv-cards { grid-template-columns: repeat(3, minmax(0,1fr)); }
}
@media (max-height: 860px) {
  .lab-grid { grid-template-rows: minmax(0,1fr) 218px; }
  .clock { font-size: 22px; }
  #d-hyp { height: 42px; }
}
