/* Device classes.
 *
 * Loaded LAST so it can restate layout rules the earlier sheets set as
 * constants. It does not restyle components — it decides, per class of screen,
 * how much room the panel gets, how tall the header is, and where the floating
 * scene chrome sits so nothing lands on top of anything else.
 *
 * The whole layout is driven by four tokens. Every magic number that used to
 * encode "the panel is 370 wide" — most damagingly #feedbackBtn's right:426px,
 * which was 370 + 22 + a gap and silently wrong the moment the panel moved —
 * is expressed in terms of them instead.
 *
 * The classes, and why each boundary is where it is:
 *
 *   phone portrait   <=720px   the bottom sheet; matches main.js isMobile(),
 *                              which owns the sheet's drag behaviour. Moving
 *                              this boundary without moving that one gives a
 *                              sheet layout with no sheet logic.
 *   short viewport   <=500px tall   a phone on its side, and a small laptop in
 *                              a video call. Vertical room is the scarce thing,
 *                              so the header shrinks and the panel keeps the
 *                              side, never the bottom.
 *   tablet           721-1179  touch, but with room for a side panel. The panel
 *                              becomes proportional and hit targets grow to the
 *                              44px both platform guidelines ask for.
 *   laptop           1180-1679 what the original layout was drawn for. Unchanged.
 *   large display    1680-2559 a sales-office screen, read from a metre or two.
 *   4K               >=2560    the same screen with four times the pixels. The
 *                              browser does NOT scale for us: 3840 CSS px means
 *                              a 370px panel is 9.6% of the width and body text
 *                              is a few millimetres tall. Everything steps up.
 */

:root {
  --header-h: 68px;
  --panel-w: 370px;
  --panel-gap: 22px;
  /* Where the panel's left edge falls, so floating chrome can clear it. */
  --panel-edge: calc(var(--panel-w) + var(--panel-gap) * 2);
}

/* Both, always, from the one token: .shell's offset and the header's own
 * height are the same measurement, and setting only the first left a 10px band
 * of nothing under the header on any class that changed it. */
header { height: var(--header-h); }
.shell { inset: var(--header-h) 0 0; }

/* Scoped away from the phone on purpose. Below 721px the panel is a bottom
 * sheet — creative-direction.css pins it with `top:auto` and drives its height
 * from a drag gesture — and restating `top` here unconditionally turned it into
 * a TOP sheet that covered the residence and clipped its own call to action. */
@media (min-width: 721px) {
  #panel {
    right: var(--panel-gap);
    top: var(--panel-gap);
    bottom: var(--panel-gap);
    width: min(var(--panel-w), calc(100% - var(--panel-gap) * 2));
  }
}

/* Was right:426px. Now it tracks the panel at every size. */
#feedbackBtn { right: calc(var(--panel-edge) + 12px); }

/* ----------------------------------------------------------------- touch */
/* Hit sizing belongs to the INPUT, not to the width. An iPad Pro in landscape
 * is 1366px — laptop-width and touch-driven — so keying 44px targets on a
 * breakpoint would have left the biggest tablet with mouse-sized controls.
 * 44px is the smallest reliable target on both platforms; these were drawn
 * at 34. */
@media (pointer: coarse) {
  header button, .lang select { min-height: 44px; }
  .season { padding: 4px; }
  #panel .tabs button { min-height: 40px; }
  .card { padding: 14px; }
  .primary, .secondary { padding: 15px; }
}

/* ---------------------------------------------------------------- tablet */
/* 721-1279: an iPad in either orientation, and an Android tablet. The panel
 * stops being a constant and takes a share of the width, so a 1180px landscape
 * iPad does not hand the residence the same 370px a 3840px wall does.
 *
 * The floor is 370 on purpose: it is what every size above a phone used to get,
 * and a proportional rule that makes a portrait tablet NARROWER than it was is
 * not an improvement. 820px portrait lands on the floor; 1180px landscape gets
 * the ceiling. */
@media (min-width: 721px) and (max-width: 1279px) {
  :root { --panel-w: clamp(370px, 40vw, 470px); --panel-gap: 18px; }
}

/* ------------------------------------------------------- large display */
/* 1680-2559: a sales-office screen. The panel is read standing up, from
 * further away than a laptop, so it gets both more width and more type. */
@media (min-width: 1680px) and (max-width: 2559px) {
  :root { --header-h: 78px; --panel-w: clamp(430px, 26vw, 560px); --panel-gap: 28px; }

  header { padding: 0 32px; }
  header button { padding: 11px 16px; font-size: 16px; }
  .lang select { padding: 9px 13px; font-size: 15px; }

  #panel { padding: 30px; }
  #panel h1 { font-size: 36px; }
  #panel p, #panel .card strong { font-size: 17px; }
  #panel .card small { font-size: 14px; }
  #panel .eyebrow { font-size: 12px; }
}

/* -------------------------------------------------------------------- 4K */
/* >=2560, which is where a 4K panel reports 3840 CSS px unless someone has set
 * a zoom. Nothing about the layout is proportional, so every constant that
 * would otherwise render at a few millimetres is stepped up here. */
@media (min-width: 2560px) {
  :root { --header-h: 104px; --panel-w: clamp(620px, 22vw, 820px); --panel-gap: 40px; }

  header { padding: 0 48px; gap: 40px; }
  .brand strong { font-size: 26px; }
  .brand span { width: 48px; height: 48px; font-size: 15px; }
  header button { padding: 15px 22px; font-size: 21px; border-radius: 999px; }
  .lang select { padding: 13px 18px; font-size: 20px; }

  #panel { padding: 40px; border-radius: 28px; }
  #panel h1 { font-size: 50px; }
  #panel h2 { font-size: 34px; }
  #panel p, #panel .card strong { font-size: 22px; line-height: 1.5; }
  #panel .card small, #panel .spec small { font-size: 18px; }
  #panel .eyebrow { font-size: 15px; }
  .primary, .secondary { padding: 20px; font-size: 21px; border-radius: 16px; }
  .card { padding: 18px; border-radius: 18px; }

  #feedbackBtn { padding: 14px 20px; font-size: 18px; }
  #feedbackBtn span { font-size: 18px; }
  .scene-note { max-width: min(700px, 60%); padding: 40px 46px; }
  .scene-note strong { font-size: 30px; }
  .scene-note small { font-size: 17px; }
}

/* --------------------------------------------------------- phone portrait */
/* creative-direction.css gives the phone header two rows and 94px, and sets
 * .shell to match. This file restates .shell in terms of the token, so the
 * token has to carry that 94 or the shell would start 26px above the content
 * it is supposed to sit under. */
@media (max-width: 720px) {
  :root { --header-h: 94px; --panel-gap: 8px; }
}

/* A touch phone: the touch block above makes every header control 44px, and
 * 94px cannot hold two rows of those. The season toggle came out 54px tall,
 * so the top row ended at y=62 while the nav row began at y=44, and the
 * controls at the top right sat on Region / Les 2 Alpes / Residence
 * (MISTAKES.md M-028). The height is now built from the targets:
 *   8 top + 44 row one + 6 gap + 44 nav + 8 bottom = 110.
 * The season toggle is held to 44 overall (2px track + 40px buttons), the
 * same height as the language menu beside it. Placed BEFORE the short-viewport
 * block, so a phone on its side still gets that block's 52px one-row header. */
@media (max-width: 720px) and (pointer: coarse) {
  :root { --header-h: 110px; }
  .season { padding: 2px; }
  .season button { min-height: 40px; }
  nav { bottom: 8px; }
}

/* ------------------------------------------------------- phone header menu */
/* Issue #9: "have the first line with all the titles and language, summer
 * winter in one line, more minimalistic, and make it a drop-down menu". The
 * two-row header above (110px of a 686px screen, before anything was shown)
 * becomes one 60px row — the brand and one button that says where you are
 * ("Résidence  ❄ FR") — and the scale, season and language controls open
 * under it as a dropdown. The controls are the SAME elements, so every
 * [data-scale] / [data-season] handler, the translations and the tests are
 * untouched; only their box changes.
 *
 * Outside this query the toggle does not exist and the wrapper is
 * display:contents, so desktop, tablet and a phone on its side (the
 * short-viewport block below, which already fits everything on one row) lay
 * out exactly as they did before. Height: 8 + 44 + 8. */
#menuToggle { display: none; }
.header-menu { display: contents; }

@media (max-width: 720px) and (min-height: 501px) {
  :root { --header-h: 60px; }
  header { padding: 8px 12px; align-items: center; gap: 10px; }
  .brand span { width: 40px; height: 40px; }

  #menuToggle {
    display: flex; align-items: center; gap: 8px; margin-left: auto;
    min-height: 44px; padding: 0 16px 0 18px;
    border: 1px solid var(--line); border-radius: 999px; background: #ffffffcc;
    color: var(--ink); font-size: 14px; font-weight: 650;
  }
  #menuMeta { color: #71817a; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
  #menuToggle .chevron {
    width: 7px; height: 7px; margin-left: 2px;
    border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
    transform: translateY(-2px) rotate(45deg); transition: transform .2s;
  }
  /* Above #feedbackBtn (25), which sits just under the header on the right. */
  header[data-menu="open"] { z-index: 60; }
  header[data-menu="open"] #menuToggle { background: var(--pine); border-color: var(--pine); color: #fff; }
  header[data-menu="open"] #menuMeta { color: #d7e2dc; }
  header[data-menu="open"] #menuToggle .chevron { transform: translateY(2px) rotate(225deg); }

  .header-menu {
    display: none; position: absolute; top: calc(100% + 6px); left: 8px; right: 8px;
    flex-direction: column; gap: 12px; padding: 14px;
    background: rgba(245,241,232,.98); border: 1px solid var(--line); border-radius: 20px;
    box-shadow: 0 18px 50px rgba(16,35,30,.25);
  }
  header[data-menu="open"] .header-menu { display: flex; }
  .header-menu nav {
    position: static; margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  }
  .header-menu nav button {
    min-height: 44px; padding: 8px 6px; border: 1px solid var(--line); background: #fff;
    font-size: 13px; white-space: nowrap;
  }
  .header-menu nav button.active { background: var(--pine); border-color: var(--pine); color: #fff; }
  .header-menu .season { margin: 0; display: grid; grid-template-columns: 1fr 1fr; padding: 3px; }
  .header-menu .season button { min-height: 40px; }
  .header-menu .lang select { width: 100%; min-height: 44px; padding: 8px 12px; font-size: 14px; }
}

/* ---------------------------------------------------------- the phone sheet */
/* Issue #11: "have the text bar minimal, so it doesn't hide the buttons of
 * the camera ... allow us to drag the box to be minimal, small, medium or full
 * screen." Four sizes, and main.js sheetHeights() mirrors them — change both.
 *
 * Each height is `var(--sheet-height, <size>)`. The drag writes --sheet-height
 * inline; the old rules set the sizes as plain heights on [data-sheet="..."],
 * which is (1,1,0) against the drag's (1,0,0) `#panel { height: var(...) }`,
 * so a drag moved nothing on screen until the finger lifted and the sheet
 * jumped. That is why the client asked for "another interaction ... by
 * sliding": the one there was invisible.
 *
 * Minimal is one line: the handle and the title. The viewer's camera bar
 * (Façade / Côté / Arrière) runs along the bottom of its frame, so the scene
 * stops above the sheet instead of running under it — at the minimal height,
 * or at the small one for any larger size. The frame is resized only when the
 * sheet settles, never during a drag. */
@media (max-width: 720px) and (min-height: 501px) {
  #panel[data-sheet="minimal"] { height: var(--sheet-height, 72px); overflow: hidden; cursor: pointer; }
  #panel[data-sheet="minimal"]:not(.dragging) > :not(.sheet-handle):not(h1) { display: none; }
  #panel[data-sheet="minimal"]:not(.dragging) h1 {
    margin: 0; font-size: 19px; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  #panel[data-sheet="small"] { height: var(--sheet-height, max(220px, 34dvh)); }
  #panel[data-sheet="medium"] { height: var(--sheet-height, max(320px, 60dvh)); }
  /* Stops under #feedbackBtn's row (header + 12px, 29px tall, z-index 25),
     which would otherwise sit on the sheet's own drag handle. */
  #panel[data-sheet="full"] { height: var(--sheet-height, calc(100dvh - var(--header-h) - 58px)); }

  /* The call to action was `position: sticky` for EVERY .primary in the panel
     (creative-direction.css), masked with a blurred shadow — so body text
     scrolled through it as half-faded words, and a tab with two stacked both.
     Only the one that ends a panel sticks, full width and flush with the
     sheet's bottom edge. The negative bottom cancels the sheet's 18px bottom
     padding: a sticky child is held inside the scroll container's CONTENT box,
     so `bottom: 0` left that padding as a live strip of text under the bar. */
  #panel .primary { position: static; box-shadow: none; }
  #panel > .primary:last-child,
  #panel .tab-body > .primary:last-child {
    position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); z-index: 6;
    width: calc(100% + 40px); margin: 14px -20px 0;
    padding: 15px 20px calc(15px + env(safe-area-inset-bottom));
    border-radius: 0 0 21px 21px;
  }
  /* The tab row bleeds to the sheet's edges, so a half-visible pill reads as
     "there is more this way". */
  #panel .tabs { margin: 12px -20px; padding-inline: 20px; }

  .shell:has(#panel[data-sheet="minimal"]) #scene {
    bottom: calc(72px + 16px + env(safe-area-inset-bottom));
  }
  .shell:has(#panel[data-sheet]:not([data-sheet="minimal"])) #scene {
    bottom: calc(max(220px, 34dvh) + 16px + env(safe-area-inset-bottom));
  }
}

/* --------------------------------------------------------- short viewport */
/* A phone on its side is 390px tall with a 68px header — 17% of the screen
 * spent on navigation before anything is shown. Height, not width, is what is
 * scarce here, so this is keyed on height and deliberately overrides the phone
 * width rules below it in specificity terms by coming later in the file. */
@media (max-height: 500px) {
  :root { --header-h: 52px; --panel-gap: 10px; }

  header { height: var(--header-h); padding: 0 12px; gap: 12px; align-items: center; }
  .brand strong { display: none; }
  .brand span { width: 30px; height: 30px; }
  header button { padding: 6px 10px; font-size: 13px; }
  .lang select { padding: 5px 8px; font-size: 13px; }
  nav { position: static; margin: auto; gap: 2px; }

  /* Never the bottom sheet in landscape: a sheet plus a 52px header would
     leave the residence a letterbox. The panel keeps the side and scrolls. */
  #panel {
    position: absolute;
    top: var(--panel-gap); bottom: var(--panel-gap); right: var(--panel-gap); left: auto;
    width: min(340px, 42%); height: auto; max-height: none;
    padding: 14px 16px; border-radius: 16px;
  }
  /* #panel[data-sheet="half"] is (1,1,0) and would keep imposing a sheet
     height on a phone held sideways. Answered at the same specificity. */
  #panel[data-sheet] {
    height: auto; min-height: 0; max-height: none; overflow: auto;
  }
  #panel h1 { font-size: 22px; margin: 4px 0 8px; }
  #panel p { font-size: 13px; line-height: 1.4; }
  .sheet-handle { display: none; }

  #feedbackBtn { top: auto; bottom: 12px; right: calc(min(340px, 42%) + 22px); }
}

/* ------------------------------------------------------------ phone chrome */
/* On a phone the sheet owns the bottom, so Feedback sits directly under the
 * header at the right edge. The left edge is the 3D viewer's: it draws its own
 * control column there (Plans, Apartments, Reset, Replay, Capture). The scene's
 * "Return to the full residence" button that used to share this row was removed
 * for issue #10 — it duplicated the viewer's own Reset. */
@media (max-width: 720px) and (min-height: 501px) {
  #feedbackBtn {
    left: auto; right: 12px; bottom: auto;
    top: calc(var(--header-h) + 12px);
    padding: 8px 12px;
  }
}

/* ------------------------------------------------- map controls vs the badge */
/* MapLibre's NavigationControl is added "bottom-left" (main.js:65), and it owns
 * that corner: the vendored maplibre-gl.css draws it 29px wide on a 10px
 * margin, so the stack occupies x 10-39 and runs 87px up from the bottom.
 * #terrainBadge was drawn at left:18px, which put it across the bottom 29px of
 * that stack — 21x29px of overlap at EVERY desktop width, measured, and the
 * badge has the higher z-index, so the compass button was not merely hidden but
 * unclickable. It sits to the right of the stack now, on the same baseline.
 *
 * Scoped to 721px and up because below that styles.css moves the badge to the
 * TOP of the map, where the stack is not in its way — and a 49px indent there
 * would just be a dent in the corner. */
@media (min-width: 721px) {
  #terrainBadge { left: 49px; }
}

/* ------------------------------------------------------- the panel's sizes */
/* Issue #21: "let us hide the card on the right — minimum, medium and high".
 * main.js writes the size to <html data-panel>: hidden | medium | full (the
 * default, the panel as it always was). #panelSize is three small buttons
 * hung off the panel's left edge at its top; hidden removes the panel AND
 * that group, leaving only #panelShow in the corner the panel occupied.
 *
 * Wherever the panel is a side panel: everything 721px and wider, and a phone
 * on its side (the short-viewport block). A phone held upright has its own
 * four sheet sizes (issue #11) and never sees any of this — which is also why
 * none of these rules may leak out of the query: a desktop window narrowed to
 * a phone width keeps its data-panel, and must still get its sheet.
 *
 * Hidden sets --panel-edge to 0, so the chrome that tracks the panel's edge
 * (#feedbackBtn, #planViewer) takes the room back. */
#panelSize, #panelShow { display: none; }
#panelShow[hidden] { display: none !important; }

@media (min-width: 721px), (max-height: 500px) {
  #panelSize {
    position: absolute; z-index: 11;
    top: calc(var(--panel-gap) + 16px);
    right: calc(var(--panel-edge) - var(--panel-gap));
    display: flex; flex-direction: column; gap: 2px; padding: 4px;
    background: rgba(245,241,232,.92); backdrop-filter: blur(18px);
    border: 1px solid var(--line); border-right: 0; border-radius: 12px 0 0 12px;
    box-shadow: -6px 10px 24px rgba(16,35,30,.14);
  }
  #panelSize button, #panelShow {
    display: grid; place-items: center; border: 0; cursor: pointer; color: var(--pine);
  }
  #panelSize button { width: 30px; height: 30px; padding: 0; border-radius: 8px; background: transparent; }
  #panelSize button:hover { background: #ffffffcc; }
  #panelSize button[aria-pressed="true"] { background: var(--pine); color: #fff; }
  #panelSize svg, #panelShow svg {
    width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6;
    stroke-linecap: round; stroke-linejoin: round;
  }
  #panelSize svg .fill { fill: currentColor; stroke: none; }
  #panelSize button:focus-visible, #panelShow:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

  #panelShow {
    position: absolute; z-index: 11; top: var(--panel-gap); right: var(--panel-gap);
    grid-auto-flow: column; gap: 6px; padding: 9px 14px 9px 10px; border-radius: 999px;
    background: rgba(245,241,232,.94); backdrop-filter: blur(18px);
    border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(16,35,30,.2);
    font-size: 13px; font-weight: 650;
  }
  #panelShow:hover { background: #fff; }

  :root[data-panel="hidden"] { --panel-edge: 0px; }
  :root[data-panel="hidden"] #panel,
  :root[data-panel="hidden"] #panelSize { display: none; }
  :root[data-panel="hidden"] #feedbackBtn { right: 12px; }
  /* Half the shell, and shorter still when the content is: a panel that only
     has three lines does not grow to fill the half. */
  :root[data-panel="medium"] #panel {
    bottom: auto; height: auto; max-height: calc(50% - var(--panel-gap));
  }
}

@media (pointer: coarse) and (min-width: 721px), (pointer: coarse) and (max-height: 500px) {
  #panelSize button { width: 44px; height: 44px; }
  #panelShow { min-height: 44px; }
}

/* The short-viewport panel is min(340px, 42%) wide, not --panel-w. */
@media (max-height: 500px) {
  #panelSize { right: calc(min(340px, 42%) + var(--panel-gap)); top: calc(var(--panel-gap) + 10px); }
}
