:root{
  --bg:#EDEBE3;
  --surface:#FFFFFF;
  --surface-2:#F6F4EC;
  --ink:#22241E;
  --ink-soft:#6B6D60;
  --ink-faint:#9A9C8C;
  --accent:#1F4E5F;
  --accent-ink:#0E2E38;
  --accent-soft:#D9E6E4;
  --line:#D8D3C4;
  --line-strong:#B9B3A0;
  --warn:#B96A22;
  --warn-soft:#F0DEC8;
  --shadow: 0 1px 2px rgba(34,36,30,.06), 0 6px 20px rgba(34,36,30,.07);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#14181A; --surface:#1B2124; --surface-2:#20272A;
    --ink:#E8E6DD; --ink-soft:#9CA096; --ink-faint:#656b62;
    --accent:#79C1CC; --accent-ink:#DCF3F5; --accent-soft:#213B3D;
    --line:#2C3336; --line-strong:#3C4448;
    --warn:#E3944F; --warn-soft:#3A2A1B;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"]{
    --bg:#14181A; --surface:#1B2124; --surface-2:#20272A;
    --ink:#E8E6DD; --ink-soft:#9CA096; --ink-faint:#656b62;
    --accent:#79C1CC; --accent-ink:#DCF3F5; --accent-soft:#213B3D;
    --line:#2C3336; --line-strong:#3C4448;
    --warn:#E3944F; --warn-soft:#3A2A1B;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

*{box-sizing:border-box;}
html,body{ height:100%; }
body{
  margin:0;
  background:var(--bg);
  color:var(--ink);
  font-family:'IBM Plex Sans',system-ui,sans-serif;
  font-size:14px;
  line-height:1.45;
}
h1,h2,h3{ font-family:'Archivo',system-ui,sans-serif; text-wrap:balance; margin:0; }
.mono{ font-family:'IBM Plex Mono',ui-monospace,monospace; font-variant-numeric:tabular-nums; }
.caption{
  font-family:'IBM Plex Mono',ui-monospace,monospace;
  font-size:10.5px; letter-spacing:.09em; text-transform:uppercase; color:var(--ink-faint);
}

.app{ display:grid; grid-template-columns:340px 1fr; gap:1px; background:var(--line); min-height:100vh; }
@media (max-width:860px){
  .app{ grid-template-columns:1fr; grid-template-rows:auto auto; }
  .stage{ order:-1; height:min(62vh,480px); min-height:340px; }
  .panel{ max-height:none; padding:18px 16px 28px; }
}

.panel{ background:var(--bg); padding:22px 20px 26px; display:flex; flex-direction:column; gap:18px; overflow-y:auto; }
.brand{ display:flex; flex-direction:column; gap:3px; padding-bottom:14px; border-bottom:2px solid var(--ink); }
.brand .kicker{ color:var(--accent); font-size:10.5px; letter-spacing:.14em; }
.brand h1{ font-size:21px; font-weight:800; letter-spacing:-.01em; }
.brand p{ margin:2px 0 0; font-size:12px; color:var(--ink-soft); }

.field{ display:flex; flex-direction:column; gap:6px; }
.field-head{ display:flex; align-items:center; justify-content:space-between; gap:8px; }
.field-row{ display:flex; gap:12px; }
.field-row > .field{ flex:1; min-width:0; }
label.caption{ display:block; }

.link-btn{
  all:unset; cursor:pointer;
  font-family:'IBM Plex Mono',monospace; font-size:10.5px; letter-spacing:.06em; text-transform:uppercase;
  color:var(--accent); padding:2px 4px;
}
.link-btn:hover{ text-decoration:underline; }

.unit-toggle{
  display:flex; background:var(--surface); border:1px solid var(--line-strong); border-radius:100px; padding:2px; gap:2px;
}
.unit-toggle button{
  all:unset; cursor:pointer; font-family:'IBM Plex Mono',monospace; font-size:10.5px;
  padding:4px 10px; border-radius:100px; color:var(--ink-soft);
}
.unit-toggle button.active{ background:var(--accent); color:var(--surface); }

.stepper{ display:flex; align-items:stretch; background:var(--surface); border:1px solid var(--line-strong); border-radius:7px; overflow:hidden; }
.stepper button{
  all:unset; cursor:pointer; width:38px; min-height:40px; display:flex; align-items:center; justify-content:center;
  color:var(--ink-soft); font-size:16px; font-family:'IBM Plex Mono',monospace;
}
.stepper button:hover{ background:var(--surface-2); color:var(--ink); }
.stepper input{
  all:unset; flex:1; min-width:0; text-align:center; font-family:'IBM Plex Mono',monospace; font-weight:500;
  font-size:15px; color:var(--ink); padding:9px 2px; border-left:1px solid var(--line); border-right:1px solid var(--line);
}
.stepper .unit{ display:flex; align-items:center; padding-right:9px; padding-left:2px; color:var(--ink-faint); font-family:'IBM Plex Mono',monospace; font-size:12px; }

.presets{ display:flex; flex-wrap:wrap; gap:6px; }
.chip{
  all:unset; cursor:pointer; font-family:'IBM Plex Mono',monospace; font-size:11.5px; padding:7px 11px; min-height:34px;
  display:inline-flex; align-items:center; border:1px solid var(--line-strong); border-radius:100px; color:var(--ink-soft);
}
.chip:hover{ border-color:var(--accent); color:var(--accent); }

select.select{
  all:unset; background:var(--surface); border:1px solid var(--line-strong); border-radius:7px; padding:10px 10px;
  min-height:40px; font-family:'IBM Plex Sans',sans-serif; font-size:14px; color:var(--ink); width:100%;
}

.facing-row{ display:flex; align-items:center; gap:12px; }
.compass{ flex:none; width:44px; height:44px; border-radius:50%; border:1.5px solid var(--line-strong); background:var(--surface); position:relative; }
.compass .n{ position:absolute; top:2px; left:50%; transform:translateX(-50%); font-size:8px; font-family:'IBM Plex Mono',monospace; color:var(--ink-faint); font-weight:600; }
.compass .needle{
  position:absolute; left:50%; top:50%; width:2px; height:16px; background:var(--accent);
  transform-origin:50% 100%; transform:translate(-50%,-100%) rotate(0deg); border-radius:2px; transition:transform .35s ease;
}

.segmented{ display:flex; flex-direction:column; gap:6px; }
.segmented button{
  all:unset; cursor:pointer; display:flex; justify-content:space-between; align-items:baseline; padding:12px 11px;
  min-height:40px; border:1px solid var(--line-strong); border-radius:7px; font-size:12.5px; color:var(--ink-soft);
}
.segmented button span.f{ font-family:'IBM Plex Mono',monospace; font-size:10.5px; color:var(--ink-faint); }
.segmented button.active{ border-color:var(--accent); background:var(--accent-soft); color:var(--accent-ink); }
.segmented button.active span.f{ color:var(--accent-ink); opacity:.7; }

.note{ font-size:11.5px; color:var(--ink-soft); background:var(--surface-2); border:1px dashed var(--line-strong); border-radius:7px; padding:8px 10px; }
.note.warn{ color:var(--warn); border-color:var(--warn); background:var(--warn-soft); }

hr.rule{ border:none; border-top:1px solid var(--line); margin:0; }

.sizing-panel{ display:flex; flex-direction:column; gap:14px; }
.size-row{ display:flex; flex-direction:column; gap:5px; }
.size-row .lbl{ display:flex; justify-content:space-between; font-size:11.5px; color:var(--ink-soft); }
.size-row .lbl b{ color:var(--ink); font-weight:600; }
.size-row input[type="range"]{
  -webkit-appearance:none; appearance:none; width:100%; height:30px; background:transparent; cursor:pointer; margin:0;
}
.size-row input[type="range"]::-webkit-slider-runnable-track{ height:5px; border-radius:100px; background:var(--line-strong); }
.size-row input[type="range"]::-moz-range-track{ height:5px; border-radius:100px; background:var(--line-strong); }
.size-row input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none; width:20px; height:20px; margin-top:-7.5px; border-radius:50%;
  background:var(--accent); border:2px solid var(--surface); box-shadow:var(--shadow);
}
.size-row input[type="range"]::-moz-range-thumb{
  width:20px; height:20px; border-radius:50%; background:var(--accent); border:2px solid var(--surface); box-shadow:var(--shadow);
}

.stats{ display:grid; grid-template-columns:1fr 1fr; gap:1px; background:var(--line); border:1px solid var(--line); border-radius:8px; overflow:hidden; }
.stat{ background:var(--surface); padding:10px 12px; display:flex; flex-direction:column; gap:3px; }
.stat .v{ font-family:'IBM Plex Mono',monospace; font-weight:600; font-size:16px; color:var(--ink); }
.stat .v .u{ font-size:10.5px; color:var(--ink-faint); font-weight:400; margin-left:3px; }

.legend{ display:flex; flex-direction:column; gap:7px; }
.legend-row{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--ink-soft); }
.swatch{ width:11px; height:11px; border-radius:3px; flex:none; border:1px solid rgba(0,0,0,.15); }

.stage{ position:relative; background:var(--surface); min-height:420px; }
#scene{ display:block; width:100%; height:100%; touch-action:none; cursor:grab; }
#scene:active{ cursor:grabbing; }

.stage-ui{ position:absolute; inset:0; pointer-events:none; }
.stage-ui > *{ pointer-events:auto; }

.scene-caption{
  position:absolute; top:16px; left:16px; background:var(--surface); border:1px solid var(--line-strong); border-radius:9px;
  box-shadow:var(--shadow); padding:9px 14px; display:flex; flex-direction:column; gap:2px; max-width:min(78vw,320px);
}
.scene-caption .t{ font-family:'Archivo',sans-serif; font-weight:800; font-size:13.5px; color:var(--ink); letter-spacing:.01em; }
.scene-caption .s{ font-family:'IBM Plex Mono',monospace; font-size:10.5px; color:var(--ink-soft); }

.view-toggle{
  position:absolute; top:16px; right:16px; display:flex; background:var(--surface); border:1px solid var(--line-strong);
  border-radius:100px; padding:3px; box-shadow:var(--shadow); gap:2px;
}
.view-toggle button{
  all:unset; cursor:pointer; font-family:'IBM Plex Mono',monospace; font-size:11px; letter-spacing:.04em;
  padding:10px 14px; border-radius:100px; color:var(--ink-soft);
}
.view-toggle button.active{ background:var(--accent); color:var(--surface); }

.zoomctl{
  position:absolute; top:70px; right:16px; display:flex; flex-direction:column; background:var(--surface);
  border:1px solid var(--line-strong); border-radius:9px; box-shadow:var(--shadow); overflow:hidden;
}
.zoomctl button{ all:unset; cursor:pointer; width:42px; height:40px; text-align:center; font-size:17px; color:var(--ink-soft); font-family:'IBM Plex Mono',monospace; }
.zoomctl button:first-child{ border-bottom:1px solid var(--line); }
.zoomctl button:hover{ color:var(--ink); background:var(--surface-2); }

.hint{
  position:absolute; bottom:16px; left:16px; font-family:'IBM Plex Mono',monospace; font-size:10.5px; color:var(--ink-faint);
  background:var(--surface); border:1px solid var(--line); border-radius:100px; padding:6px 12px; box-shadow:var(--shadow);
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; width:max-content; max-width:calc(100% - 226px);
}
@media (max-width:520px){ .hint{ display:none; } }

.stamp{
  position:absolute; bottom:16px; right:16px; font-family:'IBM Plex Mono',monospace; font-size:10px; letter-spacing:.08em;
  color:var(--warn); border:1.5px dashed var(--warn); border-radius:5px; padding:6px 10px; transform:rotate(-2.5deg);
  background:color-mix(in srgb, var(--warn-soft) 85%, transparent); max-width:180px; text-align:center; line-height:1.4;
}

@media (prefers-reduced-motion: reduce){ .compass .needle{ transition:none; } }
