/* Responsive layer for the buyer page. Loads after styles.css; the design language (ivory, forest, oxblood, Cormorant + Hanken)
   stays in styles.css. Checked by tools/check-responsive.mjs at 12 viewports.
   Breakpoints: 1100 header becomes one row | 760 phone (bottom sheet, sideways building) | max-height 500 landscape phone | 1800 / 2400 large screens. */

:root {
  --pad: clamp(16px, 4vw, 64px);
  --pad-l: max(var(--pad), env(safe-area-inset-left, 0px));
  --pad-r: max(var(--pad), env(safe-area-inset-right, 0px));
  --bar-h: 58px;                                        /* the compact header; landscape phones size the building from it */
  --stage-h-phone: max(clamp(360px, 62svh, 560px), var(--stage-h-tap, 0px));   /* how tall the building is on a phone (taller for a tower, so each home stays 46 px); its width follows the ratio */
  --w: min(2240px, max(720px, calc((100svh - 250px) * var(--ar))));   /* a 2560 screen gets a 2100 px building, not a 1400 px one; a laptop sees the whole building */
}

/* ---------- every size ---------- */
main { padding-inline: var(--pad-l) var(--pad-r); }
.bar { padding-inline: var(--pad-l) var(--pad-r); }
.foot { padding-inline: var(--pad-l) var(--pad-r); }
.brand { flex: 0 1 auto; }
.brand-meta { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.35; }
.tally-note, .facts-line { display: none; }
.intro h1 { font-size: clamp(36px, 3.6vw, 80px); }
.panel-inner { padding: 0 max(24px, env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) 24px; }
/* the title row stays put (scroll-padding keeps focused and scrolled-to controls from sliding under it) */
.panel { scroll-padding-top: calc(80px + env(safe-area-inset-top, 0px)); scroll-padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }   /* anything scrolled or tabbed into view stops above the sticky enquire bar */
/* the title row stays put while the panel scrolls, so Close is always in reach */
.panel-top {
  position: sticky; top: 0; z-index: 3; background: var(--paper);
  padding: calc(16px + env(safe-area-inset-top, 0px)) 0 10px; margin-bottom: 4px;
}
.table-wrap { overscroll-behavior-x: contain; }
td.u, th:first-child { position: sticky; left: 0; background: var(--paper); z-index: 1; }
tbody tr:hover td.u, tbody tr:focus-within td.u { background: var(--paper-2); }
.lb-stage { grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }   /* a definite track, so max-height:100% on the photo works */
.lb-svg { box-sizing: border-box; }
.lb-svg svg { height: calc(100dvh - var(--lb-chrome, 176px)); }
.lightbox { --lb-chrome: calc(176px + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)); }

/* ---------- narrower than a laptop: the facts move out of the header ---------- */
@media (max-width: 1099px) {
  .bar .tally, .brand-meta { display: none; }
  .bar .btn { margin-left: auto; }
  .facts-line { display: flex; flex-wrap: wrap; gap: 2px 14px; max-width: var(--w); margin: 0 auto 12px; font-size: 13px; color: var(--ink-2); }
  .facts-line p { margin: 0; }
  .facts-line #meta-inline { letter-spacing: 0.06em; text-transform: uppercase; font-size: 12px; }
}

/* ---------- touch: every control is a 44 px target ---------- */
@media (pointer: coarse), (max-width: 760px) {
  .btn { min-height: 44px; }
  .chip, .toggle { min-height: 44px; }
  .chip { min-width: 44px; }
  .toggle { padding-right: 6px; }
  .toggle input, .enquiry .check input { width: 22px; height: 22px; }
  .icon-btn { width: 44px; height: 44px; }
  .row-btn { min-height: 44px; min-width: 44px; padding-inline: 2px; }
  .tabs button { min-height: 44px; min-width: 44px; }
  .enlarge, .g-btn { width: 44px; height: 44px; }
  .enquiry .check { padding-block: 8px; min-height: 44px; }
  .p-actions .btn { min-height: 44px; }
  .foot-tool { display: inline-flex; align-items: center; min-height: 44px; }
}

/* ---------- phones ---------- */
@media (max-width: 760px) {
  .bar { padding-block: calc(8px + env(safe-area-inset-top, 0px)) 8px; min-height: var(--bar-h); }
  .brand-name { font-size: 24px; }
  .intro h1 { font-size: clamp(34px, 11vw, 44px); }
  .stage-wrap { margin-inline: calc(-1 * var(--pad-l)) calc(-1 * var(--pad-r)); }
  .stage { width: max(100%, calc(var(--stage-h-phone) * var(--ar))); }
  .stage-hint { padding-inline: var(--pad-l) var(--pad-r); }
  .stage-wrap { padding-bottom: 2px; }
  table { min-width: 560px; }
  .list h2 { font-size: 30px; }
  .panel { max-height: 90vh; max-height: 90dvh; scroll-padding-top: 80px; }
  .panel-top { padding-top: 16px; }   /* a bottom sheet never reaches the notch */
  .panel-inner { padding-inline: max(18px, env(safe-area-inset-left, 0px)) max(18px, env(safe-area-inset-right, 0px)); }
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lb-meta { flex-direction: column; align-items: center; gap: 2px; padding: 8px 76px calc(10px + env(safe-area-inset-bottom, 0px)); min-height: calc(68px + env(safe-area-inset-bottom, 0px)); text-align: center; }
  .lb-cap { font-size: 20px; }
  .lb-btn { top: auto; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: none; }
  .lb-prev { left: max(12px, env(safe-area-inset-left, 0px)); }
  .lb-next { right: max(12px, env(safe-area-inset-right, 0px)); }
  .lb-stage { padding-inline: 12px; }
  .lb-svg svg { max-width: calc(100vw - 56px); }
}
@media (max-width: 400px) { .lightbox { --lb-chrome: calc(200px + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px)); } }

/* ---------- landscape phone: the building fits the height, the panel is a side drawer ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --w: max(calc((100dvh - var(--bar-h) - 12px) * var(--ar)), calc(var(--stage-h-tap, 0px) * var(--ar))); }   /* fits the height, unless that would make a home smaller than a fingertip */
  .bar { padding-block: calc(6px + env(safe-area-inset-top, 0px)) 6px; }
  .brand-name { font-size: 22px; }
  .intro { padding-block: 8px 6px; }
  .intro h1 { font-size: 30px; }
  .intro p, .facts-line { display: none; }
  .filters { margin-bottom: 8px; gap: 4px 14px; }
  .legend { margin-left: auto; width: auto; }
  .stage-wrap { overflow-x: auto; margin-inline: auto; scroll-margin-top: var(--bar-h); max-width: 100%; }
  .stage { width: var(--w); max-width: none; }
  .stage-hint { display: none; }
  .stage-wrap.more .stage-hint { display: block; position: sticky; left: 0; }
  .panel {
    top: 0; bottom: 0; left: auto; right: 0; width: min(var(--panel-w), 58vw); max-height: none; border-radius: 0;
    transform: translateX(100%);
  }
  .panel.open { transform: none; }
  .panel.peek { transform: none; }
  .sheet-handle { display: none !important; }
  .panel-top { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .panel-top h2 { font-size: 28px; }
  .lb-stage { padding: 8px 76px 4px; }
  .lb-meta { flex-direction: row; justify-content: center; gap: 14px; min-height: 0; padding: 4px 76px calc(8px + env(safe-area-inset-bottom, 0px)); }
  .lb-btn { top: 50%; bottom: auto; transform: translateY(-50%); }
  .lb-prev { left: max(10px, env(safe-area-inset-left, 0px)); }
  .lb-next { right: max(10px, env(safe-area-inset-right, 0px)); }
  .lb-close { top: calc(6px + env(safe-area-inset-top, 0px)); right: max(10px, env(safe-area-inset-right, 0px)); }
  .lb-svg svg { height: calc(100dvh - 96px); max-width: calc(100vw - 180px); }
}

/* ---------- large screens: the page grows with the building ---------- */
@media (min-width: 1800px) {
  :root { --panel-w: 560px; }
  body { font-size: 17px; }
  .brand-name { font-size: 32px; }
  .brand-meta { font-size: 13px; }
  .tally { font-size: 15px; }
  .btn { font-size: 16px; padding: 13px 22px; }
  .intro p { font-size: 16px; max-width: 48ch; }
  .filters { font-size: 15px; }
  .filters-label, .legend { font-size: 13px; }
  .chip { min-height: 42px; min-width: 48px; font-size: 15px; }
  .toggle { min-height: 42px; }
  .stage-hint, .avail-note, .foot { font-size: 14px; }
  .card { min-width: 250px; padding: 14px 18px; }
  .card .c-unit { font-size: 28px; }
  .card .c-meta { font-size: 15px; }
  .card .c-price { font-size: 17px; }
  .list h2 { font-size: 44px; }
  table { font-size: 17px; }
  th { font-size: 12px; }
  td.u { font-size: 23px; }
  .panel-top h2 { font-size: 40px; }
  .p-price span:first-child { font-size: 36px; }
  .tabs button { font-size: 16px; }
  .enquiry label { font-size: 13px; }
  .enquiry .check { font-size: 13px; }
}
@media (min-width: 2400px) {
  :root { --panel-w: 640px; }
  body { font-size: 19px; }
  .brand-name { font-size: 38px; }
  .intro h1 { font-size: 100px; }
  .chip { min-height: 46px; min-width: 52px; font-size: 16px; }
  .list h2 { font-size: 52px; }
  table { font-size: 19px; }
}

/* ---------- phones, crowd-test pass: the building starts high on the first screen, the panel is a real bottom sheet ---------- */
@media (max-width: 760px) {
  .intro { padding-block: 12px 6px; }
  .intro h1 { font-size: 30px; }
  .intro p { display: none; }
  .facts-line { margin-bottom: 8px; font-size: 12px; }
  .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px 12px; margin-inline: calc(-1 * var(--pad-l)) calc(-1 * var(--pad-r)); padding-inline: var(--pad-l) var(--pad-r); margin-bottom: 8px;
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
  .filters::-webkit-scrollbar { display: none; }
  .filters > *, .chips { flex: none; }
  .chips, .block-filter { flex-wrap: nowrap; }
  .toggle { border: 1px solid var(--field-line); border-radius: 2px; padding: 0 14px 0 10px; white-space: nowrap; }
  .toggle:has(input:checked) { background: var(--ink); color: var(--paper); border-color: var(--ink); }
  .toggle input { width: 18px; height: 18px; }
  .legend { width: auto; margin-left: 4px; white-space: nowrap; font-size: 11px; gap: 10px; }
  /* the sideways building: soft edges say "there is more" */
  .stage-wrap.more { mask-image: linear-gradient(90deg, transparent 0, #000 18px, #000 calc(100% - 18px), transparent 100%); }
  .stage-hint::before { content: '↔  '; }

  /* bottom sheet: fixed height; opens half way (.peek) so the chosen home stays visible above it */
  .panel { --sheet-h: 90dvh; --peek-off: 38dvh; height: var(--sheet-h); max-height: var(--sheet-h);
    box-shadow: none; transition: transform 220ms cubic-bezier(0.4, 0, 1, 1), translate 0s, visibility 0s 220ms; }
  .panel.open { box-shadow: 0 -18px 50px -24px rgba(17, 24, 20, 0.5); transition: transform 320ms var(--ease), translate 0s; }
  .panel.open.peek { transform: translateY(var(--peek-off)); }
  .panel.dragging { transition: none; }
  .panel.peek .p-cta { bottom: var(--peek-off); }
  .panel-top { touch-action: none; padding-top: 22px; cursor: grab; }
  .sheet-handle { display: block; position: absolute; top: 8px; left: 50%; translate: -50% 0; width: 40px; height: 5px; border-radius: 3px; background: var(--field-line); opacity: 0.7; }
  .sheet-handle::after { content: ''; position: absolute; inset: -14px -22px; }   /* a 44 px tap area around the grip line */
  .panel-top h2 { font-size: 28px; }
  .p-cta { padding-inline: max(18px, env(safe-area-inset-left, 0px)) max(18px, env(safe-area-inset-right, 0px)); }
  .scrim { background: rgba(17, 24, 20, 0.08); }
}

/* tablets and other touch screens wider than a phone: homes stay 44 px+ (a thin-floored tower or dense estate scrolls sideways) */
@media (pointer: coarse) and (min-width: 761px) and (min-height: 501px) {
  .stage-wrap { overflow-x: auto; scrollbar-width: none; }
  .stage-wrap::-webkit-scrollbar { display: none; }
  .stage { width: max(100%, calc(var(--stage-h-tap, 0px) * var(--ar))); }
  .stage-wrap.more .stage-hint { display: block; position: sticky; left: 0; }
}
/* phones: a long development name wraps under itself instead of being cut */
@media (max-width: 760px) {
  .brand-name { white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.05; font-size: 22px; margin-block: 0; }
}

/* the header lines up with the building, not the window edge (here, after the base .bar padding above) */
@media (min-width: 1100px) {
  .bar { --align: min(calc((100% - var(--w)) / 2), calc(50% - 560px));   /* line up with the building, but always leave the header 1120 px */
    padding-inline: max(var(--pad-l), var(--align)) max(var(--pad-r), var(--align)); }
  .portrait .bar { padding-inline: max(48px, calc((100% - 1400px) / 2 + 48px)); }
}
@media (min-width: 1800px) { .portrait .bar { padding-inline: max(48px, calc((100% - 2200px) / 2 + 48px)); } }
