:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f7f8fa; --line: #dfe2e7; --text: #1f2328; --muted: #6b7380;
  --accent: #d9822b; --accent2: #b8691c; --accentSoft: #fbeedd; --danger: #d64545; --ok: #2f9e63;
  --drawer: #e9e4da; --drawerLine: #a79f90; --input: #fff;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16191d; --panel: #1f2328; --panel2: #262b31; --line: #343a42; --text: #e6e8eb; --muted: #959ca7;
  --accent: #e8953a; --accent2: #f0a85a; --accentSoft: #3a2c1c; --danger: #ef6464; --ok: #49c184;
  --drawer: #2c2a26; --drawerLine: #6d665b; --input: #16191d;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191d; --panel: #1f2328; --panel2: #262b31; --line: #343a42; --text: #e6e8eb; --muted: #959ca7;
    --accent: #e8953a; --accent2: #f0a85a; --accentSoft: #3a2c1c; --danger: #ef6464; --ok: #49c184;
    --drawer: #2c2a26; --drawerLine: #6d665b; --input: #16191d;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
/* The page sits inside the site's header, sidebar menu and footer
   (w3style.css), so every element rule here is scoped to the app (.sf-app),
   and the app fills the window below the site's 43px header. */
/* the site caps body and its header at 1600px wide; this page may use the whole window */
body.sf-page, body.sf-page nav.w3-top { max-width: none; }
.sf-app, .sf-app * { box-sizing: border-box; }
.sf-app { display: flex; flex-direction: column; height: calc(100vh - 43px); min-height: 520px;
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.sf-app button, .sf-app select, .sf-app input { font: inherit; color: inherit; margin: 0; }
.sf-app button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.sf-app button:hover:not(:disabled) { border-color: var(--accent); }
.sf-app button:disabled { opacity: .45; cursor: default; }
.sf-app button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.sf-app button.primary:hover { background: var(--accent2); }
.sf-app button.danger { color: var(--danger); }
.sf-app input[type=number], .sf-app input[type=text], .sf-app select { background: var(--input); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; width: 100%; min-width: 0; }
.sf-app input:focus, .sf-app select:focus { outline: 2px solid var(--accentSoft); border-color: var(--accent); }
.sf-app input[type=checkbox] { accent-color: var(--accent); }
/* the site's dark mode restyles every input and select; keep the app's own */
body.dark-mode .sf-app input[type=number], body.dark-mode .sf-app input[type=text], body.dark-mode .sf-app select {
  background-color: var(--input); color: var(--text); border-color: var(--line) !important; }

.topbar { height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 20px; height: 20px; border-radius: 5px; background:
  linear-gradient(var(--accent),var(--accent)) 0 0/9px 9px no-repeat,
  linear-gradient(var(--accent),var(--accent)) 11px 0/9px 20px no-repeat,
  linear-gradient(var(--accent2),var(--accent2)) 0 11px/9px 9px no-repeat; }
.modes { display: flex; gap: 2px; background: var(--panel2); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.modes button { border: none; background: transparent; padding: 4px 12px; }
.modes button.active { background: var(--panel); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.tb-group { display: flex; gap: 6px; align-items: center; }
.tb-group select { width: auto; }

#app { display: flex; flex: 1; min-height: 0; }
.side { width: 290px; flex: none; background: var(--panel); overflow-y: auto; padding: 10px 12px 40px; }
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); width: 310px; }
.stage { flex: 1; position: relative; min-width: 0; }
.view { position: absolute; inset: 0; }
.hidden { display: none !important; }
#svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: default; }
#threeHost { position: absolute; inset: 0; }

.sf-app h3 { font-family: inherit; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; display: flex; align-items: center; gap: 6px; }
.sf-app h3:first-child { margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.row3 { grid-template-columns: 1fr 1fr 1fr; }
.fld { display: flex; flex-direction: column; gap: 2px; }
.fld > span { font-size: 11px; color: var(--muted); }
.fld.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.fld.inline > span { font-size: 12.5px; color: var(--text); }
.fld.inline input[type=number], .fld.inline select { width: 108px; flex: none; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.btns button { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.note { font-size: 11.5px; color: var(--muted); margin: 4px 0 8px; }
.warn { color: var(--danger); font-size: 12px; }
.okc { color: var(--ok); }

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.presets button { text-align: left; padding: 6px 8px; font-size: 12px; line-height: 1.25; }
.presets button small { display: block; color: var(--muted); font-size: 10.5px; }

.traylist { display: flex; flex-direction: column; gap: 2px; }
.traylist .item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.traylist .item:hover { background: var(--panel2); }
.traylist .item.sel { background: var(--accentSoft); border-color: var(--accent); }
.traylist .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.traylist .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.traylist .dm { color: var(--muted); font-size: 11px; white-space: nowrap; }
.badge { font-size: 10px; padding: 1px 5px; border-radius: 8px; background: var(--danger); color: #fff; }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12px; }
.stats b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

details.grp { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
details.grp > summary { cursor: pointer; padding: 8px 10px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.grp > summary::after { content: '▸'; color: var(--muted); transition: transform .15s; }
details.grp[open] > summary::after { transform: rotate(90deg); }
details.grp > .body { padding: 2px 10px 10px; display: flex; flex-direction: column; gap: 6px; }

.hud { position: absolute; left: 10px; bottom: 10px; background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; pointer-events: none; box-shadow: var(--shadow); max-width: calc(100% - 20px); }
.hud:empty { display: none; }
.zoombar { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoombar button { width: 32px; height: 32px; padding: 0; background: var(--panel); box-shadow: var(--shadow); font-size: 16px; }
.viewbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; box-shadow: var(--shadow); white-space: nowrap; }
.viewbar button { padding: 3px 8px; font-size: 12px; }
.viewbar label { display: flex; align-items: center; gap: 4px; font-size: 12px; margin-left: 6px; }
.viewbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }

.profile-wrap { display: flex; gap: 8px; align-items: flex-start; }
.profile-wrap svg { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; }
.profile-wrap .cap { font-size: 10.5px; color: var(--muted); text-align: center; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; font-size: 12.5px; }
.toast.show { opacity: 1; transform: translateX(-50%); }

.sf-app kbd { font: 10.5px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel2); }
.help { font-size: 11.5px; color: var(--muted); line-height: 1.7; }

/* SVG */
.drawer-bg { fill: var(--drawer); stroke: var(--drawerLine); }
.ref-grid { stroke: var(--drawerLine); opacity: .18; }
.tray-outline { stroke: rgba(0,0,0,.45); cursor: move; }
:root[data-theme="dark"] .tray-outline { stroke: rgba(255,255,255,.35); }
.tray-inner { fill: none; stroke: rgba(0,0,0,.35); stroke-dasharray: 3 2; pointer-events: none; }
.tray-holes { fill: rgba(0,0,0,.28); pointer-events: none; }
.tray-div { stroke: rgba(0,0,0,.5); pointer-events: none; }
.tray-label { font-weight: 600; fill: #1f2328; pointer-events: none; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: rgba(255,255,255,.7); stroke-width: 3px; stroke-linejoin: round; }
.tray-dims { fill: #3a3f46; pointer-events: none; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: rgba(255,255,255,.7); stroke-width: 3px; }
.sel-halo { fill: none; stroke: var(--accent); pointer-events: none; }
.sel-edge { fill: none; stroke: var(--accent2); pointer-events: none; }
.tray.bad .tray-outline { stroke: var(--danger); stroke-dasharray: 6 3; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5px; }
.handle.vtx { fill: var(--accent); stroke: #fff; cursor: grab; }
.handle.vtx.sel { fill: #fff; stroke: var(--danger); stroke-width: 2.5px; }
.handle.mid { fill: #fff; stroke: var(--accent); opacity: .85; cursor: copy; }
.guide { stroke: #1e88e5; stroke-width: 1px; stroke-dasharray: 4 3; pointer-events: none; }
.dim-line { stroke: #1e88e5; stroke-width: 1px; pointer-events: none; }
.dim-text { fill: #1565c0; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: var(--drawer); stroke-width: 3px; }
.drawer-dim { fill: var(--muted); text-anchor: middle; dominant-baseline: middle; }
.ruler-tick { stroke: var(--muted); }
.ruler-text { fill: var(--muted); text-anchor: middle; dominant-baseline: middle; }

@media (max-width: 900px) {
  #app { flex-direction: column; height: auto; }
  .side, .side.right { width: 100%; max-height: none; }
  .stage { height: 70vh; flex: none; }
  .topbar { overflow-x: auto; }
  .brand { display: none; }
}
.handle.notch { fill: var(--accent); stroke: #fff; }
