/* The drawing owns the viewport. Controls share its coordinate space without resizing it. */
:root {
  --green: #3c6d3c;
  --line: #e4e2da;
  --muted: #565c51;
  --paper: #f7f6f2;
  --wash: #f2f8f0;
  --ink: #20251f;
  --active: #e3f0e0;
  --glass: rgb(252 253 249 / 96%);
  --rim: 1px solid rgb(71 91 77 / 18%);
  --lift: 0 3px 8px #213b2a0b, 0 12px 34px #213b2a16, inset 0 1px #fff;
  --edge: 16px;
  --left: max(var(--edge), env(safe-area-inset-left));
  --right: max(var(--edge), env(safe-area-inset-right));
  --top: max(var(--edge), env(safe-area-inset-top));
  --bottom: max(var(--edge), env(safe-area-inset-bottom));
  --panel-top: calc(var(--top) + 62px);
}
html, body { height: 100%; overflow: hidden; }
#app { position: fixed; inset: 0; display: block; width: 100%; height: 100dvh; }
main, #drawing { width: 100%; height: 100%; }
header {
  position: fixed; z-index: 5; inset: var(--top) var(--right) auto var(--left);
  height: 46px; padding: 0; background: transparent; border: 0;
  pointer-events: none; justify-content: flex-end;
}
.island, #cameraTools, #moduleTools, #shaderControl, #library, #objectPanel, dialog {
  color: var(--ink); border: var(--rim); background: var(--glass);
  border-radius: 16px; box-shadow: var(--lift);
}
.island { display: flex; align-items: center; padding: 4px; gap: 2px; pointer-events: auto; }
.island button, #moduleTools button { min-width: 36px; min-height: 36px; border-radius: 11px; }
.island .divider { height: 20px; margin-inline: 3px; background: #ccd6ce; }
svg.icon { stroke-width: 1.7; }
.island svg.icon, #moduleTools svg.icon { width: 18px; height: 18px; }
.project-island { position: absolute; left: 50%; transform: translateX(-50%); padding: 5px 12px; min-height:46px; justify-content:center; }
.brand { position:absolute; left:0; top:0; width:46px; height:46px; display:grid; place-items:center; margin:0; pointer-events:auto; background:var(--glass); border:var(--rim); border-radius:16px; box-shadow:var(--lift); }
.brand img { width: 34px; height: 34px; border-radius: 10px; }
.project-info { min-width:0; width:100%; text-align:center; }
.project-info .name {
  max-width: min(26vw, 340px); min-height: 0; padding: 1px 0; border-radius: 4px;
  font-size: 14px; line-height: 1.2; width:100%; text-align:center; letter-spacing: -.02em;
}
#stageName { display: block; margin: 2px 0 0; max-width: 26vw; color: var(--muted); font-size: 10px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-island { position: absolute; z-index: 2; top: var(--top); left: calc(var(--left) + var(--ui-tool) + 16px); }
#workspaces {
  position: static; min-height: 0; padding: 5px; white-space: nowrap;
  background: var(--glass); border: var(--rim); box-shadow: var(--lift); pointer-events: auto;
}
#workspaces button { min-width: 64px; padding-inline: 10px; background: transparent; box-shadow: none; font-size: 13px; font-weight: 550; }
#workspaces button[aria-pressed="true"], #libraryToggle[aria-expanded="true"],
#cameraTools [aria-pressed="true"], #moduleTools [aria-pressed="true"] { background: var(--active); color: var(--green); }
#libraryToggle { padding-inline: 8px; }
#library, #objectPanel {
  position: absolute; z-index: 3; top: var(--panel-top); bottom: auto;
  width: clamp(272px, 22vw, 324px); max-height: calc(100% - var(--panel-top) - var(--bottom) - 66px);
  padding: 12px; border-radius: 20px; gap: 10px;
}
#library { left: var(--left); }
#objectPanel { right: var(--right); padding: 16px; }
body.library-collapsed #library { display: none; }
.railTabs { border-radius: 12px; background: #eaf0e9; padding: 3px; gap: 1px; }
.railTabs button { font-size: 12px; font-weight: 550; border-radius: 9px; min-height: 32px; }
.railTabs button[aria-pressed="true"] { background: #fff; color: var(--green); }
#library .sideTitle { flex: none; }
#placedPanel, #catalogPanel { flex: 0 1 auto; }
#tree { max-height: none; min-height: 0; }
.tree-row.chosen { background: var(--active); border-radius: 8px; }
#library .tree-row > button, .entry, .tile, .scan-row, .finish-picker, .search, select, input[type="number"], .dimensions div { border-radius: 9px; }
#objectPanel .sideTitle { font-size: 14px; }
#objectPanel .sideTitle button { border-radius: 50%; background: var(--wash); }
#roomPanel, #placedPanel, #inspector, #catalogList { overscroll-behavior: contain; scrollbar-width: thin; }
#stageTop { inset: auto var(--right) calc(var(--bottom) + 5px) auto; z-index: 2; }
#shaderControl { gap: 2px; padding: 3px 6px 3px 10px; }
#shaderControl select { border: 0; background: transparent; font-size: 12px; padding: 6px 2px; min-height: 30px; }
.scene-bottom {
  position: absolute; z-index: 2; bottom: var(--bottom); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; width: max-content; pointer-events: none;
}
#cameraTools { position: static; transform: none; padding: 5px; gap: 2px; z-index: 2; }
#zoom { color: var(--muted); font-size: 12px; }
#moduleTools { border-radius: 14px; }
footer { inset: auto auto var(--bottom) var(--left); flex-wrap: wrap; gap: 3px 8px; max-width: 25vw; font-size: 11px; }
footer span:first-child { flex: none; }
footer span:nth-last-child(2), footer b { display: none; }
#saved { margin: 0; }
@media (max-width: 959px) {
  #library, body.library-collapsed #library { display: none; }
  body.show-library #library { display: flex; }
  body.show-library #library, #objectPanel { top: var(--panel-top); bottom: auto; width: min(306px, calc(100% - var(--left) - var(--right))); }
  #library .mobile-close { display: inline-flex; }
  .file-island button > span { display: none; }
  .file-island button { width: var(--ui-tool); min-width: var(--ui-tool); padding-inline: 0; }
}
@media (max-width: 700px) {
  :root { --edge: 9px; --panel-top: calc(var(--top) + 2 * var(--ui-tool) + 35px); }
  header { justify-content: flex-end; }
  .file-island { position:absolute; top: calc(var(--ui-tool) + 17px); right:0; }
  .project-island { max-width:calc(100% - 108px); }
  .project-info .name, #stageName { max-width: 100%; }
  .view-island { top: calc(var(--top) + var(--ui-tool) + 17px); left:var(--left); }
  #workspaces button { min-width: 50px; padding-inline: 6px; }
  #stageTop { inset:auto var(--right) calc(var(--bottom) + 72px) auto; }
  #shaderControl select { max-width: min(24vw, 115px); }
  #shaderControl svg { display: none; }
  #shaderControl { padding-left: 5px; }
  .scene-bottom { bottom: calc(var(--bottom) + 19px); }
  #cameraTools button { padding-inline: 7px; }
  footer { max-width: 100%; font-size: 10px; }
  #saved { display: inline; }
}
@media (max-width: 520px) {
  .scene-bottom { flex-direction: column; gap: 6px; }
  #library, body.show-library #library, #objectPanel { max-height: calc(100% - var(--panel-top) - var(--bottom) - 53px - 2 * var(--ui-tool)); }
}
@media (max-height: 500px) {
  :root { --edge: 6px; }
  #library, body.show-library #library, #objectPanel { max-height: calc(100% - var(--panel-top) - 10px); }
}
@media (min-width: 1100px) {
  footer span:nth-last-child(2) { display: inline; }
}

.tile-add { display:flex; align-items:center; gap:4px; color:var(--green); font-weight:550; margin:3px 7px 0; }
.tile-add .icon { width:14px; height:14px; }
.wall-key { width:100%; height:98px; background:var(--wash); border-radius:10px; }
.wall-key line { stroke:#84948a; stroke-width:2px; vector-effect:non-scaling-stroke; }
.wall-key text { text-anchor:middle; paint-order:stroke; stroke:var(--wash); stroke-width:.24em; fill:var(--ink); }
.wall-key line.wall-active, .plan-wall-target.wall-active { stroke:var(--green); stroke-width:5px; }
.project-counts { margin-top:12px; color:var(--muted); }
.delete-list { max-height:35vh; overflow:auto; }

@media(max-width:380px){ #workspaces button { min-width:40px; padding-inline:3px; } }
@media(max-width:380px){ #workspaces button .icon { display:none; } }

#projectName { cursor: text; min-width: 2ch; border: 1px solid transparent; outline: none; caret-color: var(--green); }
#projectName:focus { text-overflow: clip; }

/* Floating toolbars use one inset and one button size around the scene. */
.island, #cameraTools, #moduleTools, #workspaces { gap: 2px; padding: 4px; }
.island button, #workspaces button, #moduleTools button {
  min-height: var(--ui-tool); font-size: var(--ui-label); line-height: 18px; font-weight: 550;
}
.island button:has(> :is(.icon, i):only-child), #moduleTools button, #closeProperties, .mobile-close, #close {
  width: var(--ui-tool); min-width: var(--ui-tool); height: var(--ui-tool); padding: 0;
}
#moduleTools button, #closeProperties, .mobile-close, #close { border-radius: 50%; }
.brand, .project-island { min-height: calc(var(--ui-tool) + 10px); }
.brand { width: calc(var(--ui-tool) + 10px); }
.project-island { padding-inline: var(--ui-inset); }

#library, #objectPanel { gap: var(--ui-gap); }
#catalogPanel, #placedPanel, .fields, .actions, .menu, .gallery { gap: var(--ui-gap); }
#library .search, #library select, #inspector :is(input[type="number"], select) { border-radius: var(--ui-radius); }
.railTabs button { flex: 1 1 auto; white-space: nowrap; padding-inline: 4px; min-height: var(--ui-tool); font-size: var(--ui-label); line-height: 18px; }
#catalogList { padding-bottom: 4px; }
#roomPanel .section { margin: 0; padding: 12px 0; }
#roomPanel .section:first-child { padding-top: 0; }
.groupLabel, .section h3, .scan-section h3, .editor-placement summary {
  font-size: var(--ui-label); line-height: 18px; font-weight: 600;
}
.groupLabel { margin: 16px 0 8px; color: var(--muted); }
.tree-row .node, .entry, .scan-row { padding: 4px; gap: var(--ui-gap); border-radius: var(--ui-radius); }
.tree-row .node canvas, .scan-thumb { width: 48px; height: 42px; border-radius: 6px; }
.tree-row .node strong, .scan-caption strong, .entry strong, .tile strong, .finish-picker summary strong {
  font-size: var(--ui-body); line-height: 20px; font-weight: 550;
}
.tree-row .node small, .scan-caption small, .entry small, .tile small, .sub,
.finish-picker summary small, .module-heading small, .dimensions dt, #stageName, #zoom, footer, #saved {
  font-size: var(--ui-caption); line-height: 16px;
}
.tree-row .node span, .scan-caption { gap: 2px; }
.tile strong, .tile small { padding-inline: var(--ui-gap); }
.tile-add { margin-top: auto; margin-inline: var(--ui-gap); font-size: var(--ui-label); }
.section .actions button, .outline, .dimension-editor > button, form .primary, .wall-paints button,
.wall-sizes button, .finish-option {
  min-height: var(--ui-control); border-radius: var(--ui-radius);
  font-size: var(--ui-label); line-height: 18px;
}
.finish-picker summary { min-height: 56px; padding: var(--ui-gap); gap: var(--ui-gap); }
#scene-controls h2, .dialogHead h2, .module-heading h2 {
  font-size: var(--ui-title); line-height: 24px; font-weight: 600; letter-spacing: -.025em;
}
#scene-controls { padding: 16px; }
#scene-controls .material-field { font-size: var(--ui-label); line-height: 18px; }
#scene-controls .shadow-setting, .wall-toggle {
  min-height: 44px; margin: 0; padding: 8px 0; font-size: var(--ui-body); line-height: 20px;
}
.project-info .name, #objectPanel .sideTitle, .dimensions dd { font-size: var(--ui-body); line-height: 20px; }

header { height: calc(var(--ui-tool) + 10px); }
@media (max-width: 380px) {
  .project-island { padding-inline: 4px; }
  #stageName { letter-spacing: -.01em; }
}

#callCat {
  position: absolute;
  z-index: 2;
  left: var(--left);
  bottom: calc(var(--bottom) + 20px);
  width: 46px;
  height: 46px;
  justify-content: center;
  border-radius: 50%;
}
@media (max-width: 590px) {
  #callCat { bottom: calc(var(--bottom) + var(--ui-tool) + 37px); }
}

/* Leave room below the title for the full, wrapped notification. */
body > #notice {
  top: calc(var(--top) + var(--ui-tool) + 18px);
  bottom: auto;
  width: max-content;
  max-width: min(570px, calc(100% - var(--left) - var(--right)));
  max-height: 22dvh;
  overflow: auto;
  overflow-wrap: anywhere;
  text-align: center;
}
@media (min-width: 1100px) {
  body > #notice { max-width: min(570px, 45vw); }
}
@media (max-width: 1099px) {
  body { --panel-top: calc(var(--top) + 62px + var(--notice-space, 0px)); }
}
@media (max-width: 700px) {
  body { --panel-top: calc(var(--top) + 2 * var(--ui-tool) + 35px + var(--notice-space, 0px)); }
  .file-island, .view-island { translate: 0 var(--notice-space, 0px); }
}
