/* =========================================================
   DOORSCLOSING APP — MOBILE OPTIMISATION & PWA SHELL STYLES
   Preserves exact colours, typography, and desktop layout
   while adding native-app feel & mobile ergonomics.
   ========================================================= */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior-y: none;
    overflow-x: clip;
}

body {
    -webkit-tap-highlight-color: transparent;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    overflow-x: clip;
}

button,
a,
.line-card,
.map-card,
.fleet-card,
.spotter-item,
.spotter-header-toggle,
.timeline-content,
.filter-btn,
.option-btn,
.game-btn,
.opal-btn,
.sound-btn,
.hamburger {
    touch-action: manipulation;
}

.game-btn,
.opal-btn,
.sound-btn,
.filter-btn,
.theme-toggle,
.play-chime-btn,
.app-bottom-nav {
    -webkit-user-select: none;
    user-select: none;
}

/* Lock page scroll when a modal or mobile drawer is open */
body.app-scroll-lock {
    overflow: hidden;
}

/* Safe-area support for sticky top nav */
nav {
    padding-top: max(1.2rem, env(safe-area-inset-top, 0px));
}

/* Remove backdrop-filter while mobile drawer is open so fixed drawer sits cleanly above backdrop */
nav.menu-open {
    z-index: 1500 !important;
    background: #1a1a1a !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

/* Compact horizontal desktop nav for narrower PC windows (no hamburger on PC!) */
@media (min-width: 769px) and (max-width: 1180px) {
    nav {
        padding-left: 3%;
        padding-right: 3%;
    }
    .brand-icon {
        height: 44px;
    }
    .text-doors,
    .text-closing {
        font-size: 1.35rem;
    }
    .nav-right {
        gap: 18px;
    }
    nav ul {
        gap: 16px;
    }
    nav a {
        font-size: 0.98rem;
    }
    .theme-toggle {
        padding: 8px 14px;
        font-size: 0.92rem;
        white-space: nowrap;
    }
}

/* Never show hamburger on desktop / PC screens > 768px */
@media (min-width: 769px) {
    .hamburger {
        display: none !important;
    }
    .nav-right ul {
        position: static !important;
        height: auto !important;
        width: auto !important;
        background: transparent !important;
        flex-direction: row !important;
        border-left: none !important;
        box-shadow: none !important;
        transform: none !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
}

/* Drawer backdrop for mobile hamburger menu (below nav.menu-open z-index 1500) */
.nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
}
.nav-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* Active desktop nav link underline */
nav ul a.nav-current::after {
    width: 100%;
}

/* Smooth modal scroll containment */
.modal-overlay {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.modal-content-map {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Interactive Zoom Controls inside Network Map Modal */
.map-zoom-controls {
    position: fixed;
    bottom: max(22px, calc(16px + env(safe-area-inset-bottom, 0px)));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(26, 26, 26, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1.5px solid rgba(243, 112, 33, 0.65);
    padding: 8px 12px;
    border-radius: 50px;
    z-index: 3000;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}

.map-zoom-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.16);
    min-width: 42px;
    height: 40px;
    padding: 0 14px;
    border-radius: 50px;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.map-zoom-btn:hover,
.map-zoom-btn:active {
    background: var(--sydney-orange);
    border-color: var(--sydney-orange);
}

.map-zoom-btn:active {
    transform: scale(0.95);
}

.map-zoom-level {
    color: #f1f2f6;
    font-family: monospace;
    font-size: 0.92rem;
    font-weight: 700;
    min-width: 48px;
    text-align: center;
}

/* Pulsing Station Pin inside Map Modal */
.station-map-pin {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--sydney-orange);
    border: 3px solid #ffffff;
    box-shadow: 0 0 0 6px rgba(243, 112, 33, 0.35), 0 4px 12px rgba(0, 0, 0, 0.6);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 20;
    display: none;
    animation: stationPinPulse 1.6s ease-out infinite;
}

.station-map-pin.visible {
    display: block;
}

.station-map-pin-label {
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    background: #1a1a1a;
    color: #ffffff;
    border: 2px solid var(--sydney-orange);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.55);
}

@keyframes stationPinPulse {
    0% { box-shadow: 0 0 0 0 rgba(243, 112, 33, 0.75), 0 4px 12px rgba(0, 0, 0, 0.6); }
    70% { box-shadow: 0 0 0 18px rgba(243, 112, 33, 0), 0 4px 12px rgba(0, 0, 0, 0.6); }
    100% { box-shadow: 0 0 0 0 rgba(243, 112, 33, 0), 0 4px 12px rgba(0, 0, 0, 0.6); }
}

/* Graceful fallback for train images */
.fleet-img-wrap img.img-fallback,
.spotter-thumb.img-fallback,
.modal-img-banner img.img-fallback {
    object-fit: contain;
    padding: 18px;
    background: radial-gradient(circle at center, #262932 0%, #16171c 100%);
    box-sizing: border-box;
}

/* =========================================================
   MOBILE APP BOTTOM TAB BAR & DRAWER (screens <= 768px only)
   ========================================================= */
.app-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .nav-right ul {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: 280px !important;
        max-width: 82vw;
        background: var(--charcoal) !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 22px !important;
        z-index: 1600 !important;
        border-left: 3px solid var(--sydney-orange) !important;
        box-shadow: -8px 0 30px rgba(0, 0, 0, 0.65) !important;
        transform: translateX(100%);
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.32s cubic-bezier(0.165, 0.84, 0.44, 1), visibility 0.32s ease !important;
        padding-top: max(76px, env(safe-area-inset-top, 0px));
        padding-bottom: max(32px, env(safe-area-inset-bottom, 0px));
        box-sizing: border-box;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .nav-right ul.active {
        transform: translateX(0) !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }
    .nav-right ul li a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 44px;
        min-width: 160px;
        font-size: 1.2rem;
    }
    .hamburger {
        display: flex !important;
        position: relative;
        z-index: 1700 !important;
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
    }

    /* Native App Bottom Navigation Bar */
    .app-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1200;
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        background: rgba(26, 26, 26, 0.96);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 2px solid var(--sydney-orange);
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.35);
    }

    .app-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        text-decoration: none;
        color: #a1a1aa;
        font-family: 'Inter', sans-serif;
        font-size: 0.72rem;
        font-weight: 600;
        min-height: 48px;
        border-radius: 10px;
        transition: color 0.18s ease, background 0.18s ease, transform 0.12s ease;
    }

    .app-tab svg {
        width: 22px;
        height: 22px;
        stroke: currentColor;
        fill: none;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    .app-tab.active {
        color: var(--sydney-orange);
        background: rgba(243, 112, 33, 0.12);
    }

    .app-tab:active {
        transform: scale(0.94);
    }

    /* Leave space above the fixed bottom tab bar */
    footer {
        padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (max-width: 850px) {
    nav {
        padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
        padding-bottom: 0.75rem;
        padding-left: max(4%, env(safe-area-inset-left, 0px));
        padding-right: max(4%, env(safe-area-inset-right, 0px));
    }

    /* Prevent iOS Safari auto-zoom on form fields */
    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Comfortable touch targets on mobile */
    .theme-toggle,
    .btn-plan,
    .btn-pin,
    .btn-send,
    .btn-fleet-link,
    .play-chime-btn,
    .primary-btn,
    .option-btn,
    .game-btn,
    .opal-btn,
    .sound-btn,
    .filter-btn {
        min-height: 44px;
    }

    /* Smooth horizontal snap filter bar on Fleet page */
    .filter-bar {
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        padding: 4px 16px 8px;
        margin-left: -16px;
        margin-right: -16px;
        scrollbar-width: none;
    }
    .filter-bar::-webkit-scrollbar {
        display: none;
    }
    .filter-btn {
        flex: 0 0 auto;
        white-space: nowrap;
        scroll-snap-align: start;
    }

    /* Keep Opal TAP ON / TAP OFF side-by-side on all phones */
    .opal-controls {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 12px !important;
    }
    .opal-btn {
        min-width: 0 !important;
        width: 100%;
        padding: 16px 10px !important;
        font-size: 1.02rem !important;
    }

    /* Quiz mobile polish */
    .action-row {
        justify-content: stretch !important;
    }
    .primary-btn {
        width: 100%;
        justify-content: center;
        padding: 15px 22px !important;
        font-size: 1.08rem !important;
    }
    .option-btn {
        padding: 15px 16px !important;
        font-size: 1.02rem !important;
    }

    /* Modal ergonomics on mobile */
    .modal-overlay {
        padding: 16px 12px calc(24px + env(safe-area-inset-bottom, 0px));
    }
    .info-modal-box {
        width: 100% !important;
        margin: 4vh auto !important;
    }
    .modal-close {
        top: max(14px, env(safe-area-inset-top, 0px));
        right: 14px;
        width: 44px;
        height: 44px;
        font-size: 1.5rem;
    }
    .zoom-hint {
        top: max(16px, env(safe-area-inset-top, 0px));
        font-size: 0.82rem !important;
        padding: 8px 14px !important;
        max-width: calc(100vw - 130px);
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .map-wrapper.full-res img {
        width: 1600px;
    }

    /* Anchor scroll offset below sticky navbar */
    [id] {
        scroll-margin-top: 84px;
    }
}

/* Extra-small phones (320px - 420px) */
@media (max-width: 420px) {
    .brand-icon {
        height: 36px !important;
    }
    .text-doors,
    .text-closing {
        font-size: 1.1rem !important;
    }
    .custom-brand-logo {
        gap: 8px !important;
    }
    .theme-toggle {
        padding: 7px 10px !important;
        font-size: 0.76rem !important;
    }
    .nav-right {
        gap: 8px !important;
    }
    header h1 {
        font-size: 2.3rem !important;
    }
    #digital-clock {
        font-size: 1.85rem !important;
        padding: 8px 18px !important;
    }
    .doors-closing-banner {
        font-size: 0.74rem !important;
        padding: 10px 12px !important;
    }
    .cd-display-screen {
        font-size: 1.55rem !important;
        letter-spacing: 1px !important;
    }
    .cd-door-frame {
        width: 196px !important;
        height: 160px !important;
    }
    .cd-door-leaf {
        width: 98px !important;
    }
    .cd-tread-plate {
        width: 212px !important;
    }
    .ps-train-svg {
        height: 52px !important;
        width: 390px !important;
    }
    .spotter-controls-right {
        flex-wrap: wrap;
    }
}
