:root {
  --bg: #111317; --panel: #181b20; --panel2: #1f232a; --line: #2c323b; --text: #e7eaef; --muted: #9aa3b0;
  --accent: #ff5707; --accent2: #ff7a3d; --warn: #ffb547;
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }

.bar { display: flex; align-items: center; gap: 8px; height: 48px; padding: 0 10px; background: var(--panel);
       border-bottom: 1px solid var(--line); white-space: nowrap; }
.bar h1 { margin: 0 8px 0 4px; font-size: 16px; font-weight: 600; letter-spacing: .02em; }
.bar .spacer { flex: 1; }
.preset { display: flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; flex: 0 1 330px; }
.preset select { flex: 1 1 auto; width: 100%; min-width: 110px; }
.bar > * { flex-shrink: 0; }
.bar > .preset { flex-shrink: 1; }
.legal { display: flex; gap: 12px; margin-right: 6px; font-size: 12.5px; }
.legal a, .legal-dlg a { color: var(--muted); text-decoration: none; }
.legal a:hover, .legal-dlg a:hover { color: var(--accent2); text-decoration: underline; }
.legal-dlg { margin-right: auto; align-self: center; font-size: 12.5px; color: var(--muted); }
.preset select { max-width: 280px; }
.btn { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border: 1px solid #383e48; border-radius: 6px;
       background: var(--panel2); color: var(--text); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: #4a525e; background: #252a32; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent2); }
.btn.on { border-color: var(--accent); color: var(--accent2); }
select, input[type=number], input[type=text] { background: var(--bg); border: 1px solid #383e48; border-radius: 5px; padding: 4px 6px; }

main { position: relative; display: flex; height: calc(100% - 48px); }
#view { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #000; touch-action: none; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; }
#gl { cursor: grab; }
#gl.dragging { cursor: grabbing; }

#hud { position: absolute; left: 10px; top: 10px; max-width: min(460px, 70%); padding: 8px 10px; border-radius: 6px;
       background: rgba(10, 12, 15, .62); font-size: 12px; line-height: 1.45; pointer-events: none;
       font-variant-numeric: tabular-nums; backdrop-filter: blur(2px); }
#hud b { color: #fff; font-weight: 600; }
#hud .w { color: var(--warn); }
#hud .m { color: var(--muted); }
#status { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: var(--muted); pointer-events: none;
          text-shadow: 0 1px 2px #000; font-variant-numeric: tabular-nums; }
#legend { position: absolute; right: 10px; bottom: 8px; padding: 6px 10px; border-radius: 6px; font-size: 12px;
          background: rgba(10, 12, 15, .7); pointer-events: none; }
#legend .sw { display: inline-block; width: 12px; height: 12px; margin: 0 4px -2px 8px; border-radius: 2px; }
#legend .grad { display: inline-block; width: 160px; height: 10px; margin: 0 6px; vertical-align: middle; border-radius: 2px; }
#msg { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); max-width: 80%; padding: 8px 14px;
       border-radius: 6px; background: rgba(24, 27, 32, .92); border: 1px solid var(--line); font-size: 13px; }
#error { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--bg); }
#error div { max-width: 560px; }

#panel { width: 350px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding-bottom: 20px; }
#panel.hidden { display: none; }
.sec { border-bottom: 1px solid var(--line); }
.sec > h2 { display: flex; align-items: center; justify-content: space-between; margin: 0; padding: 10px 12px; font-size: 13px;
            font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #cfd5de; cursor: pointer; user-select: none; }
.sec > h2::after { content: "▾"; color: var(--muted); }
.sec.closed > h2::after { content: "▸"; }
.sec.closed > .body { display: none; }
.sec > .body { padding: 2px 12px 12px; }
.f { display: grid; grid-template-columns: 112px 1fr 68px; align-items: center; gap: 6px; margin: 5px 0; }
.f > label { color: var(--muted); font-size: 12.5px; }
.f.wide { grid-template-columns: 112px 1fr; }
.f input[type=range] { width: 100%; accent-color: var(--accent); }
.f input[type=number] { width: 100%; padding: 2px 4px; font-size: 12.5px; }
.f select { width: 100%; }
.f.check { grid-template-columns: 1fr; }
.f.check label { color: var(--text); display: flex; gap: 8px; align-items: center; cursor: pointer; }
.f input[type=color] { width: 100%; height: 26px; padding: 0 2px; border: 1px solid #383e48; border-radius: 5px; background: var(--bg); }
.f .vec { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; grid-column: 2 / 4; }
.note { margin: 6px 0; font-size: 12px; color: var(--muted); }
.note.w { color: var(--warn); }
.info { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.info td { padding: 2px 0; border-bottom: 1px solid #22272e; }
.info td:last-child { text-align: right; color: #fff; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.obj { margin: 8px 0; border: 1px solid var(--line); border-radius: 6px; background: var(--panel2); }
.obj > .hd { display: flex; align-items: center; gap: 6px; padding: 6px 8px; cursor: pointer; }
.obj > .hd b { flex: 1; font-weight: 600; }
.obj > .hd .x { padding: 0 6px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; }
.obj > .hd .x:hover { color: var(--accent2); }
.obj > .bd { padding: 0 8px 8px; }
.obj.closed > .bd { display: none; }
.panel-foot { padding: 12px; font-size: 12px; color: var(--muted); }
.panel-foot a { color: var(--accent2); }

dialog { padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--text); max-width: min(560px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dlg { padding: 16px 18px; }
.dlg.wide { max-width: 760px; }
dialog:has(.wide) { max-width: min(780px, 94vw); }
.dlg h2 { margin: 0 0 8px; font-size: 18px; }
.dlg h3 { margin: 14px 0 4px; font-size: 14px; color: var(--accent2); }
.dlg p, .dlg li { color: #cfd5de; }
.muted { color: var(--muted); font-size: 12.5px; }
.help { max-height: 64vh; overflow-y: auto; padding-right: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.grid2 label { display: grid; gap: 4px; color: var(--muted); font-size: 12.5px; }
.progress { position: relative; height: 22px; margin-top: 14px; border-radius: 5px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.progress div { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); }
.progress span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 20px; }

@media (max-width: 860px) {
  .bar h1, .preset span, #snapBtn, .legal { display: none; }
  .bar { gap: 5px; padding: 0 6px; }
  .btn { padding: 5px 8px; }
  .preset select { max-width: 150px; }
  #panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(350px, 100%); z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.5); }
  #hud { font-size: 11px; max-width: 75%; }
}
