/* styles/shell.css — the region layout (B1, design §3, §12). Every screen region is a fixed floating card placed on the
   12 px grid; ui/shell.js reads their live rects for shell.insets() (R3) and only adds the few measured placements CSS
   cannot express (the tool strip row, the tablet inspector sheet, phone reparenting).

   Root state attributes on #twin (set by ui/shell.js):
     data-bp      desktop (≥1280) | compact (1024–1279) | tablet (641–1023) | phone (≤640)
     data-ws / data-sub / data-lens        the workspace
     data-insp    on | off                 inspector shown (I; tablet: an overlay sheet)
     data-drawer  open | closed            the drawer above the tray
     data-layers  open | closed            the Layers drawer out of the rail
     data-chrome  off                      H: everything hides
     data-present on / data-walk on / data-sky on / data-role homeowner / data-booting on
     data-row     1 | 2                    whether the tool strip fits the top row */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 400 var(--fs-body)/1.4 var(--font);
  font-feature-settings: "tnum" 1, "cv11" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow: hidden; overscroll-behavior: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 100; padding: 8px 12px; border-radius: var(--r-input); background: var(--panel-2); color: var(--ink); box-shadow: var(--e3); text-decoration: none; }
.skip:focus { top: 12px; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; color: var(--ink-2); }

/* ── focus (design §10: 2 px --sel ring with a 2 px offset) */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }

/* ── the grid variables (desktop reference; breakpoints below override) */
.twin {
  --left: calc(var(--gutter) * 2 + var(--rail-w));                        /* 88: the free area's left edge */
  --top2: calc(var(--gutter) * 2 + var(--top-h));                         /* 68: the second row */
  --right-free: calc(var(--gutter) * 2 + var(--insp-w));                  /* the free area's right edge, from the right */
  --tray-top: calc(var(--gutter) * 2 + var(--tray-h));                    /* the tray's top, from the bottom */
  --drawer-h-live: var(--drawer-h);
  --above-tray: calc(var(--tray-top));
  /* the hint line under the tool strip: a solid HUD pill. Published for what sits under it (a tool's pill, B5 #75):
     --hint-top, --hint-h, --below-hint (the first y below the pill, with a 6 px gap) */
  --hint-top: calc(var(--gutter) + var(--top-h) + 6px);
  --hint-h: 22px;
  --below-hint: calc(var(--hint-top) + var(--hint-h) + 6px);
  position: fixed; inset: 0;
}
.twin[data-row="2"] { --hint-top: calc(var(--top2) + var(--top-h) + 6px); }
.twin[data-insp="off"] { --right-free: var(--gutter); }
.twin[data-drawer="open"] { --above-tray: calc(var(--tray-top) + var(--drawer-h-live) + var(--gutter)); }

/* ── regions: fixed cards */
.region { position: fixed; z-index: 10; }
.panel { background: var(--panel); box-shadow: var(--e1); }
.hud { background: var(--hud); box-shadow: var(--e2); -webkit-backdrop-filter: var(--hud-blur); backdrop-filter: var(--hud-blur); }
.hud-solid { background: var(--hud-solid); box-shadow: var(--e2); }

/* stage: the canvas under everything (B2 positions the canvas; the host is the keyboard target, design §10) */
.stage { inset: 0; z-index: 0; }
.canvas-host { position: fixed; inset: 0; outline: none; }
.canvas-host:focus-visible { outline: 2px solid var(--sel); outline-offset: -4px; }
.overlay-root { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.stage-shade {  /* design §10: 8% black at the top and bottom edges under the HUD glass */
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background: linear-gradient(to bottom, var(--shade), transparent 18%, transparent 82%, var(--shade));
}
.stage-state { position: fixed; inset: 0; display: none; place-items: center; z-index: 3; pointer-events: none; padding: 24px; }
.stage-state.show { display: grid; pointer-events: auto; }

/* rail (design §2.1: left, 64 px, full height, floating card, 12 px gutter) */
.rail {
  left: var(--gutter); top: var(--gutter); bottom: var(--gutter); width: var(--rail-w);
  border-radius: var(--r-panel); padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 20;
}
.rail .brand {
  width: 40px; height: 40px; margin: 2px 0 8px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center;
  transition: background var(--t-fast) var(--ease);
}
.rail .brand:hover { background: var(--accent); color: var(--on-accent-text); }
.rail .brand .i { width: 22px; height: 22px; }
.rail-ws, .rail-util { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rail-ws::after { content: ""; width: 28px; height: 1px; background: var(--line); margin: 6px 0 0; }
.rail-space { flex: 1 1 auto; min-height: 8px; }

/* top row: house chip at the left, save chip + viewbar at the right (the row box itself is not a region) */
.top { left: var(--left); right: var(--gutter); top: var(--gutter); height: var(--top-h); display: flex; align-items: flex-start; gap: var(--gutter); pointer-events: none; z-index: 15; }
.top > * { pointer-events: auto; }
.top .house-chip { flex: 0 1 auto; min-width: 0; }
.top .save-chip { margin-left: auto; }
.top .save-chip:empty { display: none; }
.top .save-chip:empty + .viewbar { margin-left: auto; }

/* tool strip: top centre; ui/shell.js measures whether it fits between the chips (row 1) or drops to row 2 */
.toolstrip { top: var(--gutter); left: 50%; transform: translateX(-50%); height: var(--top-h); max-width: calc(100vw - 2 * var(--gutter)); z-index: 16; }
.twin[data-row="2"] .toolstrip { top: var(--top2); }
.toolstrip:empty { display: none; }
.hint {   /* design §2.1: one line of key hints, ink-3, 12 px, fading after 6 s. On a solid HUD pill (no blur), because it sits on
             the 3D world — bright lawn, trees, sky or the light theme — where bare text cannot hold 4.5:1 (B5 #75) */
  position: fixed; z-index: 9; left: 50%; transform: translateX(-50%); top: var(--hint-top);
  height: var(--hint-h); line-height: var(--hint-h); padding: 0 10px; border-radius: var(--r-pill);
  background: var(--hud-solid); box-shadow: 0 0 0 1px var(--line);
  font-size: 12px; color: var(--ink-3-text); white-space: nowrap; pointer-events: none;
  max-width: calc(100vw - var(--left) - var(--right-free) - 2 * var(--gutter)); overflow: hidden; text-overflow: ellipsis;
  transition: opacity var(--t-fade) var(--ease);
}
.hint.gone, .hint:empty { opacity: 0; }

/* view cube + compass (design §2.1: 72 px, under the viewbar, at the right edge of the free area) */
.viewcube { top: var(--top2); right: var(--right-free); width: var(--cube); z-index: 14; display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* inspector (design §2.1: right, 344, top 68, bottom 12; solid; no tabs) */
.inspector {
  right: var(--gutter); top: var(--top2); bottom: var(--gutter); width: var(--insp-w);
  border-radius: var(--r-panel); display: flex; flex-direction: column; overflow: hidden; z-index: 20;
  transition: opacity var(--t-panel) var(--ease), transform var(--t-panel) var(--ease);
}
.twin[data-insp="off"] .inspector { opacity: 0; transform: translateX(16px); pointer-events: none; visibility: hidden; }

/* tray (design §2.1: 64 px, bottom 12, from x = 88 to the inspector's left − 12) */
.tray {
  left: var(--left); right: var(--right-free); bottom: var(--gutter); height: var(--tray-h);
  border-radius: var(--r-panel); z-index: 18; display: flex; align-items: center; gap: 10px; padding: 0 10px 0 12px;
  transition: height var(--t-panel) var(--ease);
}
.twin[data-sky="on"] .tray { height: 196px; align-items: stretch; }
/* Photos: the filmstrip's 88×66 thumbnails (design §5.6) need a taller tray; insets, the drawer and the Layers bottom follow
   --tray-h (B4 #59). Phone keeps its time pill. */
.twin[data-ws="photos"]:not([data-bp="phone"]) { --tray-h: 92px; }

/* drawer (design §2.1: slides up above the tray, same width, 200 px … 50 vh, default 280) */
.drawer {
  left: var(--left); right: var(--right-free); bottom: var(--tray-top); height: var(--drawer-h-live);
  border-radius: var(--r-panel); display: flex; flex-direction: column; overflow: hidden; z-index: 17;
}
.twin[data-sky="on"] .drawer { bottom: calc(var(--gutter) * 2 + 196px); }

/* Layers (design §2.1: slides out of the rail, 300 px, over the canvas's left edge) */
.layers {
  left: var(--left); top: var(--top2); bottom: var(--above-tray); width: var(--layers-w);
  border-radius: var(--r-panel); display: flex; flex-direction: column; overflow: hidden; z-index: 21;
}

/* phone-only regions */
.tabbar, .sheet { display: none; }

/* ── popovers, hover card, toasts (above every region) */
.popovers { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.popovers > * { pointer-events: auto; }
.hovercard { position: fixed; z-index: 35; pointer-events: none; }
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--above-tray) + 8px); display: flex; flex-direction: column-reverse; align-items: center; gap: 8px; pointer-events: none; width: min(560px, calc(100vw - 32px)); }
/* a drone photo is up (Photos, or Walls with a photo): toasts rise clear of the photo's own tag at the frame's bottom-left (B2 #78) */
.twin[data-photo="on"]:not([data-bp="phone"]) .toasts { bottom: calc(var(--above-tray) + 64px); }
.toasts > * { pointer-events: auto; }
.toasts.urgent { bottom: auto; top: calc(var(--top2) + 22px); flex-direction: column; }   /* below the hint line */

/* ═══════════════════════════════════════════════ breakpoints (design §3, §12) */
/* 1024–1279: rail icons only (56 px, labels in tooltips); inspector 312 */
@media (max-width: 1279.98px) {
  :root { --rail-w: 56px; --insp-w: 312px; }
  .rail .rail-item .rl { display: none; }
  .rail .rail-item { height: 44px; }
}
/* 641–1023 (tablet): the inspector is an overlay sheet from the right (360), opened by selection or I; the tray spans
   the full width minus the rail; Layers is an overlay */
@media (max-width: 1023.98px) {
  :root { --insp-w: 360px; }
  .twin { --right-free: var(--gutter); }
  .twin[data-insp="on"] .viewcube { right: calc(var(--gutter) * 2 + var(--insp-w)); }
  .inspector { bottom: var(--above-tray); box-shadow: var(--e3); }
  .twin[data-insp="on"] .layers { right: auto; }
}
/* ≤640: phone (design §12) */
@media (max-width: 640px) {
  :root { --top-h: 44px; --sheet-peek: 96px; }
  .twin { --left: var(--gutter); --top2: calc(var(--gutter) + var(--top-h) + 8px); --right-free: var(--gutter); }
  .rail, .twin > .drawer, .viewcube .cube-btns { display: none !important; }
  .top { left: var(--gutter); right: var(--gutter); top: calc(var(--gutter) + env(safe-area-inset-top, 0px)); }
  .viewcube { top: calc(var(--gutter) + env(safe-area-inset-top, 0px)); right: var(--gutter); width: var(--top-h); }
  .top .viewbar { margin-right: calc(var(--top-h) + var(--gutter)); }
  .inspector { display: none; }
  .tray { left: var(--gutter); right: auto; top: calc(var(--top2) + env(safe-area-inset-top, 0px)); bottom: auto; height: 44px; border-radius: var(--r-pill); padding: 0 14px 0 6px; }
  .twin[data-sky="on"] .tray { height: 44px; }
  .toolstrip { position: static; transform: none; height: auto; max-width: none; }
  .hint { display: none; }
  .layers { left: var(--gutter); right: var(--gutter); width: auto; top: var(--top2); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--sheet-peek) + 16px); z-index: 30; box-shadow: var(--e3); }
  .tabbar {
    display: flex; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); border-radius: var(--r-panel) var(--r-panel) 0 0; z-index: 22;
    justify-content: space-around; align-items: stretch; gap: 4px;
  }
  .sheet {
    display: flex; flex-direction: column; left: 8px; right: 8px; z-index: 21;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
    height: var(--sheet-h, 45vh); border-radius: var(--r-panel); overflow: hidden;
    transition: height var(--t-panel) var(--ease);
  }
  .toasts { bottom: calc(var(--tabbar-h) + var(--sheet-h, 45vh) + 24px); }
}

/* ═══════════════════════════════════════════════ states layered on any workspace (design §2.3) */
/* Chrome off (H): everything hides and the state is kept; any key or tap brings it back */
.twin[data-chrome="off"] .region:not(.stage),
.twin[data-chrome="off"] .hint,
.twin[data-chrome="off"] .toasts,
.twin[data-chrome="off"] .hovercard,
.twin[data-chrome="off"] .popovers { visibility: hidden !important; opacity: 0 !important; pointer-events: none !important; }
.twin[data-chrome="off"] .stage-shade { opacity: 0; }

/* Present (P): all Work chrome hides; Present's own layer (shell.host('present')) draws on top */
.twin[data-present="on"] :is(.rail, .top, .toolstrip, .hint, .viewcube, .inspector, .tray, .drawer, .layers, .tabbar, .sheet) { visibility: hidden !important; opacity: 0 !important; pointer-events: none !important; }

/* Walk (V): the walk pill replaces the tool strip; the inspector is hidden (I brings it back); the tray is the time pill */
.twin[data-walk="on"]:not([data-insp-walk="on"]) .inspector { visibility: hidden; opacity: 0; pointer-events: none; }
.twin[data-walk="on"] .tray { right: auto; min-width: 280px; border-radius: var(--r-pill); }
.twin[data-walk="on"] .drawer, .twin[data-walk="on"] .layers { display: none; }

/* homeowner: the Build chip and every Work-only affordance are removed by ui/*.js; these are belt and braces */
.twin[data-role="homeowner"] .build-chip { display: none !important; }

/* booting: skeleton house chip, 2 px progress under it (design §8 HouseChip loading) */
.twin[data-booting="on"] .hint { opacity: 0; }

/* shell-owned hosts for full-screen layers (Present caption/recap, compare divider …): shell.host(name) */
.host { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.host > * { pointer-events: auto; }

/* Display › Reduce motion (this browser) does what the OS setting does */
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after {
  transition-duration: 0ms !important; animation-duration: 0ms !important; animation-iteration-count: 1 !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; animation-iteration-count: 1 !important; }
}
