/* Phone workspace: final scoped overrides after the existing stylesheets. */
@media (max-width:900px) {
  :root, body[data-role="FREE"] { --utw-header-height:calc(104px + env(safe-area-inset-top)); --mapendium-header-height:var(--utw-header-height); }
  body > header.topbar, body[data-role="FREE"] > header.topbar {
    box-sizing:border-box; display:grid; grid-template-areas:"brand actions language" "context context context";
    grid-template-columns:minmax(0,1fr) auto 56px; grid-template-rows:44px 44px;
    height:var(--utw-header-height); min-height:0; gap:4px 6px; padding:calc(6px + env(safe-area-inset-top)) 8px 6px;
    overflow:visible;
  }
  .topbar > .brand { grid-area:brand; gap:6px; min-width:0; width:auto; overflow:hidden; }
  .topbar .brand-mark, .topbar .brand-mark img { width:24px; height:29px; min-width:24px; }
  .topbar .brand-product-lockup { min-width:0; }
  .topbar .brand-product-lockup .brand-platform { font-size:7px; letter-spacing:.12em; }
  .topbar .brand-product-lockup .brand-application { font-size:14px; line-height:1.15; white-space:nowrap; }
  .topbar .brand strong { font-size:11px; }
  .topbar .brand small { display:none; }
  body > header.topbar > .topbar-actions { grid-area:actions; min-width:0; width:auto; gap:0; flex-wrap:nowrap; }
  .topbar .topbar-actions > :is(.role-badge,.topbar-help,.topbar-account,[data-upgrade-only]) { display:none !important; }
  .topbar .domain-menu > .button, .topbar .domain-switcher > .button { width:auto; min-width:86px; min-height:44px; padding:0 9px; font-size:11px; letter-spacing:0; }
  .topbar .domain-menu-items, .topbar .domain-switcher-popover { position:fixed; top:calc(52px + env(safe-area-inset-top)); left:auto; right:8px; width:min(320px,calc(100vw - 16px)); max-height:calc(100dvh - 72px); overflow:auto; }
  .topbar > .topbar-language.language-switch.language-select { grid-area:language; box-sizing:border-box; width:56px; min-width:56px; max-width:56px; }
  .topbar-language .language-select-icon { display:none; }
  .topbar-language.language-select select { min-width:0; min-height:44px; height:44px; padding:0 17px 0 8px; font-size:16px; }
  .topbar-language .language-select-control::after { right:8px; }
  .topbar > .topbar-context { grid-area:context; min-width:0; width:100%; }
  .topbar-context:has(.country-navigation) { display:grid; grid-template-columns:minmax(0,.36fr) minmax(0,.64fr); width:100%; gap:6px; }
  .topbar-context .appellation-navigation-controls, .topbar-context .appellation-title { min-width:0; width:100%; }
  .topbar-context .appellation-title select { box-sizing:border-box; width:100%; min-width:0; min-height:44px; height:44px; padding:0 12px; font-size:16px; }
  .territory-switcher-trigger { min-width:0; min-height:44px; height:44px; padding:6px 9px; }
  .territory-switcher-current { min-width:0; }
  .territory-switcher-current small { font-size:7px; letter-spacing:.05em; }
  .territory-switcher-current strong { font-size:12px; }
  body > .topbar + .workspace, .workspace { box-sizing:border-box; height:calc(100dvh - var(--utw-header-height)); min-height:0; }
  .workspace .map-shell { height:100%; min-height:0; width:100%; }
  .map-shell > .map-controls {
    box-sizing:border-box; top:8px; right:8px; left:auto; bottom:auto; display:flex; flex-wrap:nowrap;
    width:max-content; max-width:calc(100% - 16px); height:44px; min-height:44px; overflow:visible; border-radius:10px;
  }
  .map-shell > .map-controls > button, .map-shell > .map-controls #zoom-in, .map-shell > .map-controls #zoom-out,
  .map-shell > .map-controls .map-aop-reset, .map-controls #offline-mode-button {
    box-sizing:border-box; position:static; flex:0 0 44px; grid-column:auto; width:44px; min-width:44px; max-width:44px;
    height:44px; min-height:44px; padding:0; margin:0; border:0; border-right:1px solid #ded8cc; border-radius:0; touch-action:manipulation;
  }
  .map-shell > .map-controls > button[hidden] { display:none !important; }
  .map-shell > .map-controls .map-reset-copy { display:none; }
  .map-shell > .map-controls .map-reset-icon { display:block; width:auto; font-size:24px; }
  .map-shell > .map-controls #map-recenter-selection { position:absolute; top:50px; right:0; width:auto; min-width:88px; max-width:none; height:44px; padding:0 12px; border:1px solid #ded8cc; border-radius:9px; background:#fffdf8; }
  .map-controls #offline-mode-button { border-left:0; border-top:0; border-right:0; }
  .map-shell > .tool-rail, body[data-role="FREE"] .map-shell > .tool-rail {
    box-sizing:border-box; top:auto; bottom:calc(6px + env(safe-area-inset-bottom) + var(--atlas-review-notice-height,0px));
    left:6px; right:6px; display:flex; flex-wrap:nowrap; width:auto; height:58px; min-height:58px; max-height:58px;
    padding:0; overflow:hidden; border-radius:12px;
  }
  .map-shell > .tool-rail > :is(button,a), body[data-role="FREE"] .map-shell > .tool-rail > :is(button,a) {
    box-sizing:border-box; flex:1 1 0; width:auto; min-width:0; max-width:none; height:56px; min-height:56px; padding:5px 2px; gap:3px;
    border-bottom:0; border-right:1px solid #ded8cc; touch-action:manipulation;
  }
  .map-shell > .tool-rail > [hidden], .map-shell > .tool-rail > [data-mobile-secondary] { display:none !important; }
  .map-shell > .tool-rail > :is(button,a):last-child { border-right:0; }
  .map-shell > .tool-rail > :is(button,a) > span { font-size:21px; line-height:1; }
  .map-shell > .tool-rail > :is(button,a) > small { font-size:10px; line-height:1.2; letter-spacing:.025em; }
  .map-shell > .tool-rail small[data-mobile-label]::after { font-size:10px; }
  .map-shell > .tool-rail i { font-size:7px; padding:2px 4px; }
  .map-protection-mark { top:auto; bottom:calc(91px + env(safe-area-inset-bottom) + var(--atlas-review-notice-height,0px)); right:8px; max-width:calc(100% - 16px); padding:3px 5px; font-size:7px; line-height:1.3; letter-spacing:.02em; border-radius:4px; }
  .leaflet-control-attribution { max-width:calc(100vw - 16px); font-size:8px; line-height:1.25; margin-bottom:calc(68px + env(safe-area-inset-bottom) + var(--atlas-review-notice-height,0px)) !important; }
  .leaflet-control-scale { margin-bottom:calc(88px + env(safe-area-inset-bottom) + var(--atlas-review-notice-height,0px)) !important; }
  .map-edit-cta { display:none; }
  .map-status { display:block; top:60px; bottom:auto; left:8px; right:auto; max-width:calc(100% - 16px); padding:6px 9px; font-size:11px; line-height:1.35; border-radius:7px; pointer-events:none; }
  body[data-mobile-detail="ready"] .map-status:not(.is-error) { display:none; }
  .mobile-detail-retry { position:absolute; z-index:1301; top:94px; left:8px; min-height:44px; padding:0 12px; border:1px solid #d5c6ae; border-radius:9px; color:#17232d; background:#fffdf8; font-size:13px; font-weight:700; touch-action:manipulation; }
  .mobile-detail-retry[hidden] { display:none !important; }
  .offline-mode-status:not([hidden]) { top:60px; right:8px; left:auto; max-width:calc(100% - 16px); font-size:12px; }
  .selection-dock { left:6px; right:6px; bottom:calc(72px + env(safe-area-inset-bottom)); padding:8px; gap:6px; }
  .selection-dock-actions { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:5px; }
  .selection-dock-actions button { min-width:0; min-height:44px; padding:0 6px; font-size:11px; }
  .map-shell:has(.selection-dock:not([hidden])) .map-protection-mark { display:none; }
  .workspace > .panel { box-sizing:border-box; width:100%; height:min(82dvh,760px); max-height:calc(100dvh - var(--utw-header-height) - 4px - env(safe-area-inset-bottom)); overscroll-behavior:contain; }
  .panel .panel-scroll { padding:54px 14px calc(28px + env(safe-area-inset-bottom)); overscroll-behavior-y:contain; -webkit-overflow-scrolling:touch; }
  .panel :is(input,select,textarea) { font-size:16px; }
  .panel button, .panel .button { min-height:44px; }
  .panel .panel-close { z-index:3; width:44px; height:44px; min-height:44px; top:4px; right:5px; }
  .mobile-sheet-handle { position:absolute; z-index:2; top:0; left:calc(50% - 60px); width:120px; height:44px; padding:0; border:0; background:transparent; touch-action:none; }
  .mobile-sheet-handle::before { content:""; display:block; width:40px; height:4px; margin:auto; border-radius:4px; background:#b8b3a9; }
  .mobile-sheet-backdrop { position:fixed; z-index:1701; top:var(--utw-header-height); right:0; bottom:0; left:0; padding:0; border:0; background:transparent; }
  .mobile-sheet-backdrop[hidden] { display:none !important; }
  body.mobile-panel-open .map-shell > .tool-rail { visibility:hidden; pointer-events:none; }
}
@media (max-width:360px) {
  .topbar .brand-product-lockup .brand-application { font-size:12px; }
  .topbar .domain-menu > .button, .topbar .domain-switcher > .button { min-width:74px; padding:0 6px; font-size:10px; }
  .topbar .brand-mark, .topbar .brand-mark img { width:21px; min-width:21px; }
}
@media (max-width:900px) and (orientation:landscape) and (max-height:500px) {
  :root, body[data-role="FREE"] { --utw-header-height:calc(56px + env(safe-area-inset-top)); }
  body > header.topbar, body[data-role="FREE"] > header.topbar { grid-template-areas:"context actions language"; grid-template-rows:44px; padding-top:calc(6px + env(safe-area-inset-top)); padding-inline:max(8px,env(safe-area-inset-left)) max(8px,env(safe-area-inset-right)); }
  .topbar > .brand { display:none; }
  .workspace > .panel { height:calc(100dvh - var(--utw-header-height) - env(safe-area-inset-bottom)); }
  .map-protection-mark { display:none; }
}

/* Verified mobile viewport: panels must never scroll the map/header out of view. */
@media (max-width:900px) {
 html { height:100%; overflow:hidden; }
 body { height:100dvh; max-height:100dvh; overflow:clip; }
 body > .topbar + .workspace, body > .workspace {
  position:absolute; top:var(--utw-header-height); bottom:0; left:0; right:0;
  height:auto !important; min-height:0; overflow:hidden;
 }
 .workspace > .panel { background:#fffdf8 !important; }
 .panel .panel-scroll { overflow-x:hidden; }
}

/* Long geological age labels must remain readable on narrow screens. */
@media (max-width: 600px) {
  .formation-selection-legend { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .formation-selection-legend > div { min-width: 0; }
  .formation-selection-legend .formation-selection-swatch { width: 88px; }
  .formation-selection-legend h2 { font-size: clamp(22px, 6vw, 28px); line-height: 1.15; overflow-wrap: anywhere; }
}
