/* Storyteller — landing experience */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    font-family: var(--st-font-sans);
    background: var(--st-bg);
    color: var(--st-ink);
    -webkit-font-smoothing: antialiased;
}

/* Screens */

.screen {
    display: none;
    width: 100%;
    min-height: 100vh;
    padding: var(--st-page-pad-y) var(--st-page-pad-x);
    justify-content: center;
    align-items: center;
    text-align: center;
}

.screen.is-active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.layout {
    width: 100%;
    max-width: var(--st-measure);
}

/* Brand — in document flow, upper-left */

.title {
    align-self: stretch;
    flex-shrink: 0;
    font-size: 24px;
    font-weight: 400;
    letter-spacing: -0.02em;
    color: var(--st-ink);
    text-align: left;
}

.title.brand-wordmark,
.brand-wordmark.title {
    align-self: center;
    flex-shrink: 0;
    font-family: var(--st-font-sans);
    font-size: clamp(28px, 2.2vw, 33px);
    font-weight: 500;
    letter-spacing: -0.045em;
    line-height: 1;
    color: var(--st-brand-ink);
}

.brand-wordmark .brand-story {
    color: var(--st-brand-ink);
}

.brand-wordmark .brand-fellow {
    color: var(--st-brand-gold);
}

/* Welcome screen */

/* V2.3 — Invisible App: less chrome on first-experience screens */
#screen-welcome .brand-search,
#screen-welcome .brand-note,
#screen-about .brand-search,
#screen-about .brand-note,
#screen-story .brand-search,
#screen-story .brand-note,
#screen-prologue .brand-search,
#screen-prologue .brand-note,
#screen-editorial-reading .brand-search,
#screen-editorial-reading .brand-note,
#screen-account .brand-search,
#screen-account .brand-note {
    display: none;
}

#screen-welcome .btn-welcome-secondary[hidden] {
    display: none;
}

.layout-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: none;
    min-height: 0;
    padding-bottom: 88px;
}

.hero {
    width: 100%;
    margin-top: 32px;
    margin-bottom: 80px;
}

.hero-headline {
    font-size: var(--st-size-hero);
    font-weight: 400;
    letter-spacing: var(--st-tracking-display);
    line-height: 1.08;
    color: var(--st-ink);
}

/* Supporting copy */

.copy {
    margin-bottom: 72px;
}

.layout-welcome .copy {
    margin-bottom: 96px;
}

.copy p {
    font-size: var(--st-size-lead);
    line-height: 1.7;
    color: var(--st-text-secondary);
}

.layout-welcome .copy p {
    font-weight: 400;
    line-height: 1.7;
    color: var(--st-text-secondary);
}

.layout-welcome .copy .copy-closing {
    margin-top: 18px;
}

/* About Storyfellow — public informational screen */
#screen-about {
    padding: var(--st-page-pad-y) var(--st-page-pad-x) 0;
    align-items: stretch;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    max-height: none;
    overflow: visible;
    box-sizing: border-box;
}

#screen-about > .brand-bar {
    flex: 0 0 auto;
    width: 100%;
}

#screen-about > .about-layout {
    flex: 1 1 auto;
    min-height: 0;
    overflow: visible;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 56px 0 64px;
    text-align: left;
    animation: st-fade-in var(--st-duration-slow) var(--st-ease) both;
    box-sizing: border-box;
}

.about-header {
    margin: 0 0 40px;
}

.about-title {
    margin: 0;
    font-size: clamp(1.75rem, 4vw, 2.15rem);
    font-weight: 400;
    letter-spacing: -0.035em;
    line-height: 1.15;
    color: var(--st-ink);
}

.about-copy p {
    margin: 0;
    max-width: 32em;
    font-size: var(--st-size-lead, 1.125rem);
    font-weight: 400;
    line-height: 1.7;
    color: var(--st-text-secondary);
}

.about-copy p + p {
    margin-top: 18px;
}

.about-copy-closing {
    margin-top: 18px;
}

.copy p + p {
    margin-top: 6px;
}

.copy-lead {
    font-size: 24px;
    font-weight: 400;
    letter-spacing: -0.2px;
    color: var(--color-question);
    margin-bottom: 28px;
}

.copy-reflection {
    font-size: 18px;
    line-height: 1.6;
    color: var(--color-reflection);
}

.copy-story p {
    font-size: 20px;
    color: #666;
}

.copy-story .copy-lead {
    font-size: 22px;
    letter-spacing: -0.2px;
    margin-bottom: 24px;
}

.story-upload-cta {
    display: inline-block;
    margin-top: 20px;
}

.copy-ready {
    margin-top: 28px;
    color: #999;
    font-style: italic;
}

/* Screen 1 — Let's Begin */

.btn-begin {
    width: fit-content;
    max-width: 100%;
    margin: 8px auto 0;
    font-size: 17px;
    padding: 14px 32px;
}

/* Screen 2 — Voice stage (shared mic anchor) */

:root {
    --voice-mic-size: 180px;
    --voice-meter-gap: 18px;
    /* timer + gap + waveform + gap beneath waveform */
    --voice-meter-band: 101px;
    /* Fixed track that holds meter band + mic button */
    --voice-mic-cluster: calc(var(--voice-meter-band) + var(--voice-mic-size));
    /* btn-mic::after ring extends this far below the button */
    --voice-mic-ring-bleed: 21px;
    /* Clear air between ring edge and status copy */
    --voice-status-gap: 16px;
    /* Status band: ring clearance + gap + ~2 lines (scrolls if longer) */
    --voice-status-band: calc(
        var(--voice-mic-ring-bleed) + var(--voice-status-gap) + 3.25rem
    );
}

/*
 * Microphone-led stage: CSS Grid with a fixed mic-cluster track.
 * Rows: prompt (flex) | mic cluster (fixed) | status (fixed) | type-instead (flex).
 * Prompt track is slightly taller than the composer track so the mic sits
 * below the question with comfortable air, while the composer remains
 * near the bottom (align-self:end in its track). Short/medium prompts
 * center in the upper track without moving the mic; tall prompts scroll
 * inside row 1.
 * Mic button centre within the stage:
 *   promptTrack + meterBand + micSize/2
 */
.voice-stage,
.layout-story.voice-stage,
.app-layout.voice-stage {
    flex: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows:
        minmax(0, 1.35fr)
        var(--voice-mic-cluster)
        var(--voice-status-band)
        minmax(0, 1fr);
    align-items: stretch;
    justify-items: center;
    width: 100%;
    min-height: 0;
    position: relative;
    padding-bottom: 48px;
    box-sizing: border-box;
}

.voice-stage > .copy-story,
.voice-stage > .app-question-area,
.voice-stage > .app-processing,
.voice-stage > .app-question,
.voice-stage > .copy-lead,
.voice-stage > .copy-reflection {
    opacity: 1;
}

/*
 * Row 1 — prompt / processing / resume share the upper track.
 * Content wraps/scrolls here; it never changes the mic track below.
 */
.voice-stage > .copy-story,
.voice-stage > .app-question-area,
.voice-stage > .app-processing,
.voice-stage > .copy-processing,
.voice-stage > .app-resume {
    grid-row: 1;
    grid-column: 1;
    align-self: stretch;
    justify-self: center;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    position: relative;
    z-index: 2;
    width: min(680px, 100%);
    min-height: 0;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    text-align: center;
}

/* Preserve [hidden] — display:flex above would otherwise keep this visible */
.voice-stage > .app-processing[hidden],
.voice-stage > .copy-processing[hidden] {
    display: none;
}

.voice-stage > .copy-story .copy-lead {
    font-size: 22px;
    font-weight: 400;
    letter-spacing: -0.2px;
    margin-bottom: 12px;
    color: var(--color-question);
}

.voice-stage > .copy-story .copy-reflection {
    font-size: 18px;
    font-weight: 400;
    color: var(--color-reflection);
    margin-bottom: 0;
}

.voice-stage > .copy-story .copy-invite {
    font-size: 16px;
    font-weight: 400;
    line-height: 1.6;
    color: var(--color-question);
    margin-top: 14px;
    margin-bottom: 0;
}

.voice-stage > .copy-story .copy-invite:first-of-type {
    margin-top: 36px;
}

.voice-stage > .status-area .msg-status:empty {
    display: none;
}

.voice-stage > .app-processing .copy-lead,
.voice-stage > .copy-processing .copy-lead {
    font-size: 22px;
    letter-spacing: -0.2px;
    margin-bottom: 12px;
    color: var(--color-question);
}

.voice-stage > .app-processing .copy-reflection,
.voice-stage > .copy-processing .copy-reflection {
    font-size: 18px;
    margin-bottom: 0;
}

.voice-stage > .app-question {
    font-size: 24px;
    font-weight: 400;
    letter-spacing: -0.3px;
    line-height: 1.55;
    color: var(--color-question);
}

/* Nested Continue question (inside .app-question-area) — weight only;
 * size/line-height come from the cascade already in use on screen. */
.voice-stage > .app-question-area > .app-question {
    font-weight: 400;
}

/*
 * Row 2 — fixed microphone cluster.
 * Meter/timer/waveform reserve space above the button; the button centre
 * stays at a constant offset within this track across all states.
 */
.voice-recorder-anchor {
    grid-row: 2;
    grid-column: 1;
    position: relative;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-self: center;
    align-self: stretch;
    width: min(300px, calc(100vw - 80px));
    height: var(--voice-mic-cluster);
    min-height: var(--voice-mic-cluster);
    max-height: var(--voice-mic-cluster);
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.voice-recorder-timer {
    order: 1;
    display: block;
    position: relative;
    height: 15px;
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
    color: var(--color-question);
    line-height: 1;
    pointer-events: none;
    opacity: 0;
}

.voice-waveform {
    order: 2;
    display: flex;
    position: relative;
    align-items: flex-end;
    justify-content: center;
    gap: 4px;
    width: 100%;
    height: 56px;
    margin: 0 0 var(--voice-meter-gap);
    pointer-events: none;
    opacity: 0;
}

.voice-stage.is-recording .voice-recorder-timer,
.voice-stage.is-recording .voice-waveform {
    transition: opacity 0.55s ease;
}

.voice-recorder-anchor.is-recording-active .voice-waveform,
.voice-recorder-anchor.is-recording-active .voice-recorder-timer {
    opacity: 1;
}

.voice-waveform-bar {
    display: block;
    width: 3px;
    height: 10px;
    border-radius: 999px;
    background: #888;
    transform-origin: center bottom;
}

.voice-recorder-anchor .btn-mic {
    order: 3;
    position: relative;
    inset: auto;
    width: var(--voice-mic-size);
    height: var(--voice-mic-size);
    flex-shrink: 0;
    transform: none;
}

/*
 * Row 3 — fixed status band below the mic.
 * Status copy changes cannot alter tracks above the button centre.
 * Padding clears the mic ring bleed so text never collides with the ring.
 */
.voice-stage > .status-area,
.voice-stage > .app-status-area {
    grid-row: 3;
    grid-column: 1;
    position: relative;
    z-index: 5;
    justify-self: center;
    align-self: stretch;
    width: min(680px, 100%);
    height: 100%;
    min-height: 0;
    max-height: 100%;
    margin: 0;
    padding: calc(var(--voice-mic-ring-bleed) + var(--voice-status-gap)) 12px 0;
    overflow-x: hidden;
    overflow-y: auto;
    text-align: center;
    box-sizing: border-box;
}

.msg-thankyou,
.voice-status-primary {
    font-size: 16px;
    font-weight: 400;
    color: var(--color-instruction);
    line-height: 1.5;
    margin-bottom: 8px;
}

.msg-status,
.voice-status-secondary,
.app-status {
    font-size: 16px;
    font-weight: 400;
    color: var(--color-secondary);
    line-height: 1.5;
}

.msg-status.is-processing,
.voice-status-secondary.is-processing {
    color: var(--color-instruction);
}

.voice-stage.is-processing .copy-lead,
.voice-stage.is-processing .copy-reflection,
.voice-stage.is-processing .app-processing,
.voice-stage.is-processing .copy-story {
    animation: none;
}

.layout-story {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 0;
}

/* voice-stage grid must win over layout-story's display:flex */
.layout-story.voice-stage {
    display: grid;
}

.btn-mic {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
    border: none;
    border-radius: 50%;
    background: var(--st-ink);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 28px rgba(17, 17, 17, 0.1);
    transition:
        transform var(--st-duration) var(--st-ease),
        box-shadow var(--st-duration) var(--st-ease),
        background-color var(--st-duration) var(--st-ease);
}

.btn-mic:hover:not(:disabled) {
    box-shadow: 0 8px 32px rgba(17, 17, 17, 0.14);
}

.btn-mic::after {
    content: "";
    position: absolute;
    inset: -21px;
    border-radius: 50%;
    background: conic-gradient(
        from 0deg,
        #4a90e2 0deg,
        #5b9fd9 10deg,
        rgba(74, 144, 226, 0.88) 35deg,
        rgba(91, 159, 217, 0.58) 65deg,
        rgba(107, 173, 224, 0.3) 95deg,
        rgba(91, 159, 217, 0.55) 120deg,
        #4a90e2 120deg,
        #4a90e2 360deg
    );
    -webkit-mask: radial-gradient(
        farthest-side,
        transparent calc(100% - 9px),
        #000 calc(100% - 9px)
    );
    mask: radial-gradient(
        farthest-side,
        transparent calc(100% - 9px),
        #000 calc(100% - 9px)
    );
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.voice-stage.is-processing .btn-mic::after,
.voice-stage:has(.msg-status.is-processing) .btn-mic::after {
    opacity: 1;
    animation: mic-ring-sweep 2.75s linear infinite;
}

.voice-stage.is-recording .btn-mic::after {
    opacity: 0;
    animation: none;
}

.voice-stage.is-processing .btn-mic:disabled,
.voice-stage:has(.msg-status.is-processing) .btn-mic:disabled {
    opacity: 1;
    cursor: default;
}

.voice-stage:not(.is-processing) .btn-mic:disabled {
    opacity: 1;
    cursor: default;
}

.voice-recorder-anchor:hover .btn-mic:not(:disabled) {
    transform: scale(1.04);
}

.voice-recorder-anchor:active .btn-mic:not(:disabled) {
    transform: scale(0.96);
}

.voice-stage.is-processing .voice-recorder-anchor:hover .btn-mic:not(:disabled),
.voice-stage.is-processing .voice-recorder-anchor:active .btn-mic:not(:disabled),
.voice-stage:has(.msg-status.is-processing) .voice-recorder-anchor:hover .btn-mic:not(:disabled),
.voice-stage:has(.msg-status.is-processing) .voice-recorder-anchor:active .btn-mic:not(:disabled) {
    transform: none;
}

.btn-mic:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-mic.is-listening {
    background: var(--color-record);
    animation: record-button-glow 2.4s ease-in-out infinite;
    box-shadow: 0 8px 28px rgba(229, 57, 53, 0.22);
}

.btn-mic.is-listening .icon-mic {
    display: none;
}

.btn-mic.is-listening::before {
    content: "";
    display: block;
    width: 40px;
    height: 40px;
    background: #fff;
    border-radius: 8px;
}

.icon-mic {
    width: 68px;
    height: 68px;
}

/* Animations */

@keyframes mic-pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(17, 17, 17, 0.22);
    }
    70% {
        transform: scale(1.06);
        box-shadow: 0 0 0 28px rgba(17, 17, 17, 0);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(17, 17, 17, 0);
    }
}

@keyframes mic-pulse-fixed {
    0% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 0 0 rgba(17, 17, 17, 0.22);
    }
    70% {
        transform: translate(-50%, -50%) scale(1.06);
        box-shadow: 0 0 0 28px rgba(17, 17, 17, 0);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 0 0 rgba(17, 17, 17, 0);
    }
}

@keyframes record-button-glow {
    0%,
    100% {
        box-shadow: 0 8px 28px rgba(229, 57, 53, 0.2);
    }
    50% {
        box-shadow: 0 10px 34px rgba(229, 57, 53, 0.28);
    }
}

@keyframes mic-ring-sweep {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes fade-up {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */

@media (max-width: 1024px) {
    :root {
        --st-size-hero: 44px;
    }
}

@media (max-width: 768px) {
    .title:not(.brand-wordmark) {
        font-size: 22px;
    }

    .title.brand-wordmark,
    .brand-wordmark.title {
        font-size: clamp(26px, 7vw, 30px);
    }

    .layout-welcome {
        padding-bottom: 72px;
    }

    .hero {
        margin-top: 24px;
        margin-bottom: 64px;
    }

    .hero-headline {
        letter-spacing: -0.025em;
    }

    .copy p {
        font-size: 18px;
    }

    .layout-welcome .copy {
        margin-bottom: 72px;
    }

    .copy-lead {
        font-size: 20px;
    }

    :root {
        --voice-mic-size: 150px;
    }

    .voice-stage {
        padding-bottom: 36px;
    }

    .voice-stage > .copy-story .copy-lead,
    .voice-stage > .app-question {
        font-size: 20px;
    }

    .voice-stage > .copy-story .copy-reflection,
    .voice-stage > .app-processing .copy-reflection,
    .voice-stage > .copy-processing .copy-reflection {
        font-size: 17px;
    }

    .voice-stage > .copy-story .copy-invite {
        font-size: 15px;
        margin-top: 12px;
    }

    .voice-stage > .copy-story .copy-invite:first-of-type {
        margin-top: 32px;
    }

    .btn-begin {
        font-size: 16px;
        padding: 14px 28px;
        min-height: var(--st-touch);
    }

    .icon-mic {
        width: 58px;
        height: 58px;
    }

    .msg-thankyou,
    .msg-status,
    .app-status {
        font-size: 15px;
    }
}

/* Private access gate — no manuscript data on this screen */

.layout-access {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: var(--st-measure-narrow);
    margin: 0 auto;
    text-align: center;
}

.access-title {
    font-family: var(--st-font-serif);
    font-size: var(--st-size-title);
    font-weight: 400;
    letter-spacing: var(--st-tracking-tight);
    color: var(--st-ink);
    margin-bottom: var(--st-space-2);
}

.access-copy {
    color: var(--st-text-secondary);
    font-size: var(--st-size-body);
    line-height: var(--st-line-body);
    margin-bottom: var(--st-space-4);
}

.access-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    max-width: 360px;
    gap: var(--st-space-3);
}

.access-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
    /* Never intercept taps meant for the adjacent inputs (Safari/iOS). */
    pointer-events: none;
}

.access-input {
    width: 100%;
    min-height: var(--st-touch);
    padding: 12px 16px;
    border: 1px solid var(--st-border-strong);
    border-radius: var(--st-radius-sm);
    font-family: inherit;
    font-size: var(--st-size-body);
    /* Explicit left align — inherited text-align:center breaks Safari password caret/autofill. */
    text-align: left;
    color: var(--st-ink);
    background: var(--st-bg);
    -webkit-user-select: text;
    user-select: text;
    pointer-events: auto;
}

.access-input:focus,
.access-input:focus-visible {
    outline: none;
    box-shadow: 0 0 0 1px var(--st-focus-ring, rgba(17, 17, 17, 0.28));
}

.access-input::placeholder {
    color: var(--st-text-secondary);
    opacity: 1;
}

.access-form .btn-begin {
    width: 100%;
    margin: 0;
}

.access-error {
    color: var(--st-text);
    font-size: var(--st-size-caption);
    min-height: 1.2em;
}

.account-switch {
    margin-top: var(--st-space-3);
    border: 0;
    background: transparent;
    color: var(--st-text-secondary);
    font-family: inherit;
    font-size: var(--st-size-caption);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.account-switch:focus,
.account-switch:focus-visible {
    outline: 1px solid var(--st-focus-ring, rgba(17, 17, 17, 0.28));
    outline-offset: 2px;
}
