:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel2: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: #374151;
  --accent: #f97316;
  --good: #22c55e;
  --danger: #ef4444;
  --canvas: #f8fafc;
  --selected: #06b6d4;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--text); }
button, select, input { font: inherit; }
button, .import-label { border: 1px solid var(--line); background: var(--panel2); color: var(--text); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
button:hover, .import-label:hover { border-color: var(--accent); }
button.active, .tool.active { background: var(--accent); border-color: var(--accent); color: #111827; font-weight: 700; }
button:disabled { opacity: .45; cursor: not-allowed; }
input[type="file"] { display: none; }
.version { color: var(--accent); font-size: 14px; }
.app-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 14px 18px; background: #020617; border-bottom: 1px solid var(--line); }
.app-header h1 { margin: 0; font-size: 20px; }
.app-header p { margin: 2px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.app-shell { display: grid; grid-template-columns: 305px 1fr; min-height: calc(100vh - 75px); }
.tool-panel { background: var(--panel); padding: 14px; border-right: 1px solid var(--line); overflow: auto; }
.tool-panel section { margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.tool-panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }
.tool-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.button-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 8px 0; }
.tool-panel label { display: grid; gap: 4px; margin: 8px 0; color: var(--text); }
.tool-panel input[type="number"], .tool-panel select { width: 100%; background: #020617; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px; }
.tool-panel input[type="range"] { width: 100%; }
#statusText, #selectedText { margin: 0; color: var(--muted); line-height: 1.4; }
.workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 12px; min-width: 0; }
.pane { min-width: 0; background: #0b1220; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: grid; grid-template-rows: auto 1fr; }
.pane-title { padding: 8px 10px; background: #020617; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; }
#sketchCanvas { width: 100%; height: 100%; min-height: 520px; background: var(--canvas); display: block; cursor: crosshair; touch-action: none; -webkit-user-select: none; user-select: none; }
#sketchCanvas.tool-freedraw { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 18 18'><circle cx='9' cy='9' r='4' fill='%23dc2626' stroke='%23111' stroke-width='1.5'/></svg>") 9 9, crosshair; }
.master-snap { background: #0b1220; padding: 8px; border-radius: 8px; border: 1px solid var(--accent); }
.master-snap input { transform: scale(1.3); margin-right: 6px; }
.mini-btn { font-size: 11px; padding: 2px 8px; margin-left: 4px; border-radius: 4px; }
.pane-title { display: flex; align-items: center; }
.pane-title button { margin-left: auto; }
.iso-legend { background: rgba(15,23,42,0.85); color:#fff; padding:8px 12px; border-radius:8px; font-size:12px; }
.projector .iso-legend { font-size: 16px; }
#isoScene { width: 100%; height: 100%; min-height: 520px; background: linear-gradient(#e0f2fe, #f8fafc 48%, #e2e8f0 49%, #f8fafc); display: block; }
#isoScene [data-kind] { cursor: pointer; }
#isoScene .iso-selected { filter: drop-shadow(0 0 4px #06b6d4) drop-shadow(0 0 8px #06b6d4); }

/* Fullscreen overlay toolbar — visible only when projection-pane is fullscreen */
.projection-pane { position: relative; }
.fs-toolbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; padding: 6px 10px; background: rgba(15,23,42,0.92); border: 1px solid var(--line); border-radius: 10px; z-index: 50; box-shadow: 0 4px 18px rgba(0,0,0,0.4); flex-wrap: wrap; max-width: 96vw; }
.fs-toolbar[hidden] { display: none; }
.fs-toolbar button { padding: 6px 10px; font-size: 13px; }
.fs-toolbar .fs-status { color: var(--muted); font-size: 12px; padding-right: 6px; border-right: 1px solid var(--line); margin-right: 4px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.projection-pane:fullscreen { background: #0b1220; padding: 0; }
.projection-pane:fullscreen .pane-title { display: none; }
.projection-pane:fullscreen #isoScene { width: 100vw; height: 100vh; min-height: 100vh; }
.projector .app-header, .projector .tool-panel, .projector .sketch-pane { display: none; }
.projector .app-shell { display: block; min-height: 100vh; }
.projector .workspace { display: block; padding: 0; min-height: 100vh; }
.projector .projection-pane { border: 0; border-radius: 0; min-height: 100vh; }
.projector .pane-title { display: none; }
.projector #isoScene { min-height: 100vh; }
.projector #isoScene text { user-select: none; }
@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .tool-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace { grid-template-columns: 1fr; }
}

/* Cast / projector routing dialog */
.cast-dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 0; max-width: 640px; width: 92vw; }
.cast-dialog::backdrop { background: rgba(0,0,0,0.55); }
.cast-form { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px 20px; }
.cast-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.cast-header h2 { margin: 0; font-size: 1.05rem; }
.cast-section { display: flex; flex-direction: column; gap: 8px; }
.cast-section h3 { margin: 0; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.cast-hint { margin: 0; font-size: 0.78rem; color: var(--muted); }
.cast-warn { margin: 0; padding: 8px 10px; background: rgba(239,68,68,0.12); color: #fecaca; border: 1px solid rgba(239,68,68,0.4); border-radius: 6px; font-size: 0.78rem; }
.cast-url-row { display: flex; gap: 6px; align-items: center; }
.cast-url-row input { flex: 1; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.cast-devices { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.cast-empty { padding: 12px; color: var(--muted); font-size: 0.85rem; text-align: center; }
.cast-device { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.cast-device:last-child { border-bottom: none; }
.cast-device-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cast-device-info strong { font-size: 0.9rem; }
.cast-device-url { font-family: ui-monospace, monospace; font-size: 0.74rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cast-device-source { font-size: 0.7rem; color: var(--accent); }
.cast-device-actions { display: flex; gap: 4px; flex-shrink: 0; }
.cast-add-row { display: grid; grid-template-columns: 1fr 1.4fr 80px auto; gap: 6px; }
.cast-add-row input { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 0.82rem; }
@media (max-width: 600px) { .cast-add-row { grid-template-columns: 1fr; } }

/* ---------- v1.0: accordion sections ---------- */
.app-title { display: flex; align-items: center; gap: 10px; }
.app-logo { border-radius: 6px; }
.rail-toggle { padding: 4px 8px; font-size: 14px; }
.tool-panel section { padding-bottom: 8px; }
.tool-panel h2 { display: none; } /* legacy h2; superseded by .section-toggle */
.section-toggle { width: 100%; text-align: left; background: transparent; border: none; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; padding: 6px 4px; margin-bottom: 4px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.section-toggle:hover { color: var(--accent); }
.section-toggle .caret { display: inline-block; transition: transform .15s; font-size: 11px; }
.section-toggle[aria-expanded="false"] .caret { transform: rotate(-90deg); }
.section-toggle[aria-expanded="false"] + .section-body { display: none; }
.section-body { padding: 0 2px; }

/* Left rail collapsed mode */
body.shell-rail .app-shell { grid-template-columns: 44px 1fr; }
body.shell-rail .tool-panel { padding: 8px 4px; overflow: hidden; }
body.shell-rail .tool-panel section { border-bottom: 1px solid var(--line); margin-bottom: 6px; padding-bottom: 6px; }
body.shell-rail .section-body { display: none; }
body.shell-rail .section-toggle { font-size: 0; padding: 4px 0; justify-content: center; }
body.shell-rail .section-toggle::before { content: attr(data-target); font-size: 10px; text-transform: uppercase; color: var(--muted); display: inline-block; transform: rotate(-90deg); white-space: nowrap; }
body.shell-rail .section-toggle .caret { display: none; }

/* Pane hide buttons */
.pane-hide-btn { font-size: 14px; padding: 2px 10px; min-width: 28px; }
/* Restore stubs are HIDDEN by default; their CSS [hidden] -> display:none must win.
   Visible-state rules live below in body.hide-* selectors. Do NOT put display: flex
   on the base class — that overrides [hidden] and makes the stubs occupy grid space
   even when no pane is hidden. */
.pane-restore-stub { background: var(--panel); border: 1px dashed var(--accent); border-radius: 10px; align-items: center; justify-content: center; min-height: 0; }
.pane-restore-stub[hidden] { display: none !important; }
.restore-btn { background: var(--accent); color: #111; font-weight: 700; font-size: 14px; padding: 8px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,0.35); }
.restore-btn:hover { background: #fb923c; }
body.hide-sketch .workspace { grid-template-columns: 1fr; }
body.hide-sketch .sketch-pane { display: none; }
body.hide-sketch #sketchRestoreStub { display: flex; position: fixed; left: 16px; top: 50%; transform: translateY(-50%); padding: 0; z-index: 40; border: 0; background: transparent; }
body.hide-iso .workspace { grid-template-columns: 1fr; }
body.hide-iso .projection-pane { display: none; }
body.hide-iso #isoRestoreStub { display: flex; position: fixed; right: 16px; top: 50%; transform: translateY(-50%); padding: 0; z-index: 40; border: 0; background: transparent; }

/* Free Draw 3D controls */
.freedraw3d-controls { background: #0b1220; padding: 8px; border-radius: 8px; border: 1px dashed var(--accent); }
.freedraw3d-controls label { margin: 4px 0; }
#sketchCanvas.tool-freedraw3d { cursor: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'><polygon points='10,2 18,10 10,18 2,10' fill='%23f97316' stroke='%23111' stroke-width='1.5'/></svg>") 10 10, crosshair; }
#sketchCanvas.tool-stamp { cursor: copy; }

/* Stamp panel */
.stamp-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 6px; max-height: 280px; overflow: auto; }
.stamp-thumb { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text); }
.stamp-thumb:hover { border-color: var(--accent); }
.stamp-thumb.active { border-color: var(--accent); background: rgba(249,115,22,0.15); }
.stamp-thumb svg { width: 100%; height: 60px; background: #f8fafc; border-radius: 4px; }
.stamp-thumb-name { font-weight: 600; text-align: center; }
.stamp-thumb-meta { color: var(--muted); font-size: 10px; }
.stamp-filter { display: flex; gap: 8px; font-size: 11px; }
.stamp-filter label { display: inline-flex; align-items: center; gap: 3px; margin: 0; }
.hint { font-size: 11px; color: var(--muted); margin: 4px 0; }

/* Status history */
.status-history { list-style: none; padding: 0; margin: 6px 0 0; font-size: 11px; color: var(--muted); max-height: 90px; overflow: auto; }
.status-history li { padding: 2px 0; border-top: 1px dotted var(--line); }
.status-history li:first-child { border-top: 0; }
.status-history time { color: var(--accent); margin-right: 4px; }

/* Welcome banner */
.welcome-banner { position: fixed; right: 16px; bottom: 16px; z-index: 100; max-width: 360px; pointer-events: auto; }
.welcome-card { background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 14px 16px; box-shadow: 0 12px 32px rgba(0,0,0,0.55); position: relative; }
.welcome-card h2 { margin: 0 0 4px; color: var(--accent); font-size: 15px; }
.welcome-card p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.welcome-close { position: absolute; top: 4px; right: 6px; background: transparent; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px; }
.welcome-close:hover { color: var(--accent); }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.welcome-actions button { font-size: 14px; padding: 10px 14px; }

/* Wizard styles */
.wizard-dialog { max-width: 720px; }
.wizard-steps { display: flex; gap: 12px; flex: 1; justify-content: center; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.wizard-step.active { color: var(--accent); font-weight: 700; }
.env-check-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.env-check-list li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; }
.badge { display: inline-block; min-width: 70px; text-align: center; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-pending { background: #334155; color: #cbd5e1; }
.badge-yes { background: #16a34a; color: #fff; }
.badge-no { background: #dc2626; color: #fff; }
.badge-warn { background: #f59e0b; color: #111; }
.wizard-targets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.wizard-target { display: flex; flex-direction: column; align-items: flex-start; padding: 12px; text-align: left; gap: 4px; min-height: 70px; }
.wizard-target strong { font-size: 14px; }
.wizard-target small { color: var(--muted); font-size: 11px; }
.wizard-target:not(:disabled):hover { border-color: var(--accent); background: rgba(249,115,22,0.08); }
.qr-panel, .remote-panel { background: var(--panel2); padding: 10px; border-radius: 8px; border: 1px solid var(--line); }
.qr-code { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 4px; }
.qr-code svg { display: block; }

/* High-contrast projector preset */
body.hc-projector { --canvas: #ffffff; }
body.hc-projector #isoScene { background: #ffffff; }
body.hc-projector #isoScene polygon { stroke-width: 3 !important; }
body.hc-projector #isoScene path { stroke-width: 5 !important; }
body.hc-projector #isoScene text { font-weight: 900 !important; }
body.hc-projector .iso-legend { font-size: 18px; }

/* Free Draw 3D height cue on 2D sketch */
.fd3d-marker { pointer-events: none; }

/* ---------- v1.0.3: Accessibility + workflow polish ---------- */
/* Tool button keybind chips */
.tool { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tool .tool-name { flex: 1; text-align: left; }
.tool .tool-key { background: rgba(255,255,255,0.08); border: 1px solid var(--line); color: var(--muted); font-size: 10px; padding: 1px 5px; border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; min-width: 14px; text-align: center; }
.tool.active .tool-key { background: rgba(0,0,0,0.18); border-color: rgba(0,0,0,0.35); color: #111; }

/* Slider live value readout (only on labels that contain a .slider-val) */
.tool-panel label:has(.slider-val) { grid-template-columns: 1fr auto; align-items: center; }
.tool-panel label:has(.slider-val) input[type="range"] { grid-column: 1 / -1; }
.slider-val { color: var(--accent); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; padding-left: 6px; }

/* Visible focus ring for keyboard navigation */
button:focus-visible, .import-label:focus-visible, input:focus-visible, select:focus-visible, .restore-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Make the in-pane restore "rail" feel like a tab when a pane is hidden */
body.hide-sketch #sketchRestoreStub .restore-btn,
body.hide-iso #isoRestoreStub .restore-btn {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 14px 8px;
  font-size: 13px;
  letter-spacing: 0.04em;
}
body.hide-sketch #sketchRestoreStub .restore-btn { transform: rotate(180deg); }

