:root {
  --room: #14181d;
  --panel: #262c33;
  --panel-hi: #3a4149;
  --panel-lo: #1a1e23;
  --screen: #071b3d;
  --cyan: #4fd6ff;
  --amber: #ffb020;
  --green: #6ee7a0;
  --red: #ff5a4a;
  --text: #d7e4ea;
  --text-dim: #8393a1;
  --font-label: 'Bahnschrift SemiCondensed', 'Arial Narrow', 'Segoe UI Semibold', sans-serif;
  --font-mono: 'Consolas', 'Cascadia Mono', 'SFMono-Regular', ui-monospace, monospace;
  --font-body: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% -10%, #1c2229 0%, var(--room) 55%);
  color: var(--text);
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

button, input { font-family: inherit; }

::selection { background: var(--cyan); color: #071b3d; }

.wrap {
  max-width: 1800px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-sizing: border-box;
}

/* ---------- header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 18px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid #454d56;
  border-radius: 6px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.05);
  flex-shrink: 0;
}
.topbar h1 {
  font-family: var(--font-label);
  font-size: 19px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
  color: #eef5f8;
}
.topbar .subtitle {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--cyan);
  opacity: 0.75;
  margin-top: 2px;
}
.clock-block {
  font-family: var(--font-mono);
  text-align: right;
}
.clock-block .clock-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.clock-block .clock-value {
  font-size: 22px;
  color: var(--green);
  text-shadow: 0 0 8px rgba(110,231,160,0.5);
}
.speed-group {
  display: flex;
  gap: 6px;
}
.speed-btn {
  background: var(--panel-lo);
  border: 1px solid #454d56;
  color: var(--text-dim);
  padding: 6px 10px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.speed-btn.active { color: #071b3d; background: var(--cyan); border-color: var(--cyan); font-weight: 700; }
.speed-btn:hover { border-color: var(--cyan); }

.help-btn {
  background: var(--panel-lo);
  border: 1px solid var(--amber);
  color: var(--amber);
  padding: 8px 14px;
  border-radius: 4px;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.help-btn:hover { background: var(--amber); color: #2a1a00; }

/* ---------- page layout: controls left, core+gauges center, log right ---------- */
.main-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr 290px;
  grid-template-rows: 1fr;
  gap: 10px;
}
.side-col { order: 1; }
.center-col { order: 2; }
.controls-col { order: 3; }
.controls-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}
.center-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* ---------- core map panel ---------- */
.core-panel {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 210px;
  grid-template-rows: 1fr;
  gap: 10px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid #454d56;
  border-radius: 6px;
  padding: 10px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
}
.core-canvas-holder {
  position: relative;
  height: 100%;
  min-height: 0;
  border: 2px solid #05122a;
  border-radius: 4px;
  overflow: hidden;
  background: var(--screen);
  box-shadow: inset 0 0 40px rgba(0,0,0,0.6), inset 0 0 2px #4fd6ff;
}
.core-canvas-holder canvas { display: block; width: 100%; height: 100%; }
.mode-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 1px;
  background: #05122a;
}
.mode-btn {
  flex: 1;
  background: #0b2450;
  color: var(--cyan);
  border: none;
  border-top: 1px solid #1a3a70;
  padding: 6px 2px;
  cursor: pointer;
  font-family: var(--font-label);
  font-size: 10.5px;
  letter-spacing: 0.03em;
}
.mode-btn.active { background: var(--cyan); color: #071b3d; }

.sidebar-readouts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
}
.ro-box {
  background: var(--screen);
  border: 1px solid #0f3a6e;
  border-radius: 3px;
  padding: 5px 8px;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
  flex-shrink: 0;
}
.ro-box .ro-label {
  font-family: var(--font-label);
  font-size: 10px;
  letter-spacing: 0.05em;
  color: #7fb8e6;
  text-transform: uppercase;
}
.ro-box .ro-value {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(79,214,255,0.5);
}

.hint-box {
  margin-top: auto;
  flex-shrink: 0;
  background: var(--panel-lo);
  border: 1px solid #454d56;
  border-radius: 4px;
  padding: 7px 8px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}
.hint-box .hint-label {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 3px;
}

/* ---------- gauges ---------- */
.gauge-rack {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid #454d56;
  border-radius: 6px;
  padding: 8px 8px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
}
.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--panel-lo);
  border: 1px solid #3a4149;
  border-radius: 6px;
  padding: 6px 4px 5px;
  min-width: 0;
}
.gauge canvas { width: 56px; height: 56px; }
.gauge-value { font-family: var(--font-mono); font-size: 12px; color: var(--text); }
.gauge-label { font-family: var(--font-label); font-size: 8.5px; letter-spacing: 0.03em; color: var(--text-dim); text-transform: uppercase; text-align: center; }

/* ---------- left column: control console ---------- */
.console {
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid #454d56;
  border-radius: 6px;
  padding: 10px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.control-block {
  background: var(--panel-lo);
  border: 1px solid #3a4149;
  border-radius: 5px;
  padding: 7px 10px 8px;
}
.control-block .ctl-label {
  font-family: var(--font-label);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
  display: flex;
  justify-content: space-between;
}
.control-block .ctl-label .ctl-value {
  font-family: var(--font-mono);
  color: var(--cyan);
}
.control-block .ctl-ends {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type="range"] {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--cyan);
}
.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.switch {
  position: relative;
  width: 42px;
  height: 22px;
  background: #0f1216;
  border: 1px solid #454d56;
  border-radius: 12px;
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked ~ .knob { transform: translateX(20px); background: var(--green); box-shadow: 0 0 6px var(--green); }

.az5-block {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: repeating-linear-gradient(45deg, #241414, #241414 8px, #2c1717 8px, #2c1717 16px);
  border: 1px solid #5a2a2a;
  border-radius: 5px;
  padding: 10px;
}
.az5-assembly { position: relative; width: 68px; height: 68px; flex-shrink: 0; perspective: 300px; }
.az5-button {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff8a7a, var(--red) 60%, #9c1f14 100%);
  border: 3px solid #7a1a10;
  color: #2a0602;
  font-family: var(--font-label);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 3px 0 #5c1108, 0 0 16px rgba(255,90,74,0.35);
}
.az5-button:disabled { filter: grayscale(0.6) brightness(0.7); cursor: not-allowed; }
.az5-cover {
  position: absolute;
  inset: -5px;
  background: linear-gradient(180deg, #8a8f96, #55595f);
  border: 2px solid #2c2f33;
  border-radius: 50%;
  cursor: pointer;
  transform-origin: 50% 100%;
  transition: transform 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 8px;
  color: #24272b;
  text-align: center;
  padding: 5px;
}
.az5-cover.open { transform: rotateX(115deg); pointer-events: none; }
.az5-text { text-align: left; min-width: 0; flex: 1; }
.az5-text .az5-title { font-family: var(--font-label); color: var(--red); font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; }
.az5-text p { font-size: 10px; color: var(--text-dim); margin: 3px 0 0; line-height: 1.35; }

.reset-row { flex-shrink: 0; display: flex; justify-content: stretch; }
.reset-row .btn { width: 100%; text-align: center; }
.btn {
  background: var(--panel-lo);
  border: 1px solid #454d56;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 4px;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.btn:hover { border-color: var(--cyan); color: var(--cyan); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--cyan); color: #071b3d; border-color: var(--cyan); font-weight: 700; }
.btn-primary:disabled { background: var(--panel-lo); color: var(--text-dim); border-color: #454d56; }

/* ---------- objective + log ---------- */
.side-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.objective {
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--panel-hi), var(--panel));
  border: 1px solid #454d56;
  border-radius: 6px;
  padding: 12px 14px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.35);
  max-height: 46%;
  overflow-y: auto;
}
.objective h2 {
  font-family: var(--font-label);
  font-size: 13px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--amber);
  margin: 0 0 6px;
}
.objective p { font-size: 12.5px; line-height: 1.45; color: var(--text); margin: 0 0 10px; }
.objective .test-btns { display: flex; gap: 8px; }

.log-panel {
  background: var(--panel-lo);
  border: 1px solid #454d56;
  border-radius: 6px;
  padding: 10px 12px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.log-panel h2 {
  flex-shrink: 0;
  font-family: var(--font-label);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 8px;
}
#eventLog {
  list-style: none;
  margin: 0; padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#eventLog li { display: flex; gap: 8px; }
.log-time { color: #566370; flex-shrink: 0; }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(5,8,11,0.88);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
  z-index: 50;
}
.overlay.visible { opacity: 1; pointer-events: auto; }
.overlay-card {
  max-width: 520px;
  background: var(--panel);
  border: 1px solid #454d56;
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.overlay-card h2 { font-family: var(--font-label); letter-spacing: 0.05em; font-size: 22px; margin: 0 0 14px; }
.overlay-card p { font-size: 14px; line-height: 1.6; color: var(--text-dim); margin: 0 0 20px; }

.help-card {
  max-width: 720px;
  width: 90vw;
  max-height: 86vh;
  text-align: left;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid #454d56;
  background: var(--panel-hi);
  flex-shrink: 0;
}
.help-head h2 { margin: 0; font-size: 18px; }
.help-close {
  background: var(--panel-lo);
  border: 1px solid #454d56;
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.help-close:hover { border-color: var(--red); color: var(--red); }
.help-body {
  padding: 6px 22px 22px;
  overflow-y: auto;
}
.help-body h3 {
  font-family: var(--font-label);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--amber);
  margin: 20px 0 8px;
}
.help-body h3:first-child { margin-top: 16px; }
.help-body p { font-size: 13.5px; line-height: 1.6; color: var(--text); margin: 0 0 10px; text-align: left; }
.help-body ol, .help-body ul { margin: 0 0 10px; padding-left: 22px; display: flex; flex-direction: column; gap: 7px; }
.help-body li { font-size: 13.5px; line-height: 1.55; color: var(--text); }
.help-body strong { color: var(--cyan); }

/* Below this width/height, a single no-scroll page can't fit everything
   legibly -- fall back to a scrollable, stacked layout instead of squeezing
   controls unusably small. */
@media (max-width: 1100px), (max-height: 680px) {
  html, body { height: auto; overflow: visible; }
  .wrap { height: auto; }
  .main-grid { grid-template-columns: 1fr; }
  .center-col { order: 1; }
  .controls-col { order: 2; overflow-y: visible; }
  .side-col { order: 3; }
  .core-panel { grid-template-columns: 1fr; }
  .core-canvas-holder { height: 60vh; }
  .gauge-rack { grid-template-columns: repeat(4, 1fr); }
  .objective { max-height: none; }
  .log-panel { min-height: 240px; }
}
@media (max-width: 640px) {
  .gauge-rack { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- tooltips ---------- */
[data-tip] { cursor: help; }
[data-tip].gauge, [data-tip].control-block, [data-tip].ro-box, [data-tip].core-canvas-holder { cursor: default; }
.tooltip-bubble {
  position: fixed;
  z-index: 200;
  max-width: 260px;
  background: #0b2450;
  border: 1px solid var(--cyan);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12.5px;
  line-height: 1.45;
  padding: 9px 11px;
  border-radius: 5px;
  box-shadow: 0 10px 26px rgba(0,0,0,0.55), 0 0 0 1px rgba(79,214,255,0.15);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}
.tooltip-bubble.visible { opacity: 1; transform: translateY(0); }
.tooltip-bubble::after {
  content: '';
  position: absolute;
  left: var(--arrow-left, 50%);
  width: 9px; height: 9px;
  background: #0b2450;
  transform: translateX(-50%) rotate(45deg);
}
.tooltip-bubble.arrow-top::after { bottom: -5px; border-right: 1px solid var(--cyan); border-bottom: 1px solid var(--cyan); }
.tooltip-bubble.arrow-bottom::after { top: -5px; border-left: 1px solid var(--cyan); border-top: 1px solid var(--cyan); }

@media (prefers-reduced-motion: reduce) {
  .az5-cover, .overlay, .tooltip-bubble { transition: none; }
}
