:root {
  --bg: #07090d;
  --bg-1: #0c0f15;
  --bg-2: #11151d;
  --bg-3: #171c26;
  --line: #1f2633;
  --line-2: #2a3343;
  --text: #d6dbe4;
  --text-2: #9aa4b5;
  --text-3: #6b7586;
  --accent: #f0a35a;
  --accent-2: #ffcf94;
  --cyan: #7fc4ff;
  --danger: #ff6b6b;
  --ok: #78e08f;
  --left-w: 312px;
  --right-w: 340px;
  --top-h: 44px;
  --bottom-h: 52px;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 12.5px/1.45 var(--sans); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
::selection { background: rgba(240, 163, 90, 0.35); }

/* ------------------------------------------------------------------ layout */
.app {
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr) var(--bottom-h);
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  height: 100vh;
  transition: grid-template-columns .25s ease, grid-template-rows .25s ease;
}
.app.hide-left { --left-w: 0px; }
.app.hide-right { --right-w: 0px; }
.app.hide-bars { --top-h: 0px; --bottom-h: 0px; }
.app.photo-mode { --left-w: 0px; --right-w: 0px; --top-h: 0px; --bottom-h: 0px; }
#topbar { grid-column: 1 / -1; grid-row: 1; }
#left { grid-column: 1; grid-row: 2; }
#viewport { grid-column: 2; grid-row: 2; }
#right { grid-column: 3; grid-row: 2; }
#timebar { grid-column: 1 / -1; grid-row: 3; }
.app.hide-bars #topbar, .app.hide-bars #timebar, .app.photo-mode #topbar, .app.photo-mode #timebar { overflow: hidden; border: 0; }
.app.hide-left #left, .app.hide-right #right, .app.photo-mode #left, .app.photo-mode #right { overflow: hidden; border: 0; padding: 0; }

/* ------------------------------------------------------------------ top bar */
#topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 12px;
  background: linear-gradient(#0d1117, #0a0d12); border-bottom: 1px solid var(--line); z-index: 20; min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.brand .name { font-weight: 650; letter-spacing: .18em; font-size: 12px; color: #eef1f6; }
.brand .ver { font: 10px var(--mono); color: var(--text-3); border: 1px solid var(--line-2); border-radius: 3px; padding: 0 4px; }
.menus { display: flex; gap: 2px; }
.menu { position: relative; }
.menu-btn { background: none; border: 0; padding: 6px 10px; border-radius: 4px; color: var(--text-2); cursor: pointer; }
.menu-btn:hover, .menu.open .menu-btn { background: var(--bg-3); color: var(--text); }
.menu-list {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 260px; padding: 5px;
  background: #10141b; border: 1px solid var(--line-2); border-radius: 6px; box-shadow: 0 12px 40px rgba(0,0,0,.55); z-index: 50;
}
.menu.open .menu-list { display: block; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 10px; border-radius: 4px; cursor: pointer; color: var(--text); white-space: nowrap; }
.menu-item:hover { background: var(--bg-3); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top-right .ctl-select { display: flex; align-items: center; gap: 6px; margin: 0; }
.top-right .ctl-select label { margin: 0; color: var(--text-3); }
.top-right .ctl-seg { margin: 0; }

/* ------------------------------------------------------------------ panels */
.panel { background: var(--bg-1); overflow-y: auto; overflow-x: hidden; min-width: 0; scrollbar-width: thin; scrollbar-color: #2a3343 transparent; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.panel-title {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--text-2);
  background: rgba(12,15,21,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.panel-title .legend { display: flex; gap: 4px; }

.sec { border-bottom: 1px solid var(--line); }
.sec-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 14px; background: none; border: 0; cursor: pointer;
  color: #e5e9f0; font-weight: 600; font-size: 11.5px; letter-spacing: .04em; text-align: left;
}
.sec-head:hover { background: rgba(255,255,255,.02); }
.chev { width: 7px; height: 7px; border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3); transform: rotate(-45deg); transition: transform .15s; flex: none; }
.sec.open .chev { transform: rotate(45deg); }
.sec-body { display: none; padding: 2px 14px 14px; }
.sec.open .sec-body { display: block; }
#sec-explore { display: none; }
.app[data-mode="explore"] #sec-explore { display: block; background: rgba(127,196,255,.03); }
.sub-title { margin: 12px 0 6px; font-size: 10.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .12em; }

/* ------------------------------------------------------------------ controls */
.ctl { display: block; margin: 10px 0 0; }
.ctl label, .ctl .lbl { color: var(--text-2); font-size: 11.5px; display: inline-flex; align-items: center; gap: 6px; }
.ctl-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.num-wrap { display: inline-flex; align-items: center; gap: 4px; }
.num {
  width: 78px; text-align: right; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 2px 5px;
  font: 11px var(--mono); color: var(--accent-2);
}
.num:focus { outline: none; border-color: var(--accent); }
.unit { font: 10px var(--mono); color: var(--text-3); min-width: 16px; }
.ctl.disabled { opacity: .45; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: transparent; margin: 0; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent) 0 var(--pct, 50%), #273041 var(--pct, 50%) 100%);
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: #273041; }
input[type="range"]::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4.5px; border-radius: 50%;
  background: #f4f6fa; border: 2px solid var(--accent); box-shadow: 0 0 0 3px rgba(240,163,90,.12);
}
input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: #f4f6fa; border: 2px solid var(--accent); }
input[type="range"]:disabled { cursor: not-allowed; }

.ctl-toggle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; position: relative; }
.ctl-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 28px; height: 15px; border-radius: 8px; background: #273041; position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: #9aa4b5; transition: transform .15s, background .15s; }
.ctl-toggle input:checked + .switch { background: rgba(240,163,90,.55); }
.ctl-toggle input:checked + .switch::after { transform: translateX(13px); background: #fff4e6; }
.ctl-toggle input:focus-visible + .switch { outline: 1px solid var(--accent); }

select {
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 6px; color: var(--text); cursor: pointer;
}
.ctl-select { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ctl-select select { max-width: 60%; }
.ctl-seg label { display: flex; margin-bottom: 5px; }
.segs { display: inline-flex; border: 1px solid var(--line-2); border-radius: 5px; overflow: hidden; }
.seg { background: var(--bg); border: 0; border-right: 1px solid var(--line-2); padding: 4px 9px; cursor: pointer; color: var(--text-2); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.seg:last-child { border-right: 0; }
.seg:hover { color: var(--text); background: var(--bg-3); }
.seg.active { background: rgba(240,163,90,.16); color: var(--accent-2); }
.seg .ico { display: inline-flex; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 11px; border-radius: 4px;
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a4558; background: var(--bg-3); }
.btn.small { padding: 4px 8px; font-size: 11.5px; }
.btn.primary { background: linear-gradient(#f0a35a, #d98838); border-color: #f0a35a; color: #1a0f05; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: none; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.btn.icon { padding: 5px; }
.btn.active { border-color: var(--accent); color: var(--accent-2); }
.btn .ico { display: inline-flex; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px; }
.preset-grid .btn { white-space: normal; text-align: center; line-height: 1.25; min-height: 34px; }

.ro { display: flex; align-items: baseline; gap: 6px; margin-top: 7px; font-size: 11.5px; }
.ro-lbl { color: var(--text-3); flex: 1; }
.ro-val { font: 11px var(--mono); color: var(--cyan); }
.note { color: var(--text-3); font-size: 11px; margin: 10px 0 0; line-height: 1.5; }
.note b { color: var(--text-2); }
.ctl-note { color: var(--text-3); font-size: 10.5px; margin-top: 2px; }

.tag {
  display: inline-block; font: 600 8.5px/1 var(--mono); letter-spacing: .06em; padding: 2px 4px 2px; border-radius: 2px;
  border: 1px solid; vertical-align: middle; cursor: help; white-space: nowrap;
}
.tag-phys { color: #8fd0ff; border-color: rgba(127,196,255,.35); background: rgba(127,196,255,.07); }
.tag-est { color: #ffc98a; border-color: rgba(255,190,120,.35); background: rgba(255,190,120,.07); }
.tag-vis { color: #c4a7ff; border-color: rgba(196,167,255,.35); background: rgba(196,167,255,.07); }
.tag-in { color: #a8b3c4; border-color: rgba(168,179,196,.3); }
.tag-perf { color: #8fe3a5; border-color: rgba(120,224,143,.3); }

/* ------------------------------------------------------------------ data panel */
.data { padding: 4px 0 8px; }
.dgroup { padding: 8px 14px 6px; border-bottom: 1px solid var(--line); }
.dgroup-title { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); margin-bottom: 4px; }
.drow { display: grid; grid-template-columns: minmax(0, 1fr) auto 44px; gap: 8px; align-items: baseline; padding: 2px 0; }
.dlbl { color: var(--text-2); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow:hover .dlbl { white-space: normal; }
.dval { font: 11px var(--mono); color: #e9edf3; text-align: right; white-space: nowrap; }
.dtag { text-align: right; }
.chart { width: 100%; min-height: 100px; margin-top: 4px; }
.uplot { font-family: var(--mono); }
.u-legend { font-size: 10px !important; color: var(--text-2); text-align: left !important; }
.u-legend .u-marker { width: 8px !important; height: 8px !important; }
.u-legend th, .u-legend td { padding: 1px 4px !important; }
.u-title { display: none; }

/* ------------------------------------------------------------------ viewport */
#viewport { position: relative; overflow: hidden; background: #000; min-width: 0; min-height: 0; }
#gl { display: block; width: 100%; height: 100%; outline: none; cursor: grab; touch-action: none; }
#gl:active { cursor: grabbing; }
#hud { position: absolute; left: 12px; top: 12px; pointer-events: none; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.app.hide-hud #hud, .app.photo-mode #hud { display: none; }
.hud-block { background: rgba(5,7,10,.55); border: 1px solid rgba(255,255,255,.06); border-radius: 5px; padding: 7px 10px; backdrop-filter: blur(4px); }
.hud-block div { display: flex; justify-content: space-between; gap: 14px; font-size: 11px; }
.hud-block span { color: var(--text-3); }
.hud-block b { font: 500 11px var(--mono); color: #e8ecf2; }
.hud-block.ship { border-color: rgba(127,196,255,.2); }
.hud-warn { background: rgba(60,20,10,.7); border: 1px solid rgba(255,140,90,.4); color: #ffc5a8; border-radius: 5px; padding: 6px 10px; font-size: 11px; }
#show-ui {
  position: absolute; right: 12px; top: 12px; display: none; padding: 6px 10px; border-radius: 4px; cursor: pointer;
  background: rgba(10,12,16,.6); border: 1px solid var(--line-2); color: var(--text-2);
}
.app.hide-bars #show-ui { display: block; }
#toast { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(14,17,23,.92); border: 1px solid var(--line-2); padding: 7px 14px; border-radius: 5px; opacity: 0; transform: translateY(6px); transition: all .3s; max-width: 70vw; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.toast.warn { border-color: rgba(255,140,90,.5); color: #ffd0b8; }

/* ------------------------------------------------------------------ time bar */
#timebar {
  display: flex; align-items: center; gap: 14px; padding: 0 12px; background: linear-gradient(#0a0d12, #0d1117);
  border-top: 1px solid var(--line); min-width: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tb-group { display: flex; align-items: center; gap: 6px; flex: none; }
.tb-group:last-child { margin-left: auto; }
.tb-group select.speed { font: 11.5px var(--mono); }
.btn.primary-ghost { border-color: rgba(240,163,90,.5); color: var(--accent-2); }
.btn.primary-ghost.paused { background: rgba(240,163,90,.18); }
.clocks { gap: 16px; padding: 0 6px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); height: 34px; }
.clk { display: flex; flex-direction: column; line-height: 1.15; }
.clk-l { font-size: 9.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .1em; }
.clock { font: 11.5px var(--mono); color: #e9edf3; white-space: nowrap; }
.cam-segs .seg { padding: 4px 8px; }

/* ------------------------------------------------------------------ photo panel */
.photo-panel {
  position: fixed; right: 14px; top: 14px; width: 300px; max-height: calc(100vh - 28px); overflow-y: auto;
  background: rgba(10,12,16,.82); border: 1px solid var(--line-2); border-radius: 8px; z-index: 30; backdrop-filter: blur(10px);
  box-shadow: 0 16px 50px rgba(0,0,0,.6); scrollbar-width: thin; transition: opacity .2s;
}
.photo-panel:not(:hover) { opacity: .72; }
.photo-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: rgba(10,12,16,.95); z-index: 2; }
.photo-title { flex: 1; font-size: 10.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent-2); }
.photo-panel.collapsed .photo-body { display: none; }
.photo-panel .btn.primary { width: 100%; margin-top: 12px; padding: 8px; }
.photo-status { font: 10.5px var(--mono); color: var(--text-3); margin-top: 8px; min-height: 14px; }

/* ------------------------------------------------------------------ modal */
#modal-root[hidden] { display: none; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; }
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(620px, 92vw); max-height: 84vh; display: flex; flex-direction: column;
  background: #0f1319; border: 1px solid var(--line-2); border-radius: 8px; z-index: 61; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); font-weight: 600; letter-spacing: .04em; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--text-2); }
input.text { background: var(--bg); border: 1px solid var(--line-2); border-radius: 4px; padding: 6px 8px; }
input.text:focus { outline: none; border-color: var(--accent); }
.slot-list { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--bg-2); }
.slot-info { flex: 1; display: flex; flex-direction: column; }
.slot-info small { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; }
table.keys { border-collapse: collapse; width: 100%; }
table.keys td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
kbd { font: 11px var(--mono); background: var(--bg-3); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 3px; padding: 1px 6px; white-space: nowrap; }
.doc h4 { margin: 16px 0 6px; color: var(--accent-2); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.doc h4:first-child { margin-top: 0; }
.doc p { margin: 0 0 8px; color: var(--text-2); line-height: 1.6; }
.settings .ctl { margin-top: 12px; }

/* ------------------------------------------------------------------ loading */
#loading { position: fixed; inset: 0; background: #030405; display: flex; align-items: center; justify-content: center; z-index: 100; transition: opacity .6s; }
#loading.done { opacity: 0; pointer-events: none; }
.ld-box { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.ld-ring {
  width: 64px; height: 64px; border-radius: 50%; background: #000;
  box-shadow: 0 0 0 2px rgba(255,190,120,.85), 0 0 22px 6px rgba(240,140,60,.35), inset 0 0 12px rgba(0,0,0,1);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 0 2px rgba(255,210,150,1), 0 0 34px 10px rgba(240,140,60,.45), inset 0 0 12px #000; } }
.ld-title { letter-spacing: .3em; font-weight: 600; color: #e9edf3; font-size: 12px; }
.ld-msg { font: 11px var(--mono); color: var(--text-3); max-width: 70vw; text-align: center; }
.ld-msg.err { color: var(--danger); }
.ld-bar { width: 220px; height: 2px; background: #1a1f28; border-radius: 1px; overflow: hidden; }
#ld-fill { height: 100%; width: 0; background: var(--accent); transition: width .3s; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1200px) {
  :root { --left-w: 280px; --right-w: 300px; }
  .menus .menu-btn { padding: 6px 7px; }
}
@media (max-width: 900px) {
  :root { --left-w: 0px; --right-w: 0px; }
  .brand .ver, .clocks { display: none; }
}
