/* machine — firmware layout console. Near-black terminal skin. No external assets,
   no web fonts, no CDNs. Monospace-dominant. */

:root {
  --bg:       #0a0a0b;   /* app background, near-black */
  --panel:    #0d0e10;   /* panel fill */
  --panel-2:  #101113;   /* inset rows */
  --border:   #1c1d21;   /* 1px hairline borders */
  --text:     #e6e7ea;   /* primary text */
  --dim:      #6b6e76;   /* labels */
  --dimmer:   #44464d;   /* sub-labels */
  --teal:     #2dd4bf;   /* OUTPUT / TOKENS / positive — headline accent */
  --amber:    #f59e0b;   /* FIRMWARE / GOAL / ENERGY / progress bar */
  --red:      #ef4444;   /* deficits / DATA accent */
  --green:    #4ade80;   /* positive net values */

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--mono);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.4;
  font-size: 14px;
}

.console { max-width: 1220px; margin: 0 auto; padding: 18px clamp(10px, 2.4vw, 26px) 40px; }

/* tiny uppercase label helper */
.k, .seg-k, .fld-k, .pbadge, .palette-hd, .tel-k, .res-name, .res-bk span, .panel-hd .ptitle {
  text-transform: uppercase;
  letter-spacing: 0.11em;
}

/* ------------------------------------------------------------------ HUD header */
.hud {
  display: flex; align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  margin-bottom: 12px;
}
.seg {
  flex: 1 1 0; min-width: 0;
  padding: 12px 16px;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 7px; justify-content: center;
}
.seg-goal { flex: 1.7 1 0; }
.seg-k {
  font-size: 10px; color: var(--dim); white-space: nowrap;
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
}
.seg-v { font-size: clamp(1.15rem, 2.3vw, 1.7rem); font-weight: 600; line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-v .w  { color: var(--text); }
.seg-v .am { color: var(--amber); }
.seg-v .dim { color: var(--dim); font-size: 0.62em; font-weight: 500; }
.seg-out { color: var(--teal); }
.seg-pct { color: var(--amber); font-weight: 700; }
.seg-goalv { font-size: clamp(0.9rem, 1.5vw, 1.05rem); color: var(--text); font-weight: 500; }
.seg-goalv .dim { color: var(--dim); }

.goalbar { height: 4px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); overflow: hidden; margin-top: 2px; }
.goalbar-fill { height: 100%; width: 0%; background: var(--amber); border-radius: 999px; transition: width .2s ease; }

.clear-btn {
  flex: none; width: 46px; align-self: stretch;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-left: 1px solid var(--border);
  color: var(--dim); cursor: pointer; transition: color .15s, background .15s;
}
.clear-btn:hover { color: var(--red); background: rgba(239,68,68,0.07); }
.clear-btn svg { width: 17px; height: 17px; }

/* ------------------------------------------------------------------ control strip */
.ctl {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); padding: 12px 14px; margin-bottom: 12px;
}
.ctl-fields { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.fld { display: flex; flex-direction: column; gap: 5px; flex: 1 1 92px; min-width: 78px; }
.fld-k { font-size: 9.5px; color: var(--dim); }
.chk-x { color: var(--dimmer); margin-left: 6px; text-transform: none; letter-spacing: 0; }
.fld input[type="number"], .fld input[type="text"] {
  font-family: var(--mono); font-size: 0.92rem; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; width: 100%; transition: border-color .15s, box-shadow .15s;
}
.fld input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(45,212,191,0.18); }
.fld-chk { flex-direction: row; align-items: center; gap: 8px; flex: 1 1 150px; }
.fld-chk input { width: 16px; height: 16px; accent-color: var(--amber); flex: none; margin: 0; }
.fld-chk .fld-k { display: inline-flex; align-items: baseline; }

.ctl-run { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font-family: var(--mono); font-weight: 700; font-size: 0.86rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: #05100e;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 18px; white-space: nowrap;
  background: var(--teal); transition: filter .15s, transform .08s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn .btn-ico { width: 15px; height: 15px; }
.btn.is-stop { background: var(--red); color: #1a0505; }

.progress { flex: 1; height: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; min-width: 70px; }
.progress-bar { height: 100%; width: 0%; border-radius: 999px; background: var(--amber); transition: width .18s ease; }
.hw-note { font-size: 10px; color: var(--dim); white-space: nowrap; text-transform: uppercase; letter-spacing: 0.08em; }

.ctl-status { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.status { font-size: 0.8rem; color: var(--dim); }
.status-aux { font-size: 0.74rem; color: var(--dimmer); }
.error {
  margin-top: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.09); border: 1px solid rgba(239,68,68,0.4); color: #ffb4b4; font-size: 0.8rem;
}

/* ------------------------------------------------------------------ stage / panels */
.stage { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 12px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-hd {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 15px; border-bottom: 1px solid var(--border);
}
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 2px; background: var(--dimmer); display: block; }
.dots i.on { background: var(--amber); }
.pnum { color: var(--amber); font-weight: 700; font-size: 0.82rem; }
.ptitle { font-size: 0.76rem; color: var(--text); font-weight: 600; }
.pbadge { margin-left: auto; font-size: 10px; color: var(--dim); }

/* ------------------------------------------------------------------ board / tiles */
.board-wrap { padding: 18px; overflow-x: auto; }
.board {
  display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr));
  gap: 8px; margin: 0 auto; max-width: 560px; min-width: 240px;
}
.tile {
  position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  min-height: 46px;
}
.tile.empty {
  background: transparent; border: 1px dashed var(--border);
}
.tile.filled {
  background: linear-gradient(180deg, var(--tc), var(--tc2));
  border: 1px solid rgba(0,0,0,0.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 1px 2px rgba(0,0,0,0.4);
}
.tile.misplaced { outline: 1.5px solid var(--red); outline-offset: -1.5px; }
.tile-ico { color: #fff; display: flex; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.35)); }
.tile-ico svg { width: 34px; height: 34px; }
.tile-badge {
  position: absolute; top: 5px; right: 5px;
  min-width: 17px; height: 17px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6,7,9,0.72); border-radius: 6px;
  font-size: 10px; font-weight: 700; color: #fff; line-height: 1;
}
.tile-pct {
  position: absolute; bottom: 5px; left: 0; right: 0; text-align: center;
  font-size: 10px; font-weight: 700; color: #fff; letter-spacing: 0.02em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}
.tile-pct.zero { color: rgba(255,255,255,0.55); font-weight: 500; }

@media (max-width: 620px) {
  .tile-ico svg { width: 26px; height: 26px; }
}

/* ------------------------------------------------------------------ palette */
.palette-hd { padding: 4px 15px 0; font-size: 10px; color: var(--dim); }
.palette {
  padding: 10px 15px 16px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px;
}
.pcard {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.pcard.sel { border-color: var(--amber); box-shadow: inset 0 0 0 1px rgba(245,158,11,0.35); }
.pcard-ico { flex: none; color: var(--text); display: flex; }
.pcard-ico svg { width: 20px; height: 20px; }
.pcard.sel .pcard-ico { color: var(--amber); }
.pcard-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pcard-name { font-size: 0.74rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* placeable cards carry a checkbox; excluded ones dim, non-modeled ones read as inert */
.pcard-sel { cursor: pointer; }
.pcard-chk { flex: none; width: 15px; height: 15px; margin: 0; accent-color: var(--amber); cursor: pointer; }
.pcard.is-off { opacity: 0.42; }
.pcard-off { opacity: 0.34; cursor: not-allowed; }

/* ------------------------------------------------------------------ rail */
.rail { display: flex; flex-direction: column; gap: 12px; }

/* resources */
.res { padding: 4px 15px; }
.res-row {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--border);
}
.res-row:last-child { border-bottom: none; }
.res-id { display: flex; align-items: center; gap: 9px; min-width: 0; }
.res-ico { flex: none; display: flex; }
.res-ico svg { width: 18px; height: 18px; }
.res-name { font-size: 0.72rem; color: var(--text); }
.res-big { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; line-height: 1; text-align: right; }
.res-energy .res-ico, .res-energy .res-big { color: var(--amber); }
.res-data   .res-ico, .res-data   .res-big { color: var(--red); }
.res-memory .res-ico, .res-memory .res-big { color: var(--text); }
.res-bk { display: flex; flex-direction: column; gap: 3px; text-align: right; font-size: 10px; }
.res-bk span { color: var(--dim); display: flex; justify-content: flex-end; gap: 6px; }
.res-bk .bk-v { font-family: var(--mono); letter-spacing: 0; text-transform: none; }
.res-bk .in  .bk-v { color: var(--green); }
.res-bk .need .bk-v { color: var(--red); }
.res-bk .tot .bk-v.pos { color: var(--green); }
.res-bk .tot .bk-v.neg { color: var(--red); }

.res-notes { padding: 12px 15px 15px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 5px; }
.res-notes span { font-size: 10.5px; color: var(--dimmer); }

/* telemetry */
.tel { padding: 6px 15px 14px; }
.tel-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.tel-row:last-child { border-bottom: none; }
.tel-k { font-size: 10px; color: var(--dim); }
.tel-v { font-family: var(--mono); font-size: 0.86rem; color: var(--text); font-weight: 600; text-align: right; }
.tel-v .am { color: var(--amber); }
.tel-v .teal { color: var(--teal); }
.tel-v .dim { color: var(--dim); font-weight: 500; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .hud { flex-wrap: wrap; }
  .seg { flex-basis: 50%; border-bottom: 1px solid var(--border); }
  .seg-goal { flex-basis: 100%; }
  .clear-btn { flex-basis: 100%; height: 40px; border-left: none; border-top: 1px solid var(--border); }
}
@media (max-width: 560px) {
  .seg { flex-basis: 100%; }
  .ctl-run { flex-wrap: wrap; }
  .btn { flex: 1 1 100%; justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
