/*! CubifyIt Roads. Copyright (c) 2026 Cubify It Studio. All rights reserved.
No permission is granted to copy, modify or redistribute this code. See LICENSE. */
/* ---------- Phones: the settings sit in a full-width panel along the bottom with large, touch-friendly controls;
   above it the map (left) and the 3D model (right) share the space, side by side and the same size. js/phone.js sets
   --sheet-h, the panel's height ---------- */
/* Up to 540px wide in any orientation, so the on-screen keyboard (which can make the page wider than tall) doesn't
   switch to the desktop layout; see phoneLayout in js/state.js */
@media (max-width: 540px), (max-width: 760px) and (orientation: portrait) {
  body { height: 100dvh; }

  .topbar { --ctl-h: 44px; min-height: 56px; gap: 8px 10px; padding: calc(6px + env(safe-area-inset-top)) 12px 6px; } /* as tall as the settings' controls */
  .brand { font-size: 15px; }
  /* While the search bar has focus it takes the title's room too, so a long address fits */
  .topbar:has(#search-input:focus) .brand { display: none; }
  .search { flex: 1 1 0; max-width: none; }
  .search input { font-size: 16px; } /* 16px or more, or iPhone Safari zooms the page when it is focused */
  /* No room beside the search bar: the message takes its own line under it */
  .search-error { flex: 1 1 100%; padding: 6px 12px; border-radius: 10px; font-size: 12px; white-space: normal; }

  .layout { display: block; position: relative; overflow: hidden; }
  /* z-index 0: each view keeps its own layers (the map's go up to 1000) inside it, so the settings panel, which slides
     up over them while the keyboard is open, stays on top */
  .map-wrap, .model { position: absolute; z-index: 0; top: 0; bottom: var(--sheet-h, 45%); border: 0; }
  .map-wrap { left: 0; right: 50%; }
  .model { left: 50%; right: 0; border-left: 1px solid var(--line); overflow: hidden; }
  .view3d-wrap { flex: 1; }
  .view3d { inset: 0; } /* the whole view, under the floating zoom bar */
  .zoom3d { top: auto; bottom: 8px; right: 8px; } /* same row as the map's zoom buttons */
  /* The how-to pill above the buttons, one tip a line */
  .pan-hint { left: 8px; bottom: calc(var(--zoom-btn) + 22px); max-width: calc(100% - 16px); font-size: 11px; }
  .pan-hint span { display: block; }
  .pan-hint span + span::before { content: none; }
  .model.full-screen .pan-hint span { display: inline; }
  .model.full-screen .pan-hint span + span::before { content: '· '; }
  /* The zoom buttons, a little larger for fingers, and the same in both views: as large as lets the model's three
     fit in its half of the screen (8px margins, 3px padding, 2px gaps) */
  .layout { --zoom-btn: min(36px, (50vw - 26px) / 3); }
  :root { --actions-bottom: calc(10px + env(safe-area-inset-bottom)); } /* Next and Download, at one height */
  .dim-label { padding: 0 4px; font-size: 9.5px; } /* the model is small here */
  .dim-label.dim-upright { padding: 4px 0; }
  .frame-dim { font-size: 9.5px; padding: 0 4px; }
  .frame-dim-h { padding: 4px 0; }
  .leaflet-bottom.leaflet-right .leaflet-control-zoom { margin: 0 8px 8px 0; }
  .leaflet-control-attribution { font-size: 9px; line-height: 1.4; }
  /* In two short lines, to fit beside the zoom buttons */
  .status { top: 10px; bottom: auto; left: 10px; right: 10px; }

  /* Settings panel: the same three rows, full width with larger controls, then the sizes beside the download button */
  .settings {
    position: absolute;
    z-index: 5;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 55%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-content: start;
    gap: 10px 14px;
    padding: 12px 14px var(--actions-bottom);
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 24px rgba(0,0,0,.06);
  }
  .settings .row { grid-column: 1 / -1; gap: 10px; }
  .row-label { width: 46px; font-size: 14px; }
  .settings { --ctl-h: 44px; } /* larger controls for fingers */
  .settings select,
  .settings input[type=text] { font-size: 16px; } /* 16px: no zoom on focus */
  .wood-current, .wood-menu button { width: 108px; font-size: 16px; }

  .stepper > button { width: 38px; height: 38px; font-size: 20px; }
  .stepper > .stepper-value, .stepper > .stepper-value:disabled, .stepper > .stepper-value:hover { height: 38px; font-size: 15px; }
  .stepper .note { font-size: 11px; }
  .seg { padding: 3px; gap: 4px; }
  .seg button { width: 38px; height: 38px; }
  .seg button svg { width: 20px; height: 20px; }

  /* Opens downward, over the row below: the panel scrolls, so anything outside it (such as above the Roads row) would
     be cut off */
  .palette-menu { gap: 8px; padding: 8px; top: calc(100% + 8px); bottom: auto; }
  .palette-menu button { width: 40px; height: 40px; }
  /* Last rows: Import beside Download across the panel, then the copyright line */
  .actions { grid-column: 1 / -1; grid-row: 4; margin: 0; }
  /* The menus: across the screen just above the buttons, out of the scrolling panel that would cut them off */
  .action-menu { position: fixed; left: calc(8px + env(safe-area-inset-left)); right: calc(8px + env(safe-area-inset-right)); width: auto; bottom: calc(var(--actions-bottom) + var(--ctl-h) + 8px); }
  /* Full screen: one row of Back, Download and the exploded view and reset squares. Back and Download share what the
     squares leave, Download 1.75 times as wide (room for "Download .json", never narrower than Back); Back is exactly
     where Import is (as wide, as tall, as low), and Next takes the rest of its row */
  .model { --ctl-h: 44px; }
  .actions { --back: calc((100% - 2 * var(--ctl-h) - 24px) / 2.75); grid-template-columns: var(--back) minmax(0, 1fr); }
  .actions > .action > button { font-size: 14px; letter-spacing: .03em; white-space: nowrap; }
  .model.full-screen .review-actions { left: 14px; right: calc(14px + 2 * var(--ctl-h) + 16px); width: auto; bottom: var(--actions-bottom); grid-template-columns: 1fr 1.75fr; }
  .model.full-screen .zoom3d { right: 14px; bottom: var(--actions-bottom); }
  .model.full-screen .pan-hint { bottom: 62px; }
  /* The copyright: in short lines left of the zoom bar, level with it: the count, then "© 2026 Cubify It", broken in
     two only where it doesn't fit beside the bar */
  .legal { left: 8px; right: calc(2 * var(--zoom-btn) + 24px); bottom: 8px; height: calc(var(--zoom-btn) + 6px); transform: none; display: flex; flex-direction: column; justify-content: center; font-size: 9px; line-height: 1.4; white-space: normal; }
  .legal .made, .legal .copy > span { white-space: nowrap; }
  .legal .made::after { content: none; } /* on a line of its own, above the copyright */
  .legal .made { margin-bottom: 1.5px; } /* the p of "maps" hangs toward the tall ©: a little more room so the gaps look even */
  /* Full screen: one line just above Back, as the row of buttons is full */
  .model.full-screen .legal { left: 14px; right: 14px; bottom: calc(var(--actions-bottom) + var(--ctl-h) + 10px); height: auto; display: block; font-size: 11px; line-height: 1.3; }
  .model.full-screen .legal .made { margin: 0; }
  .model.full-screen .legal .made::after { content: ' '; }
}

/* Touch screens in any orientation: text boxes and menus at 16px or more, or iPhone Safari zooms the page when one
   gets focus */
@media (pointer: coarse) {
  .search input, .settings input[type=text], .settings select { font-size: 16px; }
}
