/* Mobile Compatibility Styles */

:root {
    --mobile-panel-offset: 60px;
}

/* =========================================
   Figure Fullscreen Feature
   ========================================= */

/* Fullscreen overlay - hidden by default */
.figure-fullscreen-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(4px);
}

.figure-fullscreen-overlay.active {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.figure-fullscreen-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 10001;
    transition: background 0.2s ease, transform 0.2s ease;
}

.figure-fullscreen-close:hover,
.figure-fullscreen-close:focus {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.figure-fullscreen-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 60px 20px 20px;
    box-sizing: border-box;
}

.figure-fullscreen-img {
    max-width: 100%;
    max-height: calc(100vh - 120px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.figure-fullscreen-caption {
    display: none !important;
}

/* Expand button on figures - hidden by default (shown on mobile) */
.figure-expand-btn {
    display: none;
}

/* Body class when fullscreen is active */
body.figure-fullscreen-active {
    overflow: hidden !important;
}

/* Landscape-optimized fullscreen */
@media (orientation: landscape) {
    .figure-fullscreen-content {
        padding: 20px;
    }

    .figure-fullscreen-img {
        max-width: 95%;
        max-height: calc(100vh - 40px);
    }
}

/* Toggle button hidden by default */
.mobile-controls-header,
.landscape-title-container,
.landscape-control-cluster {
    display: none;
}

.mobile-sidebar-toggle {
    display: none !important;
}

.corner-fullscreen-toggle {
    display: none;
}

.mobile-view-all-container {
    display: none;
}

/* Mobile intro hidden by default (desktop) */
.mobile-top-intro,
.mobile-nav-toggle,
.mobile-nav-drawer,
.mobile-nav-overlay {
    display: none;
}

@media (max-width: 1024px) {
    :root {
        --mobile-panel-offset: calc(58px + env(safe-area-inset-top, 0px));
    }

    /* Abstract Page Mobile Styles */
    body.abstract-page-visible .mobile-top-intro,
    body.abstract-page-visible .mobile-nav-drawer,
    body.abstract-page-visible .mobile-nav-overlay {
        display: none !important;
    }

    .abstract-page {
        min-height: 100vh;
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top, 0px));
    }

    .abstract-page-inner {
        padding: 20px;
    }

    .abstract-page-header .jm-title-main {
        font-size: 1.3rem;
    }

    .abstract-page-header .jm-title-sub {
        font-size: 1.1rem;
    }

    .abstract-text {
        font-size: 0.9rem;
        line-height: 1.65;
    }

    /* Figure fullscreen expand button - visible on mobile */
    .figure-expand-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: absolute !important;
        top: 6px !important;
        right: 6px !important;
        left: auto !important;
        bottom: auto !important;
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        min-height: 24px !important;
        max-width: 24px !important;
        max-height: 24px !important;
        border: none !important;
        background: transparent !important;
        border-radius: 2px !important;
        color: #9ca3af !important;
        font-size: 12px !important;
        line-height: 1 !important;
        cursor: pointer;
        z-index: 100;
        transition: color 0.15s ease, background 0.15s ease;
        opacity: 0.6;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .figure-expand-btn i {
        font-size: 12px !important;
        line-height: 1 !important;
    }

    .figure-expand-btn:hover,
    .figure-expand-btn:focus {
        color: var(--accent, #1d4ed8) !important;
        background: rgba(0, 0, 0, 0.04) !important;
        opacity: 1;
    }

    .figure-expand-btn:active {
        transform: scale(0.92);
    }

    /* Ensure parent containers have relative positioning for button placement */
    .disagreement-section,
    .disagreement-content,
    .hrs-quarter-chart {
        position: relative !important;
    }

    /* Default state (Portrait): Hide the top-bar collapse button */
    .top-bar-collapse {
        display: none;
    }

    /* --- Global --- */
    html,
    body {
        height: auto;
        /* Allow body to grow */
        overflow-x: hidden;
    }

    .mobile-top-intro {
        display: block;
        padding: 12px 16px 4px;
        /* Tighter top/bottom padding to reduce gap above the chart */
        background: #fff;
        border-bottom: 1px solid rgba(17, 24, 39, 0.06);
        position: relative;
        z-index: 3000;
    }

    .mobile-top-intro-inner {
        max-width: 100%;
    }

    .mobile-top-header-container {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 42px;
    }

    /* Position the toggle button absolutely within the header */
    .mobile-top-header-container .mobile-nav-toggle {
        position: absolute;
        left: -8px;
        /* Pull left slightly into margin */
        top: 50%;
        transform: translateY(-50%);
        margin: 0;
        z-index: 10;
    }

    .mobile-title-content {
        text-align: center;
        padding: 0 32px;
        /* Clear button */
        width: 100%;
    }

    .mobile-main-title {
        font-size: 1rem;
        font-weight: 700;
        margin: 0 auto 6px auto;
        color: var(--text-primary);
        line-height: 1.35;
        max-width: 280px;
        /* Constraint width to force cleaner breaks if needed */
    }

    .mobile-author-line {
        font-size: 0.85rem;
        color: var(--text-secondary);
        margin: 0;
    }

    .mobile-nav-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 40px;
        height: 40px;
        border: none;
        border-radius: 6px;
        background: transparent;
        cursor: pointer;
        padding: 8px;
    }

    .mobile-nav-line {
        display: block;
        width: 100%;
        height: 2px;
        background: var(--text-primary);
    }

    .mobile-about-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
    }

    .mobile-nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(17, 24, 39, 0.35);
        backdrop-filter: blur(2px);
        z-index: 3500;
    }

    .mobile-nav-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(420px, 86vw);
        max-width: none;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(244, 245, 248, 0.94));
        color: var(--text-primary);
        z-index: 3600;
        padding: 26px 22px 28px;
        box-shadow: 12px 0 35px rgba(15, 23, 42, 0.22);
        border-right: 1px solid rgba(17, 24, 39, 0.08);
        transform: translateX(-104%);
        transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
        display: flex;
        flex-direction: column;
        gap: 18px;
        backdrop-filter: blur(16px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-nav-drawer.open {
        transform: translateX(0);
    }

    .mobile-nav-overlay.visible {
        display: block;
    }

    .mobile-nav-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }

    .mobile-nav-heading {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .mobile-nav-eyebrow {
        margin: 0;
        font-size: 0.68rem;
        letter-spacing: 0.18em;
        text-transform: uppercase;
        color: rgba(17, 24, 39, 0.6);
    }

    .mobile-nav-title {
        margin: 0;
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--text-primary);
    }

    .mobile-nav-close {
        align-self: flex-start;
        width: 40px;
        height: 40px;
        border: 1px solid rgba(17, 24, 39, 0.2);
        border-radius: 50%;
        background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(240, 241, 247, 0.92));
        color: var(--text-primary);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
        cursor: pointer;
        box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
        transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
    }

    .mobile-nav-close:hover,
    .mobile-nav-close:focus-visible {
        box-shadow: 0 10px 20px rgba(15, 23, 42, 0.22);
        color: var(--accent);
        transform: translateY(-1px);
    }

    /* Mobile Abstract Button */
    .mobile-abstract-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        padding: 6px 12px;
        margin: 6px 0 8px;
        border: none;
        border-radius: 6px;
        background: rgba(17, 24, 39, 0.04);
        cursor: pointer;
        transition: all 0.15s ease;
    }

    .mobile-abstract-btn:hover,
    .mobile-abstract-btn:focus-visible {
        background: rgba(17, 24, 39, 0.08);
    }

    .mobile-abstract-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: var(--accent);
        color: white;
        font-size: 0.6rem;
        font-weight: 700;
        font-style: italic;
        font-family: 'Georgia', serif;
        flex-shrink: 0;
    }

    .mobile-abstract-label {
        flex: 1;
        font-size: 0.8rem;
        font-weight: 500;
        color: var(--text-primary);
        text-align: left;
    }

    .mobile-abstract-arrow {
        font-size: 0.6rem;
        color: rgba(17, 24, 39, 0.35);
        transition: transform 0.15s ease, color 0.15s ease;
    }

    .mobile-abstract-btn:hover .mobile-abstract-arrow {
        transform: translateX(2px);
        color: var(--accent);
    }

    .mobile-nav-links {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .mobile-nav-footer {
        margin-top: auto;
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding-top: 8px;
    }

    .mobile-nav-footer .mobile-nav-divider {
        margin-bottom: 8px;
    }

    .mobile-nav-link.footer-link {
        padding: 8px 12px;
        border-radius: 6px;
    }

    .mobile-nav-link.footer-link:hover {
        background: rgba(17, 24, 39, 0.04);
    }

    .mobile-nav-dropdown {
        border: none;
        background: transparent;
        box-shadow: none;
        overflow: visible;
        border-radius: 0;
        border-bottom: 1px solid rgba(17, 24, 39, 0.08);
        transition: background 0.2s ease;
    }

    .mobile-nav-dropdown.expanded {
        border-color: rgba(17, 24, 39, 0.08);
        box-shadow: none;
        transform: none;
        background: rgba(17, 24, 39, 0.02);
        border-radius: 12px;
        border-bottom: none;
    }

    .mobile-nav-dropdown-toggle {
        width: 100%;
        border: none;
        background: transparent;
        padding: 10px 4px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: left;
        gap: 16px;
        cursor: pointer;
    }

    .mobile-nav-dropdown-copy {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 14px;
        flex: 1;
    }

    .mobile-nav-dropdown-label {
        font-weight: 700;
        font-size: 0.9rem;
        letter-spacing: 0.05em;
        color: rgba(var(--accent-rgb), 0.85);
        min-width: 44px;
        text-transform: none;
    }

    .mobile-nav-dropdown-value {
        font-size: 0.9rem;
        font-weight: 600;
        color: rgba(17, 24, 39, 0.92);
        white-space: normal !important;
        overflow-wrap: break-word !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    .mobile-nav-dropdown.expanded .mobile-nav-dropdown-value {
        color: var(--accent);
    }

    /* Dropdown with active selection - only text turns blue */
    .mobile-nav-dropdown.has-active .mobile-nav-dropdown-label {
        color: var(--accent);
    }

    .mobile-nav-dropdown.has-active .mobile-nav-dropdown-value {
        color: var(--accent);
    }

    .mobile-nav-dropdown-icon {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: transparent;
        color: rgba(17, 24, 39, 0.4);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        transition: transform 0.2s ease, color 0.2s ease;
        font-size: 0.85rem;
        flex-shrink: 0 !important;
    }

    .mobile-nav-dropdown.expanded .mobile-nav-dropdown-icon {
        transform: rotate(-180deg);
        color: var(--accent);
        background: transparent;
    }

    .mobile-nav-dropdown-menu {
        display: none;
        flex-direction: column;
        padding: 6px 0 12px;
        gap: 4px;
    }

    .mobile-nav-dropdown.expanded .mobile-nav-dropdown-menu {
        display: flex;
    }

    .mobile-nav-link {
        width: 100%;
        border: none;
        background: transparent;
        padding: 8px 20px;
        display: flex;
        align-items: center;
        gap: 14px;
        font-size: 0.85rem;
        text-align: left;
        color: rgba(17, 24, 39, 0.88);
        cursor: pointer;
        transition: color 0.2s ease, padding-left 0.2s ease;
    }

    .mobile-nav-link.top-level {
        font-size: 0.9rem;
        font-weight: 600;
        padding: 12px 4px;
        border-bottom: 1px solid rgba(17, 24, 39, 0.08);
        border-radius: 0;
        align-items: flex-start;
        height: auto !important;
        min-height: auto !important;
        white-space: normal !important;
        overflow: visible !important;
    }

    .mobile-nav-link.top-level .mobile-nav-link-marker {
        margin-top: 1px;
        /* Optically align marker with first line of title */
    }

    /* 
       Remove the "last-of-type" check because the "last" .top-level link (3.2) 
       is followed by dropdowns (3.3, 3.4), so it still needs a border.
       Instead, we can let them ALL have borders, or scope it differently. 
       Given the layout, 3.2 should definitely have a border. 
    */
    .mobile-nav-link.top-level:last-of-type {
        border-bottom: 1px solid rgba(17, 24, 39, 0.08);
    }

    .mobile-nav-link.sub-link {
        font-size: 0.9rem;
        padding: 8px 24px 8px 32px;
        color: rgba(17, 24, 39, 0.75);
    }

    .mobile-nav-link:hover,
    .mobile-nav-link:focus-visible {
        color: rgba(var(--accent-rgb), 0.95);
    }

    .mobile-nav-link.sub-link.nested-figure {
        padding-left: 42px;
        color: rgba(17, 24, 39, 0.7);
        font-size: 0.85rem;
    }

    .mobile-nav-link.sub-link.nested-figure .mobile-nav-link-marker {
        min-width: 50px;
        font-weight: 600;
        font-size: 0.8rem;
        opacity: 0.9;
    }

    .mobile-nav-link.sub-link.nested-figure:hover {
        padding-left: 46px;
        color: var(--accent);
    }

    /* Robustness section divider */
    .mobile-nav-dropdown-menu .mobile-nav-divider {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 10px 24px 6px 24px;
        margin-top: 4px;
        width: auto;
        height: auto;
        background: none;
        border: none;
    }

    .mobile-nav-divider-line {
        flex: 1;
        height: 1px;
        background: rgba(17, 24, 39, 0.15);
    }

    .mobile-nav-divider-text {
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: rgba(17, 24, 39, 0.45);
    }

    /* Robustness links - smaller and less emphasized */
    .mobile-nav-link.sub-link.robustness-link {
        font-size: 0.78rem;
        padding: 6px 24px 6px 32px;
        color: rgba(17, 24, 39, 0.55);
    }

    .mobile-nav-link.sub-link.robustness-link .mobile-nav-link-marker {
        font-size: 0.72rem;
        min-width: 40px;
        opacity: 0.7;
    }

    .mobile-nav-link.sub-link.robustness-link .mobile-nav-link-title {
        font-size: 0.75rem;
    }

    .mobile-nav-link.sub-link.robustness-link:hover,
    .mobile-nav-link.sub-link.robustness-link:focus-visible {
        color: rgba(17, 24, 39, 0.75);
    }

    .mobile-nav-link.sub-link.robustness-link.active {
        color: rgba(var(--accent-rgb), 0.8);
    }

    .mobile-nav-link.active {
        color: rgba(var(--accent-rgb), 0.95);
        font-weight: 600;
    }

    .mobile-nav-link-marker {
        font-weight: 700;
        font-size: 0.9rem;
        letter-spacing: 0.05em;
        color: rgba(var(--accent-rgb), 0.85);
        min-width: 44px;
        flex-shrink: 0 !important;
    }

    .mobile-nav-link.sub-link .mobile-nav-link-marker {
        min-width: 64px;
        font-size: 0.85rem;
    }

    .mobile-nav-link-marker.icon {
        font-size: 1rem;
        min-width: 32px;
        display: inline-flex;
        justify-content: center;
    }

    .mobile-nav-link-title {
        flex: 1;
        line-height: 1.3;
        white-space: normal !important;
        overflow-wrap: break-word !important;
        overflow: visible !important;
        text-overflow: clip !important;
        text-align: left;
    }

    .mobile-nav-drawer .top-tab-card {
        width: 100%;
        max-width: none;
        min-height: 64px;
        flex: none;
        margin: 0;
        border-radius: 14px;
        transform: none;
        transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
        white-space: normal !important;
        overflow: visible !important;
        height: auto !important;
    }

    .mobile-nav-drawer .top-tab-card::before,
    .mobile-nav-drawer .top-tab-card::after {
        display: none;
    }

    .mobile-nav-drawer .top-tab-card:not(.active):hover,
    .mobile-nav-drawer .top-tab-card:not(.active):focus-visible {
        border-color: rgba(17, 24, 39, 0.18);
        box-shadow: 0 12px 24px rgba(17, 24, 39, 0.16);
        color: rgba(17, 24, 39, 0.92);
    }

    .mobile-nav-drawer .top-tab-copy {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        display: flex !important;
    }

    .mobile-nav-drawer .top-tab-title {
        display: block;
        font-size: 0.98rem;
        line-height: 1.25;
        color: rgba(17, 24, 39, 0.9);
        white-space: normal;
    }

    .mobile-nav-drawer .toolbar-btn .text {
        display: flex !important;
        color: rgba(17, 24, 39, 0.8);
        font-size: 0.94rem;
    }

    .mobile-nav-badge {
        min-width: 48px;
        font-size: 0.85rem;
    }

    .mobile-nav-badge.icon-badge {
        font-size: 0.9rem;
        color: rgba(var(--accent-rgb), 0.85);
    }

    .mobile-nav-divider {
        width: 100%;
        height: 1px;
        background: linear-gradient(90deg, transparent, rgba(17, 24, 39, 0.15), transparent);
        border: none;
    }

    /* --- Narrative Panels (Sections 3.x) --- */
    .disagreement-panel-scroll,
    .dm-panel-scroll,
    .hrs-panel-scroll {
        flex: none;
        width: 100%;
        overflow-y: visible;
        padding: 6px clamp(2px, 0.8vw, 4px) clamp(60px, 10vw, 100px);
        justify-content: flex-start;
    }

    .disagreement-panel,
    .dm-panel,
    .hrs-panel {
        max-width: 100%;
        width: 100%;
        padding-bottom: 4px;
        gap: 4px !important;
    }

    .disagreement-overview-card,
    .dm-overview-card,
    .hrs-header-card {
        margin-left: 0;
        margin-right: 0;
        padding: 6px 10px !important;
        margin-bottom: 0 !important;
        border-radius: 8px !important;
        max-width: 100% !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .disagreement-overview-card h2,
    .dm-overview-card h2,
    .hrs-header-card h2 {
        font-size: 0.9rem !important;
        margin-bottom: 2px !important;
        line-height: 1.2 !important;
        max-width: 100% !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        white-space: normal !important;
    }

    .disagreement-overview-card p,
    .dm-overview-card p,
    .hrs-header-card p {
        font-size: 0.78rem !important;
        line-height: 1.35 !important;
        margin-bottom: 0 !important;
    }

    .disagreement-tabs-container,
    .dm-tabs-container,
    .hrs-tabs-container {
        margin-left: 0;
        margin-right: 0;
        margin-top: 0 !important;
        margin-bottom: 4px !important;
        padding: 2px 4px !important;
    }

    .disagreement-section,
    .dm-section {
        margin-left: 0;
        margin-right: 0;
        margin-top: 2px !important;
        margin-bottom: 2px !important;
    }

    .disagreement-tab-content,
    .dm-tab-content,
    .hrs-tab-content {
        padding: 6px clamp(3px, 1vw, 5px) 4px;
        max-height: none !important;
        overflow-y: visible !important;
    }

    /* Block-level math displays (centered equations) - make scrollable */
    mjx-container[display="true"] {
        display: block !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Inline math - MUST stay inline with surrounding text */
    mjx-container[display="false"] {
        display: inline !important;
        vertical-align: -0.15ex !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* --- Main Layout --- */
    /* Stack sidebar and chart vertically, but chart ON TOP like Desmos */
    .app-main {
        flex-direction: column;
        height: auto !important;
        /* Override fixed height */
        min-height: 100vh;
        overflow-y: visible;
        width: 100%;
    }

    /* --- Chart Area --- */
    .chart-area {
        order: 1;
        /* Force to top */
        width: 100% !important;
        padding: 0 8px 10px;
        /* Remove extra top padding; gap now controlled by inner container */
        border-top: none;
        border-bottom: 4px solid #f3f4f6;
        /* Visual separation below chart */
        background: #fff;
        position: sticky;
        top: 0;
        /* No artificial offset now that the desktop top toolbar is hidden on mobile */
        z-index: 50;
        /* Keep chart accessible while scrolling controls */
    }

    /* Tighten the space between the header and the actual graph, without touching the title itself */
    .chart-area>.chart-container {
        padding-top: 0;
        /* Remove residual gap between title block and chart frame */
        padding-right: 16px;
        padding-bottom: 16px;
        padding-left: 16px;
        max-width: 100%;
    }

    /* --- Sidebar --- */
    .sidebar,
    .mur-only-sidebar,
    .section-3-1-sidebar,
    .predictive-power-sidebar,
    .forecast-performance-sidebar,
    .appearance-only-sidebar {
        order: 2;
        /* Force below chart */
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        flex: none !important;
        height: auto !important;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        overflow-y: visible;
        padding-bottom: 80px;
        /* Add ample padding at bottom for scrolling */
        transition: all 0.3s ease;
    }

    /* Section navigator sidebars should trail the narrative content */
    .section-3-1-sidebar,
    .predictive-power-sidebar,
    .forecast-performance-sidebar,
    .disagreement-sidebar,
    #appendix-sidebar {
        order: 4;
        margin-top: clamp(18px, 4vw, 32px);
    }

    /* Hide inline section navigator cards on mobile; rely on drawer */
    .section-nav {
        display: none !important;
    }

    /* Collapsed State */
    .sidebar.sidebar-collapsed {
        padding-bottom: 0;
        border-bottom: none;
    }

    /* Keep tabs visible, hide content only */
    .sidebar.sidebar-collapsed .tab-content-area,
    .sidebar.sidebar-collapsed .section-nav {
        display: none !important;
    }

    .sidebar-collapse-btn {
        flex: 0 0 42px !important;
        display: none;
        align-items: center;
        justify-content: center;
        font-size: 1rem !important;
        color: var(--text-secondary);
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 10px;
        cursor: pointer;
        transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
    }

    .sidebar-collapse-btn.collapsed {
        color: #fff;
        background: var(--accent);
        border-color: transparent;
        box-shadow: 0 8px 16px rgba(15, 23, 42, 0.18);
    }

    .sidebar-collapse-btn[aria-hidden="true"] {
        opacity: 0;
        pointer-events: none;
    }

    .sidebar-collapse-btn i {
        transition: transform 0.3s ease;
    }

    .sidebar.sidebar-collapsed .sidebar-collapse-btn i {
        transform: rotate(180deg);
    }

    /* Toggle Button Styling */
    .mobile-sidebar-toggle {
        display: inline-flex !important;
        margin-left: auto;
        padding: 8px;
        border: 1px solid rgba(0, 0, 0, 0.1);
        border-radius: 6px;
        background: transparent;
        color: var(--text-secondary);
        cursor: pointer;
        font-size: 1.2rem;
    }

    /* Sidebar Header */
    .sidebar-header {
        display: none;
    }

    /* --- Sidebar Controls --- */
    .sidebar .group-box {
        margin: 12px 16px;
        padding: 16px;
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.06);
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    }

    .sidebar .group-title {
        font-family: "Computer Modern Serif", serif !important;
        font-size: 14.4px !important;
        /* Was 0.85rem */
        font-weight: 700 !important;
        color: var(--text-primary);
        margin-bottom: 12px;
        letter-spacing: 0;
        position: relative;
        padding-right: 24px;
    }

    /* Tabs as Segmented Control */
    .sidebar .tab-buttons {
        display: flex !important;
        background: #f1f3f5;
        padding: 4px;
        border-radius: 10px;
        margin: 6px 16px 4px;
        gap: 4px;
    }

    .sidebar .tab-btn {
        flex: 1;
        background: transparent;
        border: none;
        border-radius: 8px;
        padding: 8px 2px !important;
        font-family: "Computer Modern Serif", serif !important;
        font-size: 0.75rem !important;
        color: var(--text-secondary);
        font-weight: 600;
        text-align: center;
        white-space: nowrap;
        line-height: 1.3;
        min-height: 36px;
        transition: all 0.2s ease;
        box-shadow: none;
    }

    .sidebar .tab-btn.active {
        background: #fff;
        color: var(--text-primary);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        border-bottom: none;
        /* Remove desktop underline */
    }

    /* Checkbox Rows */
    .sidebar .checkbox-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        /* Label left, toggle right */
        margin-bottom: 12px;
        min-height: 32px;
        padding: 4px 0;
        gap: 12px;
    }

    .sidebar .checkbox-row label {
        font-family: "Computer Modern Serif", serif !important;
        font-size: 14.4px !important;
        color: var(--text-primary);
        line-height: 1.3;
        order: 1;
        /* Text first */
        flex: 1;
    }

    /* Modern iOS-style Switch */
    .sidebar .checkbox-row input[type="checkbox"] {
        order: 2;
        /* Toggle second */
        appearance: none;
        -webkit-appearance: none;
        width: 44px !important;
        height: 24px !important;
        background: #e5e7eb;
        border-radius: 99px;
        position: relative;
        cursor: pointer;
        transition: background 0.3s;
        margin: 0;
        border: none;
        flex-shrink: 0;
    }

    .sidebar .checkbox-row input[type="checkbox"]::after {
        content: '';
        position: absolute;
        top: 2px;
        left: 2px;
        width: 20px !important;
        height: 20px !important;
        background: #fff;
        border-radius: 50%;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
        transform: translate3d(0, 0, 0);
    }

    .sidebar .checkbox-row input[type="checkbox"]:checked {
        background: var(--accent);
    }

    .sidebar .checkbox-row input[type="checkbox"]:checked::after {
        transform: translate3d(20px, 0, 0);
    }

    /* Slider/Toggler stack */
    .horizon-control,
    .freq-control {
        margin: 12px 0 !important;
    }

    /* Dedicated mobile styling for the forecast horizon block */
    #start-horizon-control,
    #start-horizon-control+.horizon-control,
    #start-horizon-control+.horizon-control+.freq-control {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto !important;
        grid-template-rows: auto auto;
        align-items: center;
        gap: 6px 12px !important;
        padding: 12px 14px;
        background: #fff;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 14px;
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    }

    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .horizon-label,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .freq-label {
        grid-column: 1;
        grid-row: 1;
        font-family: var(--font-body) !important;
        font-size: 14.4px !important;
        font-weight: 500;
        color: var(--text-primary);
    }

    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .param-value {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
        padding: 4px 12px !important;
        min-width: 46px !important;
        background: #fff;
        border-radius: 999px;
        border: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
        font-size: 14.4px !important;
        color: var(--accent);
        font-weight: 700;
    }

    /* Core Measure dropdowns stack cleanly with consistent widths */
    #core-measures-section {
        display: flex;
        flex-direction: column;
        gap: 10px;
        width: auto;
        max-width: 100%;
        align-self: stretch;
        box-sizing: border-box;
    }

    #core-measures-section .measure-row {
        display: flex !important;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 0;
    }

    #core-measures-section .measure-row label {
        white-space: normal;
        font-size: 14px !important;
        padding-right: 0;
    }

    #core-measures-section .measure-row select {
        width: 100%;
        max-width: 100%;
        min-height: 34px;
        font-size: 0.85rem !important;
    }

    /* Taylor sensitivities sliders and math block */
    #taylor-sensitivities-section .math-display {
        font-size: clamp(0.8rem, 3.2vw, 1rem);
        text-align: center;
        padding: 4px 0;
        margin: 0 auto 8px;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    #taylor-sensitivities-section .sensitivity-controls-container,
    #start-horizon-control,
    #start-horizon-control+.horizon-control,
    #start-horizon-control+.horizon-control+.freq-control {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 6px 12px;
        padding: 12px 14px;
        background: #fff;
        border: 1px solid rgba(15, 23, 42, 0.08);
        border-radius: 14px;
        box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    }

    #taylor-sensitivities-section .sensitivity-block {
        display: contents;
    }

    #taylor-sensitivities-section .sensitivity-label {
        grid-column: 1;
        font-size: 14px !important;
        font-weight: 500;
        color: var(--text-primary);
    }

    #taylor-sensitivities-section .sensitivity-value {
        grid-column: 2;
        justify-self: end;
        padding: 4px 12px !important;
        min-width: 46px !important;
        background: #fff;
        border-radius: 999px;
        border: 1px solid rgba(15, 23, 42, 0.08);
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
        font-size: 14.4px !important;
        color: var(--accent);
        font-weight: 700;
    }

    #taylor-sensitivities-section .sensitivity-slider {
        grid-column: 1 / -1;
        width: 100%;
        margin: 6px 0 14px;
        height: 8px;
        appearance: none;
        border: none;
        border-radius: 999px;
        background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.35), rgba(var(--accent-rgb), 0.35)) left / var(--slider-fill, 50%) 100% no-repeat,
            rgba(229, 231, 235, 0.9);
    }

    #taylor-sensitivities-section .sensitivity-slider::-webkit-slider-thumb,
    #taylor-sensitivities-section .sensitivity-slider::-moz-range-thumb {
        appearance: none;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--accent-hover), var(--accent));
        border: 2px solid #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
        cursor: pointer;
    }

    /* Global math displays scale down on mobile */
    .math-display {
        font-size: clamp(0.8rem, 3.2vw, 1rem);
        overflow-x: auto;
        overflow-y: hidden;
        max-width: 100%;
        padding: 4px 0;
        -webkit-overflow-scrolling: touch;
    }

    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .param-slider,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .horizon-slider,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .freq-slider {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        height: 8px;
        margin-top: 6px;
        appearance: none;
        border: none;
        border-radius: 999px;
        background: linear-gradient(90deg, rgba(var(--accent-rgb), 0.35), rgba(var(--accent-rgb), 0.35)) left / var(--slider-fill, 50%) 100% no-repeat,
            rgba(229, 231, 235, 0.9);
    }

    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .param-slider::-webkit-slider-thumb,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .horizon-slider::-webkit-slider-thumb,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .freq-slider::-webkit-slider-thumb {
        appearance: none;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--accent-hover), var(--accent));
        border: 2px solid #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
        cursor: pointer;
    }

    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .param-slider::-moz-range-thumb,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .horizon-slider::-moz-range-thumb,
    :is(#start-horizon-control,
        #start-horizon-control + .horizon-control,
        #start-horizon-control + .horizon-control + .freq-control) .freq-slider::-moz-range-thumb {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--accent-hover), var(--accent));
        border: 2px solid #ffffff;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
        cursor: pointer;
    }

    #start-horizon-control~.checkbox-row {
        margin-top: 12px;
        padding: 12px 16px;
        border-radius: 14px;
        border: 1px solid rgba(15, 23, 42, 0.08);
        background: #fff;
        box-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
    }

    #start-horizon-control~.freq-note {
        margin-top: 8px;
        font-size: 0.85rem !important;
        text-align: center;
        color: var(--text-secondary);
    }

    /* Note text */
    .freq-note {
        font-family: "Computer Modern Serif", serif;
        font-style: italic;
        color: var(--text-secondary);
        font-size: 0.85rem;
        margin-top: 8px;
    }

    /* --- Sidebar Content Scaling (Reduced by ~50%) --- */
    .sidebar .group-title {
        font-size: 14.4px !important;
        /* Unified */
        margin-bottom: 6px;
        font-weight: 600 !important;
        letter-spacing: 0.03em;
        cursor: pointer;
        /* Indicate clickable */
        position: relative;
        padding-right: 24px;
        /* Space for chevron */
    }

    /* Chevron for collapse indication */
    .sidebar .group-title::after {
        content: '\f078';
        /* FontAwesome chevron-down */
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        font-size: 0.75rem;
        transition: transform 0.2s ease;
        opacity: 0.6;
    }

    /* Rotate chevron when collapsed */
    .group-box.mobile-collapsed .group-title::after {
        transform: translateY(-50%) rotate(-90deg);
    }

    /* Hide content when collapsed */
    .group-box.mobile-collapsed>*:not(.group-title) {
        display: none !important;
    }

    .sidebar label,
    .sidebar .checkbox-row label,
    .sidebar .measure-row label,
    .sidebar .param-label,
    .sidebar .horizon-label,
    .sidebar .freq-label,
    .sidebar .sensitivity-label {
        font-size: 14.4px !important;
        /* EXACT 14.4px */
        line-height: 1.2;
    }

    .sidebar select,
    .sidebar input[type="text"],
    .sidebar input[type="number"] {
        font-size: 0.8rem !important;
        padding: 4px 6px;
        height: 28px;
        /* Compact */
        border-radius: 4px;
    }

    /* Toggle button size */
    .mobile-sidebar-toggle {
        padding: 6px;
        font-size: 1rem;
        width: 32px;
        height: 32px;
    }

    /* Adjust vertical spacing */
    .sidebar .measure-row {
        margin-bottom: 6px;
        gap: 6px;
        min-height: 20px;
    }

    .mobile-view-all-container {
        display: block;
    }

    /* Grid layouts for controls - Adjust columns for smaller values */
    .horizon-control,
    .freq-control {
        grid-template-columns: 90px 48px 1fr !important;
        /* Shrink label and value cols */
        column-gap: 8px !important;
        margin: 6px 0 !important;
    }

    /* Explanation text override */
    .explanation-block,
    .explanation-title {
        font-size: 0.75rem !important;
    }

    /* --- Chart Area --- */
    .chart-area {
        order: 1;
        /* Force to top */
        width: 100% !important;
        padding: 0 8px 10px;
        /* Minimize whitespace above the chart */
        border-top: none;
        border-bottom: 4px solid #f3f4f6;
        background: #fff;
        position: sticky;
        top: 0;
        /* Reset to 0 now that toolbar is hidden */
        z-index: 90;
        /* Below dropdown (100+), above sidebar content */
        box-shadow: none;
    }

    .chart-area .figure-caption {
        font-size: 12px !important;
    }

    .chart-container {
        width: 100%;
        height: auto;
        display: block;
        position: relative;
    }

    .chart-frame {
        position: relative;
        width: 100%;
        height: 100%;
    }

    .chart-img {
        width: 100%;
        height: auto;
        display: block;
        object-fit: contain;
        /* Ensure chart aspect ratio is preserved */
    }

    /* --- Top Toolbar (Minimalist Dropdown Style) --- */
    .top-toolbar {
        display: none !important;
    }

    /* Hide desktop tab rail */
    .top-tab-rail {
        display: none !important;
    }

    /* remove dropdown z-index fix */

    /* Ensure toolbar buttons (About, Exit) are minimal */
    .topbar-left {
        display: none !important;
        /* Hide separate About button on mobile */
    }

    .topbar-right {
        flex: 0 0 auto;
        width: auto;
    }

    .about-trigger,
    .toolbar-btn {
        padding: 6px !important;
        height: 32px !important;
        font-size: 0.8rem !important;
    }

    /* Hide labels on small toolbar buttons */
    .toolbar-btn .text {
        display: none !important;
    }

    /* About Page Mobile Adjustments */
    .about-page-inner {
        padding: 16px;
        width: 100%;
        max-width: 100%;
    }

    .about-hero {
        flex-direction: column;
    }

    .about-portrait {
        width: 120px;
        height: 120px;
        margin: 0 auto 20px;
    }

    /* --- Panels (Appendix etc) --- */
    .disagreement-panel-container,
    .dm-panel-container,
    .hrs-panel-container {
        position: static;
        top: auto;
        left: auto;
        width: 100% !important;
        height: auto !important;
        flex: none;
        overflow-y: auto;
        overflow-x: hidden;
        z-index: auto;
        background: #fff;
        margin-top: 0;
        padding-top: 0;
        order: 3;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Overlays/Modals --- */
    /* Ensure tooltips and popovers behave on mobile */
    .abstract-tooltip {
        width: 90vw !important;
        left: 5vw !important;
        transform: translateY(10px) !important;
        /* Adjust positioning */
    }

    /* Disable fancy hover effects that might stick */
    .section-item:hover {
        transform: none;
    }
}

@media (max-width: 480px) {
    .chart-area {
        height: 50vh !important;
        min-height: 300px;
    }

    .sidebar-header h1 {
        font-size: 14px;
    }

    .top-toolbar .top-tab-title,
    .top-tab-rail .top-tab-title {
        display: none;
        /* Hide text on very small screens, keep badges */
    }

    .top-tab-badge {
        margin-right: 0;
    }
}

/* Landscape Optimizations */
@media (max-width: 1024px) and (orientation: landscape) {
    :root {
        --mobile-panel-offset: calc(40px + env(safe-area-inset-top, 0px));
    }

    /* Let body scroll so header scrolls with content in landscape */
    html, body {
        height: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* Ensure app-main doesn't create its own scroll container */
    .app-main {
        height: auto !important;
        min-height: 100vh;
        overflow-y: visible !important;
        overflow-x: hidden !important;
    }

    .mobile-top-intro {
        padding: 2px 36px !important;
        min-height: 28px;
        border-bottom: none;
    }

    .mobile-top-header-container {
        min-height: 28px;
    }

    .mobile-author-line {
        display: none !important;
    }

    .mobile-nav-toggle {
        width: 26px;
        height: 26px;
        padding: 3px;
        border-radius: 6px;
        gap: 3px;
        margin-left: 4px;
    }

    .mobile-nav-line {
        width: 14px;
        height: 2px;
    }

    .mobile-title-content {
        display: flex;
        align-items: flex-end;
        justify-content: center;
        min-height: inherit;
        padding: 2px 48px 0;
    }

    .mobile-main-title {
        margin: 0 !important;
        line-height: 1.15;
    }

    .chart-area {
        height: 90vh !important;
        /* Maximize chart height in landscape */
    }

    /* Landscape action cluster */
    .landscape-control-cluster {
        display: flex;
        align-items: center;
        gap: 8px;
        position: absolute;
        right: 16px;
        top: 50%;
        transform: translateY(-50%);
        z-index: 20;
    }

    .landscape-control-cluster .top-bar-collapse {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        border: none;
        border-radius: 50%;
        background: transparent;
        color: var(--text-primary);
        cursor: pointer;
        padding: 0;
        box-shadow: none;
        transition: color 0.2s ease, transform 0.2s ease;
    }

    .top-bar-collapse:hover,
    .top-bar-collapse:focus-visible {
        color: var(--accent);
    }

    .top-bar-collapse:active {
        transform: scale(0.95);
    }

    .top-bar-collapse i {
        font-size: 0.85rem;
        transition: transform 0.3s ease;
        line-height: 1;
        width: auto;
    }

    .top-bar-collapse.collapsed i {
        transform: rotate(180deg);
    }

    .corner-fullscreen-toggle {
        display: inline-flex;
        position: absolute;
        bottom: var(--corner-bottom-offset, clamp(4px, 1.3vw, 12px));
        right: var(--corner-right-offset, clamp(4px, 1.3vw, 12px));
        width: clamp(28px, 6.5vw, 42px);
        height: clamp(28px, 6.5vw, 42px);
        border: none;
        background: transparent;
        padding: 0;
        cursor: pointer;
        isolation: isolate;
        touch-action: manipulation;
        z-index: 5;
    }

    .corner-fullscreen-toggle::before,
    .corner-fullscreen-toggle::after {
        content: '';
        position: absolute;
        background: #1d4ed8;
        box-shadow: 0 0 8px rgba(29, 78, 216, 0.35);
        border-radius: 999px;
        transition: box-shadow 0.25s ease, transform 0.25s ease;
    }

    .corner-fullscreen-toggle::before {
        width: 2px;
        height: 60%;
        right: 0;
        bottom: 0;
    }

    .corner-fullscreen-toggle::after {
        height: 2px;
        width: 60%;
        right: 0;
        bottom: 0;
    }

    .corner-fullscreen-toggle:hover::before,
    .corner-fullscreen-toggle:hover::after,
    .corner-fullscreen-toggle:focus-visible::before,
    .corner-fullscreen-toggle:focus-visible::after {
        box-shadow: 0 0 14px rgba(29, 78, 216, 0.55);
    }

    .corner-fullscreen-toggle[aria-pressed="true"]::before,
    .corner-fullscreen-toggle[aria-pressed="true"]::after {
        background: #1d4ed8;
    }

    .corner-fullscreen-toggle:focus-visible {
        outline: none;
    }

    /* Adjust title to fit with button */
    .mobile-main-title {
        font-size: 0.95rem !important;
        /* Smaller to fit one line */
        max-width: none !important;
        /* Remove width constraint */
        margin-bottom: 4px !important;
        padding-right: 40px;
        /* Space for button */
        padding-left: 40px;
        /* Balance with left menu button */
    }

    .mobile-author-line {
        font-size: 0.8rem !important;
    }

    /* Hide default sidebar header title elements in landscape to avoid duplicates */
    .sidebar-header .default-title {
        display: none;
    }

    /* Clean up sidebar header since title is now in top bar */
    .sidebar-header {
        display: none !important;
    }

    .sidebar-title-row {
        width: 100%;
        justify-content: flex-end;
        /* Move abstract button to right */
    }

    .landscape-title-container {
        display: none !important;
        /* Ensure it's gone from sidebar if lingering */
    }

    /* Hide the old hamburger toggle in landscape since we have the Controls bar */
    .mobile-sidebar-toggle {
        display: none !important;
    }

    /* In landscape, sidebar might be better collapsed by default or smaller */
    .sidebar {
        max-height: 40vh;
        overflow-y: auto;
    }

    .sidebar.sidebar-collapsed {
        max-height: auto;
    }

    /* Panel containers - allow full page scroll in landscape (header scrolls away) */
    .disagreement-panel-container,
    .dm-panel-container,
    .hrs-panel-container {
        max-height: none !important;
        height: auto !important;
        overflow-y: visible !important;
        overflow-x: hidden !important;
    }

    .disagreement-panel-scroll,
    .dm-panel-scroll,
    .hrs-panel-scroll {
        overflow-y: visible !important;
        max-height: none !important;
        padding-top: 8px !important;
        padding-bottom: 80px;
    }

    /* Ensure panels display correctly in landscape */
    .disagreement-panel,
    .dm-panel,
    .hrs-panel {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* Ensure the chart is visible side-by-side if screen is wide enough */
    @media (min-width: 600px) {
        /* Let body scroll so header scrolls with content */
        html, body {
            height: auto !important;
            overflow-y: auto !important;
            overflow-x: hidden !important;
        }

        .app-main {
            flex-direction: row;
            /* Side by side for wider landscape phones */
            height: auto !important;
            min-height: 100vh;
            overflow-y: visible !important;
            overflow-x: hidden;
        }

        .sidebar,
        .mur-only-sidebar {
            width: 360px !important;
            height: 100% !important;
            max-height: none !important;
            /* Override the 40vh limit */
            border-right: 1px solid var(--border-color);
            border-bottom: none;
            overflow-y: auto;
            padding-bottom: 0;
            flex: 0 0 360px !important;
        }

        .disagreement-panel-container,
        .dm-panel-container,
        .hrs-panel-container {
            max-height: none !important;
            height: auto !important;
            overflow-y: visible !important;
        }

        .sidebar.sidebar-collapsed {
            width: 0 !important;
            /* Collapsed width */
            min-width: 0 !important;
            flex: 0 0 0 !important;
            padding: 0 !important;
            border: none !important;
            overflow: hidden;
        }

        /* Hide title in side-by-side collapsed mode to save space */
        .sidebar.sidebar-collapsed .sidebar-title-row h1,
        .sidebar.sidebar-collapsed .sidebar-title-row .landscape-title-container,
        .sidebar.sidebar-collapsed .sidebar-title-row .abstract-tooltip-wrapper {
            display: none;
        }

        .sidebar.sidebar-collapsed .sidebar-header {
            padding: 12px 4px;
            display: flex;
            justify-content: center;
        }

        .chart-area {
            height: 100% !important;
            border-top: none;
        }

        /* Center chart when sidebar is collapsed */
        .app-main.landscape-mode-collapsed .chart-area {
            display: grid;
            grid-template-columns: minmax(0, 1fr) minmax(160px, 0.45fr);
            align-items: flex-start;
            /* Keep chart and caption anchored to the top edge */
            align-content: flex-start;
            column-gap: clamp(4px, 1vw, 12px);
            /* Even tighter gap between chart and caption */
            padding: clamp(6px, 2.5vh, 18px) clamp(4px, 2vw, 12px);
            /* Bring caption and chart closer to screen edge */
        }

        .app-main.landscape-mode-collapsed .chart-container {
            height: 100%;
            width: 100%;
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            align-items: flex-start;
            align-self: flex-start;
            grid-column: 1;
            grid-row: 1;
        }

        .app-main.landscape-mode-collapsed .chart-img {
            max-height: 75vh;
            /* Constrain height to fit caption */
            width: auto;
            max-width: 100%;
            object-fit: contain;
            margin: 0 auto;
        }

        .app-main.landscape-mode-collapsed #chart-area>.figure-caption,
        .app-main.landscape-mode-collapsed .figure-caption {
            grid-column: 2;
            grid-row: 1;
            max-width: clamp(150px, 32vw, 240px);
            width: 100%;
            text-align: left;
            margin: clamp(20px, 6vh, 48px) 0 0;
            align-self: flex-start;
            font-size: 0.95rem;
            line-height: 1.35;
            justify-self: stretch;
            /* Let caption consume full width of narrow column */
            padding-left: 2px;
            padding-right: 2px;
        }

        .app-main.landscape-mode-collapsed .status-bar {
            grid-column: 1 / -1;
            margin-top: clamp(12px, 3vh, 24px);
        }
    }

    /* Fullscreen focus mode */
    body.landscape-fullscreen-mode .mobile-top-intro {
        display: none !important;
    }

    body.landscape-fullscreen-mode .top-toolbar,
    body.landscape-fullscreen-mode .top-tab-rail,
    body.landscape-fullscreen-mode .topbar-left,
    body.landscape-fullscreen-mode .topbar-right {
        display: none !important;
    }

    body.landscape-fullscreen-mode .mobile-main-title,
    body.landscape-fullscreen-mode .mobile-author-line {
        display: none;
    }

    body.landscape-fullscreen-mode .mobile-top-header-container {
        min-height: 0;
        align-items: flex-start;
        justify-content: flex-end;
    }

    body.landscape-fullscreen-mode .landscape-control-cluster {
        position: fixed;
        right: clamp(8px, 2vw, 18px);
        top: clamp(8px, 2vh, 18px);
        transform: none;
        background: rgba(255, 255, 255, 0.9);
        padding: 4px;
        border-radius: 999px;
        box-shadow: 0 10px 28px rgba(15, 23, 42, 0.25);
    }

    body.landscape-fullscreen-mode .app-main {
        flex-direction: column;
        height: 100vh !important;
        overflow: hidden;
    }

    body.landscape-fullscreen-mode .sidebar,
    body.landscape-fullscreen-mode .mur-only-sidebar,
    body.landscape-fullscreen-mode .section-3-1-sidebar,
    body.landscape-fullscreen-mode .predictive-power-sidebar,
    body.landscape-fullscreen-mode .forecast-performance-sidebar,
    body.landscape-fullscreen-mode .appearance-only-sidebar {
        display: none !important;
    }

    body.landscape-fullscreen-mode .chart-area {
        border: none;
        padding: clamp(4px, 1.5vw, 12px);
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        background: #fff;
        box-shadow: none;
    }

    body.landscape-fullscreen-mode .chart-container {
        height: 100%;
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    body.landscape-fullscreen-mode .chart-img {
        height: 100%;
        width: auto;
        max-width: 100vw;
        object-fit: contain;
        margin: 0;
    }

    body.landscape-fullscreen-mode .figure-caption {
        display: none;
    }

    body.landscape-fullscreen-mode .status-bar {
        display: none;
    }

    body.landscape-fullscreen-mode #mobile-collapse-btn {
        opacity: 0.35;
        pointer-events: none;
    }

    body.landscape-fullscreen-mode .corner-fullscreen-toggle {
        z-index: 220;
    }

    body.landscape-fullscreen-mode .app-main.landscape-mode-collapsed .chart-area {
        display: block;
        grid-template-columns: none;
        grid-template-rows: none;
    }

    body.landscape-fullscreen-mode .app-main.landscape-mode-collapsed .chart-container {
        height: 100%;
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    body.landscape-fullscreen-mode .app-main.landscape-mode-collapsed .chart-img {
        height: 100%;
        width: auto;
        max-width: 100vw;
        max-height: none;
        object-fit: contain;
        margin: 0;
    }

    body.landscape-fullscreen-mode .app-main.landscape-mode-collapsed #chart-area>.figure-caption {
        display: none !important;
    }

    body.landscape-fullscreen-mode .app-main.landscape-mode-collapsed .status-bar {
        display: none !important;
    }
}

/* Safety Override: Ensure desktop elements are visible on large screens */
@media (min-width: 1025px) {

    .top-toolbar,
    .top-tab-rail,
    .topbar-left,
    .segmented-control.desktop-only {
        display: flex !important;
    }

    .mobile-top-intro,
    .mobile-nav-toggle,
    .mobile-nav-drawer {
        display: none !important;
    }
}

/* Mobile formatting for sections 3.3-3.4 (matching 3.1-3.2 aesthetics) */
@media (max-width: 1024px) {

    /* Panel containers - reduce spacing and sizing */
    .disagreement-panel,
    .dm-panel-container,
    .hrs-panel-container,
    .gr-panel-container,
    #disagreement-panel,
    #dm-panel-container,
    #hrs-panel-container,
    #gr-panel-container {
        order: 3;
        width: 100% !important;
        padding: 16px 2px !important;
        margin: 0 !important;
        font-size: 0.9rem !important;
    }

    /* Section headings */
    .disagreement-panel h2,
    .disagreement-panel h3,
    .dm-panel-container h2,
    .dm-panel-container h3,
    .hrs-panel-container h2,
    .hrs-panel-container h3,
    .gr-panel-container h2,
    .gr-panel-container h3 {
        font-size: 1.15rem !important;
        margin-top: 16px !important;
        margin-bottom: 10px !important;
        line-height: 1.3 !important;
    }

    /* Paragraphs and text content */
    .disagreement-panel p,
    .dm-panel-container p,
    .hrs-panel-container p,
    .gr-panel-container p {
        font-size: 0.9rem !important;
        line-height: 1.55 !important;
        margin-bottom: 12px !important;
    }

    /* Math/formula displays - block equations only */
    .disagreement-panel .math-display,
    .dm-panel-container .math-display,
    .hrs-panel-container .math-display,
    .gr-panel-container .math-display {
        overflow-x: auto !important;
        overflow-y: hidden !important;
        max-width: 100% !important;
        padding: 2px 0 !important;
        margin: 4px 0 !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Display math (block equations) - scrollable, minimal padding */
    .disagreement-panel mjx-container[display="true"],
    .dm-panel-container mjx-container[display="true"],
    .hrs-panel-container mjx-container[display="true"],
    .gr-panel-container mjx-container[display="true"] {
        display: block !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        padding: 0 !important;
        margin: 0 !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Inline math - must stay inline with text */
    .disagreement-panel mjx-container[display="false"],
    .dm-panel-container mjx-container[display="false"],
    .hrs-panel-container mjx-container[display="false"],
    .gr-panel-container mjx-container[display="false"],
    p mjx-container[display="false"],
    mjx-container[display="false"] {
        display: inline !important;
        vertical-align: -0.15ex !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Tab buttons for DM/HRS/Disagreement sections */
    .dm-tab,
    .hrs-tab,
    .disagreement-tab {
        font-size: 0.75rem !important;
        padding: 6px 10px !important;
        margin: 2px !important;
        border-radius: 6px !important;
    }

    .dm-tab.active,
    .hrs-tab.active,
    .disagreement-tab.active {
        font-weight: 600 !important;
    }

    /* Content wrappers */
    .disagreement-content,
    .dm-content,
    .hrs-content,
    .gr-content {
        padding: 12px 2px !important;
    }

    /* Figure captions within panels */
    .disagreement-panel .figure-caption,
    .dm-panel-container .figure-caption,
    .hrs-panel-container .figure-caption,
    .gr-panel-container .figure-caption {
        font-size: 0.82rem !important;
        padding: 8px 4px !important;
        margin-top: 6px !important;
    }

    /* Callout boxes and info blocks */
    .disagreement-panel .callout-panel,
    .dm-panel-container .callout-panel,
    .hrs-panel-container .callout-panel,
    .gr-panel-container .callout-panel {
        padding: 10px 12px !important;
        margin: 12px 0 !important;
        font-size: 0.85rem !important;
    }

    /* Lists */
    .disagreement-panel ul,
    .disagreement-panel ol,
    .dm-panel-container ul,
    .dm-panel-container ol,
    .hrs-panel-container ul,
    .hrs-panel-container ol,
    .gr-panel-container ul,
    .gr-panel-container ol {
        font-size: 0.9rem !important;
        padding-left: 20px !important;
        margin: 10px 0 !important;
    }

    .disagreement-panel li,
    .dm-panel-container li,
    .hrs-panel-container li,
    .gr-panel-container li {
        margin-bottom: 6px !important;
        line-height: 1.5 !important;
    }

    /* Tables - Full width mobile optimization (portrait) */
    .dm-table-container,
    .disagreement-figure-container.dm-table-container {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-left: calc(-1 * clamp(2px, 0.8vw, 4px)) !important;
        margin-right: calc(-1 * clamp(2px, 0.8vw, 4px)) !important;
        padding: 0 !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .dm-table,
    .disagreement-panel table,
    .dm-panel-container table,
    .hrs-panel-container table,
    .gr-panel-container table {
        width: 100% !important;
        min-width: max-content !important;
        table-layout: auto !important;
        font-size: 0.7rem !important;
        border-collapse: collapse !important;
        margin: 0 !important;
    }

    .dm-table th,
    .dm-table td,
    .disagreement-panel th,
    .disagreement-panel td,
    .dm-panel-container th,
    .dm-panel-container td,
    .hrs-panel-container th,
    .hrs-panel-container td,
    .gr-panel-container th,
    .gr-panel-container td {
        padding: 6px 6px !important;
        font-size: 0.7rem !important;
        white-space: nowrap !important;
        text-align: center !important;
    }

    .dm-table th,
    .disagreement-panel th,
    .dm-panel-container th,
    .hrs-panel-container th,
    .gr-panel-container th {
        font-size: 0.68rem !important;
        font-weight: 600 !important;
        background: #f8fafc !important;
    }

    .dm-table td:first-child,
    .dm-table th:first-child {
        text-align: left !important;
        padding-left: 8px !important;
    }

    .table-panel-title {
        font-size: 0.8rem !important;
        margin: 12px 8px 6px !important;
        padding: 0 !important;
    }

    /* Table figure captions - full width */
    .dm-table-container .figure-caption,
    .disagreement-figure-container.dm-table-container .figure-caption {
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px 8px !important;
        font-size: 0.75rem !important;
        line-height: 1.4 !important;
        text-align: left !important;
    }

    /* Strong/bold text */
    .disagreement-panel strong,
    .dm-panel-container strong,
    .hrs-panel-container strong,
    .gr-panel-container strong {
        font-weight: 600 !important;
    }

    /* Code blocks if any */
    .disagreement-panel code,
    .dm-panel-container code,
    .hrs-panel-container code,
    .gr-panel-container code {
        font-size: 0.82rem !important;
        padding: 2px 4px !important;
    }

    /* Images and figures */
    .disagreement-panel img,
    .dm-panel-container img,
    .hrs-panel-container img,
    .gr-panel-container img {
        max-width: 100% !important;
        height: auto !important;
        margin: 10px 0 !important;
    }

    /* =========================================
       HRS Quarter Grid (3.4.1 & 3.4.2) - Mobile
       Clean, simple layout for figures
       ========================================= */
    .hrs-quarter-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px !important;
        margin: 16px 0 40px !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .hrs-quarter-chart {
        background: #fff !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 2px !important;
    }

    /* Quarter title - simple centered text, close to graph */
    .hrs-quarter-chart h3 {
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        color: var(--text-primary) !important;
        text-align: center !important;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
    }

    /* Chart container - remove grey background, tight to title */
    .hrs-quarter-chart .chart-container {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 2px auto 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        min-height: 150px !important;
        position: relative !important;
    }

    /* Chart images - full width, clean display */
    .quarter-chart-image {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        border-radius: 4px !important;
        object-fit: contain !important;
        margin: 0 auto !important;
    }

    /* Loading indicator */
    .hrs-quarter-chart .chart-loading {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        font-size: 0.8rem !important;
        color: var(--text-secondary) !important;
        background: rgba(255, 255, 255, 0.9) !important;
        padding: 8px 16px !important;
        border-radius: 4px !important;
    }

    /* Add subtle separator between charts */
    .hrs-quarter-chart:not(:last-child) {
        padding-bottom: 16px !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    }

    /* Shock selector dropdown - mobile optimization */
    .shock-selector-panel {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
        padding: 6px 10px !important;
        margin-top: 0 !important;
        margin-bottom: 6px !important;
    }

    .shock-selector-panel label {
        font-size: 0.75rem !important;
        white-space: normal !important;
    }

    .shock-dropdown {
        width: 100% !important;
        font-size: 0.7rem !important;
        padding: 5px 8px !important;
        max-width: 100% !important;
    }

    /* Tighten figure containers vertically */
    .disagreement-figure-container {
        margin-top: 4px !important;
        margin-bottom: 4px !important;
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }

}

/* Portrait-only: Tables extend to screen edges */
@media (max-width: 1024px) and (orientation: portrait) {
    .dm-table-container,
    .disagreement-figure-container.dm-table-container {
        width: calc(100% + 4px) !important;
        margin-left: -2px !important;
        margin-right: -2px !important;
        box-sizing: border-box;
    }
}

/* Landscape: Reset table containers to normal padding */
@media (max-width: 1024px) and (orientation: landscape) {
    .dm-table-container,
    .disagreement-figure-container.dm-table-container {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 16px !important;
    }

    .dm-table th,
    .dm-table td {
        white-space: normal !important;
        padding: 8px 10px !important;
        font-size: 0.8rem !important;
    }

    /* Landscape: HRS Quarter Grid - 2 column layout */
    .hrs-quarter-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
        margin: 12px 0 32px !important;
        padding: 0 !important;
    }

    .hrs-quarter-chart {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 8px !important;
        margin: 0 !important;
    }

    .hrs-quarter-chart h3 {
        font-size: 0.8rem !important;
        margin: 0 !important;
    }

    .hrs-quarter-chart .chart-container {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        min-height: 100px !important;
    }

    .quarter-chart-image {
        width: 100% !important;
        height: auto !important;
        border-radius: 4px !important;
    }

    /* Remove separator in landscape grid layout */
    .hrs-quarter-chart:not(:last-child) {
        border-bottom: none !important;
        padding-bottom: 8px !important;
    }

    /* Landscape: Panel container spacing from edges */
    .disagreement-panel-scroll,
    .dm-panel-scroll,
    .hrs-panel-scroll {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Landscape: Ensure title cards are fully visible and centered */
    .disagreement-overview-card,
    .dm-overview-card,
    .hrs-header-card {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        visibility: visible !important;
        opacity: 1 !important;
        text-align: center !important;
        padding: 12px 12px !important;
        margin-bottom: 8px !important;
        min-height: auto !important;
        height: auto !important;
        overflow: visible !important;
    }

    .disagreement-overview-card h2,
    .dm-overview-card h2,
    .hrs-header-card h2 {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        text-align: center !important;
        font-size: 0.95rem !important;
        line-height: 1.3 !important;
        margin: 0 !important;
        padding: 0 !important;
        color: var(--text-primary) !important;
    }

    /* For cards with only h2 (no subtitle), ensure it's centered */
    .disagreement-overview-card h2:only-child {
        margin: 0 auto !important;
    }

    .disagreement-overview-card p,
    .dm-overview-card p,
    .hrs-header-card p {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        text-align: center !important;
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
        color: var(--text-secondary) !important;
    }
}