/*
 * Storyfellow — unified workspace shell, Talk viewport contract, phone layout.
 * Phone: max-width 767px. Desk: min-width 768px.
 */

/* ——— Desktop Talk: shared grid, composer inside 100dvh ——— */

@media (min-width: 768px) {
    #screen-app.is-active
        > .app-layout.voice-stage:not(.is-writing-desk):not(.is-talk-history):not(
            .is-continuous-response
        ),
    #screen-story.is-active > .layout-story.voice-stage {
        --voice-mic-size: 152px;
        --voice-meter-band: 68px;
        --voice-status-band: calc(
            var(--voice-mic-ring-bleed) + var(--voice-status-gap) + 2.25rem
        );
        padding-bottom: 0;
        width: 100%;
        max-width: var(--st-desktop-workspace);
        align-self: center;
        box-sizing: border-box;
        grid-template-rows:
            minmax(0, 1fr)
            var(--voice-mic-cluster)
            var(--voice-status-band)
            minmax(44px, auto);
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .voice-recorder-anchor,
    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .status-area,
    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > #story-say {
        transform: none;
        margin-top: 0;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .voice-recorder-anchor
        .btn-mic,
    #screen-app.is-active .voice-recorder-anchor .btn-mic {
        width: 152px;
        height: 152px;
    }

    /*
     * Long editorial answers: AppScreen.css flex column + stage scroll (d0f4f18).
     * Do not apply the short-question voice grid here — it traps prose in row 1.
     */
    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > #story-say {
        grid-row: 4;
        grid-column: 1;
        flex: unset;
        width: 100%;
        max-width: var(--st-measure-reader);
        margin: 8px auto 0;
        min-height: 44px;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .app-say-label {
        display: none;
        margin: 0;
        height: 0;
        overflow: hidden;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .status-area {
        padding: 8px 12px 4px;
        box-sizing: border-box;
    }
}

@media (min-width: 768px) {
    .voice-stage.is-talk-fresh-welcome > .talk-fresh-intro {
        height: auto;
        min-height: 0;
    }
}

@media (min-width: 1200px) {
    #screen-app.is-active > .app-layout.voice-stage:not(.is-writing-desk),
    #screen-story.is-active > .layout-story.voice-stage {
        --voice-mic-size: 154px;
        max-width: var(--st-desktop-workspace);
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .voice-recorder-anchor
        .btn-mic {
        width: 154px;
        height: 154px;
    }
}

@media (min-width: 1440px) {
    #screen-app.is-active > .app-layout.voice-stage:not(.is-writing-desk),
    #screen-story.is-active > .layout-story.voice-stage {
        --voice-mic-size: 156px;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .voice-recorder-anchor
        .btn-mic {
        width: 156px;
        height: 156px;
    }
}

/*
 * Phone Talk — same flex column for First Talk (#screen-story) and editorial
 * (#screen-app). Matches narrowed desktop Chrome at identical CSS width.
 */
@media (max-width: 767px) {
    #screen-story.is-active {
        height: 100vh;
        height: 100dvh;
        height: 100svh;
        max-height: 100dvh;
        max-height: 100svh;
        padding-bottom: 0;
        overflow: hidden;
        box-sizing: border-box;
    }

    #screen-story.is-active > .layout-story.voice-stage.is-talk-fresh-welcome {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        grid-template-rows: none;
        grid-template-columns: none;
        flex: 1 1 0%;
        min-height: 0;
        overflow: hidden;
        padding-bottom: 0;
        gap: 0;
        max-width: 100%;
        width: 100%;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .talk-fresh-intro {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        max-height: none;
        overflow-x: hidden;
        overflow-y: auto;
        grid-row: auto;
        grid-column: auto;
        padding: 8px 0 12px;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .voice-recorder-anchor {
        flex: 0 0 auto;
        margin: 0 0 8px;
        grid-row: auto;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > .status-area {
        flex: 0 0 auto;
        height: auto;
        min-height: 0;
        max-height: none;
        padding: 4px 12px 0;
        grid-row: auto;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        > #story-say {
        flex: 0 0 auto;
        width: 100%;
        max-width: 100%;
        margin: 8px auto 0;
        position: relative;
        z-index: 5;
        padding-bottom: var(--st-voice-composer-bottom, 56px);
        box-sizing: border-box;
        grid-row: auto;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .voice-recorder-timer,
    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .voice-waveform {
        height: 0;
        margin: 0;
        overflow: hidden;
        opacity: 0;
        pointer-events: none;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .app-say-input {
        -webkit-appearance: none;
        appearance: none;
        box-sizing: border-box;
        height: 40px;
        min-height: 40px;
        max-height: 40px;
        padding: 8px 14px;
        line-height: 1.35;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .app-say-go {
        min-height: 40px;
    }

    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .app-say-input:focus,
    #screen-story.is-active
        .voice-stage.is-talk-fresh-welcome
        .app-say-input:focus-visible {
        height: auto;
        min-height: 40px;
        max-height: 168px;
    }
}

/* Manuscript outer shell: align reader chrome with workspace at desk */
@media (min-width: 768px) {
    .chapter-reader-chrome,
    .manuscript-write-chrome,
    #screen-next .next-layout,
    #screen-export > .export-layout,
    #screen-profile > .profile-layout,
    #screen-collaboration > .collaboration-layout,
    #screen-invitation > .collaboration-layout,
    #screen-writing-identity > .writing-identity-layout,
    #screen-help > .help-layout,
    #screen-subscription > .subscription-layout,
    #screen-project-home
        .project-home-layout:not(.is-versions-home):not(.is-editorial-home),
    #screen-developmental-edit .developmental-edit-workspace,
    #screen-manuscript-write .manuscript-write,
    #screen-about > .about-layout,
    #screen-standalone-editing > .standalone-editing-layout {
        width: 100%;
        max-width: var(--st-workspace-standard);
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
    }
}

#screen-import-material.is-active .import-material.import-material-screen-host {
    position: relative;
    inset: auto;
    z-index: auto;
    display: block;
    padding: 0;
    height: auto;
}

#screen-import-material.is-active .import-material-page-chrome .brand-bar {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: var(--st-page-pad-y) var(--st-page-pad-x) 8px;
    box-sizing: border-box;
}

/*
 * Utility workspace horizontal gutters (Write My Book pattern).
 * Loads after per-screen `padding: … 0 …` shorthands so inline gutters win.
 */
#screen-export > .export-layout,
#screen-profile > .profile-layout,
#screen-collaboration > .collaboration-layout,
#screen-invitation > .collaboration-layout,
#screen-help > .help-layout,
#screen-writing-identity > .writing-identity-layout,
#screen-subscription > .subscription-layout,
#screen-next > .next-layout,
#screen-project-home.is-active.is-utility-settings > .project-home-layout,
#screen-import-material
    .import-material.import-material-screen-host.import-material-page
    .import-material-panel {
    padding-left: var(--st-page-pad-x);
    padding-right: var(--st-page-pad-x);
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

/*
 * Editorial Guide — match Developmental Edit shell (620px mobile/tablet,
 * 1040px desktop). Do not set max-width: 100% here; that overrode the
 * centred workspace and painted the guide full-bleed under the brand bar.
 */
#screen-project-home .project-home-layout.is-settings {
    width: 100%;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--st-page-pad-x);
    padding-right: var(--st-page-pad-x);
    padding-bottom: 3rem;
    padding-top: 12px;
    box-sizing: border-box;
    min-width: 0;
    overflow-x: hidden;
    text-align: left;
}

#screen-project-home .project-home-layout.is-editorial-home {
    width: 100%;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--st-page-pad-x);
    padding-right: var(--st-page-pad-x);
    padding-bottom: 3rem;
    padding-top: 12px;
    box-sizing: border-box;
    min-width: 0;
    overflow-x: hidden;
}

/*
 * Same rule as #screen-developmental-edit .developmental-edit-workspace in
 * DesignSystem.css @media (min-width: 768px) — loads after padding shorthand
 * so desktop heading offset matches Developmental Edit exactly.
 */
@media (min-width: 768px) {
    #screen-project-home .project-home-layout.is-editorial-home,
    #screen-project-home .project-home-layout.is-settings {
        padding-top: var(--st-header-content-gap);
    }
}

@media (min-width: 1024px) {
    #screen-project-home .project-home-layout.is-editorial-home,
    #screen-project-home .project-home-layout.is-settings {
        max-width: 1040px;
        max-width: var(--st-workspace-standard);
    }
}

#screen-profile .profile-layout,
#screen-collaboration .collaboration-layout,
#screen-invitation .collaboration-layout,
#screen-export .export-layout,
#screen-help .help-layout,
#screen-writing-identity .writing-identity-layout,
#screen-next .next-layout {
    overflow-wrap: anywhere;
}

#screen-profile .profile-field dd,
#screen-profile .profile-field dt,
#screen-profile .profile-field a,
.collaboration-row-title,
.collaboration-row-meta,
.collaboration-invite-link {
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
    max-width: 100%;
}

.collaboration-row-main {
    flex: 1 1 auto;
    min-width: 0;
}

.collaboration-row-actions {
    flex: 0 0 auto;
    max-width: 100%;
}

.collaboration-row-actions .link-secondary {
    white-space: nowrap;
    overflow-wrap: normal;
    word-break: normal;
}

@media (min-width: 768px) {
    #screen-import-material.is-active
        .import-material.import-material-screen-host
        .import-material-panel {
        max-width: var(--st-workspace-standard);
        margin-left: auto;
        margin-right: auto;
    }
}