/* Layout: full-bleed 3D canvas; a drafting title-block panel floats top-left; north arrow bottom-right */
:root{
  --bg:#dfe4e2;
  --panel:rgba(248,249,247,.94);
  --ink:#1b2126;
  --muted:#5b656c;
  --rule:#c3cbc8;
  --accent:#1d4f91;          /* plan-set blueprint blue */
  --accent-ink:#ffffff;
  --shadow:0 6px 24px rgba(20,30,40,.18);
  --display:"Barlow Semi Condensed","Arial Narrow",system-ui,sans-serif;
  --mono:"IBM Plex Mono",ui-monospace,Menlo,Consolas,monospace;
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#1a1f23; --panel:rgba(26,31,36,.92); --ink:#e7ecef; --muted:#9aa6ae; --rule:#39434b;
    --accent:#7fb0ee; --accent-ink:#0c1620; --shadow:0 6px 24px rgba(0,0,0,.45); color-scheme:dark;
  }
}
:root[data-theme="dark"]{
  --bg:#1a1f23; --panel:rgba(26,31,36,.92); --ink:#e7ecef; --muted:#9aa6ae; --rule:#39434b;
  --accent:#7fb0ee; --accent-ink:#0c1620; --shadow:0 6px 24px rgba(0,0,0,.45); color-scheme:dark;
}
[hidden]{display:none!important}
html,body{height:100%}
body{background:var(--bg);color:var(--ink);margin:0;overflow:hidden;font-family:var(--display)}
#stage{position:fixed;inset:0}
#stage canvas{display:block;width:100%;height:100%;touch-action:none}

.panel{
  position:absolute;top:calc(14px + env(safe-area-inset-top,0px));left:16px;
  width:min(292px,calc(100% - 32px));
  background:var(--panel);border:1px solid var(--rule);border-radius:6px;box-shadow:var(--shadow);
  backdrop-filter:blur(6px);-webkit-backdrop-filter:blur(6px);
  display:flex;flex-direction:column;
}
.tb{display:grid;grid-template-columns:1fr auto;align-items:end;gap:4px 10px;padding:12px 14px 10px;border-bottom:1px solid var(--rule)}
.tb .sheet{font-family:var(--mono);font-size:11px;letter-spacing:.06em;color:var(--accent);grid-column:1/-1}
.tb h1{margin:0;font-size:24px;line-height:1.05;font-weight:700;letter-spacing:.01em;text-wrap:balance}
.tb .toggle{appearance:none;border:1px solid var(--rule);background:transparent;color:var(--muted);
  font:500 12px var(--display);letter-spacing:.06em;text-transform:uppercase;border-radius:4px;padding:4px 8px;cursor:pointer}
.tb .toggle:hover{color:var(--ink);border-color:var(--muted)}
.meta{display:grid;grid-template-columns:auto 1fr;gap:2px 10px;padding:8px 14px 10px;border-bottom:1px solid var(--rule);font-size:13px}
.meta dt{font-weight:600;letter-spacing:.08em;text-transform:uppercase;font-size:11px;color:var(--muted);padding-top:2px}
.meta dd{margin:0;font-family:var(--mono);font-size:12px}
.controls{display:flex;flex-direction:column;gap:12px;padding:12px 14px 14px}
.field{display:flex;flex-direction:column;gap:5px}
.field > label,.lbl{font-weight:600;font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--muted)}
.row{display:flex;gap:8px;align-items:center}
select{flex:1;min-width:0;font:500 15px var(--display);color:var(--ink);background:transparent;border:1px solid var(--rule);
  border-radius:4px;padding:6px 8px;cursor:pointer}
button.reset{appearance:none;border:1px solid var(--accent);background:var(--accent);color:var(--accent-ink);
  font:600 13px var(--display);letter-spacing:.06em;text-transform:uppercase;border-radius:4px;padding:7px 10px;cursor:pointer}
select:focus-visible,button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.check{display:flex;gap:8px;align-items:center;font-size:14px;cursor:pointer}
.check input{accent-color:var(--accent);width:16px;height:16px;margin:0}
input[type=range]{width:100%;accent-color:var(--accent)}
.sunval{font-family:var(--mono);font-size:12px;color:var(--ink);font-variant-numeric:tabular-nums}
.spec{border-top:1px solid var(--rule);padding:10px 14px 12px;font-size:13px;color:var(--muted);line-height:1.35}
.spec b{color:var(--ink);font-weight:600}
.panel.collapsed .meta,.panel.collapsed .controls,.panel.collapsed .spec{display:none}

#tip{position:absolute;pointer-events:none;background:var(--panel);color:var(--ink);border:1px solid var(--rule);
  border-radius:4px;padding:6px 9px;box-shadow:var(--shadow);font-size:14px;line-height:1.25;white-space:nowrap;transform:translate(14px,14px)}
#tip .code{font-family:var(--mono);font-size:13px;color:var(--accent);font-weight:500}
#tip .sub{color:var(--muted);font-size:13px}

.hint{position:absolute;left:16px;bottom:calc(14px + env(safe-area-inset-bottom,0px));font-size:13px;color:var(--muted);
  background:var(--panel);border:1px solid var(--rule);border-radius:4px;padding:5px 9px;max-width:calc(100% - 120px)}
.compass{position:absolute;right:16px;bottom:calc(14px + env(safe-area-inset-bottom,0px));width:64px;height:64px;
  background:var(--panel);border:1px solid var(--rule);border-radius:50%;box-shadow:var(--shadow);display:grid;place-items:center}
.compass svg{width:46px;height:46px;transition:transform .08s linear}
.compass .n{fill:var(--accent)} .compass .s{fill:var(--rule)} .compass text{fill:var(--ink);font:700 11px var(--display)}
#err{position:absolute;inset:0;display:grid;place-items:center;padding-inline:16px;text-align:center;color:var(--muted);font-size:16px}
@media (max-width:520px){ .hint{display:none} .tb h1{font-size:21px} }
@media (prefers-reduced-motion:reduce){ .compass svg{transition:none} }
.spec:empty{display:none}

/* ---- 3D | Plan mode ---- */
.modebar{display:flex;gap:0;padding:10px 14px 0}
.modebar button,.seg button{appearance:none;flex:1;border:1px solid var(--rule);background:transparent;color:var(--muted);
  font:600 13px var(--display);letter-spacing:.06em;text-transform:uppercase;padding:6px 8px;cursor:pointer}
.modebar button:first-child,.seg button:first-child{border-radius:4px 0 0 4px}
.modebar button:last-child,.seg button:last-child{border-radius:0 4px 4px 0;border-left:none}
.seg button+button{border-left:none}
.modebar button.on,.seg button.on{background:var(--accent);border-color:var(--accent);color:var(--accent-ink)}
.seg{display:flex}
.planhint{font-size:12px;color:var(--muted);line-height:1.3}
.panel:not(.planmode) .only-plan{display:none}
.panel.planmode .only3d{display:none}
.panel.collapsed .modebar{display:none}

#plan{position:fixed;inset:0;background:#f3f2ec;z-index:0}
.panel,.compass,#tip{z-index:2}
#plansvg{width:100%;height:100%;display:block;cursor:crosshair;touch-action:none}
#planread{position:absolute;right:96px;bottom:calc(14px + env(safe-area-inset-bottom,0px));font:500 13px var(--mono);color:#1b2126;
  background:rgba(255,255,255,.92);border:1px solid #c3cbc8;border-radius:4px;padding:5px 9px;font-variant-numeric:tabular-nums}
#planread:empty{display:none}
#planread span{color:#7a8389;font-family:var(--display);font-size:12px}
#plansvg *{vector-effect:non-scaling-stroke}
#plansvg text{font-family:"Barlow Semi Condensed","Arial Narrow",Arial,sans-serif;text-anchor:middle;dominant-baseline:middle;fill:#1b2126;stroke:none}
#plansvg .floor{fill:#ffffff;stroke:none}
#plansvg .slab{fill:#e9e8e3;stroke:none}
#plansvg .tile{fill:#eef1f3;stroke:none}
#plansvg .deck{fill:#ebe8e0;stroke:#9a958b;stroke-width:1;stroke-dasharray:6 3}
#plansvg .wall{fill:#23272b;stroke:#23272b;stroke-width:.5}
#plansvg .half{fill:#e4e2dc;stroke:#4a4f55;stroke-width:.8}
#plansvg .wall.part{fill:#4a4f55;stroke:#4a4f55}
#plansvg .jamb{stroke:#23272b;stroke-width:1.2}
#plansvg .win{stroke:#23272b;stroke-width:1.2}
#plansvg .glass{stroke:#3b6ea5;stroke-width:.9}
#plansvg .sill{stroke:#23272b;stroke-width:.8}
#plansvg .panel{fill:#fff;stroke:#23272b;stroke-width:1}
#plansvg .overhead{stroke:#23272b;stroke-width:1;stroke-dasharray:8 4}
#plansvg .leaf{stroke:#23272b;stroke-width:1.6}
#plansvg .swing{fill:none;stroke:#23272b;stroke-width:.9}
#plansvg .pocket{stroke:#23272b;stroke-width:1.6;stroke-dasharray:4 3}
#plansvg .cased{stroke:#23272b;stroke-width:.6;stroke-dasharray:2 3}
#plansvg .stair{fill:#fbfaf6;stroke:#23272b;stroke-width:1}
#plansvg .stair-above{fill:none;stroke:#23272b;stroke-width:.8;stroke-dasharray:5 4}
#plansvg .tread-above{stroke:#23272b;stroke-width:.6;stroke-dasharray:4 4}
#plansvg .break{stroke:#23272b;stroke-width:1.2}
#plansvg .tread{stroke:#23272b;stroke-width:.8}
#plansvg .arrow{stroke:#23272b;stroke-width:1.1}
#plansvg .arrowhead{fill:#23272b}
#plansvg .rail{fill:none;stroke:#23272b;stroke-width:2.2}
#plansvg .fix-o{fill:none;stroke:#5b656c;stroke-width:1}
#plansvg .fix-n{fill:none;stroke:none}
#plansvg .fix-dash{fill:none;stroke:#5b656c;stroke-width:1;stroke-dasharray:5 3}
#plansvg .room{font-weight:700;letter-spacing:.03em}
#plansvg .lab-s{fill:#4a545b}
#plansvg .code{fill:#1d4f91;font-family:"IBM Plex Mono",Menlo,monospace}
#plansvg .dim{stroke:#1d4f91;stroke-width:.8}
#plansvg .dim.tick{stroke-width:1.4}
#plansvg .dim-o{stroke-width:1}
#plansvg .dim-t{fill:#1d4f91;font-family:"IBM Plex Mono",Menlo,monospace}
#plansvg .rdim{stroke:#b5651d;stroke-width:.8}
#plansvg .rdim.tick{stroke-width:1.3}
#plansvg .rdim-t{fill:#b5651d;font-family:"IBM Plex Mono",Menlo,monospace}
#plansvg .meas{stroke:#d1242f;stroke-width:1.6}
#plansvg .meas-pt{fill:#d1242f}
#plansvg .meas-t{fill:#d1242f;font-weight:700;font-family:"IBM Plex Mono",Menlo,monospace}
/* a paper-coloured halo keeps text legible where it crosses linework */
#plansvg .room,#plansvg .dim-t,#plansvg .rdim-t,#plansvg .meas-t,#plansvg .code,#plansvg .lab-s{paint-order:stroke;stroke:#fff;stroke-width:3px;stroke-linejoin:round}
#plansvg .meas-t{stroke-width:4px}
#plansvg .door-code{stroke-width:3.5px}
#plansvg .shower-glass{stroke:#3b6ea5;stroke-width:2.4}

/* the panel scrolls when it's taller than the screen (phones, many options) */
.panel{max-height:calc(100dvh - 28px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch}
@media (max-width:520px){ .panel{max-height:calc(100dvh - 110px)} }
.planzoom{position:absolute;right:16px;bottom:calc(92px + env(safe-area-inset-bottom,0px));display:flex;flex-direction:column;gap:6px}
.planzoom button{appearance:none;width:40px;height:40px;border:1px solid #c3cbc8;border-radius:6px;background:rgba(255,255,255,.95);color:#1b2126;
  font:600 18px "Barlow Semi Condensed",system-ui,sans-serif;cursor:pointer;box-shadow:0 2px 8px rgba(20,30,40,.12)}
.planzoom button[data-fit]{font-size:12px;letter-spacing:.06em;text-transform:uppercase}
@media (max-width:520px){ #planread{right:16px;left:16px;bottom:calc(84px + env(safe-area-inset-bottom,0px));font-size:11px} .planzoom{bottom:calc(124px + env(safe-area-inset-bottom,0px))} }

/* build chrome: layer tree */
.layertree ul{list-style:none;margin:0;padding:0}
.layertree ul ul{padding-left:18px}
.layertree li{margin:2px 0}
.layertree label{display:flex;gap:6px;align-items:center;font-size:13.5px;cursor:pointer}
.layertree input{accent-color:var(--accent);width:14px;height:14px;margin:0}
.layertree > ul > li > label{font-weight:600;margin-top:4px}
.layertree .cnt{margin-left:auto;font:500 11px var(--mono);color:var(--muted)}

/* colours */
.colors .sw{display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.swatch{width:24px;height:24px;border-radius:5px;border:1px solid #9aa3a0;cursor:pointer;padding:0}
.swatch.on{outline:2px solid #1d4e89;outline-offset:2px}
.colors input[type=color]{width:30px;height:26px;border:1px solid #c3cbc8;border-radius:5px;padding:0;background:none;cursor:pointer}
.chips{display:flex;flex-wrap:wrap;gap:6px}
.chip{appearance:none;border:1px solid #c3cbc8;border-radius:14px;background:#fff;padding:5px 10px;font:inherit;font-size:12px;cursor:pointer;color:#1b2126}
.chip.on{background:#1d4e89;border-color:#1d4e89;color:#fff}
