/* Product reels (Pages/Shared/_Reel.cshtml + /assets/reel.js).
 *
 * Why it looks like this:
 * - The recording is the only lifted object on the page (--shadow-lg): it is the product, everything
 *   else is commentary about it.
 * - Notes are written as SQL comments ("-- ..."), the same voice as the site's // eyebrows, because in
 *   SQLly a comment is also how you tell the app what to do (directives).
 * - Navy notes with a pink "--" are the one accent on the stage; the ring marks the exact spot in the
 *   app the note talks about and settles after two pulses instead of looping. */

.reel { margin: 0; }

.reel-stage {
    position: relative;
    aspect-ratio: 1440 / 900;
    border-radius: 12px;
    overflow: hidden;
    background: #1e1e1e;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    isolation: isolate;
}
:root[data-theme="light"] .reel-stage { background: #fff; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .reel-stage { background: #fff; } }

.reel-cam {
    position: absolute;
    inset: 0;
    transition: transform 1.1s cubic-bezier(.65, 0, .25, 1), transform-origin 1.1s cubic-bezier(.65, 0, .25, 1);
    will-change: transform;
}
/* The still and the recording sit on top of each other; the recording covers the still once it has frames. */
.reel-cam picture,
.reel-cam video {
    position: absolute;
    inset: 0;
}
.reel-cam video,
.reel-cam img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ---------- notes ---------- */
.reel-notes { position: absolute; inset: 0; pointer-events: none; margin: 0; padding: 0; list-style: none; }
.reel-note {
    --x: 50%;
    --y: 50%;
    --lx: 50%;
    --ly: 50%;
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity .22s ease, visibility 0s linear .22s;
}
.reel-note.is-on { opacity: 1; visibility: visible; transition: opacity .22s ease, visibility 0s; }

/* The ring marks the exact spot the note is about; it rides the camera move with the app. */
.reel-note .ring {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: 26px;
    height: 26px;
    margin: -13px 0 0 -13px;
    border-radius: 50%;
    /* --pink-strong clears 3:1 against both the light (4.2:1) and dark (3.5:1) app canvas. */
    border: 2.5px solid var(--pink-strong);
    box-shadow: 0 0 0 3px rgba(4, 19, 45, .3);
    transition: left 1.1s cubic-bezier(.65, 0, .25, 1), top 1.1s cubic-bezier(.65, 0, .25, 1);
}
.reel-note.is-on .ring { animation: reel-ring 1.1s ease-out 2; }
@keyframes reel-ring {
    0% { transform: scale(.55); opacity: .2; }
    55% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Leader: a hairline from the ring's edge toward the label, drawn as it appears. */
.reel-note .lead {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--len, 0);
    height: 2px;
    margin-top: -1px;
    background: var(--pink-strong);
    transform-origin: 0 50%;
    transform: rotate(var(--angle, 0)) translateX(13px);
    transition: left 1.1s cubic-bezier(.65, 0, .25, 1), top 1.1s cubic-bezier(.65, 0, .25, 1);
}
.reel-note.is-on .lead { animation: reel-lead .35s ease-out both; }
@keyframes reel-lead { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

.reel-note .say {
    position: absolute;
    left: var(--lx);
    top: var(--ly);
    width: max-content;
    max-width: min(26ch, 30vw);
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--navy);
    color: #eaf1ff;
    border: 1px solid var(--pink);
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: clamp(.7rem, 1vw, .86rem);
    line-height: 1.45;
    box-shadow: var(--shadow);
    translate: var(--tx, 0) var(--ty, -50%);
}
/* Notes are navy in both themes, so their text uses the dark-theme token values: ink, pink, amber-ink (10:1). */
.reel-note .say::before { content: "-- "; color: var(--pink); font-weight: 600; }
.reel-note .say b { color: #f3b35a; font-weight: 600; }
.reel-note.is-on .say { animation: reel-say .32s cubic-bezier(.2, .8, .2, 1) .12s both; }
@keyframes reel-say { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Which way the label grows from its anchor. */
.reel-note[data-side="right"] .say { --tx: 0; --ty: -50%; }
.reel-note[data-side="left"]  .say { --tx: -100%; --ty: -50%; }
.reel-note[data-side="below"] .say { --tx: -12%; --ty: 0; }
.reel-note[data-side="above"] .say { --tx: -12%; --ty: -100%; }

/* ---------- key caption ---------- */
.reel-keys {
    position: absolute;
    left: 50%;
    bottom: 5.5%;
    translate: -50% 0;
    margin: 0;
    pointer-events: none;
}
.reel-key {
    position: absolute;
    left: 0;
    bottom: 0;
    translate: -50% 0;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    padding: 8px 14px 8px 10px;
    border-radius: 12px;
    background: rgba(4, 19, 45, .9);
    color: #eaf1ff;
    font-size: clamp(.72rem, 1vw, .9rem);
    font-weight: 500;
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s ease, visibility 0s linear .18s;
}
.reel-key.is-on { opacity: 1; visibility: visible; transition: opacity .12s ease, visibility 0s; }
.reel-key kbd {
    display: inline-block;
    min-width: 1.9em;
    padding: 3px 8px;
    border-radius: 4px;
    background: #eaf2ff;
    color: var(--navy);
    border-bottom: 3px solid #93a3c8;
    font-family: "Inter", system-ui, sans-serif;
    font-size: 1em;
    font-weight: 600;
    text-align: center;
}
.reel-key.is-on kbd { animation: reel-press .26s ease-out; }
@keyframes reel-press { 40% { transform: translateY(2px); border-bottom-width: 1px; } }

/* ---------- controls ---------- */
.reel-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin-top: 14px;
    min-height: 44px;
}
.reel-toggle {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px 0 12px;
    border-radius: 999px;
    border: 1.5px solid var(--line);
    background: var(--card);
    color: var(--heading);
    font: 600 .9rem/1 "Inter", system-ui, sans-serif;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.reel-toggle:hover { border-color: var(--blue-bright); }
.reel-toggle:active { background: var(--blue-soft); }
.reel-toggle svg { width: 18px; height: 18px; }
.reel-toggle .i-pause { display: none; }
.reel.is-playing .reel-toggle .i-pause { display: block; }
.reel.is-playing .reel-toggle .i-play { display: none; }
.reel-caption {
    flex: 1 1 22ch;
    min-width: 0;
    margin: 0;
    color: var(--ink);
    font-size: .98rem;
    line-height: 1.4;
}
.reel-fact {
    flex: none;
    margin: 0 0 0 auto;
    color: var(--muted);
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: .78rem;
}

/* ---------- chapters ---------- */
.reel-chapters { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
/* Under the recording the steps run across, one column each (--steps is set per page). */
.reel-below .reel-chapters { display: grid; grid-template-columns: repeat(var(--steps, 4), minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
@media (max-width: 920px) { .reel-below .reel-chapters { grid-template-columns: 1fr; } }
.reel-chapter { counter-increment: ch; }
.reel-chapter button {
    position: relative;
    display: grid;
    grid-template-columns: 2.2em 1fr;
    gap: 2px 10px;
    width: 100%;
    min-height: 44px;
    padding: 12px 14px 14px 12px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .2s ease, color .2s ease;
}
.reel-chapter button::before {
    content: counter(ch, decimal-leading-zero);
    grid-row: span 2;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: .8rem;
    padding-top: 3px;
    color: var(--muted);
}
.reel-chapter button::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 14px;
    bottom: 6px;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(var(--pink-strong), var(--pink-strong)) left / calc(var(--fill, 0) * 100%) 100% no-repeat, var(--line);
}
.reel-chapter button:hover { background: var(--blue-soft); color: var(--ink); }
.reel-chapter .t { color: var(--heading); font-weight: 600; font-size: 1rem; line-height: 1.3; }
.reel-chapter .d { font-size: .92rem; line-height: 1.45; }
.reel-chapter.is-current button { background: var(--card); color: var(--ink); box-shadow: 0 0 0 1.5px var(--line); }
.reel-chapter.is-current button::before { color: var(--pink-ink); }

/* Without the player script (or before it starts) nothing waits on JS: the poster and the steps stand alone. */
.reel:not(.reel-ready) .reel-bar,
.reel:not(.reel-ready) .reel-notes,
.reel:not(.reel-ready) .reel-keys { display: none; }
.reel.reel-failed .reel-notes,
.reel.reel-failed .reel-keys { display: none; }

/* ---------- small screens: notes dock under the recording instead of covering it ---------- */
@media (max-width: 720px) {
    /* Labels would cover most of a phone-sized recording: the ring stays, the words move to the caption. */
    .reel-note .say, .reel-note .lead { display: none; }
    .reel-note .ring { width: 18px; height: 18px; margin: -9px 0 0 -9px; border-width: 2px; }
    .reel-key { padding: 5px 9px 5px 7px; gap: 6px; }
    .reel-bar { flex-wrap: wrap; gap: 10px; }
    .reel-caption { flex-basis: calc(100% - 120px); font-size: .92rem; }
    .reel-fact { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .reel-cam, .reel-note, .reel-note.is-on { transition: none; }
    .reel-note .ring, .reel-note .lead { transition: none; }
    .reel-note.is-on .ring, .reel-note.is-on .say, .reel-note.is-on .lead, .reel-key.is-on kbd { animation: none; }
}

/* ---------- where reels sit ---------- */

/* Blog posts and docs articles hold reels inside their prose, whose list and paragraph rules (.blog-prose ol,
   .blog-prose li + li, .doc-article p) outrank the single classes above: they indented the steps, spaced every
   row of the step grid but the first one lower, and padded the caption under the play button. Two classes win. */
.reel .reel-notes,
.reel .reel-chapters { padding: 0; }
.reel .reel-chapter { margin: 0; }
.reel .reel-caption { margin: 0; color: var(--ink); line-height: 1.4; }
.reel .reel-fact { margin: 0 0 0 auto; }

/* A docs guide: the reel opens the page, above the screenshots, and waits for Play. The column is
   narrow, so the steps run two to a row instead of one per chapter. */
.doc-reel { margin: 8px 0 36px; }
.doc-reel .reel-below .reel-chapters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.doc-reel .reel-chapter .t { font-size: .95rem; }
.doc-reel .reel-chapter .d { font-size: .88rem; }
.doc-reel-more { margin: 10px 0 0; font-size: .92rem; }
@media (max-width: 920px) { .doc-reel .reel-below .reel-chapters { grid-template-columns: 1fr; } }

/* /reels/{name}: one recording, full width, with where to read more under it. */
.reel-page-head { padding-bottom: 8px; }
.reel-page { padding: 28px 0 88px; }
.reel-page-wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }
.reel-page-more { margin-top: 40px; max-width: 70ch; }
.reel-page-more h2 { font-size: 1.3rem; margin: 0 0 12px; }
.reel-page-more ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.reel-page-more li span { color: var(--muted); font-size: .92rem; }
@media (max-width: 560px) { .reel-page-wrap { padding: 0 16px; } }

/* A blog post: the stored figure (an animated preview linking to /reels/{name}) is swapped for the
   player when the page renders. It steps out of the reading column like the screenshots do. */
.blog-prose .blog-reel-live { margin: 1.8em 0; }
.blog-reel-live .reel-below .reel-chapters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.blog-reel-live .reel-chapter .t { font-size: .95rem; }
.blog-reel-live .reel-chapter .d { font-size: .88rem; }
.blog-reel-caption { font-size: .88rem; color: var(--muted); margin: 10px 0 0; line-height: 1.5; }
@media (min-width: 1120px) {
    .blog-prose .blog-reel-live { margin-inline: -6rem; }
    .blog-prose .blog-reel-caption { padding-inline: 6rem; }
}
@media (max-width: 720px) { .blog-reel-live .reel-below .reel-chapters { grid-template-columns: 1fr; } }

/* /reels: every walkthrough, as its last frame with a title. The site's theme picks the light or dark take. */
.reel-index { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 36px 28px; }
.reel-index a { display: block; color: var(--heading); text-decoration: none; }
.reel-index img { display: block; width: 100%; height: auto; aspect-ratio: 1440 / 900; border-radius: 12px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.reel-index .reel-index-dark { display: none; }
:root[data-theme="dark"] .reel-index .reel-index-light { display: none; }
:root[data-theme="dark"] .reel-index .reel-index-dark { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .reel-index .reel-index-light { display: none; }
    :root:not([data-theme="light"]) .reel-index .reel-index-dark { display: block; }
}
.reel-index-title { display: block; margin-top: 14px; font-weight: 600; font-size: 1.08rem; line-height: 1.35; }
.reel-index a:hover .reel-index-title { color: var(--blue-bright); }
.reel-index-length { display: block; margin-top: 2px; color: var(--muted); font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .8rem; }
.reel-index p { margin: 8px 0 0; color: var(--muted); font-size: .95rem; line-height: 1.5; }
