/*
 * Hosted story page (templates/users/story.html, koncept 8.4). Decoration only: the
 * layouts and step states are the library's (storymap/storymap-v1.css), shared with
 * customers' own pages.
 *
 * Every colour goes through a --story-* variable that falls back on the instance theme
 * (--smartforms-* from custom-styles.css), so a story takes the municipality's colours
 * with nothing set for it. One story is restyled through its body class sm-story-<slug>
 * in the same custom-styles.css.
 */

:root {
    --story-paper: var(--smartforms-background-color, #f5f5f2);
    --story-ink: var(--smartforms-text-color, #1f2933);
    --story-header-bg: var(--smartforms-h1-background-color, #24402f);
    --story-header-text: var(--smartforms-h1-color, #fff);
    --story-accent: var(--smartforms-button-background-color, var(--story-header-bg));
    --story-accent-text: var(--smartforms-button-text-color, #fff);
    --story-card: #fff;
    --story-line: rgba(0, 0, 0, 0.12);
    --story-radius: var(--smartforms-radius, 12px);
    --story-shadow: var(--smartforms-card-shadow, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
    --story-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
    --story-max-width: 1400px;
}

/* styles.css pads the body for the form pages; a story runs edge to edge. */
.story-page {
    margin: 0;
    padding: 0;
    background: var(--story-paper);
    color: var(--story-ink);
    line-height: 1.6;
    overflow-x: hidden;
}

.story-draft {
    margin: 0;
    padding: 10px 20px;
    background: #fff3cd;
    border-bottom: 1px solid #e6a817;
    color: #6b4a00;
    font-weight: 600;
    text-align: center;
}

/* ---------- hero ---------- */

.story-hero {
    display: grid;
    place-items: center;
    min-height: 70vh;
    min-height: 70svh;
    padding: 64px 24px;
    background: var(--story-header-bg);
    color: var(--story-header-text);
    text-align: center;
}

.story-hero-content {
    max-width: 760px;
}

.story-hero-title {
    margin: 0 0 18px;
    font-size: clamp(2.2rem, 7vw, 4.5rem);
    line-height: 1.1;
}

.story-hero-subtitle {
    margin: 0 0 18px;
    font-size: clamp(1.1rem, 2.4vw, 1.4rem);
    font-weight: 600;
}

.story-hero-intro {
    margin: 0 auto 14px;
    max-width: 620px;
    font-size: 1.05rem;
    opacity: 0.9;
}

.story-hero-start {
    display: inline-block;
    margin-top: 18px;
    padding: 12px 26px;
    border: 2px solid currentColor;
    border-radius: 100px;
    color: inherit;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.2s var(--story-ease), color 0.2s var(--story-ease);
}

.story-hero-start:hover,
.story-hero-start:focus-visible {
    background: var(--story-header-text);
    color: var(--story-header-bg);
}

/* ---------- the story ---------- */

.story-map {
    background: var(--story-line);
}

.sm-scrolly.story-main {
    max-width: var(--story-max-width);
    margin: 0 auto;
    padding: clamp(32px, 7vh, 80px) clamp(16px, 4vw, 40px);
}

.sm-scrolly .story-map {
    border-radius: var(--story-radius);
    box-shadow: var(--story-shadow);
}

.sm-map-status {
    color: var(--story-ink);
}

.sm-map-status .ld-ring {
    color: var(--story-accent);
}

.sm-scrolly .sm-step {
    margin: 0 0 4rem;
}

/* The library dims an inactive step to 0.55, which leaves body text below the 4.5:1
   contrast WCAG AA asks for. Still a hint, but one that keeps the text readable. */
.sm-scrolly .sm-step:not(.is-active) {
    opacity: 0.8;
}

/* In sidecar the step content is a card floating over the map. It fades in with its
   step, never the section itself: the library measures the section's box. The step is a
   flex box (storymap-v1.css), so without a width the card would be as wide as its text. */
.sm-sidecar .story-step {
    width: 100%;
    max-width: 440px;
    padding: clamp(20px, 3vw, 32px);
    background: var(--story-card);
    border: 1px solid var(--story-line);
    border-radius: var(--story-radius);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s var(--story-ease), transform 0.6s var(--story-ease);
}

.sm-sidecar .sm-step.is-active .story-step {
    opacity: 1;
    transform: none;
}

.story-step-kicker {
    margin: 0 0 10px;
    color: var(--story-header-bg);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.story-step-title {
    margin: 0 0 14px;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    line-height: 1.2;
}

.sm-sidecar .story-step-title {
    font-size: clamp(1.3rem, 2.4vw, 1.8rem);
}

.story-step-text {
    max-width: 60ch;
}

.story-step-text img {
    max-width: 100%;
    height: auto;
    border-radius: calc(var(--story-radius) - 4px);
}

/* styles.css drops the underline on every link; a link in the step text needs it back. */
.story-step-text a {
    color: var(--story-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.story-step-text a:hover,
.story-step-text a:focus-visible {
    text-decoration-thickness: 2px;
}

.story-step-features {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 16px 0 0;
    padding: 0;
    list-style: none;
}

.story-step-feature {
    padding: 6px 14px;
    border: 1px solid var(--story-line);
    border-radius: 100px;
    background: var(--story-card);
    color: inherit;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.story-step-feature:hover,
.story-step-feature:focus-visible {
    border-color: var(--story-accent);
}

/* The photo or video is optional: a step without one starts at the kicker. */
.story-step-figure {
    margin: 0 0 16px;
}

.sm-scrolly .story-step-figure {
    max-width: 60ch;
}

.story-step-media {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border-radius: calc(var(--story-radius) - 4px);
    background: var(--story-line);
}

/* A video or a player is 16:9, a picture 16:10 and cropped to it. */
video.story-step-media,
.story-step-embed {
    aspect-ratio: 16 / 9;
}

/* Beside the map a picture is a strip, but a video or a player keeps its 16:9 whole. */
.sm-sidecar .story-step-media {
    aspect-ratio: auto;
    height: clamp(120px, 22vh, 190px);
}

.sm-sidecar video.story-step-media,
.sm-sidecar .story-step-embed {
    aspect-ratio: 16 / 9;
    height: auto;
}

/* The author or source, small, right under the photo or video. */
.story-step-credit {
    margin: 6px 0 0;
    font-size: 0.78rem;
    opacity: 0.75;
}

/* A video is shown whole, not cropped. */
video.story-step-media {
    object-fit: contain;
    background: #000;
}

/* A hosted player: a plain box with a play button until the click, then the player fills it. */
.story-step-embed {
    position: relative;
    background: #1d1d1b;
}

.story-step-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

.story-step-embed-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    border: 0;
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: 1rem;
    cursor: pointer;
}

.story-step-embed-play::before {
    content: '';
    border-style: solid;
    border-width: 11px 0 11px 18px;
    border-color: transparent transparent transparent currentColor;
}

.story-step-embed.is-started .story-step-embed-play {
    display: none;
}

.story-step-embed-play:focus-visible {
    outline: 3px solid var(--story-accent);
    outline-offset: -3px;
}

.story-step-more {
    display: inline-block;
    margin-top: 16px;
    padding: 8px 18px;
    border: 1px solid var(--story-line);
    border-radius: 100px;
    background: var(--story-card);
    color: inherit;
    font-size: 0.9rem;
    text-decoration: none;
}

.story-step-more:hover,
.story-step-more:focus-visible {
    border-color: var(--story-accent);
}

.story-step-caption {
    margin: 14px 0 0;
    font-size: 0.85rem;
    opacity: 0.75;
}

/* ---------- reading progress (ADR-127) ---------- */

/* Over the sticky map too, so it stays in sight on a phone. Colours from the instance,
   a per-story look overrides the two variables in the instance styles.css. */
.story-progress {
    --story-progress-start: var(--story-header-bg);
    --story-progress-end: var(--story-accent);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 10;
    pointer-events: none;
}

.story-progress span {
    display: block;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, var(--story-progress-start), var(--story-progress-end));
    transition: width 0.1s linear;
}

/* ---------- scroll hint (ADR-116) ---------- */

/* Clicks pass through, so the hint never stands between the reader and the map. Centred
   by margins: with left: 50% it would only get half the screen and wrap on a phone. */
.story-scroll-hint {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 24px;
    width: max-content;
    margin: 0 auto;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    border-radius: 100px;
    background: var(--story-accent);
    color: var(--story-accent-text);
    box-shadow: var(--story-shadow);
    font-size: 0.95rem;
    font-weight: 600;
    pointer-events: none;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.4s var(--story-ease), transform 0.4s var(--story-ease);
}

.story-scroll-hint.is-visible {
    opacity: 1;
    transform: none;
}

.story-scroll-hint-arrows {
    flex: none;
    width: 12px;
}

.story-scroll-hint-arrows span {
    display: block;
    width: 9px;
    height: 9px;
    margin: -2px auto 0;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    animation: story-scroll-hint-arrow 1.8s ease-in-out infinite;
}

.story-scroll-hint-arrows span:nth-child(2) {
    animation-delay: 0.2s;
}

.story-scroll-hint-arrows span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes story-scroll-hint-arrow {
    0% {
        opacity: 0;
        transform: translateY(-4px) rotate(45deg);
    }
    40% {
        opacity: 1;
    }
    80%,
    100% {
        opacity: 0;
        transform: translateY(6px) rotate(45deg);
    }
}

@media (max-width: 768px) {
    .story-hero {
        min-height: 60vh;
        min-height: 60svh;
    }

    .sm-scrolly .sm-step {
        margin: 2rem 0;
    }

    /* Cards scroll below the map on a narrow screen, so every one stays readable; the
       active one is outlined, the others only dimmed (0.8 keeps WCAG AA contrast). */
    .sm-sidecar .story-step {
        max-width: none;
        opacity: 0.8;
        transform: none;
        border-color: transparent;
        box-shadow: var(--story-shadow), 0 0 0 2px transparent;
        transition: opacity 0.3s var(--story-ease), box-shadow 0.3s var(--story-ease);
    }

    .sm-sidecar .sm-step.is-active .story-step {
        opacity: 1;
        box-shadow: var(--story-shadow), 0 0 0 2px var(--story-accent);
    }
}

@media (prefers-reduced-motion: reduce) {
    .story-hero-start,
    .sm-sidecar .story-step,
    .story-scroll-hint,
    .story-progress span {
        transition: none;
    }

    .story-scroll-hint-arrows span {
        animation: none;
        opacity: 1;
    }

    .sm-sidecar .story-step {
        opacity: 1;
        transform: none;
    }
}
