/* Opt-in controls only: the desktop layout and artwork stay unchanged. */
.atlas-mobile-bar, .atlas-mobile-close, .atlas-mobile-backdrop, .atlas-mobile-zoom, .atlas-mobile-detail { display: none; }

@media (max-width: 850px), (max-width: 1100px) and (max-height: 500px) and (pointer: coarse) {
  .atlas-page { height: 100vh; height: 100dvh; overscroll-behavior: none; }
  .atlas-layout { display: block; position: relative; isolation: isolate; }
  .atlas-map-panel { height: 100%; padding: 0; }
  .atlas-stage { border: 0; border-radius: 0; box-shadow: none; }
  .atlas-stage::after { box-shadow: inset 0 0 25px #70502626; }
  .atlas-compass, .atlas-tooltip { display: none; }
  /* A tap identifies the place by its name/marker, without flashing the broad
     region underneath. Keep the original terrain washes and desktop hover. */
  .atlas-feature.atlas-territories:is(.is-hovered, .is-selected) .atlas-shape { fill-opacity: 0.6; stroke: #74604a; stroke-width: 1.4; stroke-opacity: 1; filter: none; }
  .atlas-feature.atlas-regions:is(.is-hovered, .is-selected) .atlas-shape { fill-opacity: 0.09; stroke: currentColor; stroke-width: 0.8; stroke-opacity: 0.24; filter: none; }
  .atlas-feature.atlas-nature:is(.is-hovered, .is-selected) .atlas-shape { fill-opacity: 0.2; stroke-opacity: 0; filter: none; }
  .atlas-feature:is(.is-hovered, .is-selected) .atlas-maritime-shape { fill-opacity: 0; stroke: none; filter: none; }
  .atlas-mobile-bar { display: flex; align-items: stretch; gap: 4px; position: absolute; z-index: 4; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); min-height: 56px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--sidebar); box-shadow: 0 3px 14px #0004; }
  .atlas-mobile-bar > a { display: grid; place-items: center; width: 44px; flex-shrink: 0; text-decoration: none; font-size: 24px; color: var(--link); }
  .atlas-mobile-bar button { border: 0; background: transparent; min-height: 44px; padding: 4px 9px; }
  .atlas-mobile-bar [data-atlas-mobile="search"] { flex: 1; min-width: 0; text-align: left; }
  .atlas-mobile-bar strong, .atlas-mobile-bar span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .atlas-mobile-bar strong { color: var(--accent); font-size: 16px; }
  .atlas-mobile-bar span { margin-top: 2px; color: var(--muted); font-size: 13px; }
  .atlas-mobile-bar [data-atlas-mobile="layers"] { font-size: 13px; border-left: 1px solid var(--line); border-radius: 0; }
  .atlas-mobile-zoom { display: grid; position: absolute; z-index: 3; right: max(12px, env(safe-area-inset-right)); top: calc(max(10px, env(safe-area-inset-top)) + 76px); gap: 4px; }
  .atlas-mobile-zoom button { width: 44px; height: 44px; padding: 0; font-size: 26px; background: var(--sidebar); box-shadow: 0 2px 8px #0003; }
  .atlas-edit-floating { top: calc(max(10px, env(safe-area-inset-top)) + 76px); left: max(12px, env(safe-area-inset-left)); min-height: 44px; font-size: 14px; }
  .atlas-sidebar { display: none; position: absolute; z-index: 6; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); max-height: calc(100% - max(10px, env(safe-area-inset-top)) - 86px); padding: 0 16px 16px; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 6px 24px #0006; overflow: auto; }
  .is-navigation-open .atlas-sidebar { display: block; }
  .is-navigation-open [data-atlas-editor-host] { visibility: hidden; }
  .atlas-mobile-close { display: block; position: sticky; top: 0; z-index: 1; width: 100%; min-height: 48px; margin: 0 0 12px; border-width: 0 0 1px; border-radius: 0; background: var(--sidebar); text-align: right; }
  .atlas-mobile-backdrop:not([hidden]) { display: block; position: absolute; inset: 0; z-index: 5; width: 100%; height: 100%; padding: 0; margin: 0; border: 0; border-radius: 0; background: #10182670; }
  .atlas-sidebar .atlas-page-title { font-size: 1.6rem; margin: 10px 0; }
  .atlas-sidebar input[type="search"] { min-height: 48px; font-size: 16px; }
  .atlas-results { max-height: 32dvh; }
  .atlas-result button, .atlas-result > a, .atlas-layers label, .atlas-sidebar summary { min-height: 44px; }
  .atlas-result button { font-size: 16px; }
  .atlas-result small { font-size: 12px; }
  .atlas-layers label { margin: 0; }
  .atlas-layers input { width: 22px; height: 22px; }
  .atlas-mobile-detail:not([hidden]) { display: flex; flex-direction: column; position: absolute; z-index: 4; bottom: max(10px, env(safe-area-inset-bottom)); left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); max-height: min(36dvh, 280px); border: 1px solid var(--line); border-radius: 16px; background: var(--sidebar); box-shadow: 0 3px 18px #0005; overflow: hidden; }
  .is-navigation-open .atlas-mobile-detail { visibility: hidden; }
  .atlas-mobile-detail.is-expanded { max-height: calc(100% - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)) - 80px); }
  .atlas-mobile-detail-actions { display: flex; flex-shrink: 0; align-items: center; border-bottom: 1px solid var(--line); padding: 0 6px 0 12px; }
  .atlas-mobile-detail-actions button { background: transparent; border: 0; min-height: 44px; }
  .atlas-mobile-detail-actions [data-atlas-mobile="expand"] { flex: 1; text-align: left; font-size: 13px; color: var(--link); }
  .atlas-mobile-detail-actions [data-atlas-mobile="dismiss"] { width: 44px; font-size: 26px; padding: 0; }
  [data-atlas-mobile-detail-host] { min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .atlas-mobile-detail .atlas-detail { margin: 0; padding: 12px 16px; border: 0; background: transparent; gap: 4px; font-size: 16px; }
  .atlas-mobile-detail h2 { margin: 2px 0 6px; font-size: 20px; }
  .atlas-mobile-detail p { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; line-height: 1.45; }
  .atlas-mobile-detail.is-expanded p { display: block; overflow: visible; }
  .atlas-mobile-detail a { display: inline-flex; align-items: center; min-height: 44px; }
  /* Keep local editing usable without making the map a second scrolling page. */
  .atlas-map-panel:has(> [data-atlas-editor-host]:not(:empty)) { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 0; }
  .atlas-map-panel:has(> [data-atlas-editor-host]:not(:empty)) > .atlas-stage { grid-row: 1; }
  .atlas-map-panel:has(> [data-atlas-editor-host]:not(:empty)) > [data-atlas-editor-host] { position: absolute; z-index: 6; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); max-height: 45%; overflow: auto; border-radius: 12px; }
  .atlas-editor :is(button, input, select) { min-height: 44px; font-size: 16px; }
  .atlas-editor-handle { stroke-width: 2.5; }
}

@media (max-height: 500px) and (max-width: 1100px) and (pointer: coarse) {
  .atlas-mobile-detail:not([hidden]) { right: calc(max(10px, env(safe-area-inset-right)) + 60px); max-height: 45dvh; }
  .atlas-mobile-detail.is-expanded { max-height: calc(100% - max(10px, env(safe-area-inset-top)) - max(10px, env(safe-area-inset-bottom)) - 80px); }
}
