/* ═══════════════════════════════════════════════════════════════════════════
   APP SHELL STYLESHEET — restructured
   ─────────────────────────────────────────────────────────────────────────
   Structure:
     01. Design tokens (colors, spacing, z-index, sizes)
     02. Base / reset / typography / scrollbars
     03. Form elements (buttons, selects, labels)
     04. App shell layout (toolbar, main content, map)
     05. Fixed utility controls (hamburger, gear, lighting, audio, sign-in…)
     06. Quick-search widget (#qs-widget)
     07. Map nav sliders (#map-nav-controls)
     08. Draw panel (#draw-panel)
     09. Floating panels (.controls, .category-filter)
     10. Reading table / status / selection UI
     11. Omniport panel
     12. Map popups & tooltips (Mapbox + custom)
     13. Modals (settings, astro, stellar, account auth)
     14. Body state classes (.table-expanded, .grid-collapsed, .ios-browser)
     15. Responsive layers
           ≥ 601px  desktop & tablet shell
           601–1024 tablet refinements
           ≤ 768px / coarse pointer  touch refinements
           ≤ 600px  phone (shared)
           ≤ 600px portrait / landscape variants
     16. Accessibility (reduced motion)

   Breakpoints (keep in sync — CSS vars can't be used in @media):
     600px  = phone | 768px = small tablet / touch | 1024px = large tablet
   ═══════════════════════════════════════════════════════════════════════ */

/* ── 01. DESIGN TOKENS ─────────────────────────────────────────────────── */
:root {
    /* Palette — dark / gold theme */
    --gold:            #d4af37;
    --gold-bright:     #FFD700;
    --gold-soft:       #f0c93a;
    --gold-pale:       #fffbe6;
    --gold-cream:      #fff8dc;
    --ink:             #111;
    --ink-2:           #181818;
    --ink-3:           #222;
    --panel:           #141414;
    --panel-night:     #181a20;
    --panel-night-2:   #23243a;
    --stellar:         #7090d0;
    --stellar-pale:    #aab8e8;
    --stellar-bg:      #090912;
    --danger:          #ff6b6b;

    /* Common alpha mixes */
    --gold-a04:  rgba(212, 175, 55, 0.04);
    --gold-a08:  rgba(212, 175, 55, 0.08);
    --gold-a10:  rgba(212, 175, 55, 0.10);
    --gold-a14:  rgba(212, 175, 55, 0.14);
    --gold-a20:  rgba(212, 175, 55, 0.20);
    --gold-a30:  rgba(212, 175, 55, 0.30);
    --gold-a55:  rgba(212, 175, 55, 0.55);
    --bright-a07: rgba(255, 215, 0, 0.07);
    --bright-a12: rgba(255, 215, 0, 0.12);
    --bright-a18: rgba(255, 215, 0, 0.18);
    --bright-a28: rgba(255, 215, 0, 0.28);

    /* Type */
    --font-body:    'Space Grotesk', 'Inter', 'Times New Roman', serif;
    --font-display: 'Unica One', 'Space Grotesk', 'Inter', serif;
    --font-serif:   'Times New Roman', serif;
    --font-symbols: 'Noto Sans Symbols2', 'Noto Sans Egyptian Hieroglyphs',
                    'Segoe UI Symbol', 'Arial Unicode MS', 'Symbola',
                    'DejaVu Sans', 'Times New Roman', serif;

    /* Spacing & radii */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 24px;
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;

    /* Shell metrics */
    --toolbar-h: 60px;
    --ctl-size: 38px;          /* desktop icon-button size            */
    --ctl-size-lg: 48px;       /* settings gear                       */
    --ctl-size-sm: 34px;       /* mobile icon-button size             */
    --edge-gap: 8px;           /* gap between fixed controls & screen */

    /* Safe-area insets (iPhone notch / Android gesture bar) */
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);

    /* Desktop fixed-control offsets along the toolbar's right edge */
    --ctl-gear-right:    0px;
    --ctl-lt-right:      120px;
    --ctl-audio-right:   162px;
    --ctl-signin-right:  230px;
    --ctl-sound-right:   330px;
    --ctl-gesture-right: 372px;

    /* Full viewport height — upgraded to dvh where supported, so rules that
       must carry !important only need a single declaration */
    --vh-full: 100vh;

    /* Z-index scale — single source of truth */
    --z-map-overlay:    10;       /* in-map overlays (category filter)   */
    --z-map-controls:   1001;     /* .controls panel                     */
    --z-map-nav:        1002;     /* nav sliders                         */
    --z-draw-panel:     11020;    /* keep draw-on-map window above astral/nav overlays */
    --z-ribbon:         2000;
    --z-flash:          6666;
    --z-hamburger:      7000;
    --z-qs-mobile:      10001;
    --z-toolbar:        10020;
    --z-webcam:         10030;
    --z-fixed-btn:      10040;
    --z-draw-toggle-m:  10042;
    --z-qs:             10045;
    --z-settings-modal: 10050;
    --z-modal:          11000;
    --z-auth:           12050;
    --z-tooltip:        100000;
}

@supports (height: 100dvh) {
    :root { --vh-full: 100dvh; }
}

/* ── 02. BASE / RESET / TYPOGRAPHY ─────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    overflow-x: hidden;
    scroll-padding-top: calc(var(--toolbar-h) + 4px);
    scrollbar-width: auto;
    scrollbar-color: var(--gold-bright) var(--ink-3);
}
html::-webkit-scrollbar, body::-webkit-scrollbar {
    width: 12px;
    background: var(--ink-3);
}
html::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb {
    background: var(--gold-bright);
    border-radius: 6px;
}
html::-webkit-scrollbar-track, body::-webkit-scrollbar-track {
    background: var(--ink-3);
}

body {
    font-family: var(--font-serif);
    background: var(--ink);
    color: var(--gold);
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* App font stacks (intentionally re-declared after the serif base) */
body, .controls, .omni-btn, #status, .popup-content {
    font-family: var(--font-body);
}
h1, h2, h3, .toolbar-title {
    font-family: var(--font-display);
}
td, th, .symbol-cell {
    font-family: var(--font-symbols);
}

h1 {
    font-size: 2em;
    margin: 10px 0 22px;
    text-align: center;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

/* Custom cursors */
.pointer-cursor        { cursor: url('Graphics/pointer1.png') 24 47, pointer; }
.grabber-open-cursor   { cursor: url('Graphics/pointer3.png') 24 47, grab; }
.grabber-closed-cursor { cursor: url('Graphics/pointer2.png') 24 47, grabbing; }
.rotate-cursor         { cursor: url('Graphics/rotate3.png') 12 12, pointer; }
.rotate-active-cursor  { cursor: url('Graphics/rotate1.png') 12 12, pointer; }
.rotate-animate-cursor { cursor: url('Graphics/rotate2.png') 12 12, pointer; }
.map-global-pointer    { cursor: url('Graphics/pointer4.png') 24 47, pointer; }

/* Shared keyframes */
@keyframes shimmer {
    0%   { opacity: 0.5; }
    50%  { opacity: 1; }
    100% { opacity: 0.5; }
}
@keyframes pulse {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ── 03. FORM ELEMENTS ─────────────────────────────────────────────────── */
button {
    display: block;
    width: 96%;
    margin: 4px 2%;
    padding: 6px 8px;
    background: transparent;
    color: var(--gold);
    border: 1px solid var(--gold);
    border-radius: 3px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1em;
    transition: all 0.3s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
button:hover {
    background: var(--gold-a10);
    box-shadow: 0 0 10px var(--gold-a30);
}

select {
    display: block;
    width: 96%;
    margin: 4px 2%;
    padding: 6px 8px;
    border: 1px solid var(--gold);
    border-radius: 3px;
    background: var(--ink-3);
    color: var(--gold);
    font-family: inherit;
    font-size: 1em;
}
select option {
    background: var(--ink-3);
    color: var(--gold);
}

label {
    margin-top: 4px;
    margin-bottom: 2px;
    display: block;
}

#current-symbol-mode { margin-bottom: 6px; }

/* ── 04. APP SHELL LAYOUT ──────────────────────────────────────────────── */
.top-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(90deg, var(--ink) 0%, #1a1a1a 50%, var(--ink) 100%);
    border-bottom: 2px solid var(--gold);
    z-index: var(--z-toolbar);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    min-height: var(--toolbar-h);
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: var(--safe-top);
}

.toolbar-center {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar-selects {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: nowrap;
}

.toolbar-title {
    font-size: 1.6em;
    margin: 0 18px;
    color: var(--gold-bright);
    letter-spacing: 2px;
    text-shadow: 0 0 10px #FFD70088;
    padding-top: 8px;
}

.music-select {
    background: var(--ink-3);
    color: var(--gold);
    border: 1px solid var(--gold);
    border-radius: 4px;
    padding: 8px 12px;
    font-family: inherit;
    min-width: 120px;
    max-width: 180px;
    flex: 0 0 auto;
    font-size: 1em;
}
#top-toolbar .music-select,
.top-toolbar .music-select,
#symbol-class.music-select,
#map-style.music-select {
    border: none;
    box-shadow: none;
}

/* Toolbar select scrollbars */
#symbol-class, #map-style {
    scrollbar-width: auto;
    scrollbar-color: var(--gold-bright) var(--ink-3);
}
#symbol-class::-webkit-scrollbar, #map-style::-webkit-scrollbar {
    width: 12px;
    background: var(--ink-3);
}
#symbol-class::-webkit-scrollbar-thumb, #map-style::-webkit-scrollbar-thumb {
    background: var(--gold-bright);
    border-radius: 6px;
}
#symbol-class::-webkit-scrollbar-track, #map-style::-webkit-scrollbar-track {
    background: var(--ink-3);
}

#main-content {
    position: relative;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
}

#map-container {
    flex: 1 1 auto;
    position: relative;
    width: 100%;
    min-height: 0;
    height: 100%;
    background: var(--ink-3);
    margin: 0 auto;
}
/* !important required: Mapbox GL writes inline width/height on the canvas */
#map-container .mapboxgl-map,
#map-container .mapboxgl-canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 0;
}
.mapboxgl-canvas {
    font-family: 'Noto Sans Egyptian Hieroglyphs', 'Noto Sans Symbols2',
                 'Segoe UI Symbol', 'Arial Unicode MS', 'Symbola', sans-serif !important;
}
/* Markers must stay clickable above Mapbox's own pointer-events handling */
.mapboxgl-marker  { pointer-events: all !important; cursor: pointer !important; }
.room-map-marker  { pointer-events: all !important; cursor: pointer !important; }
/* Hide Mapbox-Draw's default control group — the app ships its own panel */
.mapboxgl-ctrl-group.mapboxgl-ctrl { display: none; }

#ribbon {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--ink-3);
    color: var(--gold-bright);
    padding: 10px;
    z-index: var(--z-ribbon);
    text-align: center;
}

#info-terminal {
    background: var(--ink);
    color: var(--gold-bright);
    padding: 10px;
    min-height: 60px;
    border-top: 1px solid #333;
    width: 100%;
    margin: 0;
}

.teleport-flash {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    pointer-events: none;
    z-index: var(--z-flash);
}

/* ── 05. FIXED UTILITY CONTROLS ────────────────────────────────────────── */
/* Hamburger is positioned by inline styles elsewhere — stylesheet
   !important is the only way to win over those inline declarations.    */
#menu-hamburger, .menu-hamburger {
    width: 32px !important;
    height: 32px !important;
    top: calc(6px + var(--safe-top)) !important;
    left: calc(12px + var(--safe-left)) !important;
    font-size: 1.2em !important;
    z-index: var(--z-hamburger) !important;
}

#webcam-controls { z-index: var(--z-webcam) !important; } /* beats inline z-index */

/* Shared recipe for the small fixed icon buttons */
#lt-btn,
#audio-btn,
#toolbar-sound-toggle-btn {
    position: fixed;
    top: calc(11px + var(--safe-top));
    left: auto;
    width: var(--ctl-size);
    height: var(--ctl-size);
    z-index: var(--z-fixed-btn);
    background: transparent;
    border: none;
    color: var(--gold-bright);
    font-size: 1.25em;
    cursor: pointer;
    border-radius: var(--r-md);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s, opacity 0.2s;
    margin: 0;
    min-height: unset;
    max-width: unset;
    opacity: 0.7;
    line-height: 1;
}
#lt-btn                   { right: calc(var(--ctl-lt-right)    + var(--safe-right)); }
#audio-btn                { right: calc(var(--ctl-audio-right) + var(--safe-right)); }
#toolbar-sound-toggle-btn { right: calc(var(--ctl-sound-right) + var(--safe-right)); }

#lt-btn:hover, #lt-btn:focus,
#audio-btn:hover, #audio-btn:focus,
#toolbar-sound-toggle-btn:hover, #toolbar-sound-toggle-btn:focus {
    background: var(--bright-a12);
    color: var(--gold-pale);
    opacity: 1;
    box-shadow: none;
    border-color: transparent;
}

/* Settings gear — larger, with its own surface */
#settings-menu {
    position: fixed;
    top: calc(6px + var(--safe-top));
    right: calc(var(--ctl-gear-right) + var(--safe-right));
    left: auto;
    width: var(--ctl-size-lg);
    height: var(--ctl-size-lg);
    z-index: var(--z-fixed-btn);
    background: linear-gradient(135deg, var(--panel-night) 60%, var(--panel-night-2) 100%);
    border: none;
    color: var(--gold-bright);
    font-size: 1.45em;
    cursor: pointer;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
    margin: 0;
    min-height: unset;
    max-width: unset;
}
#settings-menu:hover {
    background: var(--panel-night-2);
    color: var(--gold-pale);
    box-shadow: none;
    border-color: transparent;
}

/* Toolbar sign-in link — desktop only (hidden ≤768 in §15) */
#toolbar-signin-btn {
    position: fixed;
    top: calc(6px + var(--safe-top));
    right: calc(var(--ctl-signin-right) + var(--safe-right));
    left: auto;
    z-index: var(--z-fixed-btn);
    background: none;
    border: none;
    color: var(--gold-bright);
    font-size: 0.82em;
    font-family: var(--font-serif);
    letter-spacing: 0.06em;
    cursor: pointer;
    padding: 0 10px;
    height: 42px;
    min-width: auto;
    width: auto;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    text-shadow: 0 0 12px #FFD70033;
    transition: color 0.18s, text-shadow 0.18s;
}
#toolbar-signin-btn:hover {
    color: var(--gold-pale);
    text-shadow: 0 0 10px #FFD70088;
}

/* ── 06. QUICK-SEARCH WIDGET ───────────────────────────────────────────── */
#qs-widget {
    position: fixed;
    top: calc(10px + var(--safe-top));
    left: calc(165px + var(--safe-left));
    z-index: var(--z-qs);
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: nowrap;
}
#qs-trigger {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 215, 0, 0.35);
    background: rgba(18, 18, 18, 0.85);
    color: var(--gold-bright);
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
#qs-trigger:hover {
    background: rgba(30, 30, 30, 0.95);
    border-color: var(--gold-bright);
    box-shadow: 0 0 10px #FFD70044;
}
#qs-panel {
    display: flex;
    align-items: center;
    overflow: hidden;
    max-width: 0;
    opacity: 0;
    transition: max-width 0.3s ease, opacity 0.25s ease;
    pointer-events: none;
    margin-left: 6px;
    position: relative;
}
#qs-panel.open {
    max-width: 260px;
    opacity: 1;
    pointer-events: all;
}
#qs-input {
    background: rgba(18, 18, 18, 0.92);
    border: 1.5px solid rgba(255, 215, 0, 0.4);
    border-radius: 18px;
    color: var(--gold-bright);
    font-size: 0.82em;
    font-family: 'Space Grotesk', sans-serif;
    padding: 6px 28px 6px 14px;
    width: 215px;
    outline: none;
    backdrop-filter: blur(4px);
}
#qs-input::placeholder { color: rgba(255, 215, 0, 0.35); }
#qs-input:focus { border-color: var(--gold-bright); }
#qs-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 215, 0, 0.5);
    font-size: 1em;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    display: none;
    z-index: 2;
}
#qs-clear.visible { display: block; }
#qs-results {
    position: absolute;
    top: 44px;
    left: 0;
    background: rgba(18, 18, 18, 0.97);
    border: 1px solid rgba(255, 215, 0, 0.25);
    border-radius: var(--r-md);
    width: 290px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    z-index: 10;
}
#qs-results.open { display: block; }
#qs-results::-webkit-scrollbar { width: 4px; }
#qs-results::-webkit-scrollbar-thumb { background: rgba(255, 215, 0, 0.2); border-radius: 2px; }
.qs-result {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.12s;
}
.qs-result:last-child { border-bottom: none; }
.qs-result:hover { background: var(--bright-a07); }
.qs-result-title { font-size: 0.85em; color: var(--gold-bright); font-weight: 600; }
.qs-result-meta { font-size: 0.72em; color: #888; margin-top: 1px; }
.qs-empty { padding: 12px; font-size: 0.82em; color: #555; text-align: center; }
.qs-count-bar {
    padding: 6px 12px 4px;
    font-size: 0.68em;
    color: #555;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    letter-spacing: 0.04em;
}
.qs-section-header {
    padding: 6px 12px 4px;
    font-size: 0.65em;
    color: rgba(255, 215, 0, 0.4);
    border-top: 1px solid rgba(255, 215, 0, 0.1);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.qs-result[data-address] .qs-result-title { color: #c8b8ff; }
.qs-result[data-address] .qs-result-meta { color: #6a6a8a; }
.qs-result[data-address]:hover { background: rgba(200, 184, 255, 0.07); }
.qs-addr-spinner { padding: 8px 12px; font-size: 0.78em; color: #555; font-style: italic; }

/* ── 07. MAP NAV SLIDERS ───────────────────────────────────────────────── */
#map-nav-controls {
    position: absolute;
    bottom: calc(52px + var(--safe-bottom));
    right: calc(52px + var(--safe-right));
    z-index: var(--z-map-nav);
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: flex-end;
    pointer-events: none;
}
.map-nav-ctrl {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    pointer-events: all;
}
.map-nav-ctrl label {
    font-size: 8px;
    letter-spacing: 0.08em;
    color: var(--gold-bright);
    text-transform: uppercase;
    font-family: 'Space Grotesk', sans-serif;
    text-shadow: 0 0 5px #000;
    user-select: none;
}
.map-nav-ctrl input[type=range] {
    writing-mode: vertical-lr;
    direction: rtl;
    width: 20px;
    height: 200px;
    cursor: pointer;
    appearance: none;
    background: transparent;
    padding: 0;
}
.map-nav-ctrl input[type=range]::-webkit-slider-runnable-track {
    background: #FFD70033;
    border-radius: 3px;
    width: 4px;
}
.map-nav-ctrl input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--gold-bright);
    box-shadow: 0 0 8px #FFD70099, 0 0 2px #000;
    margin-left: -4px;
    cursor: pointer;
}
.map-nav-ctrl input[type=range]::-moz-range-track {
    background: #FFD70033;
    border-radius: 3px;
    width: 4px;
}
.map-nav-ctrl input[type=range]::-moz-range-thumb {
    width: 13px;
    height: 13px;
    border: none;
    border-radius: 50%;
    background: var(--gold-bright);
    box-shadow: 0 0 8px #FFD70099;
    cursor: pointer;
}
.map-nav-ctrl::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 105%;
    right: 50%;
    transform: translateX(50%);
    white-space: pre-line;
    background: rgba(10, 8, 20, 0.93);
    color: var(--gold-bright);
    font-size: 10px;
    line-height: 1.5;
    letter-spacing: 0.04em;
    font-family: 'Space Grotesk', sans-serif;
    padding: 7px 10px;
    border-radius: var(--r-sm);
    border: 1px solid #FFD70055;
    box-shadow: 0 2px 12px #000a;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s;
    z-index: 1100;
    min-width: 140px;
    text-align: center;
}
.map-nav-ctrl:hover::after { opacity: 1; }

/* ── 08. DRAW PANEL ────────────────────────────────────────────────────── */
#draw-panel {
    position: fixed;
    left: calc(16px + var(--safe-left));
    bottom: calc(60px + var(--safe-bottom));
    z-index: var(--z-draw-panel);
    background: rgba(10, 8, 20, 0.92);
    border: 1px solid #FFD70066;
    border-radius: var(--r-md);
    padding: 12px 10px 10px;
    display: none;
    flex-direction: column;
    gap: 6px;
    min-width: 158px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    font-family: 'Space Grotesk', sans-serif;
}
#draw-panel.draw-panel-open { display: flex; }
#draw-panel-title {
    font-size: 9px;
    letter-spacing: 0.12em;
    color: var(--gold-bright);
    text-transform: uppercase;
    text-align: center;
    padding-bottom: 4px;
    border-bottom: 1px solid #FFD70033;
    margin-bottom: 2px;
}
#draw-panel-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--gold-bright);
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s;
}
#draw-panel-close:hover { background: var(--bright-a12); }
.draw-mode-btn {
    background: var(--bright-a07);
    border: 1px solid #FFD70044;
    border-radius: var(--r-sm);
    color: var(--gold-bright);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
    cursor: pointer;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: background 0.15s, border-color 0.15s;
    text-align: left;
    line-height: 1;
}
.draw-mode-btn:hover { background: var(--bright-a18); border-color: #FFD700aa; }
.draw-mode-btn.active { background: var(--bright-a28); border-color: var(--gold-bright); }
.draw-mode-btn.danger { color: var(--danger); border-color: #ff6b6b44; }
.draw-mode-btn.danger:hover { background: rgba(255, 107, 107, 0.18); border-color: #ff6b6baa; }
#draw-label-row {
    display: flex;
    gap: 5px;
    margin-top: 2px;
}
#draw-feature-label {
    flex: 1;
    background: rgba(255, 215, 0, 0.06);
    border: 1px solid #FFD70044;
    border-radius: 5px;
    color: var(--gold-bright);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 11px;
    padding: 5px 7px;
    outline: none;
}
#draw-feature-label::placeholder { color: #FFD70055; }
#draw-save-btn {
    background: rgba(255, 215, 0, 0.14);
    border: 1px solid #FFD70066;
    border-radius: 5px;
    color: var(--gold-bright);
    font-size: 12px;
    cursor: pointer;
    padding: 5px 9px;
    font-family: 'Space Grotesk', sans-serif;
    transition: background 0.15s;
}
#draw-save-btn:hover { background: var(--bright-a28); }
#draw-feature-color {
    width: 26px;
    height: 26px;
    border: 1px solid #FFD70044;
    border-radius: 4px;
    padding: 1px;
    cursor: pointer;
    background: none;
    flex-shrink: 0;
}
#draw-io-row { display: flex; gap: 5px; }
#draw-io-row .draw-mode-btn {
    flex: 1;
    justify-content: center;
    padding: 5px 4px;
    font-size: 11px;
    gap: 3px;
}
#draw-saved-count {
    font-size: 9px;
    color: #FFD70077;
    text-align: center;
    letter-spacing: 0.06em;
}

/* ── 09. FLOATING PANELS ───────────────────────────────────────────────── */
.controls {
    position: absolute;
    top: 30px;
    right: 30px;
    z-index: var(--z-map-controls);
    background: var(--panel);
    border-left: 1px solid #333;
    padding: 18px;
    min-width: 250px;
    max-width: 400px;
    border-radius: 12px;
    box-shadow: 0 4px 24px #000a;
}
.controls .top-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}

.category-filter {
    position: absolute;
    top: 80px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--gold);
    border-radius: 4px;
    padding: 10px;
    z-index: var(--z-map-overlay);
    max-width: 300px;
}
.category-filter h3 {
    margin: 0 0 10px 0;
    color: var(--gold);
    font-size: 1em;
    text-align: center;
}
.filter-btn {
    margin: 3px;
    padding: 5px 10px;
    background: var(--ink-3);
    color: var(--gold);
    border: 1px solid var(--gold);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8em;
}
.filter-btn:hover { background: #333; }
.filter-btn.active { background: var(--gold); color: #000; }

/* ── 10. READING TABLE / STATUS / SELECTION UI ─────────────────────────── */
#status {
    font-size: 0.9em;
    margin-top: 15px;
    padding: 10px;
    background: var(--gold-a10);
    border-radius: 3px;
    text-align: center;
}
.selection-mode {
    margin: 15px 0;
    padding: 10px;
    background: var(--gold-a20);
    border-radius: 3px;
    text-align: center;
    display: none;
}
.position-meanings {
    margin: 15px 0;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #666;
    border-radius: 3px;
    display: none;
}
.position-meanings select {
    width: 100%;
    margin: 5px 0;
    padding: 5px;
    background: #000000;
    border: 1px solid var(--gold);
    color: var(--gold);
}
.position-meanings select option {
    background: #000000;
    color: var(--gold);
}
.reading-layout {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 10px 0;
}
.position-label {
    font-size: 0.8em;
    color: #999;
    text-align: center;
}
#reading-table {
    margin: 32px auto 0;
    min-height: 60px;
    text-align: center;
    width: 100%;
    max-width: none;
    overflow-x: auto;
    overflow-y: auto;
    scrollbar-width: auto;
    scrollbar-color: var(--gold-bright) var(--ink-3);
}
#reading-table::-webkit-scrollbar {
    width: 12px;
    background: var(--ink-3);
}
#reading-table::-webkit-scrollbar-thumb {
    background: var(--gold-bright);
    border-radius: 6px;
}
#reading-table::-webkit-scrollbar-track { background: var(--ink-3); }

#selection-mode.highlight-btn {
    background: var(--gold-bright);
    color: var(--ink-2);
    font-weight: bold;
    border: 2px solid var(--gold-bright);
    box-shadow: 0 0 8px #FFD70055;
}
#selection-mode.active {
    background: transparent;
    color: var(--gold);
    border: 1px solid var(--gold);
    font-weight: normal;
    box-shadow: none;
}

/* ── 11. OMNIPORT PANEL ────────────────────────────────────────────────── */
#omniport-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
    margin: 32px auto 0;
    padding: 36px 32px;
    background: linear-gradient(135deg, var(--panel-night) 60%, var(--panel-night-2) 100%);
    border-radius: 24px;
    box-shadow: 0 6px 32px #000a, 0 1.5px 0 #ffd70055 inset;
    max-width: 2400px;
    width: 96vw;
}
.omniport-row {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 70px;
    margin-top: 18px;
}
.omni-btn {
    font-size: 5.2em;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--gold-bright);
    background: linear-gradient(135deg, var(--panel-night-2) 60%, var(--panel-night) 100%);
    color: var(--gold-bright);
    box-shadow: 0 4px 32px #ffd70033, 0 0 0 #ffd700;
    transition:
        background 0.2s,
        color 0.2s,
        box-shadow 0.25s cubic-bezier(.4, 2, .6, 1),
        transform 0.18s cubic-bezier(.4, 2, .6, 1);
    cursor: pointer;
    outline: none;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.omni-btn:hover, .omni-btn:focus {
    background: var(--gold-bright);
    color: var(--panel-night-2);
    box-shadow: 0 0 48px #ffd70099, 0 0 0 8px #ffd70044;
    transform: scale(1.12) rotate(-6deg);
    border-color: #fff;
}
.omniport-title {
    color: var(--gold-bright);
    font-size: 1.6em;
    font-family: 'Unica One', 'Space Grotesk', 'Inter', sans-serif;
    letter-spacing: 2px;
    margin-bottom: 12px;
    text-shadow: 0 0 8px #ffd70044;
}
.omniport-search-shell {
    width: min(980px, 100%);
    margin-bottom: 26px;
}
.omniport-search-label {
    display: block;
    margin-bottom: 10px;
    color: #fff1bf;
    font-size: 0.96em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.omniport-search-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}
.omniport-search-input,
.omniport-search-clear {
    width: 100%;
    margin: 0;
}
.omniport-search-input {
    padding: 14px 18px;
    border: 1px solid rgba(255, 215, 0, 0.45);
    border-radius: 999px;
    background: rgba(9, 11, 18, 0.86);
    color: var(--gold-cream);
    font-size: 1rem;
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.omniport-search-input::placeholder { color: rgba(255, 248, 220, 0.58); }
.omniport-search-input:focus {
    border-color: var(--gold-bright);
    box-shadow: 0 0 0 4px rgba(255, 215, 0, 0.16);
    background: rgba(16, 20, 30, 0.96);
}
.omniport-search-clear {
    width: auto;
    padding: 14px 18px;
    border: 1px solid rgba(255, 215, 0, 0.55);
    border-radius: 999px;
    background: rgba(35, 36, 58, 0.96);
    color: var(--gold-bright);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.omniport-search-count {
    margin-top: 10px;
    color: rgba(255, 248, 220, 0.78);
    font-size: 0.92em;
    letter-spacing: 0.04em;
}
.omniport-search-results {
    margin-top: 14px;
    display: grid;
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}
.omniport-search-result,
.omniport-search-empty {
    width: 100%;
    margin: 0;
    border-radius: 16px;
    border: 1px solid rgba(255, 215, 0, 0.24);
    background: linear-gradient(135deg, rgba(12, 16, 27, 0.94), rgba(33, 36, 57, 0.88));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.omniport-search-result {
    padding: 14px 16px;
    text-align: left;
}
.omniport-search-result:hover,
.omniport-search-result:focus {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(33, 36, 57, 0.96));
    border-color: rgba(255, 215, 0, 0.55);
    box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.12);
}
.omniport-search-result-title,
.omniport-search-result-meta { display: block; }
.omniport-search-result-title {
    color: #fff7d6;
    font-size: 1.02em;
    font-weight: 700;
}
.omniport-search-result-meta {
    margin-top: 4px;
    color: rgba(255, 215, 0, 0.82);
    font-size: 0.88em;
    letter-spacing: 0.03em;
}
.omniport-search-empty {
    padding: 14px 16px;
    color: rgba(255, 248, 220, 0.82);
}
.omniport-search-empty span { color: var(--gold-bright); }

/* ── 12. MAP POPUPS & TOOLTIPS ─────────────────────────────────────────── */
.popup-content {
    font-family: var(--font-serif);
    color: var(--gold);
    background: var(--ink-2);
    border-radius: var(--r-sm);
    padding: 6px 10px;
    max-width: 220px;
    text-align: center;
    line-height: 1.3;
}
.popup-content .coords {
    font-size: 0.8em;
    color: #999;
    margin-top: 5px;
}

.book-marker-logo {
    width: 54px;
    height: 54px;
    object-fit: contain;
    filter: drop-shadow(0 0 8px var(--gold-bright));
    border-radius: 8px;
}

/* Mapbox popup chrome — !important required to beat mapbox-gl.css */
.mapboxgl-popup-content {
    background: linear-gradient(180deg, rgba(24, 24, 24, 0.98), rgba(12, 12, 12, 0.96)) !important;
    color: var(--gold-bright) !important;
    border-radius: 16px !important;
    border: 2px solid rgba(212, 175, 55, 0.85) !important;
    box-shadow: 0 0 0 1px rgba(255, 215, 0, 0.18), 0 10px 30px rgba(0, 0, 0, 0.45) !important;
    padding: 14px 16px !important;
    min-width: 220px !important;
    max-width: 320px !important;
    line-height: 1.4;
}
.mapboxgl-popup-content > * { margin: 0; }
.mapboxgl-popup-content h1,
.mapboxgl-popup-content h2,
.mapboxgl-popup-content h3,
.mapboxgl-popup-content strong,
.mapboxgl-popup-content .popup-title,
.mapboxgl-popup-content .title {
    margin-top: 0 !important;
    margin-bottom: 8px !important;
    padding-bottom: 0 !important;
}
.mapboxgl-popup-content button,
.mapboxgl-popup-content input[type=button],
.mapboxgl-popup-content input[type=submit],
.mapboxgl-popup-content .btn {
    padding: 6px 10px !important;
    font-size: 0.9rem !important;
    min-width: auto !important;
    width: auto !important;
    border-radius: 8px !important;
    border: 1px solid rgba(212, 175, 55, 0.6) !important;
    background: rgba(213, 175, 60, 0.12) !important;
    color: #FFD770 !important;
    margin: 4px 3px 4px 0 !important;
}
.mapboxgl-popup-close-button {
    width: auto !important;
    height: auto !important;
    padding: 4px 8px !important;
    line-height: 1 !important;
    font-size: 16px !important;
    background: rgba(255, 215, 0, 0.08) !important;
    color: var(--gold-bright) !important;
    border: 1px solid rgba(212, 175, 55, 0.5) !important;
    cursor: pointer !important;
    position: absolute !important;
    top: 8px !important;
    right: 8px !important;
}
.mapboxgl-popup-tip {
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
}

/* Draw-feature label popups */
.tv-draw-popup .mapboxgl-popup-content,
.tv-draw-popup.mapboxgl-popup .mapboxgl-popup-content {
    background: rgba(10, 8, 20, 0.92);
    border: 1px solid #FFD70055;
    border-radius: var(--r-sm);
    padding: 5px 10px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}
.tv-draw-popup .mapboxgl-popup-tip { display: none; }
.tv-draw-popup-label {
    color: var(--gold-bright);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.tv-ll-popup-name {
    display: block;
    font-weight: 600;
    color: var(--gold-bright);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 12px;
}
.tv-ll-popup-desc {
    display: block;
    color: #d4af3799;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 10px;
    margin-top: 2px;
    line-height: 1.4;
}

/* Location popup (merged: typography from the original first block,
   surface treatment from the original second block) */
.location-popup {
    font-family: var(--font-serif);
    font-size: 1.25em;
    padding: 22px 22px 16px;
    line-height: 1.6;
    color: var(--gold-bright);
    background: var(--panel-night);
    border-radius: var(--r-lg);
    min-width: 240px;
    max-width: 340px;
}
.location-popup h3 {
    font-size: 1.3em;
    margin: 0 0 10px 0;
    color: var(--gold-bright);
    font-family: 'Unica One', 'Space Grotesk', 'Inter', sans-serif;
    border-bottom: 1px solid var(--gold-a30);
    padding-bottom: 5px;
}
.location-popup p {
    margin: 0 0 10px 0;
    color: var(--gold-pale);
    font-size: 1.1em;
    line-height: 1.4;
}
.popup-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}
.location-popup .popup-footer {
    gap: 12px;
    font-size: 1em;
}
.category-tag, .roast-tag {
    display: inline-block;
    background: var(--gold-a20);
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 0.8em;
}
.location-popup .category-tag,
.location-popup .roast-tag {
    background: var(--panel-night-2);
    color: var(--gold-bright);
    border-radius: var(--r-sm);
    padding: 3px 10px;
    font-size: 1em;
}

/* Guided-tour tooltip */
.guided-tooltip {
    background: var(--ink-2);
    color: var(--gold-bright);
    border-radius: var(--r-md);
    padding: 18px 22px 14px;
    box-shadow: 0 4px 24px #000a;
    font-size: 1.1em;
    max-width: 260px;
    position: absolute;
    z-index: var(--z-tooltip);
    border: 2px solid var(--gold-bright);
}
.tooltip-arrow {
    width: 0;
    height: 0;
    position: absolute;
}
.tooltip-arrow-left {
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-right: 14px solid var(--gold-bright);
    left: -14px;
    top: 20px;
}
.tooltip-arrow-top {
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-bottom: 14px solid var(--gold-bright);
    top: -14px;
    left: 40px;
}
.tooltip-next {
    margin-top: 12px;
    background: var(--gold-bright);
    color: var(--ink-2);
    border: none;
    border-radius: var(--r-sm);
    padding: 6px 18px;
    font-weight: bold;
    cursor: pointer;
    float: right;
}

/* ── 13. MODALS ────────────────────────────────────────────────────────── */

/* — Settings modal — */
.settings-modal {
    display: none;
    position: fixed;
    z-index: var(--z-settings-modal);
    inset: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}
.settings-content {
    background: linear-gradient(145deg, #1a1a1a, #2a2a2a);
    margin: 5% auto;
    padding: 0;
    border: 2px solid var(--gold);
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    max-height: 80dvh;
    box-shadow: 0 10px 30px var(--gold-a30);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.settings-header {
    background: linear-gradient(90deg, var(--gold), #b8941f);
    color: var(--ink);
    padding: 20px;
    border-radius: 10px 10px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.settings-header h2 {
    margin: 0;
    font-size: 1.5em;
    font-weight: bold;
}
.close-btn {
    background: none;
    border: none;
    color: var(--ink);
    font-size: 1.5em;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 50%;
    transition: background 0.3s ease;
}
#close-settings.close-btn {
    font-size: 1.1em;
    width: 32px;
    height: 32px;
    padding: 0;
    min-width: auto;
    min-height: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.close-btn:hover { background: rgba(0, 0, 0, 0.2); }
.settings-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}
.settings-section {
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--gold-a30);
}
.settings-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.settings-section h3 {
    color: var(--gold);
    margin-bottom: 15px;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--gold);
    background: var(--ink-3);
}
.settings-tab {
    flex: 1;
    padding: 12px 0;
    background: none;
    border: none;
    color: var(--gold);
    font-size: 1.1em;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 2px solid transparent;
}
.settings-tab.active {
    background: var(--ink-2);
    color: var(--gold-bright);
    border-bottom: 2px solid var(--gold-bright);
    font-weight: bold;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.layer-toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.layer-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--r-sm);
    transition: all 0.3s ease;
    background: var(--gold-a10);
    border: 1px solid var(--gold-a30);
}
.layer-toggle:hover {
    background: var(--gold-a20);
    border-color: rgba(212, 175, 55, 0.5);
}
.layer-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--gold);
    margin: 0;
}
.layer-toggle span {
    color: var(--gold);
    font-size: 0.95em;
    user-select: none;
}
.layer-accordion-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0;
}
.layer-accordion-header:hover { color: var(--gold-pale); }
.accordion-arrow {
    margin-left: auto;
    font-size: 0.85em;
    transition: transform 0.2s;
    display: inline-block;
}
.layer-accordion.open .accordion-arrow { transform: rotate(90deg); }
.layer-accordion-body { padding-top: 10px; }
.layer-note {
    font-size: 0.65em;
    color: rgba(255, 215, 0, 0.5);
    font-weight: normal;
    letter-spacing: 0.04em;
}
.layer-section-note {
    font-size: 0.78em;
    color: rgba(255, 215, 0, 0.55);
    margin: 0 0 12px 0;
    line-height: 1.45;
}
.layer-section-note code {
    background: var(--gold-a08);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.95em;
    color: var(--gold-bright);
}

/* — Astro modal — */
#astro-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
}
#astro-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(5px);
}
#astro-modal-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, #0e0e1a, #181826);
    border: 1.5px solid #d4af3755;
    border-radius: var(--r-lg);
    width: 90%;
    max-width: 460px;
    box-shadow: 0 12px 40px rgba(212, 175, 55, 0.18), 0 0 0 1px #d4af3722;
    overflow: hidden;
    scrollbar-width: thin;
    scrollbar-color: #d4af3788 #07070f;
}
#astro-modal-content::-webkit-scrollbar { width: 6px; }
#astro-modal-content::-webkit-scrollbar-track { background: #07070f; border-radius: 3px; }
#astro-modal-content::-webkit-scrollbar-thumb { background: #d4af3766; border-radius: 3px; }
#astro-modal-content::-webkit-scrollbar-thumb:hover { background: #d4af37bb; }
#astro-modal-header {
    background: linear-gradient(90deg, #1a1508, #2a2010);
    border-bottom: 1px solid #d4af3733;
    padding: 7px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#astro-modal-title {
    color: var(--gold);
    font-size: 0.88em;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-family: 'Space Grotesk', sans-serif;
}
#astro-modal-close {
    background: none;
    border: none;
    color: #d4af3788;
    font-size: 1.1em;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
#astro-modal-close:hover { color: #ff9999; background: rgba(200, 50, 50, 0.18); }
#astro-modal-body { padding: 8px 12px 12px; }

/* Shared modal loader */
.modal-loader {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 2;
    background: rgba(5, 5, 15, 0.96);
    color: #f5ecb6;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px 18px;
    backdrop-filter: blur(4px);
}
.modal-loader-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.25s ease;
}
.modal-loader.show { opacity: 1; }
.modal-loader-spiral {
    font-size: 2.1em;
    letter-spacing: 0.18em;
    color: #ffefd4;
    text-shadow: 0 0 28px rgba(255, 238, 212, 0.24);
    animation: loader-spiral 2.2s ease-in-out infinite;
}
.modal-loader-text {
    font-size: 0.88em;
    color: rgba(241, 232, 196, 0.86);
    max-width: 230px;
    line-height: 1.45;
    letter-spacing: 0.02em;
    opacity: 0.92;
}
@keyframes loader-spiral {
    0%   { transform: rotate(0deg) scale(0.94); opacity: 0.8; }
    40%  { transform: rotate(160deg) scale(1.08); opacity: 1; }
    100% { transform: rotate(360deg) scale(0.94); opacity: 0.8; }
}

#astro-tab-strip {
    display: flex;
    gap: 0;
    margin-bottom: 7px;
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid #d4af3733;
}
.astro-tab {
    flex: 1;
    padding: 4px 0;
    background: transparent;
    border: none;
    color: #d4af3766;
    font-size: 0.82em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.astro-tab:hover { background: var(--gold-a08); color: #d4af37aa; }
.astro-tab.active { background: var(--gold-a14); color: var(--gold); font-weight: 600; }
.astro-tab-panel { display: none; }
.astro-tab-panel.active { display: block; }
.astro-field-row { margin-bottom: 5px; }
.astro-label {
    display: block;
    font-size: 0.78em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #d4af37aa;
    margin-bottom: 3px;
}
.astro-input {
    width: 100%;
    background: #07070f;
    color: var(--gold);
    border: 1px solid #d4af3744;
    border-radius: var(--r-sm);
    padding: 5px 8px;
    font-family: inherit;
    font-size: 0.88em;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.astro-input:focus {
    outline: none;
    border-color: #d4af37aa;
    box-shadow: 0 0 8px rgba(212, 175, 55, 0.22);
}
.astro-input[type="date"]::-webkit-calendar-picker-indicator,
.astro-input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.7); }
.astro-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.astro-input[type="number"]::-webkit-inner-spin-button { opacity: 0.4; }
#astro-generate-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.astro-action-btn {
    background: var(--gold-a10);
    border: 1px solid #d4af3755;
    color: var(--gold);
    border-radius: var(--r-sm);
    padding: 5px 12px;
    font-size: 0.84em;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 0.06em;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}
.astro-action-btn:hover {
    background: rgba(212, 175, 55, 0.22);
    box-shadow: 0 0 10px var(--gold-a20);
}
.astro-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.astro-transit-mode-btn { min-width: 130px; white-space: nowrap; }
.astro-transit-mode-btn.active {
    background: rgba(255, 215, 0, 0.22);
    color: #fff;
    border-color: var(--gold-bright);
}
.astro-primary-btn {
    background: linear-gradient(145deg, #b8900a, #7a5e00);
    border-color: #d4af3788;
    color: #fff8e0;
    font-weight: 600;
}
.astro-primary-btn:hover {
    background: linear-gradient(145deg, var(--gold), #a07800);
    color: var(--ink);
}
#astro-status {
    margin-top: 6px;
    font-size: 0.82em;
    color: #d4af37aa;
    min-height: 1.2em;
    line-height: 1.4;
}
#astro-status.modal-loading,
#stellar-status.modal-loading {
    color: #ffe88e;
    font-weight: 600;
}
#astro-status.modal-loading::before,
#stellar-status.modal-loading::before {
    content: '';
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    margin-right: 0.45em;
    border-radius: 50%;
    background: linear-gradient(135deg, #ffd670, #ffb86c);
    animation: modal-pulse 1s linear infinite;
}
@keyframes modal-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.35); opacity: 0.6; }
}
/* Dropdown (select) scrollbar */
#astro-tz-select { scrollbar-width: thin; scrollbar-color: #d4af3788 #07070f; }
#astro-tz-select::-webkit-scrollbar { width: 6px; }
#astro-tz-select::-webkit-scrollbar-track { background: #07070f; }
#astro-tz-select::-webkit-scrollbar-thumb { background: #d4af3766; border-radius: 3px; }
#astro-tz-select::-webkit-scrollbar-thumb:hover { background: #d4af37bb; }

/* — Astro intent screen — scoped reset over global button/select rules — */
#astro-intent-screen button,
#astro-intent-screen select,
#astro-intent-screen input[type="text"] {
    display: block;
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 0.88em;
    letter-spacing: 0.04em;
    border: 1px solid rgba(212, 175, 55, 0.32);
    border-radius: var(--r-sm);
    background-color: var(--gold-a08); /* background-color, not shorthand — keeps background-image intact */
    color: var(--gold);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
}
/* Continue button needs a top gap from the fields above it.
   (Doubled-ID selector outranks the scoped reset without !important.) */
#astro-intent-screen #astro-intent-continue-btn { margin-top: 8px; }
#astro-intent-screen button:hover,
#astro-intent-screen select:hover {
    background-color: var(--gold-a14);
    border-color: var(--gold-a55);
}
#astro-intent-screen input[type="text"] { cursor: text; }
#astro-intent-screen input[type="text"]::placeholder { color: rgba(212, 175, 55, 0.35); }
#astro-intent-screen button.selected,
#astro-intent-screen #astro-intent-continue-btn:not([disabled]) {
    background-color: var(--gold);
    border-color: var(--gold);
    color: var(--ink);
    font-weight: 600;
}
#astro-intent-screen button.selected:hover,
#astro-intent-screen #astro-intent-continue-btn:not([disabled]):hover {
    background-color: var(--gold-soft);
    border-color: var(--gold-soft);
}
#astro-intent-purpose-select,
#astro-intent-thing-category,
#astro-intent-purpose-select-thing,
#astro-intent-relationship {
    text-align: center;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1 1l5.5 5.5L12 1' stroke='%23d4af37' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    padding-left: 36px;
    scrollbar-width: thin;
    scrollbar-color: #d4af3788 #07070f;
}
#astro-intent-screen select:hover {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1 1l5.5 5.5L12 1' stroke='%23f0c93a' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
#astro-intent-purpose-select::-webkit-scrollbar,
#astro-intent-thing-category::-webkit-scrollbar,
#astro-intent-purpose-select-thing::-webkit-scrollbar,
#astro-intent-relationship::-webkit-scrollbar { width: 6px; }
#astro-intent-purpose-select::-webkit-scrollbar-track,
#astro-intent-thing-category::-webkit-scrollbar-track,
#astro-intent-purpose-select-thing::-webkit-scrollbar-track,
#astro-intent-relationship::-webkit-scrollbar-track { background: #07070f; border-radius: 3px; }
#astro-intent-purpose-select::-webkit-scrollbar-thumb,
#astro-intent-thing-category::-webkit-scrollbar-thumb,
#astro-intent-purpose-select-thing::-webkit-scrollbar-thumb,
#astro-intent-relationship::-webkit-scrollbar-thumb { background: #d4af3766; border-radius: 3px; }
#astro-intent-purpose-select::-webkit-scrollbar-thumb:hover,
#astro-intent-thing-category::-webkit-scrollbar-thumb:hover,
#astro-intent-purpose-select-thing::-webkit-scrollbar-thumb:hover,
#astro-intent-relationship::-webkit-scrollbar-thumb:hover { background: #d4af37bb; }
#astro-intent-purpose-select option,
#astro-intent-purpose-select optgroup,
#astro-intent-purpose-select-thing option,
#astro-intent-purpose-select-thing optgroup,
#astro-intent-relationship option { background: var(--ink); color: var(--gold); }
#astro-intent-fields { display: none; flex-direction: column; gap: 8px; }

/* — Stellarcartography modal (blue palette) — */
#stellar-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
}
#stellar-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 5, 0.82);
    backdrop-filter: blur(6px);
}
#stellar-modal-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, var(--stellar-bg), #111128);
    border: 1.5px solid #7090d055;
    border-radius: var(--r-lg);
    width: 90%;
    max-width: 460px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(100, 140, 255, 0.18), 0 0 0 1px #5570c022;
    scrollbar-width: thin;
    scrollbar-color: #7090d088 var(--stellar-bg);
}
#stellar-modal-content::-webkit-scrollbar { width: 6px; }
#stellar-modal-content::-webkit-scrollbar-track { background: var(--stellar-bg); border-radius: 3px; }
#stellar-modal-content::-webkit-scrollbar-thumb { background: #7090d066; border-radius: 3px; }
#stellar-modal-content::-webkit-scrollbar-thumb:hover { background: #aab8e8bb; }
#stellar-modal-header {
    background: linear-gradient(90deg, #0a0a18, #141430);
    border-bottom: 1px solid #7090d033;
    padding: 7px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 2;
}
#stellar-modal-title {
    color: var(--stellar-pale);
    font-size: 0.88em;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    font-family: 'Space Grotesk', sans-serif;
}
#stellar-modal-close {
    background: none;
    border: none;
    color: #aab8e888;
    font-size: 1.1em;
    cursor: pointer;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}
#stellar-modal-close:hover { color: #ff9999; background: rgba(200, 50, 50, 0.18); }
#stellar-modal-body { padding: 8px 12px 12px; }
#stellar-tab-strip {
    display: flex;
    gap: 0;
    margin-bottom: 7px;
    border-radius: 7px;
    overflow: hidden;
    border: 1px solid #7090d033;
}
.stellar-tab {
    flex: 1;
    padding: 4px 0;
    background: transparent;
    border: none;
    color: #7090d066;
    font-size: 0.82em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s;
}
.stellar-tab:hover { background: rgba(112, 144, 208, 0.08); color: #aab8e8aa; }
.stellar-tab.active { background: rgba(112, 144, 208, 0.14); color: var(--stellar-pale); font-weight: 600; }
.stellar-tab-panel { display: none; }
.stellar-tab-panel.active { display: block; }
.stellar-field-row { margin-bottom: 5px; }
.stellar-label {
    display: block;
    font-size: 0.78em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #aab8e8aa;
    margin-bottom: 3px;
}
.stellar-input {
    width: 100%;
    background: #06060f;
    color: var(--stellar-pale);
    border: 1px solid #7090d044;
    border-radius: var(--r-sm);
    padding: 5px 8px;
    font-family: inherit;
    font-size: 0.88em;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.stellar-input:focus {
    outline: none;
    border-color: #aab8e8aa;
    box-shadow: 0 0 8px rgba(170, 184, 232, 0.18);
}
.stellar-input[type="date"]::-webkit-calendar-picker-indicator,
.stellar-input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(0.7) hue-rotate(200deg); }
.stellar-action-btn {
    background: rgba(112, 144, 208, 0.1);
    border: 1px solid #7090d055;
    color: var(--stellar-pale);
    border-radius: var(--r-sm);
    padding: 5px 12px;
    font-size: 0.84em;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 0.06em;
    transition: background 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}
.stellar-action-btn:hover {
    background: rgba(112, 144, 208, 0.22);
    box-shadow: 0 0 10px rgba(112, 144, 208, 0.2);
}
.stellar-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.stellar-primary-btn {
    background: linear-gradient(145deg, #3a4f9a, #202a5e);
    border-color: #7090d088;
    color: #dde4ff;
    font-weight: 600;
}
.stellar-primary-btn:hover {
    background: linear-gradient(145deg, #5570c0, #3a4f9a);
    color: #fff;
}
#stellar-generate-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}
#stellar-status {
    margin-top: 6px;
    font-size: 0.82em;
    color: #aab8e8aa;
    min-height: 1.2em;
    line-height: 1.4;
}

/* — Stellar intent screen — */
#stellar-intent-screen button,
#stellar-intent-screen select,
#stellar-intent-screen input[type="text"] {
    display: block;
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    font-family: inherit;
    font-size: 0.88em;
    letter-spacing: 0.04em;
    border: 1px solid rgba(112, 144, 208, 0.32);
    border-radius: var(--r-sm);
    background-color: rgba(112, 144, 208, 0.07);
    color: var(--stellar-pale);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: none;
}
#stellar-intent-screen button:hover,
#stellar-intent-screen select:hover {
    background-color: rgba(112, 144, 208, 0.14);
    border-color: rgba(112, 144, 208, 0.55);
}
#stellar-intent-screen input[type="text"] { cursor: text; }
#stellar-intent-screen input[type="text"]::placeholder { color: rgba(170, 184, 232, 0.35); }
#stellar-intent-screen button.selected,
#stellar-intent-screen #stellar-intent-continue-btn:not([disabled]) {
    background-color: var(--stellar);
    border-color: var(--stellar);
    color: #fff;
    font-weight: 600;
}
#stellar-intent-screen button.selected:hover,
#stellar-intent-screen #stellar-intent-continue-btn:not([disabled]):hover {
    background-color: #8aa4e0;
    border-color: #8aa4e0;
}
#stellar-intent-screen #stellar-intent-continue-btn { margin-top: 8px; }
#stellar-intent-purpose-select,
#stellar-intent-thing-category,
#stellar-intent-purpose-select-thing,
#stellar-intent-relationship {
    text-align: center;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1 1l5.5 5.5L12 1' stroke='%237090d0' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    padding-left: 36px;
    scrollbar-width: thin;
    scrollbar-color: #7090d088 var(--stellar-bg);
}
#stellar-intent-screen select:hover {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='13' height='8' viewBox='0 0 13 8'%3E%3Cpath d='M1 1l5.5 5.5L12 1' stroke='%238aa4e0' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
#stellar-intent-purpose-select option,
#stellar-intent-purpose-select optgroup,
#stellar-intent-thing-category option,
#stellar-intent-purpose-select-thing option,
#stellar-intent-relationship option { background: #0a0a18; color: var(--stellar-pale); }
#stellar-intent-fields { display: none; flex-direction: column; gap: 8px; }

/* Cross-utility link rows */
.utility-crosslink {
    margin-top: 8px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #ffffff11;
    border-radius: 8px;
}
.utility-crosslink label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8em;
    cursor: pointer;
    line-height: 1.4;
}
.utility-crosslink-title {
    display: block;
    font-size: 0.72em;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #ffffff44;
    margin-bottom: 4px;
}

/* — Account auth popup — */
#account-auth-popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-auth);
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
}
#account-auth-popup.open { display: flex; }
.account-auth-card {
    width: min(480px, 100%);
    max-height: min(88vh, 720px);
    max-height: min(88dvh, 720px);
    overflow-y: auto;
    background: linear-gradient(160deg, #141416, #1e1e24);
    border: 1px solid var(--gold-a30);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--gold-a04);
}
.account-auth-header {
    padding: 22px 24px 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    border-bottom: 1px solid var(--gold-a10);
}
.account-auth-header h4 {
    margin: 0;
    color: #fff4cf;
    font-size: 1.12em;
    letter-spacing: 0.03em;
}
.account-auth-header p {
    margin: 5px 0 0;
    color: rgba(255, 215, 0, 0.55);
    font-size: 0.84em;
    line-height: 1.5;
}
#auth-mode-select {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px 24px 24px;
}
.auth-mode-btn {
    width: 100%;
    padding: 14px 18px;
    background: var(--gold-a08);
    border: 1px solid rgba(212, 175, 55, 0.32);
    border-radius: 12px;
    color: var(--gold);
    font-size: 0.96em;
    font-family: inherit;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    text-align: left;
    min-height: unset;
    transition: background 0.16s, border-color 0.16s, color 0.16s, transform 0.16s;
}
.auth-mode-btn:hover {
    background: var(--gold-a14);
    border-color: var(--gold-a55);
    color: var(--gold-pale);
    transform: translateY(-1px);
}
.auth-mode-btn.selected {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--ink);
    font-weight: 600;
}
.account-auth-body {
    padding: 16px 24px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.account-auth-body label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #c8ab6a;
    font-size: 0.85em;
    letter-spacing: 0.03em;
}
.account-auth-body input,
.account-auth-body select {
    width: 100%;
    margin-top: 0;
}
.account-auth-body .timezone-input-row,
.account-auth-body .location-input-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}
.account-auth-body .timezone-input-row input,
.account-auth-body .location-input-row input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
}
.account-auth-body .timezone-input-row button,
.account-auth-body .location-input-row button {
    flex: 0 0 auto;
    margin: 0;
    min-height: unset;
    white-space: nowrap;
    font-size: 0.85em;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 215, 0, 0.22);
    background: var(--bright-a07);
    color: #e8cc80;
    cursor: pointer;
    transition: background 0.15s;
    max-width: 180px;
}
.account-auth-body .timezone-input-row button:hover { background: rgba(255, 215, 0, 0.16); }
.account-auth-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}
#auth-back-btn {
    background: none;
    border: none;
    min-height: unset;
    color: rgba(255, 215, 0, 0.42);
    font-size: 0.78em;
    cursor: pointer;
    padding: 0 0 4px;
    letter-spacing: 0.04em;
    text-align: left;
    transition: color 0.15s;
}
#auth-back-btn:hover { color: rgba(255, 215, 0, 0.85); }

/* ── 14. BODY STATE CLASSES ────────────────────────────────────────────── */
/* iOS Safari/Chrome — force a scrollable page so the URL bar can collapse.
   !important kept: these must beat JS-set inline heights on the same nodes. */
.ios-browser body {
    min-height: calc(100vh + 1px) !important;
    height: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: var(--safe-bottom, 20px) !important;
}
.ios-browser #main-content {
    overflow: visible !important;
    min-height: calc(100vh + 1px) !important;
}
.ios-browser #map-container {
    min-height: 100vh !important;
}

/* Expanded reading-table mode — map becomes a normal in-flow block.
   !important kept: Mapbox/JS write inline geometry on these elements. */
body.table-expanded #main-content {
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
}
body.table-expanded #map-container {
    position: relative !important;
    inset: auto !important;
    width: 100% !important;
    height: auto !important;
    min-height: calc(var(--vh-full) - var(--toolbar-h)) !important;
    max-height: none !important;
    margin-bottom: 12px !important;
}
body.table-expanded #map-container .mapboxgl-map,
body.table-expanded #map-container .mapboxgl-canvas {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
}
body.table-expanded #reading-table {
    position: relative !important;
    z-index: 10 !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    max-height: none !important;
}

/* ── 15. RESPONSIVE LAYERS ─────────────────────────────────────────────── */

/* ── Desktop & tablet shell (≥ 601px) ── */
@media (min-width: 601px) {
    body {
        padding-top: calc(var(--toolbar-h) + var(--safe-top));
    }
    #main-content {
        min-height: calc(100vh - var(--toolbar-h));
        min-height: calc(100dvh - var(--toolbar-h));
        height: auto;
        margin-bottom: 0;
        padding-bottom: 0;
    }
    #map-container {
        min-height: 100%;
        height: 100%;
        margin-bottom: 0;
        padding-bottom: 0;
    }
    #map-container .mapboxgl-map,
    #map-container .mapboxgl-canvas {
        min-height: 100%;
        height: 100%;
    }
    #button-grid-mount {
        margin-top: 0;
        padding-top: 0;
        background: transparent;
    }
    /* Reserve gutters so wrapping toolbar content never slides beneath the
       fixed controls pinned at the toolbar's left (hamburger + search) and
       right (sound / sign-in / audio / lighting / gear) edges. */
    .top-toolbar {
        padding-left: calc(210px + var(--safe-left));
        padding-right: calc(380px + var(--safe-right));
    }
}

/* ── Tablet refinements (601–1024px) ── */
@media (min-width: 601px) and (max-width: 1024px) {
    .toolbar-center { gap: 8px; }
    .toolbar-title { font-size: 1.4em; margin: 0 10px; }
    .toolbar-selects { flex-wrap: wrap; justify-content: center; }
    .music-select { min-width: 110px; max-width: 160px; padding: 7px 10px; }
}
/* Sign-in is hidden ≤768, so its slot can be reclaimed on small tablets */
@media (min-width: 601px) and (max-width: 768px) {
    .top-toolbar { padding-right: calc(250px + var(--safe-right)); }
    #toolbar-sound-toggle-btn { right: calc(206px + var(--safe-right)); }
}

/* ── Touch / small-tablet refinements (≤ 768px or coarse pointer) ── */
@media (max-width: 768px), (pointer: coarse) {
    /* Vertical sliders are unusable on touch — hide them.
       !important kept: defends against inline display set by map JS. */
    #map-nav-controls { display: none !important; }

    /* Quick search docks to the left edge below the toolbar.
       !important kept: overrides the fixed desktop coordinates above
       when only the (pointer: coarse) half of this query matches. */
    #qs-widget {
        position: fixed;
        left: calc(8px + var(--safe-left));
        right: auto;
        top: calc(110px + var(--safe-top));
        z-index: var(--z-qs-mobile);
    }
    #qs-panel.open { max-width: calc(100vw - 80px); }
    #qs-input { width: min(calc(100vw - 100px), 260px); }
    #qs-results { width: min(calc(100vw - 16px), 320px); }

    /* Slightly roomier touch targets */
    #qs-trigger { width: 40px; height: 40px; }
    .draw-mode-btn { padding: 8px 10px; }
}

@media (max-width: 768px) {
    #toolbar-signin-btn { display: none; }
    #ob-toggle-btn { display: none !important; }

    /* Terrain toggle tucks into the bottom-left corner.
       !important kept: this button is styled inline by JS elsewhere. */
    #terrain-toggle-btn {
        bottom: var(--safe-bottom) !important;
        left: var(--safe-left) !important;
        border-radius: 0 8px 0 0 !important;
        padding: 4px 9px !important;
        font-size: 0.72em !important;
        box-shadow: none !important;
        opacity: 0.35 !important;
        transition: opacity 0.2s !important;
    }
    #terrain-toggle-btn:active { opacity: 1 !important; }
}

/* ── Phone (≤ 600px), all orientations ── */
@media (max-width: 600px) {
    /* Toolbar joins the document flow and stacks vertically */
    #top-toolbar {
        height: auto;
        padding: calc(40px + var(--safe-top)) 0 2px;
        flex-direction: column;
        min-height: unset;
        position: relative;
    }
    .toolbar-center {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        width: 100%;
        padding: 0 6px;
        gap: 6px;
    }
    .toolbar-title {
        font-size: 1.5em;
        padding-top: 2px;
        margin: 0 0 2px 0;
        text-align: center;
        width: 100%;
    }
    #symbol-class.music-select,
    #map-style.music-select {
        display: inline-block;
        width: 40%;
        min-width: 80px;
        max-width: 42vw;
        font-size: 1em;
        margin: 0 2% 4px;
        vertical-align: middle;
    }

    /* Toolbar tooltip button swaps to its mobile variant.
       !important kept on display toggles throughout this block: these
       elements are shown/hidden by JS inline styles at runtime. */
    #tt-toolbar-btn { display: none !important; }
    #tt-mobile-btn { display: flex !important; }

    /* Draw toggle leaves the toolbar flow; pinned beside the top-right menu.
       !important kept: overrides inline positioning applied by JS. */
    #draw-toggle-btn {
        position: fixed !important;
        top: calc(4px + var(--safe-top)) !important;
        right: calc(46px + var(--safe-right)) !important;
        margin-left: 0 !important;
        width: 36px !important;
        height: 36px !important;
        z-index: var(--z-draw-toggle-m) !important;
        background: rgba(20, 20, 20, 0.92) !important;
        border: 1px solid rgba(212, 175, 55, 0.45) !important;
        border-radius: 8px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45) !important;
        padding: 0 !important;
    }

    /* Hidden on phones: roast window, desktop utility buttons, footer */
    #roast-float { display: none !important; }
    #lt-btn, #settings-menu, #audio-btn { display: none !important; }
    #privacy-attributions-footer { display: none !important; }
    #toolbar-sound-toggle-btn { display: none; }

    /* Mobile bottom-right utility stack — applies when these buttons are
       re-enabled (e.g. by removing them from the hide rule above). */
    #settings-menu {
        top: auto;
        left: auto;
        bottom: calc(var(--edge-gap) + var(--safe-bottom));
        right: calc(var(--edge-gap) + var(--safe-right));
        width: var(--ctl-size-sm);
        height: var(--ctl-size-sm);
        font-size: 1em;
        opacity: 0.45;
        border-radius: 8px;
    }
    #lt-btn {
        top: auto;
        bottom: calc(48px + var(--safe-bottom));
        right: calc(var(--edge-gap) + var(--safe-right));
        left: auto;
        width: var(--ctl-size-sm);
        height: var(--ctl-size-sm);
        font-size: 1em;
        opacity: 0.45;
        border-radius: 8px;
    }
    #audio-btn {
        top: auto;
        bottom: calc(90px + var(--safe-bottom));
        right: calc(var(--edge-gap) + var(--safe-right));
        left: auto;
        width: var(--ctl-size-sm);
        height: var(--ctl-size-sm);
        font-size: 1em;
        opacity: 0.45;
        border-radius: 8px;
    }
    #settings-menu:hover, #settings-menu:focus,
    #lt-btn:hover, #lt-btn:focus,
    #audio-btn:hover, #audio-btn:focus {
        opacity: 0.85;
    }

    /* Omniport is hidden on phones unless explicitly opened by JS.
       !important kept on display: must beat inline styles either way. */
    #omniport-container { display: none !important; }
    #omniport-container.mobile-omni-visible { display: flex !important; }
    #omniport-container {
        padding: 14px 4vw;
        max-width: 98vw;
        border-radius: var(--r-lg);
    }
    .omniport-title {
        font-size: 1.1em;
        margin-bottom: 8px;
    }
    .omniport-row {
        gap: 8px;
        margin-top: 8px;
    }
    .omniport-search-shell {
        width: 100%;
        margin-bottom: 16px;
    }
    .omniport-search-bar { grid-template-columns: 1fr; }
    .omniport-search-input,
    .omniport-search-clear {
        padding: 12px 14px;
        font-size: 0.95rem;
    }
    .omniport-search-results { max-height: 240px; }
    .omni-btn {
        font-size: 1.1em;
        width: 36px;
        height: 36px;
        border-width: 1.5px;
    }

    /* Webcam canvas scales to the viewport.
       !important kept: canvas dimensions are written inline by JS. */
    #webcam-canvas {
        width: 92vw !important;
        max-width: 92vw !important;
        height: auto !important;
        aspect-ratio: auto !important;
        margin-top: 50px !important;
    }

    /* Collapsed button grid → map claims the full viewport.
       !important kept: beats JS-set inline geometry on the map nodes. */
    body.grid-collapsed #main-content { padding-bottom: 0 !important; }
    body.grid-collapsed #map-container {
        width: 100% !important;
        height: calc(var(--vh-full) - var(--toolbar-h)) !important;
        min-height: 0 !important;
        margin-bottom: 0 !important;
    }
    body.grid-collapsed #map-container .mapboxgl-map,
    body.grid-collapsed #map-container .mapboxgl-canvas {
        width: 100% !important;
        height: 100% !important;
    }

    /* Settings modal goes near-fullscreen */
    .layer-toggles { grid-template-columns: 1fr; }
    .settings-content {
        width: 95%;
        margin: 2% auto;
        max-height: calc(96vh - var(--safe-bottom));
        max-height: calc(96dvh - var(--safe-bottom));
    }
}

/* ── Phone, portrait: map fills the viewport below the toolbar ── */
@media (max-width: 600px) and (orientation: portrait) {
    /* !important kept throughout: beats JS/Mapbox inline geometry. */
    #main-content {
        position: relative !important;
        height: calc(var(--vh-full) - var(--toolbar-h)) !important;
        min-height: calc(var(--vh-full) - var(--toolbar-h)) !important;
        padding-bottom: 0 !important;
        overflow: hidden !important;
    }
    #map-container {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        margin-bottom: 0 !important;
        overflow: hidden !important;
    }
    #map-container .mapboxgl-map,
    #map-container .mapboxgl-canvas {
        width: 100% !important;
        height: 100% !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
    }
    #omniport-container {
        display: none !important; /* must beat inline display from JS */
        position: relative;
        z-index: auto;
        margin: 32px auto 0;
    }
}

/* ── Phone, landscape: map shares the screen with the button grid ── */
@media (max-width: 600px) and (orientation: landscape) {
    #map-container {
        min-height: 200px;
        height: calc(var(--vh-full) * 0.3) !important;
        max-height: 55vh;
        max-height: 55dvh;
    }
    .button-grid { margin-bottom: 12px; }

    /* Landscape phones are short — compact the in-flow toolbar */
    #top-toolbar { padding-top: calc(10px + var(--safe-top)); }
    .toolbar-title { font-size: 1.2em; }
}

/* ── Theme switching ───────────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
    :root {
        --gold:            #b08f24;
        --gold-bright:     #d8b552;
        --gold-soft:       #f3d48f;
        --gold-pale:       #fff7d8;
        --gold-cream:      #fff8e2;
        --ink:             #111111;
        --ink-2:           #282828;
        --ink-3:           #3a3a3a;
        --panel:           #f5f3ee;
        --panel-night:     #e8e4db;
        --panel-night-2:   #d8d3c3;
        --stellar:         #5a76a3;
        --stellar-pale:    #7a95c2;
        --stellar-bg:      #f2f3f7;
        --danger:          #c13434;
    }
}
:root[data-theme="light"] {
    color-scheme: light;
    --gold:            #8f7432;
    --gold-bright:     #c9a652;
    --gold-soft:       #e7cf92;
    --gold-pale:       #f8ebcf;
    --gold-cream:      #fff7e4;
    --ink:             #f5f2ec;
    --ink-2:           #d1cabf;
    --ink-3:           #b5ad9e;
    --panel:           #ffffff;
    --panel-night:     #f2efe6;
    --panel-night-2:   #e5dfd1;
    --stellar:         #5a76a3;
    --stellar-pale:    #7a95c2;
    --stellar-bg:      #f2f3f7;
    --danger:          #a93131;
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --gold:            #d4af37;
    --gold-bright:     #ffd700;
    --gold-soft:       #f0c93a;
    --gold-pale:       #fffbe6;
    --gold-cream:      #fff8dc;
    --ink:             #111111;
    --ink-2:           #181818;
    --ink-3:           #222222;
    --panel:           #141414;
    --panel-night:     #181a20;
    --panel-night-2:   #23243a;
    --stellar:         #7090d0;
    --stellar-pale:    #aab8e8;
    --stellar-bg:      #090912;
    --danger:          #ff6b6b;
}

html[data-theme="light"] body,
body[data-theme="light"] {
    background: var(--ink);
    color: var(--gold);
}
html[data-theme="dark"] body,
body[data-theme="dark"] {
    background: var(--ink);
    color: var(--gold);
}

html[data-theme="light"] .controls,
html[data-theme="light"] .category-filter,
html[data-theme="light"] .popup-content,
html[data-theme="light"] .settings-content,
html[data-theme="light"] .account-auth-card,
html[data-theme="light"] .modal-loader,
html[data-theme="light"] .modal-loader-inner {
    background: var(--panel);
    color: var(--gold);
    border-color: var(--gold-a20);
}

html[data-theme="dark"] .controls,
html[data-theme="dark"] .category-filter,
html[data-theme="dark"] .popup-content,
html[data-theme="dark"] .settings-content,
html[data-theme="dark"] .account-auth-card,
html[data-theme="dark"] .modal-loader,
html[data-theme="dark"] .modal-loader-inner {
    background: var(--panel);
    color: var(--gold);
    border-color: var(--gold-a20);
}

html[data-theme="light"] .filter-btn:hover,
html[data-theme="dark"] .filter-btn:hover {
    background: var(--ink-2);
}

/* ── 16. ACCESSIBILITY ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
