/* Native full-screen views must keep controls outside the iPhone system areas. */
body.stool-web {
  --stool-safe-top: env(safe-area-inset-top, 0px);
  --stool-safe-right: env(safe-area-inset-right, 0px);
  --stool-safe-bottom: env(safe-area-inset-bottom, 0px);
  --stool-safe-left: env(safe-area-inset-left, 0px);
}
body.stool-web #design-root {
  top: var(--stool-safe-top);
  left: var(--stool-safe-left);
  right: var(--stool-safe-right);
}
body.stool-web #stool-ai-dialog,
body.stool-web #ai-crop-editor {
  position: fixed;
  inset: var(--stool-safe-top) var(--stool-safe-right) var(--stool-safe-bottom) var(--stool-safe-left);
  width: calc(100vw - var(--stool-safe-left) - var(--stool-safe-right));
  height: calc(100dvh - var(--stool-safe-top) - var(--stool-safe-bottom));
  max-width: none;
  max-height: calc(100dvh - var(--stool-safe-top) - var(--stool-safe-bottom));
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  border: 0;
  border-radius: 0;
}
body.stool-web #stool-ai-dialog > header { padding: 12px 16px; }
body.stool-web #ai-crop-editor > header { padding: 8px 12px; }
body.stool-web #stool-ai-dialog > footer { padding: 8px 16px 14px; }
body.stool-web #ai-crop-editor > footer { padding: 12px 16px; }
/* UIKit constrains the WKWebView itself to the safe area on all four edges.
   The remaining viewport belongs entirely to app content, in portrait and landscape. */
body.stool-web #stool-floor-intro .sfi-scene { touch-action: none; }
body.stool-web #stool-floor-intro .sfi-hint {
  position: absolute; bottom: 78px; left: 16px; right: 16px;
  text-align: center; font-size: 12px; color: #74746e; pointer-events: none;
}
body.stool-web #stool-floor-intro button { min-width: 88px; min-height: 48px; }
body.stool-web #dp-header .dp-wordmark,
body.stool-web #dp-header .dp-wordmark img { width: 74px !important; height: auto; object-fit: contain; }
body.stool-web #vim-room-sketch .sketch-body { overscroll-behavior: contain; }
body.stool-web #vim-room-sketch .sketch-actions { flex-wrap: wrap; }
body.stool-web #vim-room-sketch .sketch-actions button { min-width: 0; }
body.stool-web input:not([type="range"]):not([type="color"]),
body.stool-web select, body.stool-web textarea { font-size: max(16px, 1em) !important; }
@media (max-height: 450px) {
  body.stool-web #vim-room-sketch header { min-height: 44px; }
  body.stool-web #vim-room-sketch footer { padding-top: 4px; }
  body.stool-web #vim-room-sketch .sketch-actions button { padding: 6px; }
  body.stool-web #stool-floor-intro .sfi-hint { top: 8px; bottom: auto; margin: 0; }
  body.stool-web #stool-floor-intro button { bottom: 8px; }
}
/* Selecting a field in the short landscape picker may scroll its sheet.
   Keep its escape action visible while the remaining content scrolls. */
body.stool-web #vim-room-sketch .sa-add-sheet > header {
  position: sticky; top: 0; z-index: 2; background: #fff;
  box-sizing: border-box; flex-shrink: 0;
}
body.stool-web #sa-add-dialog,
body.stool-web #sa-opening-dialog { box-sizing: border-box; }
body.stool-web #sa-opening-dialog .sa-dialog-sheet > header,
body.stool-web #sa-opening-dialog .sa-dialog-sheet > footer { flex-shrink: 0; }

/* Native presentation rules shared across the room, furniture and handoff flows. */
body.stool-web {
  --stool-control: 44px;
  --stool-radius: 12px;
  --stool-border: #deded8;
  --stool-ink: #373735;
  --stool-muted: #686861;
}
body.stool-web button, body.stool-web summary { min-width: var(--stool-control) !important; min-height: var(--stool-control) !important; box-sizing: border-box; }
body.stool-web input:not([type=checkbox]):not([type=radio]):not([type=range]),
body.stool-web select { min-height: var(--stool-control) !important; box-sizing: border-box; }
body.stool-web [data-stool-room-id-unavailable], body.stool-web #vs-room-id, body.stool-web #muji-room-id-open { display: none !important; }
body.stool-web .stool-ux-note { font-size: 12px; line-height: 1.7; color: var(--stool-muted); margin: 8px 0 0; }
body.stool-web .stool-ux-note:empty { display: none; }
body.stool-web .stool-ux-heading::before, body.stool-web .stool-ux-heading::after { display: none !important; }
body.stool-web .stool-ux-heading { font-size: 15px; font-weight: 600; line-height: 1.5; margin: 0 0 8px; }
body.stool-web .stool-ux-automatic { font-size: 12px; line-height: 1.7; color: var(--stool-muted); margin: 0 0 16px; }
body.stool-web #dp-header #dp-undo, body.stool-web #dp-header #dp-redo { width: 44px; padding: 6px; }
body.stool-web #muji-language-header { margin: 12px 0; display: flex; justify-content: space-between; gap: 12px; }
body.stool-web #muji-language-header .muji-language-label { position: static; width: auto; height: auto; clip-path: none; font-size: 13px; }
body.stool-web .muji-language select { min-height: 44px; border-radius: 10px; width: 105px; max-width: none; }
body.stool-web #stool-joy-context { display: none !important; }
body.stool-web #design-root #dp-selection.stool-selection-compact #muji-selection-actions button { font-size: 13px !important; line-height: 1.4 !important; }
body.stool-web #dp-selected-size { font-size: 12px !important; }
body.stool-web #dp-dimensions-toggle { min-height: 44px; }
body.stool-web #muji-edit-hint { font-size: 12px; line-height: 1.65; }
body.stool-web #muji-edit-dialog #dp-colors button { min-width: 44px !important; min-height: 44px !important; }
body.stool-web #vim-floor-editor :is(#vim-floor-types, #vim-floor-colors, #vim-floor-directions) button { min-width: 44px; min-height: 44px; font-size: 13px; }
body.stool-web #vim-floor-colors { flex-wrap: wrap; gap: 8px; }
body.stool-web #vim-floor-colors button { width: 44px; height: 44px; }
body.stool-web #vim-floor-editor p { font-size: 13px !important; line-height: 1.7; }
/* Every start route uses the same icon, heading, explanation and arrow. */
body.stool-web #vim-start #vs-import-json { padding: 18px; gap: 15px; border-radius: 20px; }
body.stool-web #vs-import-json .stool-ux-copy { min-width: 0; }
body.stool-web #vs-import-json .stool-ux-label { display: block; font-size: 15px; line-height: 1.5; }
body.stool-web #vs-import-json #vs-import-json-hint { display: block; font-size: 12px !important; line-height: 1.6 !important; margin: 5px 0 0 !important; color: var(--stool-muted) !important; }
/* One scrollable save sheet, with explicit on-device and file destinations. */
body.stool-web #dp-save-dialog { padding: 16px; }
body.stool-web #dp-save-dialog > section { width: min(100%, 440px); max-width: 440px; max-height: calc(100dvh - 32px) !important; padding: 20px; border-radius: 20px; overflow-y: auto !important; overscroll-behavior: contain; box-sizing: border-box; scroll-padding: 12px; }
body.stool-web #dp-save-dialog .dp-panel-heading { position: sticky; top: 0; z-index: 2; background: #fff; margin-bottom: 12px; min-height: 44px; }
body.stool-web #dp-save-dialog .stool-save-group { width: 100%; max-width: none; padding: 0; border-radius: 0; background: transparent; }
body.stool-web #dp-save-dialog .stool-save-group + .stool-save-group { border-top: 1px solid var(--stool-border); margin-top: 18px; padding-top: 18px; }
body.stool-web #dp-save-dialog .stool-save-group button { width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px !important; font-size: 14px; line-height: 1.5; white-space: normal; margin: 8px 0 0 !important; }
body.stool-web #vim-project-save-form { margin: 0; }
body.stool-web #vim-project-save-form label { display: grid; gap: 8px; font-size: 13px; }
body.stool-web #vim-project-name { margin: 0; width: 100%; border-radius: 10px; min-height: 48px; }
body.stool-web #vim-project-save-status:empty,
body.stool-web #stool-file-status:empty,
body.stool-web #stool-import-status:empty { display: none; }
body.stool-web #dp-save-dialog #dp-export { background: #fff; color: var(--stool-ink); border: 1px solid var(--stool-border); }
body.stool-web #dp-save-dialog #stool-import-open { border-color: var(--stool-border); }
body.stool-web #dp-save-dialog .stool-ux-note { font-size: 12px; }
/* The preview may scroll away. It must never sit over the floor controls. */
body.stool-web #muji-room-units .unit-flow-body { scroll-padding-top: 12px !important; }
body.stool-web #muji-room-units input, body.stool-web #muji-room-units select { scroll-margin-top: 12px !important; }
body.stool-web #muji-room-units .unit-flow-history button { min-height: 44px !important; font-size: 12px !important; }
body.stool-web #muji-room-units .unit-actions button { min-height: 44px !important; font-size: 13px !important; }
body.stool-web #muji-room-units #muji-unit-fields label { font-size: 13px; }
/* Put overall dimensions before the drawing on phones, alongside it on desktop. */
body.stool-web #vim-room-sketch #sketch-edit.stool-ux-sketch { grid-template-areas: 'preview dimensions' 'preview details'; grid-template-rows: auto 1fr; gap: 16px 24px; }
body.stool-web #vim-room-sketch #sketch-quick { grid-area: dimensions; margin: 0; }
body.stool-web #vim-room-sketch .muji-sketch-preview { grid-area: preview; }
body.stool-web #vim-room-sketch .muji-sketch-settings { grid-area: details; }
body.stool-web #vim-room-sketch #sketch-presets { gap: 8px; margin-bottom: 12px; min-height: 44px; }
body.stool-web #vim-room-sketch #sketch-presets button { min-width: 48px !important; min-height: 44px !important; padding: 8px 10px; font-size: 13px !important; border: 1px solid var(--stool-border) !important; border-radius: 10px !important; }
body.stool-web #vim-room-sketch .muji-sketch-preview-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px; }
body.stool-web #vim-room-sketch .muji-sketch-preview-head > span { flex: 1 0 auto; font-size: 13px; }
body.stool-web #vim-room-sketch .sketch-history { gap: 4px; width: auto; }
body.stool-web #vim-room-sketch .sketch-history button { min-height: 44px !important; min-width: 52px !important; font-size: 12px !important; padding: 6px; }
body.stool-web #vim-room-sketch #stool-sketch-preview-toggle { min-height: 44px; font-size: 12px; padding: 6px 8px; border-color: var(--stool-border); }
body.stool-web #vim-room-sketch #sketch-diagram { min-height: 0; height: 280px; }
body.stool-web #vim-room-sketch #sa-jump { display: none; }
body.stool-web #vim-room-sketch :is(.muji-sketch-hint, #sa-legend, #sketch-description, #sketch-step, #sketch-size, .muji-sketch-unit) { font-size: 12px !important; opacity: 1; line-height: 1.7; }
body.stool-web #vim-room-sketch .sketch-overall label { font-size: 13px; }
body.stool-web #vim-room-sketch .sketch-actions button { font-size: 13px !important; min-width: 60px !important; padding: 10px 12px !important; }
body.stool-web #vim-room-sketch #sketch-redraw { min-width: 64px !important; }
body.stool-web #vim-room-sketch #sketch-apply { min-width: 0 !important; }
body.stool-web #vim-room-sketch .muji-sketch-settings > small { font-size: 12px; opacity: 1; }
/* The handoff actions stay together, with a capability-specific alternate route. */
body.stool-web #stool-ai-dialog .ai-intro { font-size: 13px; }
body.stool-web #stool-ai-dialog .ai-note { font-size: 12px; }
body.stool-web #stool-ai-dialog > footer button { min-height: 48px; font-size: 13px; border-radius: 12px; }
body.stool-web #stool-ai-dialog #ai-share { width: 100%; min-height: 48px; margin-top: 12px; border: 1px solid var(--stool-border); border-radius: 12px; background: #fff; padding: 10px 12px; font-size: 13px; }
body.stool-web #stool-ai-dialog #stool-ai-share-note { font-size: 12px; line-height: 1.7; color: var(--stool-muted); margin: 8px 0 0; }
body.stool-web #stool-ai-dialog #ai-status { font-size: 12px; }
/* Consistent close targets, while preserving each action's cancel/apply semantics. */
body.stool-web :is(#sketch-close, #dp-mode-close, #dp-save-close, #muji-edit-close, #architecture-close, #builder-close, #ai-close, #stool-lighting-close, #sa-add-close, #sa-dialog-cancel) { min-width: 44px !important; min-height: 44px !important; }
body.stool-web #stool-floor-intro button { left: 50%; right: auto; transform: translateX(-50%); bottom: 24px; min-width: 160px !important; min-height: 52px !important; padding: 12px 32px; background: #373735 !important; color: #fff; border-radius: 12px; font-size: 15px; font-weight: 600; }
body.stool-web #stool-floor-intro .sfi-hint { bottom: 94px; }
@media (max-width: 900px) {
  body.stool-web #muji-room-units .unit-flow-preview { position: static !important; }
  body.stool-web #vim-room-sketch #sketch-edit.stool-ux-sketch { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'dimensions' 'preview' 'details'; gap: 12px; }
  body.stool-web #vim-room-sketch #sketch-diagram { min-height: 0; height: 200px; }
  body.stool-web #vim-room-sketch .muji-sketch-unit { margin-bottom: 12px; }
}
@media (max-height: 450px) {
  body.stool-web #muji-room-units .unit-flow-preview { position: static !important; }
  body.stool-web #muji-room-units .unit-flow-body { grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); gap: 16px; }
  body.stool-web #muji-room-units #muji-units-map { height: 150px; }
  body.stool-web #muji-room-units .unit-actions { display: flex; flex-wrap: wrap; }
  body.stool-web #muji-room-units .unit-actions button { flex: 1 1 110px; }
  body.stool-web #stool-floor-intro button { bottom: 12px; min-height: 44px !important; min-width: 128px !important; padding: 8px 24px; font-size: 14px; }
  body.stool-web #stool-floor-intro .sfi-hint { top: 8px; bottom: auto; }
}
@media (max-width: 380px) {
  body.stool-web #dp-header { padding-left: 8px; padding-right: 8px; }
  body.stool-web #dp-header .dp-header-actions { gap: 4px; }
  body.stool-web #dp-header #dp-mode-toggle { min-width: 76px; font-size: 13px; }
  body.stool-web #vim-room-sketch { padding-left: 12px; padding-right: 12px; }
  body.stool-web #vim-room-sketch #sa-install { padding: 8px !important; }
}
body.stool-web :is(#muji-units-apply, #architecture-apply, #builder-save, #muji-edit-done, #muji-move-done, #muji-rotate-done, #ai-save, #ai-crop-apply, #sketch-apply, #sketch-next) {
  border-radius: 12px !important; min-height: 48px !important; font-size: 14px !important;
}
body.stool-web :is(#sketch-close, #dp-mode-close, #dp-save-close, #muji-edit-close, #architecture-close, #builder-close, #ai-close, #stool-lighting-close) {
  width: 44px; height: 44px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 12px !important; background: #f5f5f1; color: #373735; font-size: 24px;
}
/* Keep tall form content in the scroll area instead of shrinking it under the footer. */
body.stool-web #vim-room-sketch .sketch-body > :is(#sketch-edit, #sketch-description, #sketch-presets) { flex-shrink: 0; }
body.stool-web #vim-room-sketch .sketch-body { scroll-padding-block: 48px; }
body.stool-web #vim-room-sketch #stool-sketch-preview-toggle { scroll-margin-block: 48px; }
/* The rotation dial owns touch gestures; only the surrounding sheet scrolls. */
body.stool-web #stool-rotation-dial, body.stool-web #stool-rotation-dial * { touch-action: none !important; -webkit-touch-callout: none; }
body.stool-web .stool-rotation-steps { display: flex; gap: 8px; margin: 8px 0; }
body.stool-web .stool-rotation-steps button { flex: 1; min-height: 44px; border: 1px solid #deded8; border-radius: 12px; background: #fff; font-size: 14px; }
body.stool-web #stool-pallet-dialog { width: min(460px, calc(100vw - 24px)); }
body.stool-web .stool-pallet-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
body.stool-web .stool-pallet-fields label { display: grid; gap: 8px; font-size: 14px; }
body.stool-web .stool-pallet-fields select { width: 100%; min-height: 48px; padding: 8px 12px; font: inherit; border-radius: 12px; border: 1px solid #deded8; background: #fff; }
body.stool-web #stool-pallet-preview { display: block; width: 100%; max-height: 200px; background: #faf9f6; border-radius: 12px; margin-top: 16px; }
body.stool-web #stool-pallet-size { font-weight: 600; }
body.stool-web #stool-pallet-add { width: 100%; min-height: 48px; }
body.stool-web #stool-pallet-error:empty { display: none; }
@media(max-height:450px) { body.stool-web #stool-pallet-preview { max-height: 110px; } }
body.stool-web .stool-pallet-fields { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
body.stool-web .stool-pallet-fields label { min-width: 0; font-size: 13px; }

body.stool-web .stool-launch-dialog { width: min(940px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-sizing: border-box; padding: 0; border: 0; border-radius: 20px; background: #fff; color: #373735; font-family: NotoSansJP, sans-serif; }
body.stool-web .stool-launch-dialog::backdrop { background: #0005; }
body.stool-web .stool-launch-dialog header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; background: #fff; border-bottom: 1px solid #deded8; }
body.stool-web .stool-launch-dialog h2 { margin: 0; font-size: 18px; }
body.stool-web .stool-launch-dialog header button { width: 44px; height: 44px; font-size: 26px; }
body.stool-web .stool-launch-content { padding: 0 20px 20px; }
body.stool-web .stool-launch-dialog p { font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }
body.stool-web .stool-launch-dialog h3 { font-size: 16px; margin: 12px 0 8px; overflow-wrap: anywhere; }
body.stool-web .stool-launch-dialog :is(button,input,summary) { font: inherit; font-size: 14px; min-height: 44px; padding: 10px 12px; border: 1px solid #deded8; border-radius: 12px; background: #fff; color: #373735; box-sizing: border-box; }
body.stool-web .stool-launch-dialog button { white-space: normal; cursor: pointer; }
body.stool-web .stool-launch-dialog button:disabled { opacity: .5; cursor: default; }
body.stool-web .stool-launch-content > button { display: block; width: 100%; margin: 10px 0; }
body.stool-web .stool-launch-dialog .stool-launch-primary { background: #373735; color: #fff; }
body.stool-web .stool-launch-dialog .stool-launch-delete { color: #973c32; }
body.stool-web .stool-launch-message { margin: 0 20px; }
body.stool-web .stool-launch-message:empty { display: none; }
body.stool-web .stool-room-grid, body.stool-web .stool-compare-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; margin: 16px 0; }
body.stool-web .stool-room-card { min-width: 0; border: 1px solid #deded8; border-radius: 16px; padding: 12px; }
body.stool-web .stool-room-card figure { margin: 0; }
body.stool-web .stool-room-card :is(canvas,img) { display: block; width: 100%; height: auto; aspect-ratio: 5/4; object-fit: contain; background: #faf9f6; border-radius: 10px; }
body.stool-web .stool-room-card button { margin: 8px 0 0; width: 100%; }
body.stool-web .stool-room-card label { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 13px; }
body.stool-web .stool-room-card input[type=checkbox] { width: 22px; height: 22px; min-height: 22px; }
body.stool-web .stool-room-card input[type=text] { width: 100%; margin-top: 10px; }
body.stool-web .stool-room-card details { margin-top: 10px; }
body.stool-web .stool-launch-preview { padding: 12px; border-radius: 10px; background: #f5f3eb; }
body.stool-web .stool-launch-content > a { display: inline-block; min-height: 44px; padding: 12px; box-sizing: border-box; color: inherit; }
@media(max-width:600px) { body.stool-web .stool-room-grid, body.stool-web .stool-compare-grid { grid-template-columns: minmax(0,1fr); } body.stool-web .stool-launch-dialog header, body.stool-web .stool-launch-content { padding-left: 14px; padding-right: 14px; } }
body.stool-web .stool-launch-dialog h2::before, body.stool-web .stool-launch-dialog h2::after { display: none !important; }
