/*
 * v4-story.css — "how I build things": chapters along a spine, each with a
 * live app window floating on a painted panel.
 */

.v4-story { position: relative; max-width: 1240px; margin: 0 auto; padding: 60px 24px 40px; }

.v4-story-intro { max-width: 760px; margin: 0 auto 70px; text-align: center; }
.v4-story-intro h2 { margin: 18px 0 14px; font-size: clamp(2.2rem, 5.4vw, 4.2rem); font-weight: 600; line-height: 1.05; letter-spacing: -.02em; }
.v4-story-intro h2,
.v4-story-intro p { text-wrap: balance; }
.v4-story-intro p { margin: 0; color: var(--v4-muted); font-size: 1.2rem; }
.v4-story .v4-mark { box-shadow: 0 .1em .3em rgba(240, 165, 22, .35); }

/* the spine runs down the middle; its fill follows your scroll */
.v4-spine {
    position: absolute;
    top: 330px;
    bottom: 80px;
    left: 50%;
    width: 4px;
    margin-left: -2px;
    border-radius: 4px;
    background: rgba(24, 38, 43, .1);
}

.v4-spine-fill {
    display: block;
    width: 100%;
    height: var(--fill, 0%);
    border-radius: 4px;
    background: linear-gradient(180deg, var(--v4-yellow-hi), var(--v4-yellow) 60%, var(--v4-yellow-lo));
    box-shadow: 0 0 14px rgba(255, 194, 71, .8);
}

.v4-chapters { position: relative; margin: 0; padding: 0; list-style: none; display: grid; gap: 150px; }

.v4-chapter {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px minmax(0, 1.25fr);
    align-items: center;
    gap: 0 34px;
}

.v4-chapter:nth-child(even) { grid-template-columns: minmax(0, 1.25fr) 76px minmax(0, 1fr); }
.v4-chapter:nth-child(even) .v4-chapter-text { order: 3; }
.v4-chapter:nth-child(even) .v4-node { order: 2; }
.v4-chapter:nth-child(even) .v4-stage { order: 1; }

.v4-chapter-text h3 { margin: 10px 0 14px; font-size: clamp(2rem, 3.6vw, 2.9rem); font-weight: 600; line-height: 1.05; letter-spacing: -.015em; }
.v4-chapter-text p { margin: 0; color: var(--v4-muted); font-size: 1.15rem; line-height: 1.65; }
.v4-chapter-text strong { color: var(--v4-ink); font-weight: 600; }

.v4-file { display: inline-flex; align-items: center; gap: 7px; color: var(--v4-ink-2); font: 500 .86rem var(--v4-mono); }
.v4-file svg { width: 22px; height: 22px; fill: #fff; stroke: var(--v4-ink-2); stroke-width: 1.5; stroke-linejoin: round; }

.v4-node {
    position: relative;
    z-index: 2;
    justify-self: center;
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--v4-shadow-card);
    transition: transform .4s var(--v4-ease), background .3s ease;
}

.v4-node svg { width: 26px; height: 26px; fill: none; stroke: var(--v4-ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.v4-chapter.is-active .v4-node {
    background: linear-gradient(180deg, #ffe39b, var(--v4-yellow) 55%, var(--v4-yellow-lo));
    box-shadow: 0 2px 0 rgba(255, 255, 255, .8) inset, 0 0 0 1.5px rgba(150, 85, 0, .4), 0 0 0 8px rgba(255, 194, 71, .22), 0 12px 26px -10px rgba(220, 140, 0, .7);
    transform: scale(1.08);
}

/* ---------- stage: a painted panel the window floats on ---------- */

.v4-stage { position: relative; margin: 0; }

.v4-art {
    display: grid;
    place-items: center;
    min-height: 360px;
    padding: 44px 34px;
    border-radius: 26px;
    background-size: cover;
    background-position: center;
    box-shadow: 0 0 0 1px rgba(24, 38, 43, .08), 0 24px 48px -26px rgba(24, 38, 43, .45);
}

/*
 * Art slots. Painted backgrounds live in /assets/v4/art/<slot>.webp; until a
 * slot has its painting, it shows a soft gradient in the same light. The
 * gradient stays underneath the painting while it loads.
 */
.v4-art { --art-fallback: linear-gradient(180deg, #8cc8f0, #6aae50); background-image: var(--art, none), var(--art-fallback); }

.v4-art--meadow { --art: url('/assets/v4/art/meadow-1200.webp'); --art-fallback: linear-gradient(180deg, #8cc8f0 0%, #cfe8f2 45%, #a6d27f 46%, #6aae50 100%); }
.v4-art--hills { --art: url('/assets/v4/art/hills-1200.webp'); --art-fallback: linear-gradient(180deg, #f6c58f 0%, #f3dcb7 40%, #a9cf86 41%, #78b25d 100%); }
.v4-art--night { --art: url('/assets/v4/art/night-1200.webp'); --art-fallback: linear-gradient(180deg, #121a3a 0%, #23305e 55%, #2e4a4a 56%, #1d3330 100%); }
.v4-art--forest { --art: url('/assets/v4/art/forest-1200.webp'); --art-fallback: linear-gradient(180deg, #6fae7d 0%, #3f7f55 50%, #2f6646 100%); }
.v4-art--town { --art: url('/assets/v4/art/town-1200.webp'); --art-fallback: linear-gradient(180deg, #f2a96b 0%, #f7d3a0 45%, #9bbf8a 46%, #5d8f59 100%); }

.js .v4-art:not(.is-near) { background-image: var(--art-fallback); }

/* phones get the lighter cut of each painting */
@media (max-width: 700px) {
    .v4-art--meadow { --art: url('/assets/v4/art/meadow-720.webp'); }
    .v4-art--hills { --art: url('/assets/v4/art/hills-720.webp'); }
    .v4-art--night { --art: url('/assets/v4/art/night-720.webp'); }
    .v4-art--forest { --art: url('/assets/v4/art/forest-720.webp'); }
    .v4-art--town { --art: url('/assets/v4/art/town-720.webp'); }
}

.v4-stage-meta { position: absolute; left: 14px; right: 14px; bottom: -20px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }

.v4-meta-chip,
.v4-replay {
    padding: 6px 12px;
    border-radius: 999px;
    background: #fff;
    box-shadow: var(--v4-shadow-card);
    color: var(--v4-ink-2);
    font: 500 .8rem var(--v4-mono);
    white-space: nowrap;
}

.v4-replay { border: 0; cursor: pointer; color: var(--v4-ink); font: 600 .9rem var(--v4-font); }
.v4-replay:hover { background: var(--v4-yellow-hi); }

/* ---------- the app window ---------- */

.v4-window {
    position: relative;
    width: min(100%, 470px);
    border-radius: 14px;
    background: #fbfaf7;
    box-shadow: 0 1px 0 #fff inset, 0 0 0 1px rgba(24, 38, 43, .14), 0 30px 60px -24px rgba(10, 30, 40, .55);
    overflow: hidden;
    text-align: left;
}

.v4-window-bar {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 12px;
    background: linear-gradient(180deg, #f4f2ec, #ebe7de);
    border-bottom: 1px solid rgba(24, 38, 43, .1);
    color: var(--v4-ink-2);
    font: 500 .8rem var(--v4-mono);
}

.v4-window-bar i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.v4-window-bar i:nth-child(2) { background: #febc2e; }
.v4-window-bar i:nth-child(3) { background: #28c840; }
.v4-window-bar span { flex: 1; margin-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v4-window-bar em { padding: 1px 8px; border-radius: 999px; background: rgba(24, 38, 43, .07); font-style: normal; font-size: .72rem; }

.v4-window-body { min-height: 200px; padding: 18px 20px 20px; }

.v4-window--dark { background: #15181d; color: #e8ebef; }
.v4-window--dark .v4-window-bar { background: linear-gradient(180deg, #24282f, #1c2026); color: #aab2bd; border-bottom-color: rgba(255, 255, 255, .06); }
.v4-window--dark .v4-window-bar em { background: rgba(255, 255, 255, .08); }

.v4-window--term { background: #0f1216; color: #e9ece8; }
.v4-window--term .v4-window-bar { background: linear-gradient(180deg, #2a2d33, #222429); color: #b8bcc4; border-bottom-color: rgba(255, 255, 255, .06); }
.v4-window--term .v4-window-bar em { background: rgba(61, 190, 122, .2); color: #7fe2a8; }

/* 01 · notes */
.v4-notes p { min-height: 1.5em; margin: 0 0 10px; color: var(--v4-ink); font-size: 1.05rem; line-height: 1.5; }
.v4-notes p:first-child { font-size: 1.15rem; font-weight: 600; }
.v4-notes p.is-typing::after { content: ''; display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--v4-ink); animation: v4-blink .8s steps(1) infinite; }

/* 02 · plan */
.v4-plan ul { display: grid; gap: 9px; margin: 0 0 16px; padding: 0; list-style: none; }
.v4-plan li { position: relative; padding-left: 30px; color: var(--v4-ink-2); font-size: 1rem; transition: color .3s ease; }
.v4-plan li::before { content: ''; position: absolute; left: 0; top: 1px; width: 18px; height: 18px; border-radius: 6px; box-shadow: 0 0 0 1.5px rgba(24, 38, 43, .3) inset; transition: background .25s ease, box-shadow .25s ease; }
.v4-plan li.is-done { color: var(--v4-ink); }
.v4-plan li.is-done::before { background: var(--v4-leaf) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12 4 4 8-8'/%3E%3C/svg%3E") center / 14px no-repeat; box-shadow: none; }
.v4-plan-bar { height: 8px; border-radius: 99px; background: rgba(24, 38, 43, .08); overflow: hidden; }
.v4-plan-bar span { display: block; width: var(--plan, 0%); height: 100%; background: linear-gradient(90deg, var(--v4-leaf), #7fe2a8); transition: width .4s ease; }

/* 03 · RomkaSLM */
.v4-slm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: .95rem; }
.v4-slm-head small { color: #8b94a0; font-family: var(--v4-mono); }
.v4-slm-live { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: rgba(111, 183, 255, .15); color: #8cc4ff; font-size: .8rem; }
.v4-slm-live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #6fb7ff; animation: v4-pulse 1.4s ease-in-out infinite; }
.v4-slm-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0 12px; }
.v4-slm-stats div { padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .04); box-shadow: 0 0 0 1px rgba(255, 255, 255, .06) inset; }
.v4-slm-stats dt { color: #8b94a0; font: 500 .7rem var(--v4-mono); letter-spacing: .04em; text-transform: uppercase; }
.v4-slm-stats dd { margin: 2px 0 0; font: 600 1.2rem var(--v4-mono); }
.v4-slm-chart { display: block; width: 100%; height: auto; }
.v4-slm-grid { fill: none; stroke: rgba(255, 255, 255, .07); stroke-width: 1; }
.v4-slm-curve { fill: none; stroke: #6fb7ff; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: var(--curve, 0); filter: drop-shadow(0 0 6px rgba(111, 183, 255, .6)); }

/* 04 · RomkaVoice */
.v4-voice-text { min-height: 3.2em; margin: 0 0 22px; font-size: 1.12rem; line-height: 1.5; }
.v4-voice-text span { background: linear-gradient(transparent 62%, rgba(255, 194, 71, .55) 62%); }
.v4-caret { display: inline-block; width: 2px; height: 1.1em; margin-left: 2px; vertical-align: -3px; background: var(--v4-ink); animation: v4-blink .8s steps(1) infinite; }
.v4-voice-dock { display: flex; align-items: center; gap: 14px; }

.v4-key {
    display: grid;
    place-items: center;
    width: 50px;
    height: 44px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 0 0 1.5px rgba(24, 38, 43, .25), 0 5px 0 rgba(24, 38, 43, .25);
    font: 600 .95rem var(--v4-mono);
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.v4-key.is-down { transform: translateY(4px); background: var(--v4-yellow-hi); box-shadow: 0 0 0 1.5px rgba(24, 38, 43, .25), 0 1px 0 rgba(24, 38, 43, .25); }

.v4-voice-pill { display: inline-flex; align-items: center; gap: 10px; padding: 9px 16px 9px 12px; border-radius: 999px; background: #161b26; color: #fff; font: 500 .85rem var(--v4-mono); opacity: .85; transition: opacity .2s ease; }
.v4-voice-pill.is-on { opacity: 1; }
.v4-voice-dot { width: 9px; height: 9px; border-radius: 50%; background: #ff5f56; box-shadow: 0 0 0 3px rgba(255, 95, 86, .25); }
.v4-voice-wave { display: flex; align-items: center; gap: 3px; height: 20px; }
.v4-voice-wave i { width: 3px; height: 25%; border-radius: 2px; background: #7aa7ff; }
.v4-voice-pill.is-on .v4-voice-wave i { animation: v4-wave .8s ease-in-out infinite alternate; }
.v4-voice-wave i:nth-child(2) { animation-delay: -.2s; }
.v4-voice-wave i:nth-child(3) { animation-delay: -.5s; }
.v4-voice-wave i:nth-child(4) { animation-delay: -.1s; }
.v4-voice-wave i:nth-child(5) { animation-delay: -.6s; }
.v4-voice-wave i:nth-child(6) { animation-delay: -.3s; }
.v4-voice-wave i:nth-child(7) { animation-delay: -.7s; }

/* 05 · ship */
.v4-term p { margin: 0 0 7px; font: 500 .95rem/1.5 var(--v4-mono); transition: opacity .25s ease, transform .25s ease; }
/* hidden until the demo reveals them; without JS everything is simply shown */
.v4-story.is-live .v4-term p:not(.is-in) { opacity: 0; transform: translateY(4px); }
.v4-term p[data-line="cmd"]::before { content: '$ '; color: var(--v4-yellow); }
.v4-term p[data-line="ok"] { color: #7fe2a8; }
.v4-term p[data-line="dim"] { color: #8c949e; }

.v4-ship-toast {
    position: absolute;
    right: 14px;
    bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 8px 8px;
    border-radius: 999px;
    background: #fff;
    color: var(--v4-ink);
    font: 600 .9rem var(--v4-font);
    box-shadow: var(--v4-shadow-card);
    transition: opacity .3s ease, transform .4s var(--v4-ease);
}

.v4-story.is-live .v4-ship-toast:not(.is-in) { opacity: 0; transform: translateY(10px) scale(.9); }

.v4-ship-toast span { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--v4-leaf); color: #fff; font-size: .8rem; }

@keyframes v4-blink { 50% { opacity: 0; } }
@keyframes v4-pulse { 50% { transform: scale(.6); opacity: .5; } }
@keyframes v4-wave { from { height: 20%; } to { height: 100%; } }

/* chapters drift in as you reach them */
@media (prefers-reduced-motion: no-preference) {
    .v4-story.is-live .v4-chapter .v4-chapter-text,
    .v4-story.is-live .v4-chapter .v4-stage { opacity: 0; transform: translateY(26px); transition: opacity .7s ease, transform .8s var(--v4-ease); }
    .v4-story.is-live .v4-chapter.is-seen .v4-chapter-text,
    .v4-story.is-live .v4-chapter.is-seen .v4-stage { opacity: 1; transform: none; }
    .v4-story.is-live .v4-chapter.is-seen .v4-stage { transition-delay: .12s; }
}

/* ---------- tablets and phones: the spine moves to the left ---------- */

@media (max-width: 900px) {
    .v4-story { padding: 40px 18px 20px; }
    .v4-story-intro { margin-bottom: 50px; }
    .v4-spine { left: 49px; top: 300px; }
    .v4-chapters { gap: 90px; }

    .v4-chapter,
    .v4-chapter:nth-child(even) { grid-template-columns: 62px minmax(0, 1fr); gap: 22px 16px; align-items: start; }

    .v4-chapter .v4-node,
    .v4-chapter:nth-child(even) .v4-node { order: 0; grid-row: 1; grid-column: 1; width: 52px; height: 52px; border-radius: 15px; }

    .v4-chapter .v4-chapter-text,
    .v4-chapter:nth-child(even) .v4-chapter-text { order: 0; grid-row: 1; grid-column: 2; }

    .v4-chapter .v4-stage,
    .v4-chapter:nth-child(even) .v4-stage { order: 0; grid-row: 2; grid-column: 1 / -1; }

    .v4-art { min-height: 0; padding: 30px 16px; }
    .v4-chapter-text p { font-size: 1.05rem; }
}

@media (max-width: 520px) {
    .v4-slm-stats dd { font-size: 1rem; }
    .v4-stage-meta { bottom: -18px; }
    .v4-meta-chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
}

@media (prefers-reduced-motion: reduce) {
    .v4-node, .v4-plan li, .v4-term p, .v4-ship-toast, .v4-key { transition: none; }
    .v4-caret, .v4-slm-live::before, .v4-notes p.is-typing::after { animation: none; }
}
