/* Studio — live parametric massing configurator. Markup: index.html #studio; behaviour: js/studio*.js */

/* the Studio sits on raised slate (.surface-blueprint, css/tokens.css): a plain ground, no drafting grid */

.studio-app {
  --studio-stage: #172026; /* keep in sync with BG in js/studio-scene.js: the slate, one step below the section */
  --studio-panel: rgba(var(--ink2-rgb), 0.86);
  display: grid;
  grid-template-columns: minmax(0, 8fr) minmax(0, 4fr);
  gap: clamp(20px, 2.4vw, 40px);
  align-items: start;
  position: relative; /* holds the stuck-stage sentinel (js/studio-ui.js) */
}
.studio-app [hidden] { display: none !important; }
.studio-sentinel { position: absolute; top: 0; left: 0; width: 1px; height: 1px; pointer-events: none; }

/* ---------- stage ---------- */
.studio-stage {
  position: sticky;
  top: calc(var(--header-h) + 24px);
  width: 100%; /* without it min-height widens the 16/10 box past its grid track (over the parameters, ~1024–1100px) */
  aspect-ratio: 16 / 10;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background-color: var(--studio-stage);
}
.studio-stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; outline: none; }
.studio-stage > canvas:active { cursor: grabbing; }

/* registration crosshairs at the four corners of the sheet */
.studio-stage::after {
  --c: rgba(211, 226, 224, 0.7);
  content: "";
  position: absolute;
  inset: 10px;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(var(--c), var(--c)) left 0 top 7px / 15px 1px no-repeat,
    linear-gradient(var(--c), var(--c)) left 7px top 0 / 1px 15px no-repeat,
    linear-gradient(var(--c), var(--c)) right 0 top 7px / 15px 1px no-repeat,
    linear-gradient(var(--c), var(--c)) right 7px top 0 / 1px 15px no-repeat,
    linear-gradient(var(--c), var(--c)) left 0 bottom 7px / 15px 1px no-repeat,
    linear-gradient(var(--c), var(--c)) left 7px bottom 0 / 1px 15px no-repeat,
    linear-gradient(var(--c), var(--c)) right 0 bottom 7px / 15px 1px no-repeat,
    linear-gradient(var(--c), var(--c)) right 7px bottom 0 / 1px 15px no-repeat;
}

/* CSS2D layer and dimension tags */
.studio-labels { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; }
.studio-dim {
  padding: 3px 5px 2px;
  border: 1px solid rgba(211, 226, 224, 0.42);
  background: rgba(var(--ink2-rgb), 0.9);
  color: var(--off-white);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem); /* the 12 px floor */
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease);
}
.studio-dim.is-occluded { opacity: 0.45; }
.studio-dim--height { border-color: rgba(var(--on-rgb), 0.75); }
.studio-dim--setback { border-color: rgba(var(--amber-rgb), 0.55); color: var(--amber-soft); }
.studio-dim--north { padding: 0; border: 0; background: none; color: var(--amber); font-size: 12px; }

/* overlays */
.studio-views {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 3;
  display: flex;
  border: 1px solid var(--line-strong);
  background: var(--studio-panel);
}
.studio-views button {
  min-width: 40px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.studio-views button:first-child { border-left: 0; }
.studio-views button:hover { color: var(--fg); background: rgba(211, 226, 224, 0.08); }
.studio-views button[aria-pressed="true"] { background: var(--amber); color: var(--ink); }
.studio-views button:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.studio-views button[aria-pressed="true"]:focus-visible { outline-color: var(--ink); } /* white on amber is under 3:1 */
.studio-views .studio-zoom { padding: 0; font-size: 16px; letter-spacing: 0; }
.studio-views .studio-zoom[data-zoom="-1"] { border-left-color: var(--line-strong); }

.studio-hint {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 3;
  max-width: 46%;
  margin: 0;
  padding: 6px 9px;
  background: rgba(var(--ink2-rgb), 0.6);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-align: right;
  text-transform: uppercase;
  text-wrap: balance; /* two even lines, never a lone "ZOOM" (1024–1239 px) */
  pointer-events: none;
  transition: color var(--t-med) var(--ease), background var(--t-med) var(--ease);
}
.studio-hint.is-nudge { background: var(--amber); color: var(--ink); }

.studio-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  align-content: center;
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  pointer-events: none;
}
.studio-loading::after {
  content: "";
  width: 140px;
  height: 1px;
  margin-top: 14px;
  background: linear-gradient(90deg, transparent 0 30%, var(--amber) 30% 60%, transparent 60%) 0 0 / 200% 100%;
  animation: studio-scan 1.4s linear infinite;
}
@keyframes studio-scan { to { background-position: -200% 0; } }

.studio-fallback {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 32px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.6;
  text-align: center;
}
.studio-app.is-fallback { grid-template-columns: minmax(0, 1fr); }
.studio-app.is-fallback .studio-stage { position: relative; top: auto; aspect-ratio: auto; min-height: 240px; }

/* ---------- HUD: indicative area schedule ---------- */
.studio-hud {
  position: absolute;
  left: 22px;
  bottom: 22px;
  z-index: 3;
  width: min(390px, calc(100% - 44px));
  padding: 10px 12px 11px;
  border: 1px solid var(--line-strong);
  background: var(--studio-panel);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--fg);
  font-size: var(--fs-label, 0.75rem);
  line-height: 1.35;
  pointer-events: none;
}
.studio-hud-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.studio-hud-tag { color: var(--amber); }
/* columns weighted to their longest readings (site coverage · footprint/height · 2 + attic + B1), so none wraps over the canvas */
.studio-hud-grid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.85fr) minmax(0, 1.1fr); gap: 8px 14px; margin: 0; }
/* Each term/value pair takes two rows of the grid, so when a term wraps in a narrow column the terms of its row
   still sit on one line (bottom-aligned) and the values on the next. Without subgrid: one stacked pair per cell. */
.studio-hud-cell { display: grid; grid-row: span 2; grid-template-rows: subgrid; row-gap: 2px; min-width: 0; }
/* readouts on the canvas stay compact: dt 12px (the floor), dd 13px. They wrap rather than clip. */
.studio-hud dt { align-self: end; color: var(--muted); font-size: var(--fs-label, 0.75rem); letter-spacing: 0.1em; text-transform: uppercase; overflow-wrap: anywhere; }
.studio-hud dd { margin: 0; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.studio-hud-sun { display: flex; gap: 10px; margin: 9px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: var(--fs-label, 0.75rem); } /* a reading, at the 12 px floor */
.lang-zh .studio-hud-sun { word-break: keep-all; } /* breaks only at the · spaces, never inside 方位角 */
.studio-hud-k { flex: none; display: inline-flex; align-items: center; gap: 6px; color: var(--amber); font-size: var(--fs-label, 0.75rem); letter-spacing: 0.12em; text-transform: uppercase; }
.studio-hud-k::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }

/* ---------- parameters sheet ---------- */
.studio-controls {
  display: grid;
  align-content: start;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(var(--ink-rgb), 0.32);
  transition: opacity var(--t-med) var(--ease);
}
.studio-controls.is-disabled { opacity: 0.55; }
.studio-sheet-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.studio-sheet-head span:first-child { color: var(--fg); }
.studio-group { min-width: 0; margin: 0; padding: 16px 18px 20px; border: 0; border-bottom: 1px solid var(--line); }
.studio-legend {
  float: left; /* lets the legend sit in normal flow inside the fieldset */
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 14px;
  padding: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.studio-legend::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.studio-legend-no { color: var(--amber); }
.studio-group-body { clear: both; display: grid; gap: 16px; }

.studio-field { display: grid; gap: 4px; min-width: 0; }
.studio-field-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 24px; }
.studio-field-head label, .studio-field-label { color: var(--fg); font-size: var(--fs-sm); }
.studio-field-label { margin-bottom: 4px; }
.studio-out-wrap { display: inline-flex; align-items: center; gap: 8px; }
.studio-out { color: var(--amber-soft); font-family: var(--font-mono); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.studio-compass { width: 20px; height: 20px; flex: none; overflow: visible; }
.studio-compass circle { fill: none; stroke: var(--line-strong); stroke-width: 1; }
.studio-compass-n { stroke: var(--fg); stroke-width: 1.2; }
.studio-compass-needle { fill: var(--amber); }
.studio-help { margin: -4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; text-wrap: pretty; } /* "party walls." stays together */

/* range inputs: hairline track, amber fill, target thumb, tick marks */
.studio-range { --thumb: 18px; position: relative; }
.studio-range::before {
  content: "";
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  top: calc(50% + 6px);
  height: 6px;
  border-right: 1px solid var(--line-strong);
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 1px, transparent 1px calc(100% / var(--ticks, 10)));
  pointer-events: none;
}
.studio-range input[type="range"] {
  --track: rgba(211, 226, 224, 0.3);
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.studio-range input[type="range"]:focus-visible { outline: none; }
.studio-range input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--amber) 0 var(--fill, 0%), var(--track) var(--fill, 0%) 100%);
}
.studio-range input[type="range"]::-moz-range-track {
  height: 2px;
  background: linear-gradient(90deg, var(--amber) 0 var(--fill, 0%), var(--track) var(--fill, 0%) 100%);
}
.studio-range input[type="range"]::-webkit-slider-thumb {
  width: var(--thumb);
  height: var(--thumb);
  margin-top: -8px;
  border: 2px solid var(--amber);
  border-radius: 2px;
  background: var(--blueprint);
  box-shadow: inset 0 0 0 3px var(--blueprint), inset 0 0 0 9px var(--amber);
  transition: transform var(--t-fast) var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.studio-range input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--thumb);
  height: var(--thumb);
  border: 2px solid var(--amber);
  border-radius: 2px;
  background: var(--blueprint);
  box-shadow: inset 0 0 0 3px var(--blueprint), inset 0 0 0 9px var(--amber);
}
.studio-range input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.12); }
.studio-range input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--studio-stage), 0 0 0 5px #fff, inset 0 0 0 3px var(--blueprint), inset 0 0 0 9px var(--amber);
}
.studio-range input[type="range"]:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 3px var(--studio-stage), 0 0 0 5px #fff, inset 0 0 0 3px var(--blueprint), inset 0 0 0 9px var(--amber);
}
.studio-scale {
  display: flex;
  justify-content: space-between;
  margin-top: -6px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--fs-label, 0.75rem);
  letter-spacing: 0.06em;
}

/* The date and time fields lay out their own contents by their own width (sidebar, the tablet's three-up row, phones) */
.studio-field { container: studio-field / inline-size; }
/* five time labels need about 15.5rem to stay apart; below that the scale reads 07:00 · 13:00 · 19:00 */
@container studio-field (max-width: 15.49rem) {
  .studio-scale[data-scale="time"] > :nth-child(even) { display: none; }
}

/* segmented controls (radio groups) */
.studio-seg {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.studio-seg-item { position: relative; display: block; min-width: 0; }
.studio-seg-item + .studio-seg-item { border-left: 1px solid var(--line-strong); }
.studio-seg-item input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.studio-seg-face {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 6px 4px;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
  text-wrap: balance; /* a two-line option splits evenly (半独立 / 式洋房), never a lone 房 */
  pointer-events: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.studio-seg--compact .studio-seg-face { font-size: 12.5px; white-space: nowrap; }
/* The four dates go two by two when four across would crowd them; hanzi dates are wider, so Chinese switches sooner */
@container studio-field (max-width: 14.99rem) {
  .studio-seg--compact { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .studio-seg--compact .studio-seg-item:nth-child(3) { border-left: 0; }
  .studio-seg--compact .studio-seg-item:nth-child(n + 3) { border-top: 1px solid var(--line-strong); }
}
@container studio-field (max-width: 20.49rem) {
  .lang-zh .studio-seg--compact { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lang-zh .studio-seg--compact .studio-seg-item:nth-child(3) { border-left: 0; }
  .lang-zh .studio-seg--compact .studio-seg-item:nth-child(n + 3) { border-top: 1px solid var(--line-strong); }
}
.studio-seg-item input:hover + .studio-seg-face { background: rgba(211, 226, 224, 0.08); }
.studio-seg-item input:checked + .studio-seg-face { background: var(--amber); color: var(--ink); font-weight: 600; }
.studio-seg-item input:focus-visible + .studio-seg-face { outline: 2px solid #fff; outline-offset: -5px; }
.studio-seg-item input:checked:focus-visible + .studio-seg-face { outline-color: var(--ink); } /* the focused radio is the amber one */

/* switches */
.studio-toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.studio-switch { position: relative; display: flex; align-items: flex-start; gap: 10px; min-height: 44px; padding-top: 4px; cursor: pointer; }
.studio-switch input { position: absolute; top: 0; left: 0; width: 44px; height: 44px; margin: 0; opacity: 0; cursor: pointer;
  scroll-margin-bottom: 48px; } /* its label's second line too */
.studio-switch-track {
  position: relative;
  flex: none;
  width: 38px;
  height: 20px;
  margin-top: 1px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.studio-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  background: var(--muted);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.studio-switch input:checked + .studio-switch-track { border-color: var(--amber); background: rgba(var(--amber-rgb), 0.14); }
.studio-switch input:checked + .studio-switch-track::after { transform: translateX(18px); background: var(--amber); }
.studio-switch input:focus-visible + .studio-switch-track { outline: 2px solid var(--focus); outline-offset: 3px; }
.studio-switch-text { display: grid; gap: 2px; font-size: var(--fs-sm); line-height: 1.3; text-wrap: balance; } /* "Vertical fins / on the front" */
.studio-switch-text small { color: var(--muted); font-size: var(--fs-label, 0.75rem); }

/* actions */
.studio-actions { display: grid; gap: 10px; padding: 18px 18px 14px; }
.studio-attach { width: 100%; justify-content: space-between; text-align: left; }
.studio-reset { justify-self: start; }
.studio-status { min-height: 1.5em; margin: 0; padding: 0 18px 16px; color: var(--amber-soft); font-family: var(--font-mono); font-size: var(--fs-label, 0.75rem); }
.studio-status:empty { min-height: 0; padding-bottom: 0; }

/* a reading note, not a label: body face (the markup's .mono is overridden here) */
.studio-note { max-width: 90ch; margin: 20px 0 0; color: var(--muted); font-family: var(--font-body); font-size: 12px; line-height: 1.5; letter-spacing: 0; text-wrap: pretty; }

.lang-zh :is(.studio-legend, .studio-sheet-head, .studio-hud-head, .studio-hud-k, .studio-hud-sun, .studio-views button:not(.studio-zoom), .studio-hint, .studio-loading, .studio-status,
  .studio-help, .studio-note, .studio-switch-text small, .studio-seg-face) {
  font-size: var(--fs-label-zh, 0.8125rem);
  letter-spacing: 0.04em;
}
.lang-zh .studio-hud dt { font-size: var(--fs-label-zh, 0.8125rem); letter-spacing: 0.04em; }
.lang-zh .studio-hud :is(dt, dd) { word-break: keep-all; } /* a narrow term wraps at its bracket (总楼面面积 / （约）), not inside a word */
.lang-zh .studio-help { text-wrap: balance; } /* "除外。" never split to "外。" alone (1024 px) */
.lang-zh .studio-scale[data-scale="orientation"] { font-size: var(--fs-label-zh, 0.8125rem); letter-spacing: 0.04em; } /* 北 东 南 西 at the hanzi floor */
.lang-zh .studio-dim--north { font-size: var(--fs-label-zh, 0.8125rem); } /* 北 at the 13 px hanzi floor */

/* ---------- responsive ---------- */
@media (pointer: coarse) {
  .studio-views button { min-width: 44px; min-height: 44px; }
}

/* Phones and tablets: the stage stays in view above the controls, so every change is seen as it is made.
   It sits under the header while that is shown (the brief's progress strip does the same). The controls
   scroll under its opaque sheet; vertical swipes on the canvas still scroll the page (touch-action: pan-y). */
@media (max-width: 1023px) {
  .studio-app { grid-template-columns: minmax(0, 1fr); }
  html:has(.site-header:not(.is-hidden)) .studio-app { --studio-stick: var(--header-h); }
  .studio-stage { position: sticky; top: var(--studio-stick, 0px); z-index: 3; transition: top 240ms var(--ease); }
  /* While stuck the HUD is one row: GFA · height · levels (studio-ui.js toggles .is-stuck). Height reads short,
     so it gives width to the other two; on the narrowest phones a long term wraps onto a second line. */
  .studio-stage.is-stuck :is(.studio-hud-head, .studio-hud-sun, .studio-hint),
  .studio-stage.is-stuck .studio-hud-cell:not([data-k="gfa"], [data-k="height"], [data-k="storeys"]) { display: none; }
  .studio-stage.is-stuck .studio-hud { padding: 8px 12px 9px; }
  .studio-stage.is-stuck .studio-hud-grid { grid-template-columns: minmax(0, 1.3fr) minmax(0, 0.9fr) minmax(0, 1.3fr); gap: 0 14px; }
  .studio-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .studio-sheet-head, .studio-actions, .studio-status,
  .studio-group:first-of-type, .studio-group:last-of-type { grid-column: 1 / -1; }
  .studio-group:nth-of-type(2) { border-right: 1px solid var(--line); }
  .studio-group:last-of-type .studio-group-body { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px 28px; align-items: start; }
  .studio-actions { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .studio-attach { width: auto; }
}

@media (max-width: 720px) {
  .studio-controls { grid-template-columns: minmax(0, 1fr); }
  .studio-group:nth-of-type(2) { border-right: 0; }
  .studio-group:last-of-type .studio-group-body { grid-template-columns: minmax(0, 1fr); }
  .studio-actions { grid-template-columns: minmax(0, 1fr); }
  .studio-attach { width: 100%; }
}

/* Tablets: a shorter stage with the HUD still over the canvas */
@media (min-width: 640px) and (max-width: 1023px) {
  .studio-app { --stage-h: clamp(300px, 48svh, 520px); }
  .studio-stage { aspect-ratio: auto; min-height: 0; height: var(--stage-h); }
  /* a control reached with Tab never lands under the stuck stage */
  #studio-controls :is(input, button, select, label) { scroll-margin-top: calc(var(--stage-h) + var(--header-h) + 16px); }
}

@media (max-width: 639px) {
  /* on the app, not the stage, so the controls' scroll margin can use it too */
  .studio-app { --canvas-h: clamp(220px, 38svh, 340px); }
  .studio-views { top: 12px; left: 12px; }
  .studio-hint { top: calc(var(--canvas-h) - 42px); right: 12px; max-width: calc(100% - 24px); letter-spacing: 0.05em; }
  /* the stuck stage is the canvas plus a one-row HUD */
  #studio-controls :is(input, button, select, label) { scroll-margin-top: calc(var(--canvas-h) + 64px + var(--header-h)); }
  .studio-group { padding-inline: 16px; }
  .studio-actions { padding-inline: 16px; }
}
/* canvas at a set height, the HUD under it: phones, 1024–1239 px desktops (over a canvas this narrow the HUD would
   cover the house and its dimension tags, in Plan view too), short landscape */
@media (max-width: 639px), (min-width: 1024px) and (max-width: 1239.98px), (orientation: landscape) and (max-height: 500px) {
  .studio-stage { aspect-ratio: auto; min-height: 0; }
  .studio-stage > canvas { position: relative; height: var(--canvas-h); }
  .studio-stage::after { bottom: auto; height: calc(var(--canvas-h) - 20px); }
  .studio-loading { bottom: auto; height: var(--canvas-h); }
  .studio-hud {
    position: relative;
    left: auto;
    bottom: auto;
    width: auto;
    padding: 12px 14px 14px;
    border: 0;
    border-top: 1px solid var(--line-strong);
    background: rgba(var(--ink-rgb), 0.6);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media (min-width: 1024px) and (max-width: 1239.98px) { .studio-app { --canvas-h: min(418px, calc(100svh - 290px)); } }

@media (max-width: 400px) {
  .studio-hud-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* here a stuck term and value can each take two lines (a HUD of up to ~90px) */
  #studio-controls :is(input, button, select, label) { scroll-margin-top: calc(var(--canvas-h) + 100px + var(--header-h)); }
  .studio-toggles { grid-template-columns: minmax(0, 1fr); }
}

/* Short landscape (phones on their side, zoomed windows): a sticky stage would fill the screen, so it scrolls. */
@media (orientation: landscape) and (max-height: 500px) {
  .studio-stage { position: relative; top: auto; height: auto; }
  #studio-controls :is(input, button, select, label) { scroll-margin-top: calc(var(--header-h) + 16px); }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 640px) { .studio-app { --canvas-h: calc(100dvh - 18px); } }

/* Windows High Contrast: selected states and switch knobs keep a visible fill */
@media (forced-colors: active) {
  .studio-views button[aria-pressed="true"],
  .studio-seg-item input:checked + .studio-seg-face {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }
  /* and their focus rings (ink on Highlight is ~1.25:1) */
  .studio-seg-item input:focus-visible + .studio-seg-face, .studio-views button:focus-visible { outline-color: CanvasText; }
  .studio-seg-item input:checked:focus-visible + .studio-seg-face,
  .studio-views button[aria-pressed="true"]:focus-visible { outline-color: HighlightText; }
  .studio-range input[type="range"] { forced-color-adjust: auto; }
  /* forced colours drop gradient backgrounds, which are the whole track and the tick ruler: redraw them in system colours */
  .studio-range input[type="range"]::-webkit-slider-runnable-track { forced-color-adjust: none; background: linear-gradient(90deg, Highlight 0 var(--fill, 0%), CanvasText var(--fill, 0%) 100%); }
  .studio-range input[type="range"]::-moz-range-track { forced-color-adjust: none; background: linear-gradient(90deg, Highlight 0 var(--fill, 0%), CanvasText var(--fill, 0%) 100%); }
  .studio-range::before { forced-color-adjust: none; border-right-color: CanvasText; background: repeating-linear-gradient(90deg, CanvasText 0 1px, transparent 1px calc(100% / var(--ticks, 10))); }
  .studio-switch input:checked + .studio-switch-track { forced-color-adjust: none; background: Highlight; }
  .studio-switch-track::after { forced-color-adjust: none; background: CanvasText; }
  .studio-switch input:checked + .studio-switch-track::after { background: HighlightText; }
}
