/* Home Mapper Now - web UI, Lumen glass.
   The same look as the iPhone app (mobile/src/constants/theme.ts): graphite page, frosted-glass
   panels with a bright rim, silver ink and one icy-cyan accent. Dark is the designed look and the
   default whatever the OS says, as in the app; a frosted-silver light variant exists under
   [data-theme="light"], switched on from Options > Appearance (remembered per browser). The diagram sheet stays paper: it is a
   printable document, not chrome. Designed for a phone in one hand on a driveway, and for a
   desktop report bench. */

/* ---------- tokens ---------------------------------------------------------- */
:root {
  color-scheme: dark;

  --canvas: #090b0d;
  --canvas-well: #0f1215;          /* where the paper sheet rests */
  --surface: #14181c;
  --raised: #1d2227;
  --ink: #f3f6f7;
  --ink-2: #cbd3d8;
  --mute: #98a2a9;
  --line: rgba(255, 255, 255, .12);
  --line-2: rgba(255, 255, 255, .07);
  --fill: rgba(255, 255, 255, .06);    /* segmented track, quiet fills */
  --fill-2: rgba(255, 255, 255, .10);

  --accent: #8de8ee;
  --accent-text: #8de8ee;           /* the accent as small text */
  --on-accent: #04181a;
  --accent-soft: rgba(141, 232, 238, .15);
  --accent-line: rgba(141, 232, 238, .40);

  --danger: #ff7a70;
  --danger-soft: rgba(255, 122, 112, .13);
  --good: #6fe0a0;
  --good-soft: rgba(111, 224, 160, .13);
  --warn: #e5a76c;                  /* T-5 codes: the sheet's own finding brown, lifted for dark */
  --warn-soft: rgba(229, 167, 108, .11);
  --warn-line: rgba(229, 167, 108, .30);

  --glass: rgba(255, 255, 255, .075);
  --glass-edge: rgba(255, 255, 255, .20);   /* the bright rim of a glass panel */
  --glass-strong: rgba(26, 30, 34, .86);
  --blur: blur(22px) saturate(150%);
  --scrim: rgba(0, 0, 0, .6);
  --glow: 0 0 18px rgba(141, 232, 238, .28);   /* the one lit control */
  --bloom: rgba(152, 162, 169, .13);           /* the page's cool light, high up */
  --bloom-2: rgba(141, 232, 238, .10);         /* and a faint cyan low on the right */

  --shadow-float: 0 12px 40px rgba(0, 0, 0, .35);
  --shadow-paper: drop-shadow(0 12px 40px rgba(0, 0, 0, .45));
  --shadow-seg: 0 1px 2px rgba(0, 0, 0, .4);

  /* The diagram sheet and the outline editor are paper, not chrome: these stay
     fixed in every theme, because the sheet is a printable document. */
  --sheet: #fbfaf8;
  --rule: #d8d1c4;
  --wall: #1f4a68;
  --dim: #10314c;
  --front: #8a3b12;
  --paper-gold: #b8892a;
  --paper-ink: #1c1a17;
  --paper-mute: #55504a;

  /* Georgia first, as on the phone's hero text. */
  --font-display: Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --r-control: 14px;
  --r-small: 10px;
  --r-card: 24px;
  --r-sheet: 32px;
  --h-btn: 52px;
  --h-sm: 44px;
  --gutter: 16px;
  --header-h: 68px;
  --stick: calc(var(--header-h) + 16px);   /* where desk chrome sticks under the bar */
  --ease: cubic-bezier(.2, .7, .3, 1);
  --spring: cubic-bezier(.34, 1.3, .64, 1);
  --dur: 160ms;

  /* Older names still read by markup app.js builds (swatch ring, empty list). */
  --brand: var(--accent);
  --brand-soft: var(--accent-soft);
  --brand-line: var(--accent-line);
  --muted: var(--mute);
  --surface-2: var(--surface);
}

/* The frosted-silver variant (the app's light tokens). Nothing switches it on yet. */
:root[data-theme="light"] {
  color-scheme: light;
  --canvas: #e6ecef;
  --canvas-well: #dce4e8;
  --surface: #f6f9fa;
  --raised: #ffffff;
  --ink: #0e1417;
  --ink-2: #2f3a40;
  --mute: #5b676f;
  --line: rgba(14, 20, 23, .11);
  --line-2: rgba(14, 20, 23, .06);
  --fill: rgba(14, 20, 23, .05);
  --fill-2: rgba(14, 20, 23, .08);
  --accent: #0e7c86;
  --accent-text: #0b6870;
  --on-accent: #ffffff;
  --accent-soft: rgba(14, 124, 134, .12);
  --accent-line: rgba(14, 124, 134, .38);
  --danger: #c43a2f;
  --danger-soft: rgba(196, 58, 47, .10);
  --good: #23744a;
  --good-soft: rgba(35, 116, 74, .11);
  --warn: #8a4a12;
  --warn-soft: rgba(138, 74, 18, .09);
  --warn-line: rgba(138, 74, 18, .28);
  --glass: rgba(255, 255, 255, .55);
  --glass-edge: rgba(255, 255, 255, .9);
  --glass-strong: rgba(246, 249, 250, .88);
  --scrim: rgba(14, 20, 23, .32);
  --glow: 0 0 18px rgba(14, 124, 134, .22);
  --bloom: rgba(255, 255, 255, .55);
  --bloom-2: rgba(14, 124, 134, .14);
  --shadow-float: 0 1px 2px rgba(14, 20, 23, .05), 0 18px 44px -20px rgba(14, 20, 23, .30);
  --shadow-paper: drop-shadow(0 1px 1px rgba(14, 20, 23, .08)) drop-shadow(0 10px 22px rgba(14, 20, 23, .12));
  --shadow-seg: 0 1px 2px rgba(14, 20, 23, .08), 0 1px 1px rgba(14, 20, 23, .04);
}

/* ---------- base ------------------------------------------------------------ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body {
  margin: 0;
  background-color: var(--canvas);
  background-image:
    radial-gradient(ellipse 90% 50% at 50% 32%, var(--bloom), transparent 72%),
    radial-gradient(ellipse 70% 45% at 85% 80%, var(--bloom-2), transparent 72%);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; }
a { color: var(--accent-text); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.num, .rail-level, .ie-value, .north-read { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible { outline: none; }

.wrap { width: min(1600px, 100% - 40px); margin-inline: auto; }

/* ---------- buttons ---------------------------------------------------------
   Secondary is the default; the lit accent is kept for the one primary action a view has. */
.btn {
  min-height: var(--h-btn); padding: 0 20px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 16px/1.1 var(--font-ui); letter-spacing: -.005em;
  color: var(--ink); background: var(--glass);
  border: 1px solid var(--glass-edge); border-radius: 999px;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
              border-color var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:hover { background: var(--fill-2); border-color: var(--accent-line); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .4; cursor: default; pointer-events: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.btn-primary { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); box-shadow: var(--glow); }
.btn-primary:hover { background: var(--accent-soft); filter: brightness(1.12); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn-danger { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-quiet { /* links app.js builds (aerial / street view) */ }
.btn.is-on, .btn[aria-pressed="true"] {
  background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line);
}
.btn-sm { min-height: var(--h-sm); padding: 0 14px; font-size: 15px; border-radius: 999px; }
.btn.icon-only { padding: 0; width: var(--h-sm); }

/* ---------- inputs ---------------------------------------------------------- */
.input {
  width: 100%; min-height: var(--h-btn); padding: 0 20px;   /* a capsule curves in: keep the text clear of it */
  font: 400 16px/1.2 var(--font-ui); /* 16px stops iOS zooming on focus */
  color: var(--ink); background: var(--glass);
  border: 1px solid var(--glass-edge); border-radius: 999px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea.input { border-radius: var(--r-control); padding: 12px 14px; }
.input::placeholder { color: var(--mute); }
.input:focus, .input:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 0 0 1px var(--accent);
}

/* A checkbox drawn as a toggle; the element, its id and its change event are
   the same checkbox app.js has always listened to. */
.switch-input, .switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  width: 51px; height: 31px; border-radius: 999px; position: relative; cursor: pointer;
  background: var(--fill-2); border: 1px solid var(--line);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch-input::after, .switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25), 0 0 0 .5px rgba(0, 0, 0, .06);
  transition: transform 240ms var(--spring);
}
.switch-input:checked, .switch input:checked { background: var(--accent); border-color: transparent; }
.switch-input:checked::after, .switch input:checked::after { transform: translateX(20px); }
.switch-input:focus-visible, .switch input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch .track { display: none; }   /* the old painted track; the input is the toggle now */

/* A range slider, same on every engine. */
.slider {
  -webkit-appearance: none; appearance: none; background: transparent;
  flex: 1 1 120px; min-width: 100px; height: 32px; margin: 0; cursor: pointer;
}
.slider::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: var(--fill-2); }
.slider::-moz-range-track { height: 4px; border-radius: 4px; background: var(--fill-2); }
.slider::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--accent); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; margin-top: -11px; border-radius: 50%;
  background: #fff; border: .5px solid rgba(0, 0, 0, .08); box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
}
.slider::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; border: .5px solid rgba(0, 0, 0, .08); box-shadow: 0 2px 6px rgba(0, 0, 0, .22);
}
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 4px var(--accent); }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 4px var(--accent); }

/* Segmented control: sheet/edit, tabs, text size, the editor's tools. */
.seg {
  display: flex; gap: 2px; padding: 3px;
  background: var(--fill); border: 1px solid var(--line-2); border-radius: 999px;
}
.seg-item {
  flex: 1 1 auto; appearance: none; border: 0; background: transparent; cursor: pointer;
  min-height: 38px; padding: 0 14px; border-radius: 999px; white-space: nowrap;
  font: 500 14px/1 var(--font-ui); color: var(--mute);
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.seg-item:hover { color: var(--ink); }
.seg-item.is-on, .seg-item[aria-selected="true"], .seg-item[aria-checked="true"] {
  background: var(--accent-soft); color: var(--ink); font-weight: 650; box-shadow: inset 0 0 0 1px var(--accent);
}
.seg-item:focus-visible { outline-offset: -2px; }

/* ---------- app bar (glass chrome) ------------------------------------------ */
.appbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-edge);
}
.appbar .bar {
  width: min(1600px, 100% - 40px); margin-inline: auto; height: var(--header-h);
  display: flex; align-items: center; gap: 20px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent);
}
.brand .mark svg { width: 16px; height: 16px; }
.brand-name {
  font: 600 19px/1 var(--font-display); letter-spacing: -.01em; white-space: nowrap; color: var(--ink);
}
.search { flex: 1 1 auto; max-width: 660px; display: flex; gap: 8px; margin: 0 auto 0 12px; }
.input-shell { position: relative; flex: 1 1 auto; min-width: 0; display: flex; align-items: center; }
.input-shell svg {
  position: absolute; left: 14px; width: 18px; height: 18px; color: var(--mute); pointer-events: none;
}
#addr { min-height: 44px; padding-left: 40px; border-radius: 999px; background: var(--glass); }
#go { min-height: 44px; border-radius: 999px; padding: 0 22px; }
/* Once there is a sheet, the sheet's view owns the accent; Generate steps back. */
body.has-result #go { background: var(--glass); color: var(--ink); border-color: var(--glass-edge); box-shadow: none; }
body.has-result #go:hover { border-color: var(--accent-line); filter: none; }
/* An error state carries its own accent action; Generate steps back for it too. */
body:has(.status.err:not([hidden])) #go { background: var(--glass); color: var(--ink); border-color: var(--glass-edge); box-shadow: none; }
.stage-modes { flex: none; min-width: 168px; }
body:not(.has-result) .stage-modes { display: none; }

/* ---------- main ------------------------------------------------------------ */
.main { min-height: calc(100vh - var(--header-h) - 120px); }

/* ---------- empty, loading, error ------------------------------------------- */
.status {
  width: min(560px, 100% - 40px); margin: clamp(40px, 10vh, 120px) auto 40px;
  text-align: center;
}
.status h3 {
  font: 500 clamp(26px, 3.6vw, 34px)/1.15 var(--font-display); letter-spacing: -.015em; color: var(--ink);
}
.status p { margin: 10px auto 0; max-width: 46ch; color: var(--mute); font-size: 16px; }
.status .status-action { margin-top: 26px; min-width: 220px; }
.status:not([hidden]) ~ .landing { display: none; }
body.has-result .status { margin-top: 20px; margin-bottom: 8px; }
.status.warn {
  width: min(1600px, 100% - 40px); margin: 16px auto 0; text-align: left;
  padding: 14px 18px; border-radius: var(--r-control);
  background: var(--accent-soft); border: 1px solid var(--accent-line);
}
.status.warn p { margin: 0; max-width: none; color: var(--ink-2); font-size: 15px; }

/* A sheet-shaped shimmer: discreet, on surface, no cartoon spinner. */
.shimmer-sheet {
  position: relative; width: min(340px, 80%); aspect-ratio: 1000 / 760; margin: 0 auto 30px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--line); overflow: hidden;
  display: grid; align-content: center; justify-items: center; gap: 10px;
}
.shimmer-sheet span { display: block; height: 8px; border-radius: 4px; background: var(--fill-2); }
.shimmer-sheet span:nth-child(1) { width: 52%; height: 64px; border-radius: 6px; background: transparent; border: 2px solid var(--fill-2); }
.shimmer-sheet span:nth-child(2) { width: 44%; }
.shimmer-sheet span:nth-child(3) { width: 30%; }
.shimmer-sheet::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%, var(--accent-soft) 50%, transparent 80%);
  transform: translateX(-100%); animation: shimmer 1.6s var(--ease) infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---------- landing (the empty state before a lookup) ----------------------- */
.landing { width: min(960px, 100% - 40px); margin: 0 auto; padding-bottom: 72px; }
.empty { text-align: center; padding: clamp(56px, 13vh, 140px) 0 clamp(48px, 9vh, 96px); }
.display {
  font: 500 clamp(40px, 6vw, 56px)/1.04 var(--font-display); letter-spacing: -.025em; color: var(--ink);
}
.lede { margin: 18px auto 0; max-width: 44ch; color: var(--mute); font-size: 17px; line-height: 1.5; }
.landing-body { display: flex; flex-direction: column; gap: 0; }
.section { padding: 32px 0; border-top: 1px solid var(--line); }
.section-title { font: 600 20px/1.25 var(--font-display); letter-spacing: -.01em; margin-bottom: 16px; }
.prose { margin: 0; max-width: 68ch; color: var(--ink-2); font-size: 16px; line-height: 1.6; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px 36px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.step { display: grid; grid-template-columns: 36px 1fr; gap: 12px; }
.step .num { font: 500 28px/1 var(--font-display); color: var(--accent-text); }
.step h3 { font-size: 16px; font-weight: 600; margin: 2px 0 4px; }
.step p { margin: 0; font-size: 15px; color: var(--ink-2); line-height: 1.55; }
.two { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.note-card { border-radius: var(--r-card); padding: 20px; background: var(--surface); border: 1px solid var(--line); }
.note-card h3 { font-size: 16px; font-weight: 650; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.note-card h3::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.note-card.limit h3::before { background: var(--accent); }
.note-card ul { margin: 0; padding-left: 18px; font-size: 15px; color: var(--ink-2); }
.note-card li { margin-bottom: 6px; }
.fineprint { margin: 18px 0 0; font-size: 13px; color: var(--mute); max-width: 72ch; }

/* ---------- result: sheet left, tools right --------------------------------- */
.result {
  width: min(1600px, 100% - 40px); margin: 0 auto; padding: 16px 0 48px;
  display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 24px; align-items: start;
}
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Sheet toolbar: glass, floating over the paper as it scrolls. */
.toolbar {
  position: sticky; top: var(--stick); z-index: 20;
  display: flex; align-items: center; gap: 4px; padding: 5px;
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-float);
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-divider { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.rail-gap { flex: 1; }
.rail-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  min-height: 40px; min-width: 40px; padding: 0 12px; border-radius: 11px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 500 14px/1 var(--font-ui); white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.rail-btn.icon-only { padding: 0; }
.rail-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.rail-btn:hover { background: var(--fill); }
.rail-btn:active { transform: scale(.97); }
.rail-btn[disabled] { opacity: .35; cursor: default; pointer-events: none; }
.rail-level {
  min-width: 52px; text-align: center; font: 500 13px/1 var(--font-mono); color: var(--mute);
}
/* Small always-visible controls on the canvas itself, bottom-left: zoom on the sheet, turn and fit on
   the outline editor. Round glass buttons about the size of the phone's. */
.canvas-tools { position: absolute; left: 10px; bottom: 10px; z-index: 5; display: flex; align-items: center; gap: 6px; }
.draw-wrap { position: relative; }
.draw-host[hidden] + .canvas-tools { display: none; }
.mini-btn {
  appearance: none; cursor: pointer; color: var(--ink);
  min-width: 34px; height: 34px; padding: 0 6px; border-radius: 999px;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--line); box-shadow: var(--shadow-float);
  display: inline-flex; align-items: center; justify-content: center;
  font: 600 12px/1 var(--font-ui); -webkit-tap-highlight-color: transparent;
}
.canvas-tools .mini-btn svg { display: block; width: 17px; height: 17px; max-height: none; margin: 0; filter: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mini-btn:hover { background: var(--fill); }
.mini-btn[disabled] { opacity: .35; cursor: default; pointer-events: none; }
.mini-level {
  font: 500 12px/1 var(--font-mono); color: var(--ink); min-width: 44px; text-align: center; padding: 8px 6px;
  border-radius: 999px; background: var(--glass-strong); border: 1px solid var(--line);
}
/* In Edit, the zoom/print rail belongs to the sheet that is not on screen. */
.result:has(#drawHost:not([hidden])) .toolbar { display: none; }

.sheet {
  position: relative; background: var(--canvas-well);
  border: 1px solid var(--line-2); border-radius: var(--r-card);
  overflow: hidden; overflow: clip;   /* clip, so the edit toolbar can still stick */
}
.sheet-body {
  position: relative; padding: 28px;
  max-height: calc(100vh - var(--header-h) - 96px);
}
/* The zoom/pan frame: a fixed box the same size "Fit" always was: its own
   layout size never changes with zoom (a CSS transform paints outside the
   box without resizing it), so overflow:hidden clips a zoomed-in sheet
   exactly at the old fitted edge. touch-action:none hands pinch/pan/double-
   tap to our own JS instead of the browser's page-zoom or scroll. */
.sheet-viewport {
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; touch-action: none; cursor: grab; border-radius: inherit;
}
.sheet-viewport.panning { cursor: grabbing; }
.sheet-body.placing .sheet-viewport { cursor: crosshair; }
.sheet-body svg {
  display: block; width: 100%; height: auto; margin: 0 auto;
  max-height: calc(100vh - var(--header-h) - 152px);
  filter: var(--shadow-paper);
}
.sheet-viewport svg { transform-origin: 50% 50%; will-change: transform; }
.result.is-busy .sheet-body::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; z-index: 2;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: progress 1.1s var(--ease) infinite;
}
@keyframes progress { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.sheet-body.placing, .sheet-body.placing svg { cursor: crosshair; }
.sheet-body.placing::after {
  content: "Tap the diagram to place it";
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); white-space: nowrap;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  color: var(--ink); border: 1px solid var(--accent-line);
  font: 600 14px/1 var(--font-ui); padding: 11px 16px; border-radius: 999px; pointer-events: none;
  box-shadow: var(--shadow-float);
}

/* ---------- edit mode ------------------------------------------------------- */
.edit-tools {
  position: sticky; top: var(--header-h); z-index: 15;
  display: flex; flex-direction: column; gap: 10px; padding: 12px;
  /* Over the paper canvas as the page scrolls: mostly opaque, or the tools read as a smear on white. */
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--line);
}
.tool-seg { overflow-x: auto; scrollbar-width: none; }
.tool-seg::-webkit-scrollbar { display: none; }
.north-row { display: flex; align-items: center; gap: 14px; padding: 0 6px; }
.sub-seg { margin-top: 6px; }
.profile-id { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
.profile-id code { font: 500 12px var(--font-mono); color: var(--ink); }
/* The Buildings list under Shape. */
.buildings { display: grid; gap: 8px; padding: 10px 6px 0; }
.buildings[hidden] { display: none; }
.buildings-head { font: 600 13px var(--font-ui); color: var(--mute); }
.buildings-list { display: grid; gap: 8px; }
.b-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; padding: 8px; border: 1px solid var(--rule); border-radius: 12px; }
.b-row.is-active { border-color: var(--accent-text, #c8a15a); }
.b-pick { appearance: none; border: 0; background: none; text-align: left; cursor: pointer; display: grid; gap: 2px; color: inherit; font: inherit; padding: 0; }
.b-pick small { color: var(--mute); }
.b-kind { grid-column: 1 / -1; }
.b-kind .seg-item { min-height: 34px; padding: 0 8px; }
.b-turn { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.b-turn .btn { min-height: 34px; padding: 0 10px; }
.cut-row { display: flex; gap: 6px; padding: 6px 6px 0; }
.nudge-row { flex-wrap: wrap; align-items: center; }
.nudge-label { font: 600 13px var(--font-ui); color: var(--accent-text); min-width: 7.5em; }
.eb-inline { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.eb-inline[hidden] { display: none; }
.picker-kinds { margin: 4px 0 2px; }
.picker-kinds .seg-item { flex: 1 1 0; min-width: 0; padding: 0 4px; text-align: center; }
.opt-group .seg .seg-item { padding: 0 6px; min-width: 0; }
.north-label { font-size: 14px; color: var(--mute); white-space: nowrap; }
.north-read { min-width: 132px; font-size: 14px; font-weight: 600; color: var(--ink); }
.draw-hint { margin: 0; padding: 0 6px; font-size: 14px; color: var(--mute); }

.draw-host {
  position: relative; height: calc(100vh - var(--header-h) - 260px); min-height: 420px;
  background: var(--sheet); overflow: hidden; touch-action: none;
}
.edit-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 12px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.eb-group { display: flex; flex-wrap: wrap; gap: 6px; }
.eb-primary { margin-left: auto; min-width: 200px; }
#drawPorch.is-on { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-line); }

/* The outline editor draws on paper, which keeps its light colour in both
   themes, so its handles use fixed paper colours - never chrome tokens. */
.draw-canvas { display: block; cursor: crosshair; }
.draw-grid line { stroke: var(--rule); stroke-width: .7; opacity: .55; }
.draw-shape { fill: rgba(139, 174, 200, .16); stroke: var(--wall); stroke-width: 2.4; stroke-linejoin: miter; }
.draw-shape.closed { fill: rgba(139, 174, 200, .26); }
.draw-shape.porch { stroke-dasharray: 7 4; }
.draw-shape.garage, .draw-shape.closed.garage { fill: rgba(235, 228, 211, .78); }
.draw-shape.live { stroke-width: 2.8; }
.draw-shape:not(.live) { stroke-opacity: .55; }
.draw-cut-start { fill: var(--front); stroke: #fff; stroke-width: 2; }
.draw-cut-preview { stroke: var(--front); stroke-width: 2.4; stroke-dasharray: 6 5; stroke-linecap: round; }
/* A wall's length sits on a small chip beside the wall, the same as on the sheet. */
.draw-dim-chip { fill: var(--sheet); fill-opacity: .95; stroke: var(--rule, #c9c2b6); stroke-width: .6; pointer-events: none; }
.draw-dim {
  font: 500 10.5px var(--font-ui); fill: var(--dim); text-anchor: middle; pointer-events: none;
}
/* One family of handles, the same as the phone: a corner is a white dot with a teal ring, a wall's middle a
   smaller solid teal dot, both with a soft shadow. The circle that is drawn takes no touches; the invisible
   .draw-hit circle over it is the 44 px target. */
.draw-node { fill: #fff; stroke: #0e7c86; stroke-width: 2.5; pointer-events: none; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .35)); }
.draw-node.first { stroke: var(--front); }
.draw-node.sel { fill: #0e7c86; stroke: #fff; stroke-width: 3; }
.draw-hit:focus-visible { outline: 3px solid var(--accent-text); outline-offset: 1px; }
.draw-node.quiet { stroke-opacity: .5; }
.draw-hit { fill: rgba(255, 255, 255, .001); stroke: none; cursor: grab; }
.draw-hit:active { cursor: grabbing; }
.draw-area {
  font: 500 11px var(--font-ui); fill: var(--paper-mute); text-anchor: middle;
  paint-order: stroke; stroke: var(--sheet); stroke-width: 3px;
}
.draw-wall { fill: #0e7c86; stroke: #fff; stroke-width: 2; pointer-events: none; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .35)); }
.draw-wall.quiet { opacity: .45; }
.draw-wall.front { fill: #c0392b; stroke: #fff; }
.draw-front { stroke: #c0392b; stroke-width: 4; stroke-linecap: round; } /* the front side is red, as on the sheet */
.draw-front-label {
  fill: #c0392b; font: 600 10px/1 var(--font-ui); letter-spacing: .08em; text-anchor: middle; cursor: grab;
}
.draw-front-grab { fill: transparent; cursor: grab; }
.draw-front-grab:active { cursor: grabbing; }
.draw-label { fill: var(--paper-ink); font: 600 13px/1 var(--font-ui); text-anchor: middle; cursor: grab; }
.draw-label-grab { fill: rgba(184, 137, 42, .001); cursor: grab; }

/* ---------- item editor: a sheet over the drawing --------------------------- */
/* On a desk it slides in over the tool panel, so the whole drawing stays
   clear for dragging; on a phone it is a bottom sheet (see below). */
.item-editor {
  position: fixed; z-index: 35;
  top: var(--stick); right: calc((100% - min(1600px, 100% - 40px)) / 2);
  width: 400px; max-height: calc(100vh - var(--stick) - 16px); overflow: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 14px; padding: 10px 22px 22px;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--line); border-radius: var(--r-sheet); box-shadow: var(--shadow-float);
  animation: sheet-in 240ms var(--ease);
}
@keyframes sheet-in { from { opacity: 0; transform: translateX(16px); } }
.grabber { display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--fill-2); margin: 0 auto 2px; }
.item-editor .grabber { display: none; }
.ie-head { display: flex; align-items: center; gap: 12px; padding-top: 8px; }
.ie-title { flex: 1; font: 600 20px/1.2 var(--font-display); letter-spacing: -.01em; }
.ie-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ie-stack { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; }
.ie-label { font-size: 13px; color: var(--mute); min-width: 44px; }
.ie-value { min-width: 54px; text-align: right; font: 500 14px/1 var(--font-mono); color: var(--ink); }
.code-grid.ie-code-grid { flex: none; align-content: start; grid-auto-rows: min-content; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
.ie-code-grid .code-btn { min-height: 44px; padding: 6px 9px; }
.ie-code-grid .code-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ie-swatches { flex: 1 1 200px; display: flex; gap: 8px; flex-wrap: wrap; }
.ie-swatch {
  width: 32px; height: 32px; border-radius: 50%; padding: 0; cursor: pointer;
  border: 1px solid rgba(0, 0, 0, .12);
  transition: transform var(--dur) var(--ease);
}
.ie-swatch:hover { transform: scale(1.08); }
.ie-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--raised), 0 0 0 4px var(--accent) !important; }
.ie-swatch-default {
  background: var(--raised); color: var(--mute); font-size: 16px; display: grid; place-items: center;
  border: 1px dashed var(--mute);
}
.ie-foot { justify-content: space-between; border-top: 1px solid var(--line-2); padding-top: 12px; }

/* The Bold switch - a button with aria-pressed, drawn as a toggle. */
.toggle-btn {
  appearance: none; border: 0; background: transparent; color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; gap: 12px; min-height: var(--h-sm); padding: 0;
  font: 500 16px/1 var(--font-ui);
}
.toggle-track {
  width: 51px; height: 31px; border-radius: 999px; position: relative; flex: none;
  background: var(--fill-2); border: 1px solid var(--line);
  transition: background var(--dur) var(--ease);
}
.toggle-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform 240ms var(--spring);
}
.toggle-btn[aria-pressed="true"] .toggle-track { background: var(--accent); border-color: transparent; }
.toggle-btn[aria-pressed="true"] .toggle-track::after { transform: translateX(20px); }

/* ---------- panel ----------------------------------------------------------- */
.panel {
  position: sticky; top: var(--stick);
  max-height: calc(100vh - var(--stick) - 16px); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  scrollbar-width: thin;
}
.panel-head { padding: 22px 22px 18px; }
.panel-title { font: 500 24px/1.2 var(--font-display); letter-spacing: -.015em; color: var(--ink); }
.metrics { display: flex; gap: 28px; margin-top: 16px; }
.metrics:empty { display: none; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric-label { font-size: 13px; color: var(--mute); }
.metric-value { font: 500 24px/1.15 var(--font-display); font-variant-numeric: tabular-nums lining-nums; color: var(--ink); }
.metric-value small { font: 400 14px var(--font-ui); color: var(--mute); }

.tabs { margin: 0 16px; }
.tabs .tab { padding: 0 8px; font-size: 14px; }
.tabpane { padding: 16px 22px 20px; }
.tabpane > :first-child { margin-top: 0; }
.pane-section { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line-2); }
.pane-title { font: 600 17px/1.3 var(--font-ui); color: var(--ink); margin: 0 0 4px; }
.hint { font-size: 14px; color: var(--mute); margin: 8px 0 0; line-height: 1.45; }
.hint:empty { display: none; }

.views { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.views .btn { min-height: var(--h-sm); font-size: 15px; flex: 1 1 auto; border-radius: 12px; }
.views .views-note { flex: 1 1 100%; margin: 2px 0 0; font-size: 13px; }

.struct {
  margin-top: 12px; padding: 16px; border-radius: var(--r-control);
  background: var(--raised); border: 1px solid var(--line);
}
.struct.off { opacity: .6; }
.struct.off h3 { text-decoration: line-through; text-decoration-color: var(--mute); }
.struct-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.struct-top h3 { flex: 1; font-size: 16px; font-weight: 600; }
.tag {
  font: 600 13px/1 var(--font-ui); font-variant-numeric: tabular-nums; white-space: nowrap;
  padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text);
}
.tag.res { background: var(--good-soft); color: var(--good); }
.added-tag {
  margin-left: 6px; padding: 3px 8px; border-radius: 999px; vertical-align: middle;
  background: var(--accent-soft); color: var(--accent-text); font: 600 12px/1 var(--font-ui);
}
.facts { display: flex; gap: 28px; margin-top: 12px; }
.fact b { display: block; font: 500 22px/1.1 var(--font-display); font-variant-numeric: tabular-nums lining-nums; }
.fact span { font-size: 13px; color: var(--mute); }
.struct .switch, .nearby-row {
  display: flex; align-items: center; gap: 12px; margin-top: 12px; min-height: var(--h-sm);
  cursor: pointer; font-size: 15px; color: var(--ink-2);
}
.struct .switch, .nearby-row { flex-direction: row-reverse; justify-content: space-between; }

details.more { margin-top: 12px; }
details.more summary {
  cursor: pointer; list-style: none; min-height: var(--h-sm);
  display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--accent-text);
}
details.more summary::-webkit-details-marker { display: none; }
details.more summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform var(--dur) var(--ease); margin-right: 2px;
}
details.more[open] summary::before { transform: rotate(45deg); }
.scroller { max-height: 260px; overflow-y: auto; }
table.walls { width: 100%; border-collapse: collapse; font-size: 14px; }
table.walls th, table.walls td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line-2); }
table.walls th { font-size: 13px; font-weight: 500; color: var(--mute); position: sticky; top: 0; background: var(--raised); }
table.walls td.n { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 13px; }

.evidence { padding: 16px; border-radius: var(--r-control); background: var(--raised); border: 1px solid var(--line); }
.tier-row { margin-bottom: 10px; }
.tier {
  display: inline-block; font: 600 13px/1 var(--font-ui); padding: 7px 11px; border-radius: 999px;
  background: var(--good-soft); color: var(--good);
}
.tier.approx { background: var(--accent-soft); color: var(--accent-text); }
.evidence p { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); }
.evidence p:last-child { margin-bottom: 0; }
.evidence .caveat { color: var(--warn); font-weight: 600; }
ul.reasons { margin: 0; padding-left: 18px; font-size: 14px; color: var(--ink-2); }
ul.reasons li { margin-bottom: 6px; }

/* Findings */
.code-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin: 14px 0; }
.code-btn {
  font: inherit; text-align: left; cursor: pointer; padding: 10px 11px; min-height: 52px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 12px; color: var(--ink);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.code-btn:hover { border-color: var(--warn-line); }
.code-btn:active { transform: scale(.97); }
.code-btn b { display: block; font: 700 15px/1.2 var(--font-mono); color: var(--warn); }
.code-btn span { display: block; font-size: 12px; line-height: 1.3; color: var(--mute); margin-top: 2px; }
.code-btn[aria-pressed="true"] { background: var(--warn-soft); border-color: var(--warn); }
.inline-field { display: flex; gap: 8px; margin-bottom: 8px; }
.inline-field .input { min-height: var(--h-sm); border-radius: 12px; }
#noteInput { min-height: var(--h-sm); border-radius: 12px; }

.finding-list { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.finding-list li {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 12px 12px 14px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 12px; font-size: 14px;
}
.finding-list .idx {
  width: 24px; height: 24px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--warn); color: var(--canvas); font: 700 12px/1 var(--font-ui); font-variant-numeric: tabular-nums;
}
.finding-list .body { flex: 1; min-width: 0; color: var(--ink-2); }
.finding-list .body b { font-family: var(--font-mono); color: var(--warn); }
.finding-list .body em { font-style: normal; color: var(--mute); display: block; font-size: 13px; margin-top: 2px; }
.icon-btn {
  flex: none; border: 0; background: none; cursor: pointer; color: var(--mute); font-size: 20px; line-height: 1;
  width: 36px; height: 36px; margin: -6px -4px -6px 0; border-radius: 10px;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }

#labelBtn { margin-top: 12px; }
.label-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 4px 0 14px; min-height: 40px;
  border-radius: 999px; background: var(--raised); border: 1px solid var(--line); font-size: 15px; color: var(--ink);
}
.chip .x {
  border: 0; background: transparent; color: var(--mute); cursor: pointer; font-size: 18px; line-height: 1;
  width: 32px; height: 32px; border-radius: 50%;
}
.chip .x:hover { background: var(--danger-soft); color: var(--danger); }

/* Options (tab and the Sheet section) */
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; padding: 10px 0; cursor: pointer; border-bottom: 1px solid var(--line-2);
}
.opt-text { display: flex; flex-direction: column; gap: 2px; }
.opt-text b { font-weight: 500; font-size: 16px; color: var(--ink); }
.opt-text small { font-size: 13px; color: var(--mute); line-height: 1.35; }
.opt-group { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; }
.opt-title { font-size: 16px; font-weight: 500; color: var(--ink); }
.opt-note { font-size: 13px; color: var(--mute); }
.slider-row { display: flex; align-items: center; gap: 12px; }
.sheet-options { padding: 18px 22px 6px; border-top: 1px solid var(--line); }
.sheet-options .pane-title, .exports-wrap .pane-title { margin-bottom: 4px; }
.chk-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chk {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px 0 10px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--raised);
  font-size: 14px; color: var(--ink-2); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chk input {
  appearance: none; -webkit-appearance: none; margin: 0; width: 18px; height: 18px; flex: none; cursor: pointer;
  border-radius: 50%; border: 1.5px solid var(--mute); display: grid; place-items: center;
}
.chk input:checked { background: var(--accent); border-color: var(--accent); }
.chk input:checked::after {
  content: ""; width: 5px; height: 9px; margin-top: -2px;
  border-right: 2px solid var(--on-accent); border-bottom: 2px solid var(--on-accent); transform: rotate(45deg);
}
.chk:has(input:checked) { background: var(--accent-soft); border-color: var(--accent-line); color: var(--ink); }
.chk:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.chk input:focus-visible { outline: none; }

.exports-wrap { padding: 18px 22px 22px; border-top: 1px solid var(--line); }
.exports { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.exports .btn { padding: 0 6px; font-size: 14px; }

code { font-family: var(--font-mono); font-size: .9em; background: var(--fill); padding: 1px 5px; border-radius: 5px; }

/* ---------- footer ---------------------------------------------------------- */
footer.foot { border-top: 1px solid var(--line); padding: 24px 0 40px; font-size: 13px; color: var(--mute); }
footer.foot p { margin: 0 0 4px; }

/* ---------- export preview -------------------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--scrim);
  animation: fade-in 200ms var(--ease);
}
@keyframes fade-in { from { opacity: 0; } }
.modal-card {
  display: flex; flex-direction: column; width: min(1120px, 100%); max-height: 92vh; overflow: hidden;
  background: var(--canvas-well); border: 1px solid var(--line); border-radius: var(--r-sheet);
  box-shadow: var(--shadow-float);
}
.modal-head, .modal-foot {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px 12px 24px;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.modal-head { border-bottom: 1px solid var(--line); }
.modal-head h2 { flex: 1; font: 500 22px/1.2 var(--font-display); letter-spacing: -.01em; }
.modal-foot { border-top: 1px solid var(--line); flex-wrap: wrap; padding: 12px 16px; }
.modal .hint { margin: 0; padding: 12px 24px 0; }
.modal-body { flex: 1; overflow: auto; padding: 20px 24px 24px; }
.modal-body svg { display: block; width: 100%; height: auto; filter: var(--shadow-paper); }

/* ---------- dialog: in-page prompt, alert and choice ------------------------ */
.dialog-layer {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: var(--scrim);
  animation: fade-in 180ms var(--ease);
}
.dialog {
  width: min(440px, 100%); max-height: calc(100vh - 40px); overflow: auto;
  padding: 14px 24px 24px; display: flex; flex-direction: column; gap: 10px;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--line); border-radius: var(--r-sheet); box-shadow: var(--shadow-float);
  animation: dialog-in 260ms var(--spring);
}
@keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.dialog .grabber { visibility: hidden; margin-bottom: 4px; }
.dialog-title { font: 500 24px/1.2 var(--font-display); letter-spacing: -.015em; color: var(--ink); }
.dialog-msg { margin: 0; font-size: 15px; color: var(--mute); }
.dialog-field { margin-top: 6px; }
.dialog-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.dialog-actions .btn { width: 100%; }
.dialog-actions.is-row { flex-direction: row; }
.dialog-actions.is-row .btn { flex: 1; }
body.dialog-open { overflow: hidden; }

/* ---------- motion ---------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .btn:active, .rail-btn:active, .code-btn:active, .ie-swatch:hover { transform: none; }
  .shimmer-sheet::after, .result.is-busy .sheet-body::before { display: none; }
  .dialog, .item-editor { animation: fade-in 1ms; }
}

/* ---------- narrower desks: panel slims ------------------------------------- */
@media (max-width: 1180px) {
  .result { grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; }
  .item-editor { width: 360px; }
  .rail-btn span { display: none; }
  .rail-btn:not(.icon-only) { padding: 0 11px; }
  #zoomFit { font-size: 14px; }
}

/* ---------- phone and tablet: one column, sheet first ----------------------- */
@media (max-width: 959px) {
  :root { --gutter: 16px; }
  /* The header scrolls away; only the sheet's own toolbar stays, so nothing
     sticky sits on top of the controls below it. */
  .appbar { position: static; }
  .appbar .bar {
    width: auto; height: auto; padding: 12px var(--gutter) 14px; padding-top: max(12px, env(safe-area-inset-top));
    flex-wrap: wrap; gap: 12px;
  }
  .brand { flex: 1; }
  .stage-modes { min-width: 0; }
  .stage-modes .seg-item { min-height: 36px; padding: 0 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  #addr, #go { min-height: var(--h-btn); border-radius: var(--r-control); }

  .result {
    width: 100%; padding: 12px 0 32px; display: flex; flex-direction: column; align-items: stretch; gap: 16px;
  }
  .stage { gap: 10px; }
  .toolbar {
    top: 0; margin: 0; border-radius: 0; border-left: 0; border-right: 0; box-shadow: none;
    gap: 0; justify-content: space-between;
    overflow-x: auto; scrollbar-width: none; padding-top: max(5px, env(safe-area-inset-top));
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .rail-btn { min-height: var(--h-sm); min-width: var(--h-sm); flex: none; }
  .rail-btn span { display: none; }
  #undoBtn span { display: inline; }
  .rail-btn:not(.icon-only) { padding: 0 10px; }
  .sheet { border-radius: 0; border-left: 0; border-right: 0; }
  .sheet-body { padding: 14px; max-height: 78vh; }
  .sheet-body svg { max-height: none; }
  .edit-tools { top: 0; padding: 10px var(--gutter); padding-top: max(10px, env(safe-area-inset-top)); }
  .tool-seg .seg-item { min-height: var(--h-sm); flex: none; }
  .draw-host { height: 62vh; min-height: 340px; }
  .edit-bar { padding: 12px var(--gutter) 16px; }
  .eb-group { width: 100%; }
  .eb-primary { width: 100%; margin: 4px 0 0; min-height: var(--h-btn); }

  /* The item editor becomes a real bottom sheet. */
  .item-editor {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: auto; z-index: 60;
    max-height: 58vh; border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-bottom: 0;
    padding: 10px var(--gutter) max(20px, env(safe-area-inset-bottom));
    animation: sheet-up 280ms var(--ease);
  }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
  /* Room to scroll the marker being edited up above the sheet. */
  body:has(#itemEditor:not([hidden])) { padding-bottom: 58vh; }
  .item-editor .grabber { display: block; }
  .item-editor .ie-head { padding-top: 0; }

  .panel {
    position: static; max-height: none; overflow: visible;
    margin: 0 var(--gutter); border-radius: var(--r-card);
  }
  .panel-head { padding: 20px 18px 14px; }
  .tabs { margin: 0 12px; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs .tab { min-height: var(--h-sm); }
  .seg-btn, .seg-item { min-height: var(--h-sm); }
  .nudge-row .btn { min-height: var(--h-sm); }
  .tabpane { padding: 16px 18px 20px; }
  .sheet-options, .exports-wrap { padding-left: 18px; padding-right: 18px; }

  .dialog-layer { align-items: flex-end; padding: 0; }
  .dialog {
    width: 100%; max-height: 88vh; border-radius: var(--r-sheet) var(--r-sheet) 0 0; border-bottom: 0;
    padding: 10px 20px max(20px, env(safe-area-inset-bottom));
    animation: sheet-up 280ms var(--ease);
  }
  .dialog .grabber { visibility: visible; }
  .dialog-actions .btn { min-height: var(--h-btn); }

  .modal { padding: 0; align-items: flex-end; }
  .modal-card { max-height: 94vh; border-radius: var(--r-sheet) var(--r-sheet) 0 0; }
  .modal-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1 1 auto; }

  .landing { width: auto; padding: 0 var(--gutter) 56px; }
}

@media (max-width: 520px) {
  .display { font-size: 38px; }
  .lede { font-size: 16px; }
  .brand-name { font-size: 18px; }
  .exports { grid-template-columns: repeat(3, 1fr); }
  .steps { grid-template-columns: 1fr; }
  #undoBtn span, .tb-divider, .rail-gap { display: none; }
  .metrics { gap: 22px; }
  .north-row { flex-wrap: wrap; gap: 6px 12px; }
  .north-read { min-width: 0; }
}

/* ---------- print: the sheet and nothing else ------------------------------- */
@media print {
  .appbar, .toolbar, .landing, footer.foot, .panel, .status, .edit-tools, .edit-bar,
  .item-editor, .dialog-layer, .modal-head, .modal-foot, .modal .hint, .draw-host, .canvas-tools { display: none !important; }
  body { background: #fff; background-image: none; }
  .result { display: block; width: auto; padding: 0; }
  .sheet { border: 0; background: none; border-radius: 0; }
  .sheet-body { padding: 0; max-height: none !important; overflow: visible !important; }
  .sheet-body::before, .sheet-body::after { display: none !important; }
  /* Zoom is a screen convenience; a print is the sheet at its own size. */
  .sheet-viewport { overflow: visible !important; }
  .sheet-body svg { transform: none !important; max-height: none; filter: none; }

  /* When the preview is open, it is the thing being printed. */
  .modal { position: static; inset: auto; padding: 0; background: none; display: block; animation: none; }
  .modal-card { max-height: none; width: 100%; border: 0; border-radius: 0; box-shadow: none; background: none; }
  .modal-body { overflow: visible; padding: 0; }
  .modal-body svg { filter: none; }
  body:has(.modal:not([hidden])) .result { display: none !important; }

  @page { margin: 10mm; }
}
