/* Engine-X — instrument-panel UI over a full-viewport 3D stage */

/* ============================================================
   Design tokens
   Light values are the source of truth; the dark palette is kept
   as one block and applied both automatically (prefers-color-scheme)
   and manually (data-theme="dark") so there is only one place that
   ever needs the dark numbers.
   ============================================================ */
:root {
  --bg: #eef2fb;          /* cool tech-blue ground */
  --bg-3d: #eef2fb;
  --panel: #ffffff;
  --panel-2: #f2f5fc;
  --line: rgba(20, 40, 75, 0.09);
  --line-strong: rgba(20, 40, 75, 0.18);
  --ink: #0c1526;
  --ink-2: #4a5975;
  --ink-3: #8393b0;
  --accent: #2f6fed;      /* engine-x blue */
  --accent2: #8a6cff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(47, 111, 237, 0.12);
  --focus: #2f6fed;
  --shadow: 0 1px 2px rgba(10, 20, 40, 0.05), 0 10px 30px -10px rgba(10, 20, 40, 0.18);
  --shadow-sm: 0 1px 2px rgba(10, 20, 40, 0.06), 0 4px 12px -6px rgba(10, 20, 40, 0.14);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --track: rgba(20, 40, 75, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #070b14; --bg-3d: #070b14; --panel: #0e1626; --panel-2: #111d31; --line: rgba(94, 167, 255, 0.14); --line-strong: rgba(94, 167, 255, 0.26); --ink: #e8eef9; --ink-2: #8fa1bc; --ink-3: #5c7396; --accent: #5ea7ff; --accent2: #8a6cff; --accent-ink: #07101e; --accent-soft: rgba(94, 167, 255, 0.16); --focus: #8a6cff; --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 32px -10px rgba(0,0,0,0.7); --shadow-sm: 0 1px 2px rgba(0,0,0,0.4), 0 4px 14px -6px rgba(0,0,0,0.6); --track: rgba(94, 167, 255, 0.18); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #070b14; --bg-3d: #070b14; --panel: #0e1626; --panel-2: #111d31; --line: rgba(94, 167, 255, 0.14); --line-strong: rgba(94, 167, 255, 0.26); --ink: #e8eef9; --ink-2: #8fa1bc; --ink-3: #5c7396; --accent: #5ea7ff; --accent2: #8a6cff; --accent-ink: #07101e; --accent-soft: rgba(94, 167, 255, 0.16); --focus: #8a6cff; --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 32px -10px rgba(0,0,0,0.7); --shadow-sm: 0 1px 2px rgba(0,0,0,0.4), 0 4px 14px -6px rgba(0,0,0,0.6); --track: rgba(94, 167, 255, 0.18); color-scheme: dark; }

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: inherit; }

/* Small reusable utility hooks used across several components. */
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.lbl { font: 500 11px/1 var(--font); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }

/* ============================================================
   App shell & 3D stage
   ============================================================ */
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; touch-action: none; }
#stage canvas { display: block; outline: none; }
#stage.grab { cursor: grab; }
#stage.pick { cursor: pointer; }

/* ============================================================
   Top bar: brand + machine switcher + search + icon buttons
   ============================================================ */
.topbar {
  position: absolute; inset: 0 0 auto 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 20px; pointer-events: none; z-index: 5;
}
.topbar > * { pointer-events: auto; }
.brand { position: relative; }
.eyebrow { display: flex; align-items: center; gap: 7px; font: 500 10.5px/1 var(--font); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.eyebrow-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.title { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 24px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.title-x { background: linear-gradient(100deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.badge { font: 600 10px/1 var(--font); letter-spacing: 0.06em; color: var(--accent); border: 1px solid var(--line-strong); border-radius: 5px; padding: 2px 5px; background: var(--accent-soft); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12.5px; }
.meta-sep { color: var(--ink-3); }
.machine-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 11px; font-weight: 500; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-sm); }
.machine-btn:hover { border-color: var(--line-strong); }
.topright { display: flex; align-items: center; gap: 8px; }
.search { position: relative; display: flex; align-items: center; gap: 8px; height: 36px; width: 240px; padding: 0 8px 0 10px; color: var(--ink-3); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-sm); }
.search:focus-within { border-color: var(--focus); color: var(--ink-2); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; color: var(--ink); }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd { font-family: var(--mono); font-size: 10.5px; line-height: 16px; color: var(--ink-3); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 5px; }
.iconbtn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-sm); }
.iconbtn:hover { color: var(--ink); border-color: var(--line-strong); }
.iconbtn.small { width: 26px; height: 26px; border-radius: 7px; box-shadow: none; }

/* ============================================================
   Dropdown menus (machine switcher, search results)
   ============================================================ */
.menu { position: absolute; z-index: 20; min-width: 260px; max-height: 60vh; overflow: auto; padding: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
#machineMenu { top: 100%; left: 0; margin-top: 6px; width: 330px; }
#searchResults { top: calc(100% + 6px); right: 0; width: 320px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; text-align: left; color: var(--ink); border-radius: 8px; }
.menu-item:hover, .menu-item.active { background: var(--panel-2); }
.menu-item .mi-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.menu-item .mi-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.menu-item .mi-name, .menu-item .mi-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-item .mi-name { font-weight: 500; }
.menu-item .mi-sub { font-size: 11.5px; color: var(--ink-3); }
.menu-item .mi-count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.menu-item.current .mi-name { color: var(--accent); }
.menu-empty { padding: 10px; font-size: 12.5px; color: var(--ink-3); }

/* ============================================================
   Floating panels (shared shell used by Systems + Inspector)
   ============================================================ */
.panel { position: absolute; z-index: 4; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* --- Systems panel --- */
.systems { left: 20px; top: 128px; width: 262px; max-height: calc(100vh - 128px - 168px); display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.panel-head h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 600; }
.count-pill { font-size: 11px; color: var(--ink-2); background: var(--panel-2); border-radius: 999px; padding: 2px 8px; }
.collapse { width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-3); border-radius: 6px; }
.collapse:hover { color: var(--ink); background: var(--panel-2); }
.systems.collapsed .segmented, .systems.collapsed .system-list, .systems.collapsed .panel-foot { display: none; }
.systems.collapsed .collapse svg { transform: rotate(180deg); }
.segmented { display: flex; gap: 2px; margin: 0 12px 6px; padding: 3px; background: var(--panel-2); border-radius: 8px; }
.segmented button { flex: 1; padding: 5px 6px; font: 500 12px/1 var(--font); color: var(--ink-2); border-radius: 6px; }
.segmented button.on { color: var(--ink); background: var(--panel); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.segmented.tiny { margin: 0; }
.segmented.tiny button { padding: 3px 8px; font-size: 11px; }
.system-list { list-style: none; flex: 1; min-height: 0; margin: 0; padding: 4px 6px; overflow: auto; }
.system-row { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 8px; }
.system-row:hover { background: var(--panel-2); }
.system-row.off .sys-name { color: var(--ink-3); }
.sys-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.sys-name { flex: 1; min-width: 0; text-align: left; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sys-name:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--ink-3); }
.sys-count { font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.switch { position: relative; flex: none; width: 30px; height: 18px; background: var(--track); border-radius: 999px; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform .15s; }
.switch.on, :root[data-theme="dark"] .switch.on { background: var(--sw-on, var(--ink)); }
.switch.on::after { transform: translateX(12px); }
.panel-foot { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px 12px; font-size: 11.5px; color: var(--ink-3); border-top: 1px solid var(--line); }
.linkbtn { font-size: 12px; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.linkbtn:hover { color: var(--ink); }

/* --- Inspector panel (drawing title-block style) --- */
.info { right: 76px; top: 128px; width: 318px; max-height: calc(100vh - 128px - 168px); display: flex; flex-direction: column; }
.info-body { min-height: 0; padding: 14px 16px 6px; overflow: auto; }
.info-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font: 500 11px/1 var(--font); letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.info-name { margin: 8px 0 6px; font-size: 20px; font-weight: 600; letter-spacing: -0.015em; line-height: 1.15; text-wrap: balance; }
.info-desc { max-width: 60ch; margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }
.titleblock { display: grid; grid-template-columns: max-content 1fr; margin: 0 0 10px; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.titleblock dt, .titleblock dd { margin: 0; padding: 5px 9px; font-size: 12px; border-top: 1px solid var(--line); }
.titleblock dt { font: 400 10px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); background: var(--panel-2); border-right: 1px solid var(--line); }
.titleblock dd { color: var(--ink); }
.titleblock dt:first-of-type, .titleblock dd:first-of-type { border-top: 0; }
.info-notes { margin: 0 0 8px; padding: 0 0 0 16px; font-size: 12.5px; color: var(--ink-2); }
.info-notes li { margin: 4px 0; }
.info-notes li::marker { color: var(--accent); }
.info-actions { display: flex; flex: none; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.btn { padding: 7px 12px; font: 500 12.5px/1 var(--font); background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; }
.btn:hover { background: var(--panel-2); }
.btn.primary { color: var(--panel); background: var(--ink); border-color: var(--ink); }
.btn.primary:hover { opacity: 0.9; }
.btn.primary.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* ============================================================
   Right-side view rail & section controls
   ============================================================ */
.rail { position: absolute; right: 20px; top: 50%; z-index: 4; display: flex; flex-direction: column; gap: 4px; padding: 5px; transform: translateY(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.rail button { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; font: 500 13px/1 var(--font); color: var(--ink-2); border-radius: 8px; }
.rail button:hover { color: var(--ink); background: var(--panel-2); }
.rail button.on { color: var(--panel); background: var(--ink); }
.rail-sep { height: 1px; margin: 3px 4px; background: var(--line); }
.section-ctl { position: absolute; right: 70px; top: 50%; z-index: 4; display: flex; align-items: center; gap: 10px; padding: 8px 10px; transform: translateY(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.section-ctl input[type=range] { width: 150px; }

/* ============================================================
   Bottom console (drive readout, cycle strip, explode slider)
   ============================================================ */
.console { left: 50%; bottom: 22px; z-index: 4; width: min(640px, calc(100vw - 40px)); padding: 12px 16px; transform: translateX(-50%); }
.console-row { display: flex; align-items: center; gap: 14px; }
.console-row + .console-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.playbtn { flex: none; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--panel); background: var(--ink); border-radius: 50%; transition: background .15s; }
.playbtn .ic-pause { display: none; }
.playbtn.on { color: var(--accent-ink); background: var(--accent); }
.playbtn.on .ic-play { display: none; }
.playbtn.on .ic-pause { display: block; }
.console-main { flex: 1; min-width: 0; }
.console-top { display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px; }
.console-top .lbl { flex: 1; }
.readout { font-size: 13px; color: var(--ink); }
.readout .unit { font-size: 10.5px; letter-spacing: 0.04em; color: var(--ink-3); }
.readout.dim { min-width: 4.2ch; font-size: 12px; text-align: right; color: var(--ink-3); }
.console-sub { display: flex; justify-content: space-between; margin-top: 2px; font-size: 10.5px; color: var(--ink-3); }
.cycle { flex: none; width: 168px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.cycle.hidden { display: none; }
.cycle span { position: relative; padding-top: 9px; font: 500 9.5px/1 var(--font); letter-spacing: 0.05em; text-transform: uppercase; text-align: center; color: var(--ink-3); }
.cycle span::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--track); border-radius: 2px; }
.cycle span.on { color: var(--ink); }
.cycle span.on::before { background: var(--cyc, var(--ink)); }
.cycle-title { grid-column: 1 / -1; padding-top: 0 !important; font: 400 9.5px/1 var(--font); letter-spacing: 0.08em; text-transform: uppercase; text-align: left !important; color: var(--ink-3); }
.cycle-title::before { display: none; }
.modes { flex: none; display: flex; flex-direction: column; gap: 5px; }
.modes .segmented button { padding: 4px 9px; }
.explode-row .lbl { width: 62px; }
.explode-row input[type=range] { flex: 1; }
.explode-row .readout { width: 5ch; text-align: right; }

/* ============================================================
   Range sliders (shared across section + speed + explode)
   ============================================================ */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--track); border-radius: 2px; }
input[type=range]::-moz-range-track { height: 4px; background: var(--track); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; margin-top: -6px; background: var(--panel); border: 2px solid var(--ink); border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); cursor: pointer; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; background: var(--panel); border: 2px solid var(--ink); border-radius: 50%; cursor: pointer; }

/* ============================================================
   Loose overlays: hint, credit link, tooltip, loader, about modal
   ============================================================ */
.hint { position: absolute; left: 20px; bottom: 22px; z-index: 3; font-size: 11.5px; color: var(--ink-3); pointer-events: none; }
.credits { position: absolute; right: 20px; bottom: 22px; z-index: 3; font-size: 11.5px; color: var(--ink-3); }
.credits a { text-decoration: none; }
.credits a:hover { color: var(--ink); }
.tooltip { position: absolute; z-index: 6; padding: 5px 9px; font: 500 12px/1 var(--font); white-space: nowrap; color: var(--panel); background: var(--ink); border-radius: 7px; box-shadow: var(--shadow-sm); transform: translate(12px, 14px); pointer-events: none; }
.tooltip small { display: block; margin-top: 1px; font: 400 10.5px/1 var(--font); letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.7; }

.loader { position: absolute; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; pointer-events: none; transition: opacity .35s; }
.loader.fade { opacity: 0; }
.loader-card { display: flex; align-items: center; gap: 14px; min-width: 300px; padding: 16px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.loader-ring { flex: none; width: 26px; height: 26px; border: 2.5px solid var(--track); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-title { font-size: 14px; font-weight: 600; }
.loader-sub { margin-top: 2px; font-size: 11.5px; color: var(--ink-3); }
.loader-bar { width: 200px; height: 3px; margin-top: 8px; overflow: hidden; background: var(--track); border-radius: 2px; }
.loader-bar i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .15s; }

.modal { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(10, 14, 18, 0.45); }
.modal-card { width: min(560px, 100%); max-height: 85vh; padding: 22px 24px; overflow: auto; background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.modal-body { max-width: 62ch; font-size: 13.5px; color: var(--ink-2); }
.modal-body p { margin: 0 0 10px; }
.modal-body h3 { margin: 18px 0 6px; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.modal-body ul { margin: 0 0 10px; padding-left: 18px; }
.modal-body li { margin: 3px 0; }
.modal-body kbd { font-family: var(--mono); font-size: 11px; padding: 0 5px; border: 1px solid var(--line-strong); border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  .loader-ring { animation-duration: 3s; }
  * { transition-duration: 0s !important; }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .search { width: 170px; }
  .systems { width: 230px; }
  .info { width: 280px; }
  .cycle, .modes { display: none; }
}
@media (max-width: 680px) {
  body { font-size: 13px; }
  .topbar { padding: 12px; }
  .eyebrow { font-size: 9.5px; letter-spacing: 0.1em; white-space: nowrap; }
  .title { font-size: 20px; }
  .meta { font-size: 12px; }
  #machineSub, .meta-sep:last-of-type { display: none; }
  .topright { gap: 6px; }
  .search { width: 40px; padding: 0 0 0 12px; }
  .search input, .search kbd { display: none; }
  .search.open { position: fixed; left: 12px; top: 12px; z-index: 40; width: calc(100vw - 24px); padding: 0 8px 0 10px; }
  .search.open input { display: block; }
  #searchResults, #machineMenu { width: calc(100vw - 24px); }
  .systems { left: 12px; top: auto; bottom: 150px; width: calc(100vw - 24px); max-height: 42vh; }
  .systems:not(.collapsed) { z-index: 7; }
  .info { left: 12px; right: 12px; top: 120px; width: auto; max-height: 44vh; z-index: 8; }
  .rail { right: 12px; top: 50%; flex-direction: column; gap: 2px; padding: 4px; transform: translateY(-50%); }
  .rail button { width: 32px; height: 32px; }
  .section-ctl { left: 12px; right: 12px; top: 122px; transform: none; }
  .section-ctl input[type=range] { flex: 1; width: auto; }
  .console { bottom: 12px; width: calc(100vw - 24px); padding: 10px 12px; }
  .console-row { gap: 10px; }
  .hint, .credits { display: none; }
  .info-name { font-size: 18px; }
}
