:root {
  --bg: #090d15;
  --panel: #101623;
  --panel-2: #151c2c;
  --line: #222b3f;
  --text: #e6ebf5;
  --muted: #8b96ad;
  --accent: #5eead4;
  --accent-dim: rgba(94, 234, 212, .14);
  --warn: #fbbf24;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #14203a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  min-height: 100vh;
}

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 21, .8);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .02em; color: var(--text); }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.preset { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

/* ---------- Generic controls ---------- */
select, .btn {
  font: inherit; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; cursor: pointer;
}
select:hover, .btn:hover { border-color: #3a4763; }
select:focus-visible, .btn:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.icon { padding: 4px 9px; font-size: 12px; line-height: 1.4; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; background: transparent; margin: 0; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
}
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
input[type=range]:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); align-items: start; }
.side {
  position: sticky; top: 61px; height: calc(100vh - 61px); overflow-y: auto;
  border-right: 1px solid var(--line); padding: 8px 14px 30px;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
main { padding: 16px 20px 24px; min-width: 0; }

details { border-bottom: 1px solid var(--line); padding: 4px 0 10px; }
summary {
  cursor: pointer; list-style: none; padding: 10px 0 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--accent);
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
summary::-webkit-details-marker { display: none; }
summary .hint { text-transform: none; letter-spacing: 0; font-weight: 400; }
.hint { font-size: 11px; color: var(--muted); }
.sec { padding: 2px 0 4px; }

.ctl { display: grid; grid-template-columns: 1fr auto; column-gap: 8px; align-items: baseline; margin: 7px 0 2px; }
.ctl span { color: var(--muted); font-size: 12.5px; }
.ctl output { font: 12.5px var(--mono); color: var(--text); }
.ctl input { grid-column: 1 / -1; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0; color: var(--muted); font-size: 12.5px; }
.row select { max-width: 60%; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--muted); margin: 8px 0; cursor: pointer; }
.check input { accent-color: var(--accent); margin-top: 2px; }
.note { font-size: 11.5px; color: var(--muted); margin: 6px 0 0; }
.plot-s11 { position: relative; height: 120px; margin-top: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }

/* ---------- Beams ---------- */
.beam {
  border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 8px;
  background: var(--panel); padding: 6px 10px 8px; margin-bottom: 8px; cursor: pointer;
}
.beam.sel { background: var(--panel-2); border-color: var(--c); box-shadow: 0 0 0 1px var(--c) inset; }
.beam-h { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 600; }
.beam-h i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 7px; }
.beam-h button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0 2px; }
.beam-h button:hover { color: #f87171; }
.beam .ctl { margin-top: 3px; }
.beam input[type=range]::-webkit-slider-thumb { background: var(--c); }
.beam input[type=range]::-moz-range-thumb { background: var(--c); }

/* ---------- Metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; }
.metric .k { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric .v { font: 600 18px/1.3 var(--mono); white-space: nowrap; }
.metric .v small { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.metric .s { font: 11px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.warns { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; min-height: 0; }
.warn { font-size: 12px; color: var(--warn); background: rgba(251, 191, 36, .1); border: 1px solid rgba(251, 191, 36, .35); border-radius: 999px; padding: 3px 11px; }

/* ---------- Panels ---------- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 0; font-size: 13px; font-weight: 600; }
.cv { position: relative; flex: 1; min-height: 0; }
.cv canvas, .plot-s11 canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.p-3d { grid-column: span 5; height: 380px; }
.p-uv { grid-column: span 4; height: 380px; }
.p-arr { grid-column: span 3; height: 380px; }
.p-near { grid-column: span 7; height: 400px; }
.p-cut { grid-column: span 5; height: 400px; }
#cv-3d { cursor: grab; }
#cv-uv, #cv-near { cursor: crosshair; }

.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tools select { padding: 3px 8px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: 12px var(--mono); color: var(--muted); background: var(--panel-2); border: 0; padding: 4px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-dim); color: var(--accent); }
.mini { display: flex; align-items: center; gap: 6px; font: 12px var(--mono); color: var(--muted); }
.mini input { width: 80px; }

.foot { margin-top: 14px; font-size: 12px; color: var(--muted); }
.foot a { color: var(--accent); }

/* ---------- Guide ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(760px, 92vw); max-height: 86vh; }
dialog::backdrop { background: rgba(3, 6, 12, .7); backdrop-filter: blur(3px); }
dialog article { padding: 6px 26px 24px; }
dialog article > header { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--panel); padding: 14px 0 8px; }
dialog h2 { margin: 0; font-size: 18px; }
dialog h3 { margin: 20px 0 8px; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
dialog li, dialog dd { color: #c3cbdc; }
dialog li { margin: 4px 0; }
dialog dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; margin: 0; }
dialog dt { font-weight: 600; }
dialog dd { margin: 0; }

/* ---------- Narrow screens ---------- */
@media (max-width: 1250px) {
  .p-3d, .p-uv { grid-column: span 6; }
  .p-arr { grid-column: span 4; height: 320px; }
  .p-cut { grid-column: span 8; height: 320px; }
  .p-near { grid-column: span 12; order: 3; }
  .p-arr, .p-cut { order: 4; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .top { position: static; }
  .grid > .panel { grid-column: 1 / -1; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog dl { grid-template-columns: 1fr; }
}
