/* ===========================================================================
   Phoenix - mobile layer
   ---------------------------------------------------------------------------
   Loaded last, and every rule lives inside the breakpoint below, so this file
   can only ever add to the phone/tablet experience - the desktop cascade is
   left untouched.

   Two jobs:
     1. Strip the decorative motion (see scripts/mobile.js for the JS half).
     2. Re-flow the desktop layout - which is built around full-viewport
        sections and multi-column rows - into a single readable column.

   The breakpoint matches Materialize's `hide-on-med-and-down` (992px) and
   window.PHOENIX_MOBILE_MAX_WIDTH in scripts/mobile.js. Change all three
   together, or a dead zone opens up where neither nav is visible.
   =========================================================================== */

@media only screen and (max-width: 992px) {

    /* -------------------------------------------------------------------
       1. Motion
       -------------------------------------------------------------------
       Durations collapse to ~0 rather than `animation: none`, and that
       distinction matters: several elements are hidden by default and are
       revealed only by a `forwards` animation (.product-card,
       .nav-company_name, .landing-nav). Killing the animation outright would
       leave those permanently invisible; running it instantly lands them on
       their end state with no motion.

       Components that use opacity as a genuine open/closed state are left
       alone - stripping their transitions would make them pop rather than
       break, and the sidenav in particular reads far better with its slide. */
    *:not(.sidenav):not(.sidenav-overlay):not(.modal):not(.modal-overlay):not(.dropdown-content):not(.chat-window):not(.chat-widget) {
        animation-duration: 0.001s !important;
        animation-delay: 0s !important;
        transition-duration: 0.001s !important;
        transition-delay: 0s !important;
        scroll-behavior: auto !important;
    }

    /* GSAP hides these in CSS and reveals them by writing inline styles. With
       GSAP switched off on mobile they would stay invisible, so force them
       back. !important earns its keep twice here: it beats the per-page inline
       <style> blocks that declare `.fade-up, .fade-in { opacity: 0 }`, and it
       beats any inline style GSAP may already have written. */
    .fade-up,
    .fade-in,
    .fade-in-down,
    .fadein,
    .hero-left,
    .hero-left .line,
    .hero-logo,
    .hero-tagline,
    .info-card,
    .info-card img,
    .info-card .info-text,
    .product-card,
    .carousel-caption,
    .gallery-item,
    .immersive-gallery .gallery-item,
    .nav-company_name,
    .landing-nav,
    .newtech-panel,
    .feature-item,
    .products-hero {
        opacity: 1 !important;
        transform: none !important;
        visibility: visible !important;
    }

    /* The homepage preloader is dismissed by an anime.js timeline that never
       runs on mobile. Without this the page would sit behind it forever. */
    #preloader {
        display: none !important;
    }

    /* Full-page scroll snapping is added to <html> by initHomeScroll. It is
       suppressed in JS on mobile; this is the belt-and-braces half, because a
       mandatory snap with sections taller than the viewport traps scrolling. */
    html,
    html.snap-scroll {
        scroll-snap-type: none !important;
    }

    html.snap-scroll #hero-v2,
    html.snap-scroll #section-two-v2,
    html.snap-scroll #section-three,
    html.snap-scroll #section-four,
    html.snap-scroll #footer {
        scroll-snap-align: none !important;
        scroll-snap-stop: normal !important;
    }

    /* Fixed-viewport backgrounds are expensive and jitter against the mobile
       address bar resizing on scroll. */
    .cyber-bg {
        position: absolute !important;
        height: 100% !important;
    }

    /* -------------------------------------------------------------------
       2. Page frame
       ------------------------------------------------------------------- */
    html,
    body {
        overflow-x: hidden !important;
        max-width: 100% !important;
    }

    body {
        /* The header is fixed; keep content clear of it. */
        padding-top: 56px;
    }

    img,
    video,
    svg,
    iframe,
    object,
    embed {
        max-width: 100%;
        height: auto;
    }

    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Desktop builds these as full-viewport panels. On a phone they need to be
       as tall as their content, or text is clipped and simply unreachable. */
    .section,
    .section-one,
    .section-two-v2,
    .section-three,
    .section-four,
    #section-two,
    #section-two-v2,
    #section-three,
    #section-four,
    .hero-v2,
    .console-hero,
    .bench-hero {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        position: relative !important;
        top: auto !important;
        padding-top: 48px !important;
        padding-bottom: 48px !important;
        overflow: visible !important;
    }

    /* This one is 50%-wide on desktop. */
    #section-four {
        width: 100% !important;
    }

    /* -------------------------------------------------------------------
       3. Typography - scale the desktop display sizes down to phone sizes
       ------------------------------------------------------------------- */
    h1 { font-size: 2rem !important; line-height: 1.2 !important; }
    h2 { font-size: 1.65rem !important; line-height: 1.25 !important; }
    h3 { font-size: 1.4rem !important; line-height: 1.3 !important; }
    h4 { font-size: 1.2rem !important; line-height: 1.35 !important; }
    h5 { font-size: 1.05rem !important; }

    p,
    li {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }

    .company-name,
    .footer-company-name {
        font-size: 1.75em !important;
        margin-top: 0.5em !important;
        /* Letter-spacing on the last glyph pushes this a couple of pixels past
           the viewport, which is enough to start a sideways scroll. */
        max-width: 100% !important;
        overflow-wrap: break-word !important;
    }

    .hero-tagline {
        font-size: 1.05rem !important;
    }

    .carousel-caption {
        font-size: 1.4rem !important;
    }

    /* Long stop names and model numbers must not force the page wide. */
    h1, h2, h3, h4, h5, p, li, a, span {
        overflow-wrap: break-word;
        word-wrap: break-word;
    }

    /* -------------------------------------------------------------------
       4. Header and mobile navigation
       ------------------------------------------------------------------- */
    header .navbar-fixed {
        height: 56px !important;
    }

    header nav,
    header .nav-wrapper {
        height: 56px !important;
        line-height: 56px !important;
        /* The desktop nav fades out of black over the hero; on mobile it sits
           over ordinary content all the way down, so it needs a solid ground
           to stay legible. */
        background: #1a1a1a !important;
    }

    /* The wordmark is absolutely positioned at a desktop offset. */
    .brand-logo {
        position: static !important;
    }

    .nav-company_name {
        position: absolute !important;
        top: 0 !important;
        left: 16px !important;
        right: 64px !important;
        line-height: 56px !important;
        font-size: 1.1em !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        /* .brand-logo precedes <nav> in the markup, and both are `z-index:
           auto` positioned boxes in the same stacking context, so the nav's
           solid mobile background would paint straight over the wordmark.
           An explicit z-index lifts it back out - it has to live here rather
           than on .brand-logo, which is unpositioned above and so ignores
           z-index entirely. Kept below the menu button's 100. */
        z-index: 99 !important;
    }

    .sidenav-trigger {
        display: block !important;
        position: absolute !important;
        top: 0 !important;
        right: 8px !important;
        height: 56px !important;
        line-height: 56px !important;
        margin: 0 !important;
        padding: 0 12px !important;
        color: #ffffff !important;
        z-index: 100 !important;
    }

    .sidenav-trigger i {
        font-size: 2rem !important;
        line-height: 56px !important;
    }

    /* The drawer itself. */
    .sidenav {
        width: 280px !important;
        background: #1a1a1a !important;
    }

    .sidenav li > a,
    .sidenav li > span {
        color: #ffffff !important;
        font-family: 'Encode Sans SC', sans-serif;
        font-size: 1rem !important;
        line-height: 56px !important;
        height: 56px !important;
        padding: 0 24px !important;
    }

    .sidenav li > a:hover,
    .sidenav li > a:active {
        background: rgba(218, 165, 32, 0.15) !important;
    }

    .sidenav .sidenav-section-title {
        display: block;
        color: #daa520 !important;
        font-size: 0.75rem !important;
        letter-spacing: 2px;
        text-transform: uppercase;
        line-height: 40px !important;
        height: 40px !important;
        padding: 0 24px !important;
        margin: 0 !important;
        opacity: 0.9;
    }

    .sidenav .sidenav-sub a {
        padding-left: 40px !important;
        font-size: 0.95rem !important;
    }

    /* main.css carries a decorative `.divider { width: 25%; border-bottom:
       solid #2596be 1px }` used elsewhere on the site, which collides with
       Materialize's `li.divider` separators in the drawer and renders them as
       short blue stubs. Restate the whole box here. */
    .sidenav .divider {
        width: 100% !important;
        height: 1px !important;
        border: none !important;
        margin: 8px 0 !important;
        background-color: rgba(255, 255, 255, 0.12) !important;
    }

    .sidenav .sidenav-brand {
        padding: 20px 24px 12px !important;
        color: #ffffff !important;
        font-family: 'Encode Sans SC', sans-serif;
        font-size: 1.2rem;
        font-weight: bold;
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    .sidenav .sidenav-brand span {
        font-weight: 100;
    }

    .sidenav-overlay {
        z-index: 997 !important;
    }

    /* The desktop hover dropdowns have no place here - the drawer lists the
       same destinations as flat links. */
    #products_dropdown,
    #build_dropdown,
    #about_dropdown {
        display: none !important;
    }

    /* -------------------------------------------------------------------
       5. Homepage
       ------------------------------------------------------------------- */
    .hero-v2 {
        display: flex !important;
        align-items: center !important;
        /* Enough to read as a hero without pushing what follows it out of
           reach on a short screen. */
        min-height: 78vh !important;
    }

    .hero-container {
        flex-direction: column !important;
        width: 100% !important;
        padding: 0 16px !important;
        gap: 1.25rem !important;
        text-align: center !important;
    }

    .hero-left {
        width: 100% !important;
        flex: 1 1 auto !important;
    }

    /* The organ render is the wrong shape for a portrait screen, and it is the
       single heaviest asset on the page. */
    .hero-right {
        display: none !important;
    }

    .hero-left .line {
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .scroll-indicator {
        display: none !important;
    }

    /* Three fused panels on desktop -> a plain stack, each with its own border
       radius (the desktop rules strip the inner edges to merge them). */
    .cards-container,
    .section-two-v2 .cards-container {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        /* Desktop fixes this at 80vh to hold one row; stacked, it has to grow. */
        height: auto !important;
        gap: 16px !important;
        margin: 1.5rem 0 0 !important;
    }

    .info-card,
    .section-two-v2 .info-card,
    .section-two-v2 .cards-container .info-card {
        width: 100% !important;
        /* Desktop pins these to 75vh; on a phone they have to grow to fit
           their own contents or the artwork and copy get clipped. */
        height: auto !important;
        min-height: 0 !important;
        flex: 1 1 auto !important;
        padding: 1.5rem !important;
        border-width: 1px !important;
        border-radius: 20px !important;
        /* backdrop-filter is a real cost on mobile GPUs for no visible gain
           over the flat panel background. */
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* Note: background is deliberately left alone here. The homepage cards
       carry their own artwork, and the plain glass panels elsewhere already
       get a fill from main.css - overriding it would flatten both. */

    /* The artwork frame is a fixed 350px square that refuses to shrink
       (`flex-shrink: 0`), so on a phone it stands taller than the card and
       spills out of the top. Make it a square that scales with the card
       instead of a fixed one. */
    .card-icon-container {
        width: 100% !important;
        max-width: 210px !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        flex-shrink: 1 !important;
        margin-bottom: 1.25rem !important;
        border-radius: 18px !important;
    }

    /* Testimonials */
    .testim .cont > div {
        padding: 0 16px 60px !important;
    }

    .testim .arrow {
        font-size: 1.5rem !important;
    }

    .testim .arrow.left { left: 4px !important; }
    .testim .arrow.right { right: 4px !important; }

    /* -------------------------------------------------------------------
       6. Products page
       ------------------------------------------------------------------- */
    .products-hero {
        height: 180px !important;
    }

    .products-hero img {
        height: 100% !important;
        object-fit: cover !important;
    }

    #products-title {
        font-size: 1.65rem !important;
    }

    .products-filters {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 8px !important;
        padding: 16px 0 !important;
    }

    .filter-btn {
        flex: 0 0 auto !important;
        font-size: 0.8rem !important;
        padding: 8px 14px !important;
        min-height: 40px !important;
    }

    .product-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }

    .card-image-wrapper {
        height: auto !important;
    }

    .card-image-wrapper img {
        width: 100% !important;
        height: auto !important;
    }

    .pdf-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .btn-features,
    .btn-stoplist {
        width: 100% !important;
        text-align: center !important;
        min-height: 44px !important;
        line-height: 44px !important;
        padding: 0 12px !important;
    }

    /* -------------------------------------------------------------------
       7. Interactive stop list modal
       -------------------------------------------------------------------
       Desktop lays the divisions out as side-by-side columns. That cannot work
       at this width, so they stack and the modal becomes one full-screen
       scroller - which also stops a 70-stop list from being cut off. */
    .modal.stoplist-overlay,
    #interactive-stoplist-modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        height: 100% !important;
        top: 0 !important;
        left: 0 !important;
        margin: 0 !important;
        border-radius: 0 !important;
        transform: none !important;
    }

    .stoplist-content {
        padding: 16px !important;
        max-height: 100% !important;
        height: 100% !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .stoplist-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding-right: 56px !important;
    }

    .header-branding {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
    }

    .header-organ-image {
        width: 64px !important;
        height: auto !important;
    }

    .model-title {
        font-size: 1.3rem !important;
        margin: 0 !important;
    }

    .model-subtitle {
        font-size: 0.8rem !important;
        margin: 2px 0 0 !important;
    }

    .style-selector-container {
        width: 100% !important;
    }

    .style-toggles {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .style-btn {
        flex: 1 1 auto !important;
        min-height: 40px !important;
        font-size: 0.8rem !important;
        padding: 0 12px !important;
    }

    .divisions-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }

    .division-column {
        width: 100% !important;
    }

    .stop-list li {
        display: flex !important;
        justify-content: space-between !important;
        gap: 12px !important;
        font-size: 0.9rem !important;
        padding: 6px 0 !important;
    }

    .stoplist-close-btn {
        position: absolute !important;
        top: 8px !important;
        right: 8px !important;
        z-index: 5 !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
    }

    /* -------------------------------------------------------------------
       8. Interior pages - collapse every multi-column row to one column
       ------------------------------------------------------------------- */
    .feature-grid,
    .newtech-grid,
    .console-grid,
    .immersive-gallery,
    .audio-features,
    .keyboard-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .console-nav {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap !important;
        gap: 4px !important;
        padding: 0 8px !important;
    }

    .console-nav a {
        flex: 0 0 auto !important;
        font-size: 0.8rem !important;
        padding: 12px 10px !important;
    }

    /* Any wide fixed-width block gets its own scroller rather than widening
       the whole page. */
    table,
    pre {
        display: block !important;
        max-width: 100% !important;
        overflow-x: auto !important;
    }

    /* -------------------------------------------------------------------
       9. Footer
       ------------------------------------------------------------------- */
    .page-footer .row {
        display: flex !important;
        flex-direction: column !important;
        gap: 24px !important;
    }

    .footer-logo-container,
    .footer-links-container {
        width: 100% !important;
        text-align: center !important;
    }

    .footer-links-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
    }

    .footer-link-item {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        min-height: 40px !important;
    }

    .footer-link-item svg {
        width: 20px !important;
        height: 20px !important;
        flex: 0 0 20px !important;
    }

    .logo-circle {
        margin: 0 auto !important;
    }

    /* -------------------------------------------------------------------
       10. Chat assistant - a fixed panel sized for a desktop corner
       ------------------------------------------------------------------- */
    .chat-widget {
        right: 12px !important;
        bottom: 12px !important;
        left: auto !important;
    }

    .chat-toggle {
        width: 52px !important;
        height: 52px !important;
    }

    .chat-label {
        display: none !important;
    }

    .chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
    }

    .chat-messages {
        flex: 1 1 auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* 16px keeps iOS Safari from zooming the viewport when the field focuses. */
    #chat-input {
        font-size: 16px !important;
    }

    .chat-suggestions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .suggestion-chip {
        font-size: 0.8rem !important;
    }

    /* -------------------------------------------------------------------
       11. Tap targets
       ------------------------------------------------------------------- */
    nav a,
    .btn,
    .btn-large,
    .btn-flat,
    button {
        min-height: 44px;
    }

    /* Hover styling is meaningless on touch and tends to stick after a tap. */
    .info-card:hover,
    .product-card:hover,
    .gallery-item:hover {
        transform: none !important;
    }
}
