/* ============================================================ */
/* Tools page: the toolkit as one composition, a layer per tool  */
/* Layout works without JS; tools.js layers the motion on top.   */
/* ============================================================ */

body.tools-page {
    padding-bottom: var(--scrubber-h);
}

/* ------------------------------------------------------------ */
/* Intro                                                         */
/* ------------------------------------------------------------ */

.tools-hero {
    max-width: var(--max);
    margin: 0 auto;
    padding: calc(var(--nav-h) + clamp(32px, 8vh, 88px)) var(--gutter) 0;
}

.tools-hero-main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 400px);
    align-items: end;
    gap: 28px 64px;
    margin-bottom: clamp(40px, 7vh, 72px);
}

.tools-title {
    font-size: clamp(3rem, 7.4vw, 7.4rem);
    font-weight: 650;
    line-height: 0.9;
    letter-spacing: -0.055em;
    text-wrap: balance;
}

.tools-hero-side {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 0.4rem;
}

.tools-lede {
    font-size: clamp(1.05rem, 1.3vw, 1.2rem);
    line-height: 1.55;
    color: var(--text-dim);
}

@media (max-width: 900px) {
    .tools-hero-main {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Index: one timeline layer per tool */
.tool-index {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    overflow: hidden;
}

.tool-index .timeline {
    --name-w: clamp(260px, 44%, 600px);
    border-top: 0;
}

.tool-index .tl-head,
.tool-index .tl-layer {
    height: 44px;
}

.tool-index .tl-layer {
    color: inherit;
    text-decoration: none;
}

.tool-index .tl-layer:focus-visible {
    outline-offset: -2px;
}

.tool-index .tl-name {
    gap: 12px;
    font-size: 0.8rem;
}

.tl-cat {
    min-width: 0;
    margin-left: auto;
    padding-left: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.64rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tool-index .tl-bar {
    top: 13px;
    bottom: 13px;
    transform-origin: left;
}

.tool-index .tl-layer:hover .tl-bar,
.tool-index .tl-layer:focus-visible .tl-bar {
    background: var(--label);
    border-color: var(--label);
}

@media (max-width: 640px) {
    .tool-index .tl-head,
    .tool-index .tl-track,
    .tool-index .tl-playhead {
        display: none;
    }

    .tool-index .tl-layer {
        grid-template-columns: minmax(0, 1fr);
    }

    .tool-index .tl-name {
        border-right: 0;
    }
}

/* ------------------------------------------------------------ */
/* Chapters: one per tool                                        */
/* ------------------------------------------------------------ */

.chapter {
    --label: var(--accent);
    max-width: var(--max);
    margin: clamp(112px, 18vh, 200px) auto 0;
    padding: 0 var(--gutter);
    scroll-margin-top: calc(var(--nav-h) + 24px);
}

.chapter-head {
    position: relative;
    padding-top: 30px;
    margin-bottom: clamp(28px, 5vh, 48px);
}

/* Time ruler across the top of each chapter */
.chapter-ruler {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 12px;
    border-top: 1px solid var(--line-strong);
    background-image:
        repeating-linear-gradient(to right, var(--line-strong) 0 1px, transparent 1px 120px),
        repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px 24px);
    background-size: 100% 12px, 100% 6px;
    background-repeat: no-repeat;
    transform-origin: left;
}

.chapter-index {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin-bottom: clamp(16px, 3vh, 28px);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.chapter-num {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-variant-numeric: tabular-nums;
}

.chapter-num .tl-swatch {
    width: 10px;
    height: 10px;
}

.chapter-tags {
    color: var(--text-dim);
}

.chapter-title {
    font-size: clamp(2.8rem, 7.6vw, 7rem);
    font-weight: 650;
    line-height: 0.92;
    letter-spacing: -0.055em;
}

/* Media: an AE viewer with its own bar and timecode */
.chapter-media {
    margin-bottom: clamp(56px, 9vh, 104px);
}

.viewer-frame {
    --ix: 0%;
    --iy: 0%;
    --r: 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    overflow: hidden;
    clip-path: inset(var(--iy) var(--ix) round var(--r));
}

.media-tc {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.media-stage {
    position: relative;
    aspect-ratio: var(--ar, 16 / 9);
    overflow: hidden;
    background: #000;
}

.media-stage video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Stills sit on a canvas, like a panel docked in a comp */
.media-stage--still {
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    padding: clamp(20px, 4vw, 56px);
    background-color: var(--bg-raised);
    background-image: radial-gradient(var(--line-strong) 1px, transparent 1.2px);
    background-size: 24px 24px;
}

.media-stage--still img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.55);
}

.media-caption {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    padding-top: 16px;
    font-size: 0.72rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.media-caption-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

.media-caption-label::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--label);
    transform: rotate(45deg);
}

/* Body: facts on the left, the story on the right */
.chapter-body {
    display: grid;
    grid-template-columns: minmax(0, 4fr) minmax(0, 8fr);
    align-items: start;
    gap: 48px clamp(40px, 6vw, 112px);
}

.chapter-facts {
    position: sticky;
    top: calc(var(--nav-h) + 32px);
    display: flex;
    flex-direction: column;
    gap: 44px;
}

.facts-metrics {
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.fact {
    --draw: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.fact::before {
    content: '';
    display: block;
    height: 1px;
    margin-bottom: 8px;
    background: var(--line-strong);
    transform: scaleX(var(--draw));
    transform-origin: left;
}

.fact-num {
    font-size: clamp(2rem, 3.2vw, 3rem);
    font-weight: 600;
    line-height: 1;
    letter-spacing: -0.045em;
    font-variant-numeric: tabular-nums;
}

.fact-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.facts-label {
    margin-bottom: 14px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.stack-badges {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.badge {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    font: 400 0.72rem var(--font-mono);
    color: var(--text);
}

.chapter-story {
    display: flex;
    flex-direction: column;
    gap: clamp(40px, 6vh, 64px);
}

.story-block {
    --draw: 1;
    position: relative;
    padding-top: 22px;
}

.story-block::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--line);
    transform: scaleX(var(--draw));
    transform-origin: left;
}

.story-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.story-label::before {
    content: '';
    width: 7px;
    height: 7px;
    background: var(--label);
    transform: rotate(45deg);
}

.story-block p {
    max-width: 62ch;
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--text-dim);
}

.story-cta {
    margin-top: 24px;
}

.story-block .feature-tags {
    display: block;
    margin-top: 16px;
}

/* Key features: a full-width row once the story is told */
.chapter-features {
    margin-top: clamp(72px, 12vh, 136px);
}

.chapter-features > .story-label {
    margin-bottom: 28px;
}

.feature-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 40px clamp(24px, 3vw, 48px);
    margin-bottom: clamp(48px, 8vh, 88px);
}

.feature {
    --draw: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-top: 22px;
}

.feature::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--line-strong);
    transform: scaleX(var(--draw));
    transform-origin: left;
}

.feature-num {
    font-size: 0.72rem;
    color: var(--label);
    letter-spacing: 0.08em;
}

.feature-name {
    font-size: clamp(1.5rem, 2.2vw, 2rem);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.035em;
}

.feature p {
    font-size: 1.02rem;
    line-height: 1.6;
    color: var(--text-dim);
}

.feature-tags {
    font-size: 0.66rem;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.feature .feature-tags {
    margin-top: auto;
    padding-top: 4px;
}

.chapter-features .chapter-media {
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .feature-list {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 900px) {
    .chapter-body {
        grid-template-columns: minmax(0, 1fr);
    }

    .chapter-facts {
        position: static;
    }

    .facts-metrics {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 24px 32px;
    }

    .fact {
        flex: 1 1 160px;
    }
}

/* How it works: a layer track, one keyframe per step */
.flow {
    --p: 1;
    position: relative;
    list-style: none;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 20px;
    padding-top: 30px;
}

.flow::before,
.flow::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--line-strong);
}

.flow::after {
    background: var(--label);
    transform: scaleX(var(--p));
    transform-origin: left;
}

.flow li {
    position: relative;
    font-size: 0.98rem;
    line-height: 1.4;
    transition: color 0.4s ease;
}

.flow li::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 0;
    z-index: 1;
    width: 9px;
    height: 9px;
    border: 1px solid var(--label);
    background: var(--label);
    transform: rotate(45deg);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.flow small {
    display: block;
    margin-top: 4px;
    font: 400 0.68rem var(--font-mono);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Scrubbed: each step lights up as the playhead reaches it */
.flow.is-scrub li:not(.is-hit) {
    color: var(--text-faint);
}

.flow.is-scrub li:not(.is-hit)::before {
    border-color: var(--text-faint);
    background: var(--bg);
}

.flow.is-scrub li.is-hit::before {
    animation: kf-pop 0.45s var(--ease-out);
}

@media (max-width: 900px) {
    .flow {
        grid-auto-flow: row;
        gap: 22px;
        padding: 0 0 0 30px;
    }

    .flow::before,
    .flow::after {
        top: 0;
        bottom: 0;
        left: 4px;
        right: auto;
        width: 1px;
        height: auto;
    }

    .flow::after {
        transform: scaleY(var(--p));
        transform-origin: top;
    }

    .flow li::before {
        top: 0.4em;
        left: -30px;
    }
}

/* Under the hood: a code panel in the site's palette */
.code-panel {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-raised);
    overflow: hidden;
}

.code-panel pre {
    padding: 18px 0;
    overflow-x: auto;
    font: 400 0.8rem/1.75 var(--font-mono);
    counter-reset: ln;
    scrollbar-width: thin;
    scrollbar-color: var(--line-strong) transparent;
}

.code-panel code {
    display: block;
    width: max-content;
    min-width: 100%;
    font: inherit;
    /* Each .cl keeps its own whitespace; the gaps between them collapse */
    white-space: normal;
}

.code-panel .cl {
    display: block;
    padding-right: 24px;
    white-space: pre;
    counter-increment: ln;
}

.code-panel .cl::before {
    content: counter(ln);
    display: inline-block;
    width: 3em;
    margin-right: 1.4em;
    text-align: right;
    color: var(--text-faint);
    user-select: none;
}

.code-keyword {
    color: var(--accent);
}

.code-function {
    color: var(--label-aqua);
}

.code-string {
    color: var(--label-peach);
}

.code-comment {
    color: var(--text-faint);
    font-style: italic;
}

/* ------------------------------------------------------------ */
/* Contact, footer & scrubber                                    */
/* ------------------------------------------------------------ */

/* Same rhythm as the gaps between chapters */
.tools-page .contact {
    padding-top: clamp(112px, 18vh, 200px);
}

.footer-back {
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-back:hover {
    color: var(--text);
}

/* Passed markers take their tool's label colour */
.tools-page .scrubber-marker.is-passed i {
    border-color: var(--label, var(--accent));
    background: var(--label, var(--accent));
}
