:root {
  --navy: #0b132b;
  --ink: #0f172a;
  --muted: #64748b;
  --teal: #2563eb;
  --light: #eff6ff;
  --line: #e2e8f0;
  --bg: #f8fafc;
  font-family: Inter, "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  font-size: 13px;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { height: 100dvh; min-height: 0; overflow: hidden; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font-family: inherit; }
button { transition: color .16s ease, background-color .16s ease, border-color .16s ease, box-shadow .16s ease; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

.topbar {
  height: 64px;
  min-height: 64px;
  padding: 0 20px;
  gap: 16px;
  color: #0f172a;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
}
.brand { gap: 10px; color: #0f172a; font-size: 17px; letter-spacing: -.35px; }
.brand:hover { color: #1d4ed8; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: #2563eb; color: #fff; }
.brand-mark .icon { width: 25px; height: 25px; color: #fff; }
.brand small { margin-top: 2px; color: #64748b; font-size: 10px; letter-spacing: 0; }
.top-note { display: none; }
.top-actions { gap: 5px; }
.top-actions .btn { min-height: 36px; border-radius: 9px; }
.top-ghost { color: #475569; border: 1px solid transparent; }
.top-ghost:hover { color: #1d4ed8; background: #eff6ff; border-color: #dbeafe; }
.topbar .primary { color: #fff; background: #2563eb; border-color: #2563eb; }
.topbar .primary:hover { background: #1d4ed8; border-color: #1d4ed8; }

.app-layout {
  height: calc(100dvh - 64px);
  min-height: 0;
  grid-template-columns: minmax(250px, 280px) minmax(0, 1fr) minmax(240px, 270px);
  gap: 12px;
  padding: 12px;
  background: #f8fafc;
}
.left-panel, .right-panel {
  min-width: 0;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
}
.left-panel { border-right: 1px solid #e2e8f0; }
.right-panel { border-left: 1px solid #e2e8f0; }
.panel-tabs { height: 48px; min-height: 48px; padding: 0 12px; gap: 8px; border-bottom-color: #e2e8f0; }
.panel-tabs > button { border-bottom-width: 2px; border-radius: 8px 8px 0 0; color: #64748b; font-size: 12px; }
.panel-tabs > button.active { color: #1d4ed8; border-bottom-color: #2563eb; }
.panel-content { min-height: 0; }
.intro { padding: 16px 16px 10px; }
.intro .eyebrow { display: none; }
.intro h2 { margin: 0; color: #0f172a; font-size: 19px; font-weight: 700; letter-spacing: -.4px; }
.intro p { margin: 6px 0 0; color: #64748b; font-size: 12px; line-height: 1.55; }
.search { margin: 8px 12px 10px; border: 1px solid #e2e8f0; border-radius: 9px; background: #fff; }
.search:focus-within { border-color: #93c5fd; box-shadow: 0 0 0 3px rgb(37 99 235 / 10%); }
.search .icon { color: #64748b; }
.grade-filter { padding: 0 12px 10px; gap: 5px; }
.grade-filter button { min-height: 29px; padding: 5px 9px; border: 1px solid #e2e8f0; border-radius: 999px; color: #475569; background: #fff; }
.grade-filter button:hover, .grade-filter button.active { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.template-scroll { padding: 0 12px 12px; }
.template-group-title { margin: 12px 0 8px; color: #334155; font-size: 11px; font-weight: 700; letter-spacing: 0; text-transform: none; }
.template-grid { gap: 8px; }
.template-card { overflow: hidden; border: 1px solid #e2e8f0; border-radius: 10px; background: #fff; box-shadow: 0 1px 2px rgb(15 23 42 / 4%); }
.template-card:hover, .template-card.active { border-color: #93c5fd; background: #f8fbff; box-shadow: 0 0 0 2px rgb(37 99 235 / 8%); }
.template-art { background: #f8fafc; }
.template-title { color: #0f172a; font-size: 11px; }
.template-meta { color: #64748b; }
.panel-foot { border-top-color: #e2e8f0; color: #64748b; }
.tiny-tag { color: #64748b; letter-spacing: .3px; }

.tools-scroll { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 6px; padding: 10px 12px; overflow: auto; }
.tools-group-title { grid-column: 1 / -1; margin: 10px 0 2px; color: #475569; font-size: 11px; font-weight: 700; }
.tool-item { min-width: 0; min-height: 48px; padding: 7px; gap: 7px; border: 1px solid #e2e8f0; border-radius: 9px; background: #fff; }
.tool-item .icon { flex: 0 0 17px; color: #64748b; }
.tool-item strong { display: flex; align-items: center; gap: 4px; color: #334155; font-size: 10px; line-height: 1.3; }
.tool-item small { display: none; }
.tool-item kbd, .quick-tools kbd { margin-left: auto; padding: 1px 4px; border: 1px solid #dbeafe; border-radius: 4px; color: #1d4ed8; background: #eff6ff; font-size: 9px; }
.tool-item:hover, .tool-item.active { border-color: #bfdbfe; color: #1d4ed8; background: #eff6ff; }
.panel-foot .text-btn { color: #2563eb; }

.workspace { min-width: 0; gap: 8px; padding: 0; }
.document-bar { height: 50px; min-height: 50px; gap: 8px; }
.document-title input { color: #0f172a; font-size: 16px; font-weight: 700; }
.document-title .eyebrow { color: #64748b; font-size: 9px; letter-spacing: .35px; }
#saveStatus { color: #64748b; font-size: 10px; }
.document-actions { gap: 6px; }
.document-actions .btn, .document-actions .icon-btn { min-height: 34px; border-radius: 8px; }
.btn { border-radius: 8px; }
.btn.primary { color: #fff; background: #2563eb; border-color: #2563eb; }
.btn.primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn.subtle { color: #334155; border-color: #e2e8f0; background: #fff; }
.btn.subtle:hover { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.canvas-card { min-height: 240px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; box-shadow: 0 1px 3px rgb(15 23 42 / 5%); }
.canvas-top { position: relative; top: auto; left: auto; right: auto; margin: 12px 14px 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.canvas-top .view-mode-switch > button,
.canvas-top-actions #multiSelectBtn,
.canvas-top-actions #lockViewBtn,
.canvas-top-actions #examBtn { white-space: nowrap; flex-shrink: 0; }
.canvas-top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; min-width: 0; }
.toolbar-restore { position: absolute; z-index: 31; top: 50%; right: 14px; transform: translateY(-50%); white-space: nowrap; flex-shrink: 0; }
.canvas-badge { color: #64748b; font-size: 9px; letter-spacing: .35px; }
.small-btn { min-height: 31px; border: 1px solid #e2e8f0; border-radius: 8px; color: #475569; background: #fff; }
.small-btn:hover, .small-btn.active { color: #1d4ed8; border-color: #bfdbfe; background: #eff6ff; }
.floating-toolbar { top: 50%; right: 14px; bottom: auto; transform: translateY(-50%); padding: 5px 9px; gap: 4px; border-color: #e2e8f0; border-radius: 999px; background: rgb(255 255 255 / 90%); box-shadow: 0 5px 18px rgb(15 23 42 / 12%); backdrop-filter: blur(12px); }
.tool-btn { border-radius: 999px; color: #475569; }
.tool-btn:hover, .tool-btn.active { color: #1d4ed8; background: #eff6ff; }
.toolbar-handle { border-radius: 999px; color: #64748b; }
.canvas-controls { left: 50%; right: auto; bottom: 12px; width: max-content; max-width: calc(100% - 24px); transform: translateX(-50%); gap: 2px; padding: 4px 8px; border: 1px solid #e2e8f0; border-radius: 999px; background: rgb(255 255 255 / 92%); box-shadow: 0 5px 18px rgb(15 23 42 / 12%); backdrop-filter: blur(12px); }
.canvas-controls > div { border: 0; border-radius: 999px; background: transparent; box-shadow: none; }
.canvas-controls .icon-btn { width: 31px; height: 31px; border-radius: 999px; color: #475569; }
.canvas-controls .icon-btn:hover, .canvas-controls .icon-btn.active { color: #1d4ed8; background: #eff6ff; }
.camera-menu select { max-width: 200px; border-color: #e2e8f0; border-radius: 999px; color: #334155; background: #fff; }
.zoom-controls #zoomValue { color: #475569; }
.canvas-empty { top: 56px; left: 50%; right: auto; bottom: auto; width: min(520px, calc(100% - 32px)); transform: translateX(-50%); padding: 10px 14px; border: 1px solid #e2e8f0; border-radius: 14px; background: rgb(255 255 255 / 92%); color: #64748b; text-align: center; pointer-events: none; }
.canvas-empty .quick-start { pointer-events: auto; }
.canvas-empty .icon { color: #2563eb; }
.canvas-empty h2 { margin: 10px 0 5px; color: #0f172a; font-size: 19px; letter-spacing: -.25px; }
.canvas-empty p { margin: 0 auto; max-width: 420px; color: #64748b; font-size: 12px; }
.quick-start { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; pointer-events: auto; }
.quick-start .btn { min-height: 38px; padding: 8px 12px; border-color: #dbeafe; color: #1d4ed8; background: #fff; }
.quick-start .btn:hover { background: #eff6ff; }
.workplane-row { color: #64748b; }
.workplane-row select { border-color: #e2e8f0; border-radius: 7px; }
.workspace-bottom { color: #64748b; }
.history-controls .icon-btn { border: 1px solid #e2e8f0; border-radius: 8px; }
.tool-hint { color: #64748b; }
.context-bar button { border-radius: 8px; }
.invalid-banner { color: #991b1b; background: #fef2f2; border-color: #fecaca; }

.inspector-actions { display: grid; gap: 7px; padding: 12px; border-bottom: 1px solid #e2e8f0; }
.inspector-actions > .btn { min-height: 38px; }
.inspector-actions > div { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.inspector-actions > div .btn { min-height: 34px; padding: 6px 8px; }
.right-panel .panel-tabs { flex-shrink: 0; }
.inspector-scroll { padding: 10px 12px; }
.inspector-section { border-bottom-color: #e2e8f0; }
.advanced-settings { margin-bottom: 8px; border: 1px solid #e2e8f0; border-radius: 9px; background: #fff; }
.advanced-settings > summary { padding: 10px 11px; color: #334155; font-size: 11px; font-weight: 700; cursor: pointer; }
.advanced-settings[open] > summary { border-bottom: 1px solid #e2e8f0; color: #1d4ed8; }
.advanced-settings .inspector-section { padding: 10px; }
.field-label { color: #475569; }
input, select, textarea { border-color: #cbd5e1; border-radius: 8px; }
.object-intro, .context-section p, .inspector-note { color: #64748b; }
.object-row { border-bottom-color: #e2e8f0; }
.object-row:hover, .object-row.selected { background: #eff6ff; }
.object-row .icon-btn { border-radius: 7px; }
.inspector-foot { border-top-color: #e2e8f0; color: #64748b; }

dialog.app-dialog { border: 1px solid #e2e8f0; border-radius: 16px; color: #0f172a; background: #fff; box-shadow: 0 24px 60px rgb(15 23 42 / 22%); }
dialog.app-dialog::backdrop { background: rgb(15 23 42 / 42%); backdrop-filter: blur(3px); }
.dialog-head { border-bottom-color: #e2e8f0; }
.dialog-head h2 { color: #0f172a; letter-spacing: -.25px; }
.dialog-head .eyebrow { color: #64748b; letter-spacing: .4px; }
.dialog-body { color: #334155; }
.dialog-footer { border-top-color: #e2e8f0; }
.dialog-head .icon-btn, .dialog-footer .btn { border-radius: 8px; }
.ai-geometry-dialog { width: min(620px, calc(100vw - 28px)); max-height: min(88vh, 780px); }
.ai-geometry-dialog form { display: flex; flex-direction: column; min-height: 0; }
.ai-geometry-dialog .dialog-head h2 { margin: 4px 0 0; font-size: 20px; }
.ai-geometry-body { display: grid; gap: 11px; }
.ai-prompt-wrap { position: relative; }
.ai-prompt-wrap textarea { display: block; width: 100%; min-height: 124px; resize: vertical; border: 1px solid #cbd5e1; border-radius: 12px; background: #fff; padding: 12px 54px 42px 13px; color: #0f172a; font: inherit; font-size: 13px; line-height: 1.65; outline: none; }
.ai-prompt-wrap textarea:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgb(79 70 229 / 12%); }
.ai-prompt-wrap textarea::placeholder { color: #94a3b8; }
.ai-mic { position: absolute; right: 9px; bottom: 9px; display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #cbd5e1; border-radius: 50%; background: #fff; color: #475569; cursor: pointer; transition: .18s ease; }
.ai-mic svg { width: 19px; height: 19px; }
.ai-mic:hover { border-color: #6366f1; color: #4338ca; background: #eef2ff; }
.ai-mic.listening { border-color: #ef4444; background: #fef2f2; color: #dc2626; animation: ai-mic-pulse 1.4s ease-out infinite; }
@keyframes ai-mic-pulse { 50% { box-shadow: 0 0 0 6px rgb(239 68 68 / 12%); } }
.ai-geometry-status { min-height: 16px; margin: -7px 1px 0; color: #64748b; font-size: 11px; }
.ai-prompt-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.ai-prompt-chips button { min-height: 30px; padding: 5px 10px; border: 1px solid #e2e8f0; border-radius: 999px; background: #f8fafc; color: #475569; font: inherit; font-size: 11px; cursor: pointer; transition: .18s ease; }
.ai-prompt-chips button:hover { border-color: #c7d2fe; background: #eef2ff; color: #4338ca; }
.ai-merge-option { display: flex; align-items: center; gap: 8px; color: #334155; font-size: 12px; cursor: pointer; }
.ai-merge-option input { width: 15px; height: 15px; accent-color: #4f46e5; }
.ai-spec-link { width: fit-content; border: 0; background: transparent; padding: 0; color: #4f46e5; font: inherit; font-size: 11px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.ai-geometry-footer { align-items: center; gap: 12px; }
.ai-geometry-footer > span { color: #64748b; font-size: 11px; }
.ai-geometry-footer > div { display: flex; gap: 8px; margin-left: auto; }
.ai-geometry-footer #aiGeometrySubmit { display: inline-flex; align-items: center; gap: 7px; }
.ai-geometry-footer #aiGeometrySubmit .icon { width: 16px; height: 16px; }
.ai-geometry-progress { display: grid; gap: 9px; padding: 11px 12px; border: 1px solid #e2e8f0; border-radius: 12px; background: #f8fafc; }
.ai-geometry-progress[hidden] { display: none; }
.ai-progress-heading { display: flex; align-items: center; gap: 8px; color: #334155; font-size: 11px; }
.ai-progress-heading strong { flex: 1; font-weight: 600; }
.ai-progress-heading span { color: #4f46e5; font-variant-numeric: tabular-nums; font-weight: 700; }
.ai-progress-spinner { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.ai-geometry-progress.is-running .ai-progress-spinner { animation: ai-progress-spin .9s linear infinite; }
@keyframes ai-progress-spin { to { transform: rotate(360deg); } }
.ai-progress-track { height: 6px; overflow: hidden; border-radius: 999px; background: #e2e8f0; }
.ai-progress-track > span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg,#4f46e5,#2563eb); transition: width .18s ease-out; }
.ai-progress-steps { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; margin: 0; padding: 0; list-style: none; }
.ai-progress-steps li { color: #94a3b8; font-size: 9px; line-height: 1.3; }
.ai-progress-steps li.active { color: #4338ca; font-weight: 700; }
.ai-progress-steps li.complete { color: #059669; }
.ai-geometry-footer #aiGeometryCancel.danger { border-color: #fecaca; background: #fff1f2; color: #b91c1c; }
.ai-prompt-chips { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; padding: 2px 1px 5px; scrollbar-width: thin; }
.ai-prompt-chips button { flex: none; white-space: nowrap; }
.scene-history-dialog { width: min(620px, calc(100vw - 28px)); max-height: min(86vh, 720px); }
.scene-history-dialog .dialog-head h2 { margin: 4px 0 0; font-size: 20px; }
.scene-history-list { display: grid; gap: 9px; margin-top: 14px; }
.scene-history-empty { margin: 0; padding: 18px; border: 1px dashed #cbd5e1; border-radius: 12px; color: #64748b; text-align: center; font-size: 12px; }
.scene-history-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border: 1px solid #e2e8f0; border-radius: 12px; background: #fff; }
.scene-history-details { display: grid; gap: 3px; min-width: 0; }
.scene-history-details strong { overflow: hidden; color: #0f172a; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.scene-history-details time, .scene-history-details small { color: #64748b; font-size: 10px; }
.scene-history-actions { display: flex; flex: none; gap: 6px; }
.scene-history-actions .btn { min-height: 32px; padding: 6px 10px; font-size: 11px; }
@media (max-width: 560px) { .ai-geometry-dialog { padding: 16px; } .ai-geometry-dialog .dialog-head h2 { font-size: 17px; } .ai-geometry-footer { align-items: flex-start; flex-direction: column; } .ai-geometry-footer > div { width: 100%; justify-content: flex-end; } .ai-progress-steps li { font-size: 8px; } }
@media (max-width: 480px) { .scene-history-item { align-items: flex-start; flex-direction: column; } .scene-history-actions { width: 100%; justify-content: flex-end; } }
.form-error { color: #b91c1c; }
.muted { color: #64748b; }

@media (max-width: 1000px) {
  .app-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .right-panel { display: none; }
  .right-panel.mobile-open { position: fixed; top: 76px; right: 10px; bottom: 10px; width: min(330px, calc(100vw - 20px)); border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 16px 40px rgb(15 23 42 / 18%); }
  .topbar { padding: 0 14px; }
  .brand { font-size: 15px; }
  .top-actions { gap: 2px; }
  .canvas-controls { max-width: calc(100% - 16px); }
  .camera-menu select { max-width: 160px; }
}

@media (max-width: 700px) {
  .app-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(130px, 27dvh) minmax(0, 1fr); min-height: 0; padding: 8px; gap: 8px; }
  .left-panel { display: flex; border: 1px solid #e2e8f0; border-radius: 12px; }
  .panel-tabs { height: 38px; min-height: 38px; }
  .intro { padding: 8px 12px 5px; }
  .intro h2 { font-size: 15px; }
  .intro p { display: none; }
  .search { margin: 3px 10px 6px; height: 35px; }
  .grade-filter { padding: 0 10px 6px; gap: 4px; }
  .grade-filter button { min-height: 25px; padding: 3px 7px; font-size: 10px; }
  .template-scroll { padding: 0 10px 8px; }
  .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .template-card { min-height: 0; }
  .template-art { height: 46px; }
  .template-meta { display: none; }
  .panel-foot { display: none; }
  .workspace { min-height: 0; }
  .document-bar { height: 38px; min-height: 38px; }
  .document-title input { font-size: 13px; }
  .document-title .eyebrow { display: none; }
  #saveStatus { display: none; }
  .document-actions .btn { min-height: 31px; padding: 5px 8px; }
  .canvas-card { min-height: 0; }
  .canvas-top { margin: 7px 8px 0; }
  .canvas-badge { display: none; }
  .canvas-top-actions { gap: 3px; }
  .canvas-top-actions .small-btn { min-height: 28px; padding: 4px 7px; font-size: 9px; }
  .canvas-top-actions { flex-wrap: wrap; }
  .floating-toolbar { bottom: 54px; }
  .canvas-controls { bottom: 7px; padding: 3px 5px; }
  .camera-menu select { max-width: 125px; font-size: 10px; }
  .canvas-empty { top: 50px; left: 4%; right: 4%; bottom: auto; width: auto; transform: none; padding: 8px; }
  .canvas-empty h2 { font-size: 15px; }
  .canvas-empty p { font-size: 10px; }
  .quick-start { gap: 5px; margin-top: 10px; }
  .quick-start .btn { min-height: 34px; padding: 6px 8px; font-size: 10px; }
  .workplane-row { height: 26px; min-height: 26px; }
  .workspace-bottom { min-height: 27px; height: 27px; }
  .right-panel.mobile-open { top: 66px; bottom: 8px; width: min(340px, calc(100vw - 16px)); }
}

@media (max-width: 460px) {
  .topbar { height: 56px; min-height: 56px; padding: 0 8px; gap: 5px; }
  .brand { font-size: 13px; gap: 6px; }
  .brand-mark { width: 30px; height: 30px; }
  .brand small { font-size: 8px; }
  .top-actions .top-ghost { display: none; }
  .top-actions #arBtn { display: inline-flex; flex: none; width: 36px; min-width: 36px; height: 32px; min-height: 32px; justify-content: center; padding: 6px; }
  .top-actions #arBtn span { display: none; }
  .top-actions #exportBtn { min-height: 32px; padding: 6px 9px; }
  .app-layout { height: calc(100dvh - 56px); grid-template-rows: minmax(118px, 24dvh) minmax(0, 1fr); padding: 6px; gap: 6px; }
  .document-actions #newBtn span, .document-actions #paramsBtn span { display: none; }
  .document-actions { gap: 3px; }
  .document-actions .btn { padding: 5px 7px; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-art { height: 36px; }
  .canvas-top-actions #multiSelectBtn, .canvas-top-actions #examBtn { display: none; }
  .camera-menu select { max-width: 100px; }
  .canvas-controls .icon-btn { width: 27px; height: 27px; }
  .canvas-controls .zoom-controls { display: none; }
}

.grade-filter [data-grade='7'], .grade-filter [data-grade='8'], .grade-filter [data-grade='9'] { display: none; }

/* Mobile 3D workspace: keep the drawing full-screen and bring controls to the thumb zone. */
.mobile-sheet-handle, .mobile-action-bar { display: none; }
@media (max-width: 700px) {
  .topbar { height: 56px; min-height: 56px; padding-inline: 8px; }
  .topbar .brand small { display: none; }
  .top-actions .top-ghost { display: none; }
  .top-actions #arBtn { display: inline-flex; width: 44px; min-width: 44px; height: 44px; min-height: 44px; align-items: center; justify-content: center; padding: 8px; }
  .top-actions #arBtn span { display: none; }
  .top-actions #exportBtn { min-width: 44px; min-height: 44px; }
  html, body { height: 100%; min-height: 100%; overscroll-behavior: none; }
  .app-layout {
    position: relative;
    display: block;
    height: calc(100dvh - 56px);
    min-height: 0;
    padding: 0;
    overflow: hidden;
  }
  .workspace {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    min-height: 0;
    overflow: hidden;
  }
  .document-bar {
    flex: 0 0 42px;
    height: 42px;
    min-height: 42px;
    padding: 0 10px;
    background: #f8fafc;
  }
  .document-title { min-width: 0; }
  .document-title input { min-width: 0; max-width: min(52vw, 240px); }
  .canvas-card {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    touch-action: none;
    overscroll-behavior: none;
  }
  #board { touch-action: none; overscroll-behavior: none; }
  .workspace-bottom, .workplane-row { display: none; }
  .canvas-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    margin: 8px 8px 0;
  }
  .canvas-top-leading { grid-column: 1; min-width: 0; }
  .canvas-top-actions { grid-column: 2; flex-wrap: nowrap; min-width: 0; }
  .mobile-action-bar {
    position: static;
    grid-column: 1 / -1;
    z-index: 8;
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 6px;
    padding: 5px;
    transform: none;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    background: rgb(255 255 255 / 92%);
    box-shadow: 0 4px 14px rgb(15 23 42 / 10%);
    backdrop-filter: blur(14px);
  }
  .mobile-action-bar button {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 10px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #334155;
    font: inherit;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
  }
  .mobile-action-bar button:first-child { color: #1d4ed8; }
  .mobile-action-bar .icon { width: 17px; height: 17px; }
  .mobile-sheet-handle {
    display: flex;
    width: 100%;
    min-height: 48px;
    flex: 0 0 48px;
    position: relative;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 8px 14px 0;
    border: 0;
    background: #fff;
    color: #334155;
    font: inherit;
    font-size: 11px;
  }
  .mobile-sheet-handle > span { position: absolute; top: 6px; width: 38px; height: 4px; border-radius: 999px; background: #cbd5e1; }
  .mobile-sheet-handle .icon { width: 14px; height: 14px; transition: transform .2s ease; }
  .left-panel {
    position: fixed;
    z-index: 40;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    width: 100%;
    height: calc(54px + env(safe-area-inset-bottom));
    max-height: 45dvh;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff;
    box-shadow: 0 -8px 26px rgb(15 23 42 / 10%);
    transition: height .22s ease, transform .22s ease;
  }
  .left-panel.mobile-hidden, .left-panel.mobile-minimized { transform: translateY(calc(100% + env(safe-area-inset-bottom))); }
  .left-panel .panel-tabs > #mobileSheetClose { width: 44px; min-width: 44px; max-width: 44px; flex: 0 0 44px; padding: 0; }
  .mobile-sheet-reopen { display: none; }
  .mobile-sheet-reopen:not([hidden]) { position: fixed; z-index: 31; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); display: inline-flex; min-width: 88px; min-height: 44px; align-items: center; justify-content: center; border: 1px solid #bfdbfe; border-radius: 999px; background: rgb(255 255 255 / 94%); color: #1d4ed8; box-shadow: 0 4px 14px rgb(15 23 42 / 14%); font: inherit; font-size: 11px; font-weight: 700; }
  .left-panel.mobile-expanded { height: 45dvh; }
  .left-panel .panel-tabs { display: none; flex: 0 0 48px; height: 48px; min-height: 48px; padding: 0 8px; gap: 3px; }
  .left-panel.mobile-expanded .panel-tabs { display: flex; }
  .left-panel .panel-tabs > button { min-height: 44px; flex: 1 1 0; justify-content: center; gap: 4px; padding: 0 6px; font-size: 10px; white-space: nowrap; }
  .mobile-sheet-handle strong { display: block; color: #334155; font-size: 11px; font-weight: 700; }
  .mobile-sheet-handle .icon { display: block; width: 16px; height: 16px; color: #64748b; }
  .left-panel .panel-tabs .icon { width: 15px; height: 15px; }
  .left-panel .panel-content { display: none; min-height: 0; flex: 1 1 auto; overflow: hidden; }
  .left-panel.mobile-expanded .panel-content:not(.hidden) { display: flex; flex-direction: column; }
  .left-panel.mobile-expanded .mobile-sheet-handle .icon { transform: rotate(180deg); }
  .left-panel .intro, .left-panel .panel-foot { display: none; }
  .left-panel .search { flex: 0 0 40px; height: 40px; min-height: 40px; margin: 6px 10px; }
  .left-panel .grade-filter { flex: 0 0 auto; overflow-x: auto; flex-wrap: nowrap; padding: 0 10px 8px; }
  .left-panel .grade-filter button { min-height: 40px; padding: 0 12px; font-size: 11px; white-space: nowrap; }
  .left-panel .template-scroll, .left-panel .tools-scroll { min-height: 0; flex: 1 1 auto; overflow: auto; padding-bottom: 10px; }
  .left-panel .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .left-panel .template-art { height: 56px; }
  .left-panel .tool-item { min-height: 48px; }
  .right-panel.mobile-open {
    position: fixed;
    z-index: 42;
    inset: auto 0 0;
    display: flex;
    width: 100%;
    height: calc(45dvh + env(safe-area-inset-bottom));
    max-height: 70dvh;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff;
    box-shadow: 0 -8px 26px rgb(15 23 42 / 12%);
  }
  .right-panel.mobile-open .inspector-scroll { min-height: 0; flex: 1; overflow: auto; }
  .right-panel.mobile-open .inspector-actions > .btn,
  .right-panel.mobile-open .inspector-actions > div .btn,
  .right-panel.mobile-open .panel-tabs > button { min-height: 44px; }
  .properties-backdrop:not([hidden]) { position: fixed; z-index: 39; inset: 0; display: block; background: rgb(15 23 42 / 28%); }
  .floating-toolbar { z-index: 30; top: auto; right: 12px; bottom: calc(60px + env(safe-area-inset-bottom)); left: 12px; display: flex; width: auto; height: 48px; min-height: 48px; max-height: 48px; max-width: calc(100vw - 24px); flex: 0 0 48px; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 4px; padding: 1px 4px; transform: none; overflow-x: auto; overflow-y: hidden; border-radius: 16px; touch-action: pan-x; }
  .quick-tools { display: flex; flex: 0 0 auto; width: max-content; gap: 4px; overflow: visible; }
  .tool-btn { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
  .toolbar-handle, .toolbar-collapse { display: none; }
  .canvas-controls { z-index: 20; bottom: calc(112px + env(safe-area-inset-bottom)); max-width: calc(100% - 16px); }
  .canvas-controls .icon-btn { width: 44px; height: 44px; }
  .camera-menu select { min-height: 44px; max-width: min(36vw, 150px); font-size: 11px; }
  .canvas-top-actions .small-btn { min-height: 44px; }
  .toolbar-restore { position: absolute; top: auto; right: 12px; bottom: calc(60px + env(safe-area-inset-bottom)); left: 12px; width: max-content; max-width: calc(100vw - 24px); height: 48px; min-height: 48px; transform: none; border-radius: 16px; }
  .canvas-empty { top: 62px; left: 4%; right: 4%; bottom: auto; width: auto; transform: none; }
  .quick-start .btn { min-height: 44px; font-size: 11px; }
  .document-actions .btn, .document-actions .icon-btn { min-height: 44px; }
  .template-card { min-height: 44px; }
  .field-label input, .field-label select, .ai-prompt-wrap textarea { font-size: 16px; }
  input[type="range"] { min-height: 44px; touch-action: pan-y; }
  .grade-filter button { min-height: 44px; }
  .ai-mic { width: 46px; height: 46px; }
  .ai-prompt-chips button, .ai-geometry-footer .btn, .dialog-head .icon-btn { min-height: 44px; }
  dialog.ai-geometry-dialog, dialog.scene-history-dialog {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    max-height: calc(92dvh - env(safe-area-inset-top));
    margin: 0;
    padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .ai-prompt-wrap textarea { min-height: 132px; font-size: 16px; }
}
@media (max-width: 460px) {
  .app-layout { height: calc(100dvh - 56px); grid-template-rows: minmax(0, 1fr); }
  .topbar { height: 56px; min-height: 56px; }
  .mobile-action-bar button { padding: 0 8px; font-size: 10px; }
  .floating-toolbar { bottom: calc(60px + env(safe-area-inset-bottom)); }
}


.canvas-controls { overflow-x: auto; overflow-y: hidden; justify-content: flex-start; scrollbar-width: thin; }

/* Keep both floating controls in one row stack on every viewport. */
.canvas-control-dock {
  position: absolute;
  z-index: 30;
  right: 12px;
  bottom: 20px;
  left: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  pointer-events: none;
}
.canvas-control-dock > * { max-width: 100%; min-width: 0; pointer-events: auto; }
.canvas-control-dock .canvas-controls,
.canvas-control-dock #quickToolbar,
.canvas-control-dock #showToolbarBtn {
  position: relative !important;
  inset: auto !important;
  transform: none !important;
}
.canvas-control-dock .canvas-controls {
  align-self: center;
  width: max-content;
  max-width: 100%;
  flex: 0 1 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.canvas-control-dock .canvas-controls > * { flex: 0 0 auto; }
.canvas-control-dock #quickToolbar {
  align-self: center;
  width: max-content;
  max-width: 100%;
  flex: 0 1 auto;
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: pan-x;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.canvas-control-dock #showToolbarBtn { align-self: center; margin: 0; }
.canvas-control-dock .canvas-controls::-webkit-scrollbar,
.canvas-control-dock #quickToolbar::-webkit-scrollbar { display: none; }

@media (max-width: 700px) {
  .canvas-control-dock {
    position: absolute;
    z-index: 32;
    right: 8px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
    pointer-events: none;
  }
  .canvas-control-dock > * { max-width: 100%; min-width: 0; pointer-events: auto; }
  .canvas-control-dock .canvas-controls,
  .canvas-control-dock #quickToolbar,
  .canvas-control-dock #showToolbarBtn {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
  }
  .canvas-control-dock .canvas-controls {
    max-height: 48px;
  }
  .canvas-control-dock #quickToolbar {
    height: 48px;
    min-height: 48px;
    max-height: 48px;
  }
}
.canvas-controls > div { flex-shrink: 0; }
#quickToolbar { max-width: calc(100% - 16px); max-height: calc(100% - 16px); overflow: auto; }
