:root {
  --cyan: #0087b3;
  --teal: #0a6f8f;
  --primary: #0a3040;
  --secondary: #0087b3;
  --ink: #0a3040;
  --mute: #5b6b75;
  --line: #c5d0db;
  --panel: #ffffff;
  --floor: #e8eef4;
  --fg: #1f2933;
  --card: #ffffff;
  --card-2: #f3f7fa;
  --meter: #d5dee6;
  --help-fg: #334155;
  --btn-ink: #0a3040;
  --fault: #ff0000;
  --nst: #c0c0c0;
  --prd: #9bcc00;
  --sby: #ffff00;
  --udt: #ff0000;
  --sdt: #ff8081;
}
html.theme-dark {
  --floor: #0a1622;
  --panel: #0b1520;
  --ink: #e2e8f0;
  --mute: #94a3b8;
  --line: #1e3a48;
  --fg: #e2e8f0;
  --card: #111c28;
  --card-2: #0a121a;
  --meter: #1e293b;
  --help-fg: #cbd5e1;
  --btn-ink: #e2e8f0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--floor); color: var(--fg); font-family: Arial, Helvetica, sans-serif; }
body { display: flex; flex-direction: column; }

.chrome { position: relative; z-index: 20; }
.primary-bar, .bot {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; background: var(--primary); color: #fff;
  z-index: 4;
}
.primary-bar { position: relative; }
.secondary-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 14px; background: var(--secondary); color: #fff;
  z-index: 4;
}
.bot { border-bottom: 0; justify-content: space-between; font-size: 12px; color: #cfe8f0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 48px; height: 48px; flex: 0 0 48px;
  display: block; object-fit: contain;
  border: 0; border-radius: 0; background: transparent;
}
.brand-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand strong { font-size: 30px; line-height: 1.1; color: #fff; }
.brand-ver { font-size: 12px; line-height: 1.3; color: #9ad4e6; }
.product-title {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  font-style: normal;
  color: #9ad4e6;
  font-size: 22px;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}
.brand small { display: block; color: #9ad4e6; font-size: 12px; line-height: 1.3; margin-top: 2px; }
.live { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #d7f3fb; margin-left: auto; }
.live:not(.idle) .live-text { color: #bfff00; font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9bcc00; box-shadow: 0 0 10px #9bcc00; animation: pulse 1.4s infinite; }
.live.idle .dot { background: #3b82f6; box-shadow: 0 0 10px #3b82f6; animation: none; opacity: 1; }
@keyframes pulse { 50% { opacity: 0.35; } }
@keyframes replayCall {
  0%, 100% {
    color: #fff;
    border-color: #3b82f6;
    background: #3b82f6;
    box-shadow: 0 0 14px #3b82f6;
  }
  50% {
    color: #0f172a;
    border-color: #facc15;
    background: #facc15;
    box-shadow: 0 0 14px #facc15;
  }
}
.alert-count { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; color: #94a3b8; }
.alert-count.has-alert { color: #ff8081; }
@keyframes jiggle {
  0%, 100% { transform: rotate(0); }
  16% { transform: rotate(-16deg); }
  32% { transform: rotate(14deg); }
  48% { transform: rotate(-10deg); }
  64% { transform: rotate(8deg); }
  80% { transform: rotate(-4deg); }
}
.alert-btn.jiggle { animation: jiggle 0.55s ease-in-out; }
.bar-group { display: flex; gap: 4px; flex-wrap: wrap; }
.sim-time { font-size: 12px; font-variant-numeric: tabular-nums; margin-left: auto; }
.icon-btn {
  width: 32px; height: 32px; padding: 0;
  display: grid; place-items: center;
  border-color: rgb(255 255 255 / 0.35);
  color: #fff;
}
.alert-btn.has-alert { color: #ff8081; border-color: #ff8081; }
button {
  background: transparent; color: #fff; border: 1px solid rgb(255 255 255 / 0.35);
  border-radius: 6px; padding: 6px 10px; font: 700 12px Arial, Helvetica, sans-serif; cursor: pointer;
}
.secondary-bar button.on, .secondary-bar button:hover,
.primary-bar button.on, .primary-bar button:hover {
  background: rgb(255 255 255 / 0.18);
  border-color: #fff;
}
#btnTwin[aria-pressed="true"], #btnFoop[aria-pressed="true"], #btnLabels[aria-pressed="true"] {
  background: rgb(255 255 255 / 0.28);
  box-shadow: 0 0 0 1px #fff;
}
#btnPause.call,
.secondary-bar #btnPause.call:hover {
  color: #fff;
  border-color: #3b82f6;
  background: #3b82f6;
  box-shadow: 0 0 14px #3b82f6;
  animation: replayCall 1.4s infinite;
}
#btnPinTraffic.on { background: rgb(0 135 179 / 0.18); }
.help-pop {
  position: absolute; left: 16px; top: 100%; z-index: 30;
  margin-top: 8px;
  width: min(380px, calc(100% - 32px));
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: 8px; padding: 12px 14px;
  box-shadow: 0 12px 28px rgb(10 48 64 / 0.2);
}
.help-pop.alert-pop {
  left: auto;
  right: 14px;
  width: min(320px, 70vw);
}
.help-pop.hidden { display: none; }
.help-pop strong { display: block; margin-bottom: 8px; color: var(--ink); }
.help-pop p { margin: 0 0 8px; font-size: 13px; line-height: 1.4; color: var(--help-fg); }
.alert-body { display: flex; flex-direction: column; gap: 6px; }
.alert-empty { margin: 0; color: var(--help-fg); }
.alert-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  width: 100%; text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--fg);
  cursor: pointer;
}
.alert-item b { font-size: 12px; color: #ff8081; }
.alert-item span { font-size: 11px; font-weight: 500; line-height: 1.35; color: var(--help-fg); }
.alert-item:hover, .help-pop .alert-item:hover {
  border-color: #ff8081;
  background: rgb(255 128 129 / 0.12);
}

main { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; position: relative; overflow: hidden; }
main.nav-collapsed { grid-template-columns: 0 1fr; }
main.nav-collapsed .col.left { overflow: hidden; padding: 0; border: 0; }
.col { padding: 14px; overflow: auto; background: var(--panel); border-right: 1px solid var(--line); }
.col button, .teach button, .host-panel button, .drawer button, .help-pop button {
  color: var(--btn-ink); border-color: var(--line);
}
.col button.on, .col button:hover, .teach button.on, .teach button:hover,
.host-panel button:hover, .drawer button:hover {
  background: rgb(0 135 179 / 0.12); border-color: var(--cyan);
}
.col h1, .drawer-head h1 { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--cyan); }
.layout-toggle { display: flex; gap: 4px; margin: 0 0 16px; }
.layout-toggle button {
  flex: 1;
  padding: 7px 8px;
  border-radius: 6px;
  background: var(--card-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.lede { margin: 0 0 12px; font-size: 12px; color: var(--mute); line-height: 1.45; }
.meter { height: 8px; background: var(--meter); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--cyan), var(--teal)); }
.pct { font-size: 28px; font-weight: 700; margin: 8px 0 12px; color: var(--ink); }
#twinList { margin: 0 0 18px; padding: 0 0 0 18px; font-size: 12px; line-height: 1.55; }
#twinList li {
  padding: 4px 8px 4px 4px; margin: 0 0 4px -4px; border-radius: 6px;
  outline: 2px solid transparent;
  background: transparent;
  transition: outline-color 0.28s ease, background-color 0.28s ease;
}
#twinList li.hot {
  outline-color: #38bdf8;
  background: rgb(56 189 248 / 0.14);
}
#twinList b { color: var(--cyan); }
#twinList .fault { color: var(--udt); font-weight: 700; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.layer-card {
  display: block; width: 100%; text-align: left;
  padding: 10px 10px 11px; border-radius: 10px;
  background: var(--card-2);
}
.layer-card b { display: block; color: var(--cyan); font-size: 12px; margin-bottom: 2px; }
.layer-card em { display: block; font-style: normal; color: var(--teal); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.layer-card span { display: block; font-weight: 500; color: var(--mute); font-size: 11px; line-height: 1.4; }
.layer-card .hl-online { display: inline; color: #bfff00; font-weight: 700; }
.layer-card .hl-say { display: inline; color: #ffe600; font-weight: 700; }
.layer-card.on, .layer-card:hover { background: rgb(8 145 178 / 0.22); }

.teach {
  position: absolute; left: 12px; bottom: 52px; z-index: 5;
  width: min(420px, calc(100% - 24px));
  max-height: min(52vh, 420px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow: 0 16px 40px rgb(10 48 64 / 0.18);
}
.teach.hidden { display: none; }
.teach-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.teach-head h2 { margin: 0; font-size: 14px; color: var(--ink); }
.teach-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 10px; }
.teach-tabs button { padding: 5px 8px; font-size: 10px; }
.teach-tabs button.on { background: rgb(8 145 178 / 0.35); }
.teach-layer { font-size: 12px; color: var(--help-fg); line-height: 1.45; margin-bottom: 10px; }
.teach-layer strong { color: var(--cyan); }
.teach-payload {
  margin: 0; padding: 10px; background: var(--card-2); border-radius: 8px;
  font: 11px ui-monospace, Menlo, monospace; color: var(--help-fg); line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}

.host-panel {
  position: absolute; left: 12px; top: 96px; z-index: 5;
  width: min(320px, calc(100% - 24px));
  max-height: calc(100% - 160px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow: 0 16px 40px rgb(10 48 64 / 0.18);
}
.host-panel.hidden { display: none; }
.host-panel { border-color: rgb(168 85 247 / 0.45); }
.host-panel h1 { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #6d28d9; }
.host-panel code { color: #6d28d9; }
.host-field {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--mute); margin-bottom: 8px;
}
.host-field input {
  width: 120px; background: var(--card-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font: 12px ui-monospace, monospace;
}
.cmd {
  display: block; width: 100%; margin: 0 0 8px; text-align: left;
  padding: 10px 12px; background: rgb(168 85 247 / 0.18);
}
.cmd:hover { background: rgb(168 85 247 / 0.32); border-color: #a855f7; }
#hostStatus { margin: 10px 0 8px; color: #6d28d9; }
#hostWire { max-height: 180px; overflow: auto; }

#viewport { position: relative; background: var(--floor); min-width: 0; }
#viewport > canvas { display: block; width: 100%; height: 100%; }
.foop-overlay {
  position: absolute; inset: 0; z-index: 8;
  display: flex; flex-direction: column;
  padding: 16px 18px 12px;
  background: rgb(2 6 23 / 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: grab;
}
.foop-overlay.hidden { display: none; }
.foop-overlay.dragging { cursor: grabbing; }
.foop-overlay.panning { cursor: move; }
.foup-heading {
  margin: 10px 0;
  text-align: center;
  pointer-events: none;
}
.foup-title {
  margin: 0;
  font-size: 60px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #ecfeff;
}
.foup-subtitle {
  margin: 8px 0 0;
  font-size: 30pt;
  font-weight: 500;
  color: #94a3b8;
}
.foup-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
}
.foup-leads {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}
.foup-leads line {
  stroke: var(--foup-color, #22d3ee);
  stroke-width: 1.8;
  stroke-linecap: round;
}
.foup-leads circle {
  fill: var(--foup-color, #22d3ee);
  stroke: #ecfeff;
  stroke-width: 1.2;
}
.foup-metrics {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: auto auto auto;
  gap: 8px;
  margin-top: 10px;
}
.foup-metric {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  grid-template-areas: "sym name name" "sym val unit";
  column-gap: 10px;
  row-gap: 4px;
  padding: 10px 12px;
  background: rgb(8 15 28 / 0.82);
  border: 1px solid rgb(8 145 178 / 0.38);
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.foup-metric[data-sensor="d"] { --foup-color: #22d3ee; }
.foup-metric[data-sensor="rh"] { --foup-color: #f59e0b; }
.foup-metric[data-sensor="t"] { --foup-color: #c084fc; }
.foup-metric[data-sensor="uStar"] { --foup-color: #4ade80; }
.foup-metric[data-sensor="u"] { --foup-color: #fb923c; }
.foup-metric[data-sensor="uf"] { --foup-color: #34d399; }
.foup-metric[data-sensor="x"] { --foup-color: #f472b6; }
.foup-metric[data-sensor="y"] { --foup-color: #60a5fa; }
.foup-metric[data-sensor="w"] { --foup-color: #facc15; }
.foup-metric[data-sensor="st"] { --foup-color: #22d3ee; }
.foup-metric[data-sensor="on"] { --foup-color: #9bcc00; }
.foup-metric[data-sensor="al"] { --foup-color: #ff0000; }
.foup-metric[data-sensor="id"] { --foup-color: #c084fc; }
.foup-metric[data-sensor="hs"] { --foup-color: #60a5fa; }
.foup-metric[data-sensor="tw"] { --foup-color: #f59e0b; }
.foup-metric[data-sensor="sx"] { --foup-color: #34d399; }
.foup-metric[data-sensor="last"] { --foup-color: #fb923c; }
.foup-metric .sym {
  grid-area: sym;
  align-self: center;
  font: 700 30px "Cambria Math", "Times New Roman", serif;
}
.foup-metric .sym,
.foup-metric small { color: var(--foup-color, #67e8f9); }
.foup-metric[aria-pressed="true"] {
  background: color-mix(in srgb, var(--foup-color) 22%, rgb(8 15 28 / 0.9));
  border-color: var(--foup-color);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foup-color) 55%, transparent);
}
.foup-metric .name {
  grid-area: name;
  font-size: 20px;
  line-height: 1.3;
  color: var(--mute);
}
.foup-metric b {
  grid-area: val;
  font-size: 20px;
  color: #f8fafc;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.foup-metric small {
  grid-area: unit;
  align-self: end;
  font-size: 20px;
}
.foop-overlay canvas { width: 100%; height: 100%; display: block; touch-action: none; min-height: 0; }
.insp-close {
  position: relative;
  z-index: 4;
  align-self: flex-end;
  margin: 8px 0 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #ecfeff;
  border-color: rgb(255 255 255 / 0.35);
}
.insp-x {
  color: #ff4d4f;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.foop-hint {
  margin: 10px 0 0;
  text-align: center;
  pointer-events: none;
  font-size: 12px; color: #ecfeff; text-shadow: 0 1px 4px #0f172a;
}
#btnFoop[aria-pressed="true"] {
  background: rgb(255 255 255 / 0.28);
  box-shadow: 0 0 0 1px #fff;
}
.kpis {
  position: absolute; left: 12px; right: 12px; top: 12px; z-index: 3;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px;
  pointer-events: none;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
  min-height: 72px;
  box-shadow: 0 6px 16px rgb(10 48 64 / 0.08);
}
.kpi small {
  display: block; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--mute); margin-bottom: 6px;
}
.kpi b { display: block; font-size: 22px; color: var(--ink); font-weight: 700; }
.kpi.fault b { color: var(--udt); }
#clickHint {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  text-align: center; font-size: 26px; font-weight: 700; color: rgb(45 45 45 / 0.5);
  pointer-events: none; z-index: 2;
}
#clickHint small { display: block; color: var(--mute); margin-top: 4px; }
.zoom-ctl[hidden] { display: none; }
.zoom-ctl {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgb(11 21 32 / 0.72);
  border: 1px solid var(--line);
  color: var(--mute);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.zoom-ctl input[type="range"] {
  width: 120px;
  accent-color: var(--cyan);
}
#err {
  display: none; position: absolute; left: 12px; top: 12px; z-index: 4;
  background: #7f1d1d; color: #fecaca; padding: 10px 12px; max-width: 420px;
  font: 12px ui-monospace, monospace; white-space: pre-wrap;
}

.drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(400px, 92vw);
  z-index: 6;
  pointer-events: none;
}
.drawer-tab {
  pointer-events: auto;
  position: absolute;
  top: 18px;
  right: 0;
  transform: translateX(0);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 8px 0 0 8px;
  border-right: 0;
  padding: 14px 8px;
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  z-index: 7;
  transition: right 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer.open .drawer-tab,
.drawer.pinned .drawer-tab { right: 100%; }
.drawer-body {
  pointer-events: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px rgb(10 48 64 / 0.16);
  transform: translateX(100%);
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}
.drawer.open .drawer-body,
.drawer.pinned .drawer-body { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.drawer-head h1 { margin: 0; }
.drawer-actions { display: flex; gap: 6px; }
.drawer-head button { padding: 5px 10px; }

.frames { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; flex: 1; }
.frame {
  display: grid; grid-template-columns: 52px 52px 1fr;
  gap: 6px; padding: 6px 4px; border-bottom: 1px solid rgb(148 163 184 / 0.12); cursor: pointer;
}
.frame:hover, .frame.sel { background: rgb(8 145 178 / 0.18); }
.frame .t { color: var(--mute); }
.frame .ly { color: #fde047; }
.frame .sx { color: #67e8f9; }
.frame.err { background: rgb(127 29 29 / 0.4); }
.frame.err .ly, .frame.err .sx { color: #fecaca; }
.frame.err:hover, .frame.err.sel { background: rgb(185 28 28 / 0.55); }
.inspect {
  margin-top: 12px; padding: 10px; background: var(--card-2); border-radius: 8px;
  font: 11px ui-monospace, Menlo, monospace; color: var(--help-fg); line-height: 1.5; min-height: 88px;
}
.inspect.err { color: #fecaca; border: 1px solid rgb(220 38 38 / 0.5); }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .col.left { max-height: 28vh; }
  #viewport { min-height: 44vh; }
}
