/* Phone layouts use content-sized navigation and a dedicated activity scroll area. */
.mobile-room-nav { display: none; }

@media (max-width: 800px), (max-width: 1100px) and (max-height: 500px) {
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    #app button { min-height: 44px; touch-action: manipulation; }
    #app button, #app a { overflow-wrap: anywhere; }

    .immersive-screen .location-stage {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: auto auto auto minmax(0, 1fr);
        align-content: stretch;
        gap: 8px;
        padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }
    .immersive-screen :is(.location-stage, .hub-stage) > .scene-heading {
        position: relative;
        inset: auto;
        grid-column: 1 / -1;
        grid-row: 1;
        width: 100%;
        min-width: 0;
        max-width: none;
        margin: 0;
        padding: 9px 12px;
        border-radius: 12px;
    }
    .immersive-screen :is(.location-stage, .hub-stage) > .scene-heading h1 {
        font-size: 20px;
        line-height: 1.2;
        white-space: normal;
        overflow: visible;
        overflow-wrap: anywhere;
        text-overflow: clip;
    }
    .immersive-screen :is(.location-stage, .hub-stage) > .scene-heading .scene-eyebrow,
    .immersive-screen :is(.location-stage, .hub-stage) > .scene-heading p { display: none; }
    .immersive-screen :is(.location-stage, .hub-stage) > .scene-actions {
        position: relative;
        inset: auto;
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: flex-end;
        gap: 8px;
        width: 100%;
        min-width: 0;
    }
    .scene-actions .scene-icon-button { flex: 0 0 44px; width: 44px; height: 44px; }
    .scene-actions .scene-notebook-button { display: flex; flex: 1 1 auto; min-width: 0; width: auto; min-height: 44px; height: auto; padding: 8px 10px; gap: 8px; }
    .scene-actions .notebook-button-label { display: inline; font-size: 14px; }
    .scene-actions .notebook-button-count { position: static; min-width: 0; padding: 3px 5px; font-size: 12px; }
    .scene-actions .progress-badge { display: none; }

    .immersive-screen .location-stage > .back-button,
    .immersive-screen .location-stage > .room-look-button {
        position: relative;
        inset: auto;
        grid-row: 3;
        width: 100%;
        min-width: 0;
        max-width: none;
        min-height: 44px;
        margin: 0;
        padding: 8px;
        gap: 6px;
        justify-content: center;
        align-self: stretch;
        font-size: 14px;
        line-height: 1.3;
        white-space: normal;
        border-radius: 11px;
    }
    .immersive-screen .location-stage > .back-button { grid-column: 1; }
    .immersive-screen .location-stage > .room-look-button { grid-column: 2; }
    .immersive-screen .location-stage:not(:has(.room-look-button)) > .back-button { grid-column: 1 / -1; }
    .immersive-screen .location-stage > .back-button > span:last-child {
        min-width: 0;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
    }
    .immersive-screen .location-stage > .back-button .nav-arrow { flex: 0 0 24px; width: 24px; height: 24px; }
    .immersive-screen .location-stage > :is(.reception-workspace, .ward-workspace, .office-workspace, .aftercare-workspace, .synthesis-workspace) {
        position: relative;
        inset: auto;
        grid-column: 1 / -1;
        grid-row: 4;
        width: 100%;
        min-width: 0;
        height: 100%;
        min-height: 0;
        max-height: none;
        margin: 0;
        transform: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        border-radius: 14px;
        scrollbar-gutter: auto;
    }

    /* Room art and the invitation share one scrollable page on a phone. */
    .immersive-screen .room-overview-stage {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .room-overview-stage > .scene-heading { order: 1; flex: 0 0 auto; }
    .room-overview-stage > .scene-actions { order: 2; flex: 0 0 auto; }
    .room-overview-stage > .back-button { order: 3; flex: 0 0 auto; }
    .room-overview-stage > .room-art-frame {
        position: relative;
        inset: auto;
        order: 4;
        flex: 0 0 auto;
        width: 100%;
        height: auto;
        min-height: 0;
        aspect-ratio: 16 / 9;
    }
    .room-overview-stage > .room-arrival {
        position: relative;
        inset: auto;
        order: 5;
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        max-height: none;
        margin: 0;
        padding: 18px;
        overflow: visible;
    }
    .room-arrival h2 { font-size: 25px; overflow-wrap: anywhere; }
    .room-arrival .room-arrival-copy { font-size: 16px; line-height: 1.6; }
    .room-arrival .room-arrival-note { font-size: 14px; line-height: 1.5; }
    .room-arrival :is(.room-eyebrow, .room-status) { font-size: 12px; line-height: 1.45; }
    .room-arrival .primary-button { white-space: normal; }
    .office-builder > :is(.office-picker, .office-review-note) { order: 0; }

    .immersive-screen .hub-stage:not(.start-hub-stage) {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
    .hub-stage:not(.start-hub-stage) > .scene-heading { order: 1; flex: 0 0 auto; }
    .hub-stage:not(.start-hub-stage) > .scene-actions { order: 2; flex: 0 0 auto; }
    .immersive-screen .hub-stage:not(.start-hub-stage) > .hub-canvas {
        position: relative;
        inset: auto;
        order: 3;
        flex: 0 0 auto;
        width: 100%;
        max-width: none;
        height: auto;
        max-height: none;
        transform: none;
        aspect-ratio: 16 / 9;
        border-radius: 12px;
    }
    .hub-stage:not(.start-hub-stage) .hotspot { display: none; }
    .mobile-room-nav {
        position: relative;
        z-index: 8;
        order: 4;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        flex: 0 0 auto;
    }
    .mobile-room-button {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        min-width: 0;
        min-height: 64px;
        padding: 12px;
        border: 1px solid #cabb9c;
        border-radius: 12px;
        color: #3d4632;
        background: #fff8e9;
        font-size: 16px;
        font-weight: 700;
        line-height: 1.4;
        text-align: left;
        cursor: pointer;
    }
    .mobile-room-button small { font-size: 12px; font-weight: 400; line-height: 1.4; }
    .mobile-room-button.is-visited { border-color: #98ac80; background: #eaf0df; }
    .immersive-screen .hub-stage > .synthesis-invitation {
        position: relative;
        inset: auto;
        order: 5;
        flex: 0 0 auto;
        width: 100%;
        max-height: none;
        margin: 0;
        padding: 18px;
        overflow: visible;
        transform: none;
    }

    .start-hub-stage .start-overlay {
        padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        min-width: 0;
        min-height: 0;
    }
    .start-overlay .research-welcome {
        width: 100%;
        max-width: 680px;
        max-height: 100%;
        min-width: 0;
        min-height: 0;
        padding: 20px 18px;
        overflow-wrap: anywhere;
        scrollbar-gutter: auto;
    }
    .start-overlay .research-welcome .start-title { font-size: clamp(30px, 8vw, 38px); }
    .start-overlay .research-welcome .start-kicker { font-size: 12px; }
    .start-overlay .research-welcome .start-question { font-size: 18px; line-height: 1.5; }
    .research-welcome :is(.welcome-lead, .welcome-steps p, .welcome-finale > p) { font-size: 16px; line-height: 1.55; }
    .research-welcome :is(.welcome-order, .start-status, .welcome-chain > span, .welcome-finale .welcome-outcome) { font-size: 14px; line-height: 1.5; }
    .research-welcome .welcome-eyebrow { font-size: 12px; }
    .research-welcome .welcome-steps { grid-template-columns: minmax(0, 1fr); }
    .research-welcome .welcome-actions { flex-direction: column; align-items: stretch; }
    .research-welcome button { max-width: 100%; white-space: normal; }
    .research-welcome .welcome-chain { display: grid; grid-template-columns: minmax(0, 1fr); text-align: center; }
    .research-welcome .welcome-chain > i { transform: rotate(90deg); }
}

/* A wider landscape phone can place the title and toolbar side by side. */
@media (min-width: 600px) and (max-width: 1100px) and (max-height: 500px) {
    .immersive-screen .location-stage { grid-template-rows: auto auto minmax(0, 1fr); }
    .immersive-screen .location-stage > .scene-heading { grid-column: 1; grid-row: 1; align-self: center; }
    .immersive-screen .location-stage > .scene-actions { grid-column: 2; grid-row: 1; }
    .immersive-screen .location-stage > .back-button,
    .immersive-screen .location-stage > .room-look-button { grid-row: 2; }
    .immersive-screen .location-stage > :is(.reception-workspace, .ward-workspace, .office-workspace, .aftercare-workspace, .synthesis-workspace) { grid-row: 3; }
}
