/*
    The story page (/how-it-works). Linked after site.css, which holds the tokens, the font, the
    header, the footer and the buttons. Used by the story page only.

    Sizes, from the UXD's layout table:
    - desktop (900px and wider): three columns, Hani and her bubble in the right column; the stage
      is the window height minus 240px, at most 634px;
    - tablet portrait and phone (under 900px): one column, Hani in a strip under the stage; the
      stage is the window height minus 460px, never under 280px;
    - phone held sideways (500px tall or less, landscape): stage left; heading, Hani and the rest
      right.
    story.js sets the stage's width per scene and scales the frame; the rules here are what holds
    without it.
*/

.story-main {
    width: min(1240px, 100% - 40px);
    margin: 0 auto;
    padding: 20px 0 40px;
}

/* "hidden" must win over every display rule below: the controls, progress bar, toggle, note and
   end panel are rendered hidden and only story.js shows them. */
.story-main [hidden] {
    display: none !important;
}

.story-layout {
    display: grid;
    grid-template-columns: minmax(240px, 280px) minmax(0, 1fr) 220px;
    gap: 24px;
    align-items: start;
}

.story-side h1 {
    margin: 0 0 10px;
    font-size: 38px;
    line-height: 1.1;
    letter-spacing: -.01em;
    color: var(--ink);
    text-wrap: balance;
}

.story-intro {
    margin: 0 0 18px;
    font-size: 18px;
    color: var(--muted);
    text-wrap: pretty;
}

.story-rm-note {
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 12px;
    background: #E8F0FF;
    color: var(--ink);
    font-size: 16px;
    font-weight: 700;
}

.story-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* The stage: the story frame, scaled and cropped to the scene by story.js. */
.story-stage {
    position: relative;
    margin: 0 auto;
    width: 100%;
    height: min(634px, calc(100vh - 240px));
    min-height: 280px;
    overflow: hidden;
    border: 4px solid var(--ink);
    border-radius: 18px;
    background: #0A0A0A;
    transition: width .6s ease-in-out;
}

.story-stage iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    transform-origin: 0 0;
    pointer-events: none;
    background: #0A0A0A;
    transition: transform .6s ease-in-out;
}

.story-stage:focus-visible {
    outline-offset: 4px;
}

/* Progress through the story. */
.story-meter {
    height: 8px;
    margin: 8px 0 0;
    border-radius: 4px;
    background: #E3E6EF;
    overflow: hidden;
}

.story-meter i {
    display: block;
    width: 0;
    height: 100%;
    background: var(--gold);
}

/* Controls: visible text labels, 44px targets. */
.story-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 14px 0 6px;
}

.story-ctl {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 16px;
    border: 2px solid var(--ink);
    border-radius: 12px;
    background: #FFFFFF;
    color: var(--ink);
    font: 700 16px/1 'Montserrat', system-ui, sans-serif;
    cursor: pointer;
}

.story-ctl--main {
    background: var(--ink);
    color: #FFFFFF;
}

.story-ctl[disabled] {
    cursor: default;
    border-color: #B8BECB;
    background: #F3F4F7;
    color: #6B7280;
}

.story-ctl svg {
    flex: none;
    width: 16px;
    height: 16px;
}

.story-counter {
    margin-left: 4px;
    white-space: nowrap;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
}

/* Hani: her picture and her bubble, beside the stage or in the strip under it. */
.story-bubble {
    position: relative;
    margin: 0;
    padding: 22px 16px 14px;
    border: 3px solid var(--ink);
    background: #FFF6DC;
    box-shadow: 5px 5px 0 var(--gold);
    font-size: 20px;
    font-weight: 800;
    line-height: 1.3;
    color: var(--ink);
}

.story-bubble b {
    position: absolute;
    top: -14px;
    left: 10px;
    padding: 2px 8px;
    background: var(--ink);
    color: var(--gold);
    font-size: 14px;
}

.story-hani-side {
    padding-top: 8px;
}

.story-hani-side img {
    display: block;
    width: 170px;
    height: auto;
    margin: 0 auto 6px;
}

.story-hani-strip {
    display: none;
}

/* The end of the story. */
.story-end {
    margin: 22px 0 0;
    padding: 18px;
    border-radius: 16px;
    background: var(--navy);
    color: #FFFFFF;
}

.story-end p {
    margin: 0 0 14px;
    font-size: 20px;
    font-weight: 800;
}

.story-end-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
}

.story-textlink {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: #FFFFFF;
    font-weight: 700;
    text-underline-offset: 4px;
}

/* "The story, in words". */
/* The toggle is a quiet text link, not a button: small, underlined, no box, centred under the
   controls. It keeps a 44px tap target and the shared focus outline. */
.story-text-toggle {
    display: flex;
    align-items: center;
    min-height: 44px;
    margin: 6px auto 0;
    padding: 0 6px;
    border: 0;
    background: none;
    color: var(--muted);
    font: 600 15px/1.2 'Montserrat', system-ui, sans-serif;
    text-decoration: underline;
    text-underline-offset: 4px;
    cursor: pointer;
}

.story-text-toggle:hover {
    color: var(--navy);
}

.story-text {
    margin-top: 12px;
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #FFFFFF;
}

.story-text h2 {
    margin: 0 0 10px;
    font-size: 20px;
    color: var(--ink);
}

.story-text ol {
    margin: 0;
    padding-left: 22px;
}

.story-text li {
    margin: 0 0 8px;
    font-size: 16px;
    text-wrap: pretty;
}

.story-text q {
    font-weight: 700;
    color: var(--ink);
}

@media (max-width: 1199px) {
    .story-layout {
        grid-template-columns: minmax(200px, 230px) minmax(0, 1fr) 200px;
        gap: 20px;
    }

    .story-hani-side img {
        width: 150px;
    }

    .story-hani-side .story-bubble {
        font-size: 18px;
    }
}

/* Tablet portrait and phone: one column, the stage straight after the heading and intro. */
@media (max-width: 899px) {
    .story-layout {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .story-side {
        display: contents;
    }

    .story-side h1 {
        order: 1;
        margin-bottom: 4px;
        font-size: 28px;
    }

    .story-intro {
        order: 2;
        margin-bottom: 10px;
        font-size: 16px;
    }

    .story-rm-note {
        order: 3;
    }

    .story-player {
        order: 4;
    }

    .story-end {
        order: 5;
    }

    .story-text-toggle {
        order: 6;
    }

    .story-text {
        order: 7;
    }

    .story-stage {
        height: max(280px, calc(100svh - 460px));
    }

    .story-hani-side {
        display: none;
    }

    .story-hani-strip {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: 96px;
        margin: 10px 0 0;
    }

    .story-hani-strip img {
        flex: none;
        width: 64px;
        height: 64px;
        object-fit: contain;
    }

    .story-hani-strip .story-bubble {
        flex: 1;
        margin: 6px 0 0;
        padding: 14px 12px 10px;
        box-shadow: 4px 4px 0 var(--gold);
        font-size: 16px;
        font-weight: 700;
    }

    .story-hani-strip .story-bubble b {
        top: -12px;
        left: 8px;
        padding: 1px 7px;
        font-size: 13px;
    }
}

@media (max-width: 600px) {
    .story-main {
        padding-top: 12px;
    }

    .story-controls {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        margin-top: 10px;
    }

    .story-controls .story-ctl {
        justify-content: center;
        gap: 6px;
        padding: 0 10px;
        font-size: 15px;
    }

    .story-controls .story-counter {
        grid-column: 2 / span 2;
        justify-self: end;
        align-self: center;
        margin: 0;
        font-size: 15px;
    }
}

/* Phone held sideways: the stage left; heading, Hani and the rest right, so nothing scrolls. */
@media (max-height: 500px) and (orientation: landscape) {
    .story-main {
        padding-top: 10px;
    }

    .story-layout {
        grid-template-columns: minmax(0, 1fr) 260px;
        gap: 18px;
    }

    .story-side {
        display: contents;
    }

    .story-player {
        grid-column: 1;
        grid-row: 1 / span 8;
        order: 0;
    }

    .story-side > *,
    .story-hani-side {
        grid-column: 2;
        grid-row: auto;
    }

    .story-side h1 {
        order: 1;
        margin: 0 0 6px;
        font-size: 22px;
    }

    .story-hani-side {
        display: flex;
        order: 2;
        align-items: center;
        gap: 8px;
        padding: 0 0 10px;
    }

    .story-hani-side img {
        flex: none;
        width: 56px;
        margin: 0;
    }

    .story-hani-side .story-bubble {
        flex: 1;
        padding: 14px 10px 8px;
        font-size: 15px;
    }

    .story-hani-side .story-bubble b {
        top: -11px;
        font-size: 13px;
    }

    .story-hani-strip {
        display: none;
    }

    .story-intro {
        order: 3;
        font-size: 15px;
    }

    .story-rm-note {
        order: 4;
    }

    .story-end {
        order: 5;
    }

    .story-text-toggle {
        order: 6;
    }

    .story-text {
        order: 7;
    }

    .story-stage {
        height: calc(100svh - 180px);
        min-height: 0;
    }

    .story-controls {
        gap: 6px;
        margin-top: 8px;
    }

    .story-ctl {
        padding: 0 10px;
    }
}

/* Above 760px the header's logo hangs about 58px below the header bar (site.css), on the story
   page as on the homepage. The heading and everything under it start below it: on desktop only
   the left column moves, so the stage keeps its height; on a tablet held upright the whole page
   moves. Phones, including a phone held sideways (500px tall or less), keep the logo inside the
   bar and get neither rule. Kept after the tablet and phone rules above, so it wins over them. */
@media (min-width: 761px) and (min-height: 501px) {
    .story-side {
        padding-top: 56px;
    }
}

@media (min-width: 761px) and (max-width: 899px) and (min-height: 501px) {
    .story-side {
        padding-top: 0;
    }

    .story-main {
        padding-top: 76px;
    }

    /* The stage gives back the 56px the page moved down, so the controls stay on the first screen. */
    .story-stage {
        height: max(280px, calc(100svh - 516px));
    }
}

/* Reduced motion: no width or zoom transitions. */
@media (prefers-reduced-motion: reduce) {
    .story-stage,
    .story-stage iframe,
    .story-meter i {
        transition: none;
    }
}
