/**
 * The Skill tiles on the home page (#skills), each a short loop of its Skill
 * at work. js/home.js adds .is-playing to each [data-loop-scene] while it is
 * on screen. Every loop is 8 s; in the grids each cell runs the same 8 s
 * cycle a little later than the one before (--i), so they build one by one.
 * Sizes are in cqi, so a tile scales as one piece. Reduced motion shows the
 * end state. The Light (the logo's blue → mint) marks only the moments the
 * AI is at work: a cell being made, a wipe, a repair.
 *
 * Images are Tiguan Edition 20 stills; New background and the launch kit use
 * them as stand-ins (TEMP) until real product photos replace them.
 */

/* The tile's media box is the container, so the scene's own padding and
   gaps in cqi measure the scene, not the page. */
.skill-tile__media { container-type: inline-size; }

.sk-scene {
    --sk-t: 8s;
    --sk-light: linear-gradient(90deg, #296cfd, #1c91ff 35%, #05c7bb 70%, #38ffc7);
    --sk-ok: #43c283;
    --sk-warn: #fbbf24;
    --sk-accent: #05c7bb;
    --sk-panel: rgba(9, 12, 14, 0.8);
    --sk-edge: rgba(255, 255, 255, 0.14);
    --sk-muted: #989ea1;

    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    isolation: isolate;
    border-radius: 0.75rem;
    background: #141617;
    color: #e5e7eb;
    font: 3.4cqi/1.3 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.sk-scene img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
}

.sk-chip {
    position: absolute;
    z-index: 3;
    padding: 0.8cqi 1.8cqi;
    border: 1px solid var(--sk-edge);
    border-radius: 2px;
    background: var(--sk-panel);
    font: 500 3cqi/1.2 'JetBrains Mono', ui-monospace, monospace;
    white-space: nowrap;
}

/* The TEMP mark: small, in a corner */
.sk-scene .sk-temp {
    position: absolute;
    z-index: 4;
    right: 2cqi;
    bottom: 2cqi;
    width: auto;
    height: auto;
    padding: 0.6cqi 1.4cqi;
}

/* ── Grids: the launch kit and the car locations ───────────────────────── */

.sk-kit,
.sk-cars {
    display: grid;
    gap: 1.4cqi;
    padding: 1.4cqi;
}

.sk-cars {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.sk-kit {
    grid-template-columns: 1.3fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.sk-cell--hero { grid-row: 1 / 3; }

.sk-cell {
    position: relative;
    min-height: 0;
    overflow: hidden;
    border-radius: 3px;
    background: #1d2022;
}

/* While a cell is being made, the Light runs across it. */
.sk-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--sk-light) 0 0 / 220% 100%;
    opacity: 0;
    animation: skCellMake var(--sk-t) linear calc(var(--i) * 0.7s) infinite both;
}

.sk-cell > img,
.sk-cell > b {
    opacity: 0;
    animation: skCellIn var(--sk-t) ease calc(var(--i) * 0.7s) infinite both;
}

.sk-cell > b {
    position: absolute;
    z-index: 2;
    left: 1.2cqi;
    bottom: 1.2cqi;
    padding: 0.4cqi 1.1cqi;
    border-radius: 2px;
    background: var(--sk-panel);
    font: 500 2.6cqi/1.2 'JetBrains Mono', ui-monospace, monospace;
    white-space: nowrap;
}

.sk-chip--count { left: 2.8cqi; top: 2.8cqi; }

/* The formats cell: the three crops, drawn one after another */
.sk-cell--formats > i {
    position: absolute;
    z-index: 2;
    left: 50%;
    top: 44%;
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    border-radius: 1px;
    opacity: 0;
    transform: translate(-50%, -50%);
    animation: skCellIn var(--sk-t) ease calc(var(--i) * 0.7s + var(--f) * 0.35s + 0.5s) infinite both;
}

.sk-cell--formats > i:nth-of-type(1) { --f: 0; height: 74%; aspect-ratio: 9 / 16; }
.sk-cell--formats > i:nth-of-type(2) { --f: 1; height: 58%; aspect-ratio: 1; }
.sk-cell--formats > i:nth-of-type(3) { --f: 2; width: 80%; aspect-ratio: 16 / 9; }

.sk-chip--clip {
    left: 2.8cqi;
    top: 2.8cqi;
    opacity: 0;
    animation: skClip var(--sk-t) ease infinite both;
}

.sk-kit .sk-temp { top: 2cqi; bottom: auto; }

/* ── New background: the prompt types, the new background wipes in ──── */

.sk-bg__before,
.sk-bg__after {
    position: absolute;
    inset: 0;
}

/* Stand-in for the plain backdrop: the same still, washed out */
.sk-bg__before { filter: grayscale(1) brightness(1.45) contrast(0.7); }

.sk-bg__after {
    clip-path: inset(0 100% 0 0);
    animation: skWipe var(--sk-t) cubic-bezier(0.6, 0, 0.3, 1) infinite;
}

.sk-bg__line {
    position: absolute;
    z-index: 2;
    top: 0;
    bottom: 0;
    left: 0;
    width: 0.8cqi;
    margin-left: -0.4cqi;
    background: linear-gradient(180deg, #296cfd, #05c7bb 60%, #38ffc7);
    opacity: 0;
    animation: skLine var(--sk-t) cubic-bezier(0.6, 0, 0.3, 1) infinite;
}

.sk-prompt {
    position: absolute;
    z-index: 3;
    left: 3cqi;
    right: 3cqi;
    top: 3cqi;
    display: flex;
    padding: 1.6cqi 2.2cqi;
    border: 1px solid var(--sk-edge);
    border-radius: 3px;
    background: var(--sk-panel);
    font-size: 3.2cqi;
}

.sk-prompt > span {
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--sk-accent);
    animation: skType var(--sk-t) steps(48) infinite;
}

/* ── Clean up & inspect: repair, inspect, the report comes out ─────────── */

.sk-insp__photo {
    position: absolute;
    inset: 0;
}

/* The badge sits at 46–75 % across, 26–56 % down. */
.sk-insp__smear,
.sk-insp__box {
    position: absolute;
    left: 46%;
    top: 26%;
    width: 29%;
    height: 30%;
    border-radius: 3px;
}

.sk-insp__smear {
    -webkit-backdrop-filter: blur(2px) contrast(1.15);
    backdrop-filter: blur(2px) contrast(1.15);
    animation: skSmear var(--sk-t) linear infinite;
}

.sk-insp__box {
    border: 1.5px solid var(--sk-warn);
    opacity: 0;
    animation: skBox var(--sk-t) linear infinite;
}

.sk-insp__box::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--sk-light) 0 0 / 220% 100%;
    opacity: 0;
    animation: skRepair var(--sk-t) linear infinite;
}

.sk-steps {
    position: absolute;
    z-index: 3;
    left: 3cqi;
    top: 3cqi;
    display: flex;
    gap: 1.2cqi;
}

.sk-step {
    display: flex;
    align-items: center;
    gap: 1cqi;
    padding: 0.7cqi 1.8cqi 0.7cqi 0.9cqi;
    border: 1px solid var(--sk-edge);
    border-radius: 2px;
    background: var(--sk-panel);
    font-size: 3cqi;
    font-weight: 600;
    color: var(--sk-muted);
}

/* Step numbers are small flat-top hexagons. */
.sk-step > i {
    display: inline-grid;
    place-items: center;
    width: 3.8cqi;
    height: 3.3cqi;
    clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
    background: #343739;
    color: #fff;
    font: 600 2.2cqi/1 'JetBrains Mono', ui-monospace, monospace;
    font-style: normal;
}

.sk-step--1 { animation: skStep1 var(--sk-t) linear infinite; }
.sk-step--2 { animation: skStep2 var(--sk-t) linear infinite; }

.sk-mini {
    position: absolute;
    z-index: 3;
    left: 4cqi;
    bottom: 4cqi;
    display: flex;
    flex-direction: column;
    gap: 1.5cqi;
    width: 27cqi;
    aspect-ratio: 210 / 297;
    padding: 2.4cqi;
    border-radius: 2px;
    background: #fbfbf9;
    box-shadow: 0 2cqi 5cqi -1cqi rgba(0, 0, 0, 0.6);
    opacity: 0;
    animation: skMini var(--sk-t) ease infinite;
}

.sk-mini__head {
    flex: none;
    width: 60%;
    height: 1.5cqi;
    border-radius: 1px;
    background: #15191b;
}

.sk-mini__thumb {
    flex: none;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border-radius: 1px;
}

.sk-mini__rows { display: grid; gap: 1.2cqi; }

.sk-mini__rows > i {
    height: 0.9cqi;
    border-radius: 1px;
    background: rgba(21, 25, 27, 0.16);
}

.sk-mini__rows > i:nth-child(1) { width: 92%; }
.sk-mini__rows > i:nth-child(2) { width: 70%; }
.sk-mini__rows > i:nth-child(3) { width: 82%; }

.sk-mini__tag {
    align-self: flex-start;
    margin-top: auto;
    padding: 0.6cqi 1.1cqi;
    border: 1px solid #16855a;
    border-radius: 2px;
    color: #16855a;
    font: 600 2.2cqi/1 'JetBrains Mono', ui-monospace, monospace;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0;
    animation: skTag var(--sk-t) ease infinite;
}

/* ── Timelines ─────────────────────────────────────────────────────────── */

@keyframes skCellMake {
    0% { opacity: 0; background-position: 100% 0; }
    3% { opacity: 0.4; }
    15% { opacity: 0.4; }
    19%, 100% { opacity: 0; background-position: 0 0; }
}

@keyframes skCellIn {
    0%, 15% { opacity: 0; translate: 0 3px; }
    20%, 86% { opacity: 1; translate: 0 0; }
    93%, 100% { opacity: 0; translate: 0 0; }
}

@keyframes skClip {
    0%, 52% { opacity: 0; transform: translateY(3px); }
    57%, 88% { opacity: 1; transform: none; }
    94%, 100% { opacity: 0; transform: none; }
}

@keyframes skType {
    0% { max-width: 0; }
    30%, 92% { max-width: 100%; }
    96%, 100% { max-width: 0; }
}

@keyframes skWipe {
    0%, 34% { clip-path: inset(0 100% 0 0); }
    62%, 90% { clip-path: inset(0 0 0 0); }
    98%, 100% { clip-path: inset(0 0 0 100%); }
}

@keyframes skLine {
    0%, 33% { left: 0; opacity: 0; }
    35% { opacity: 1; }
    61% { opacity: 1; }
    62% { left: 100%; }
    64%, 100% { left: 100%; opacity: 0; }
}

@keyframes skSmear {
    0%, 36% { opacity: 1; }
    44%, 94% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes skBox {
    0%, 8% { opacity: 0; border-color: #fbbf24; }
    12%, 36% { opacity: 1; border-color: #fbbf24; }
    44%, 90% { opacity: 1; border-color: #43c283; }
    96%, 100% { opacity: 0; border-color: #43c283; }
}

@keyframes skRepair {
    0%, 34% { opacity: 0; background-position: 100% 0; }
    36% { opacity: 0.5; }
    44%, 100% { opacity: 0; background-position: 0 0; }
}

@keyframes skStep1 {
    0%, 46% { color: #fff; border-color: #05c7bb; }
    48%, 94% { color: #989ea1; border-color: rgba(255, 255, 255, 0.14); }
    100% { color: #fff; border-color: #05c7bb; }
}

@keyframes skStep2 {
    0%, 46% { color: #989ea1; border-color: rgba(255, 255, 255, 0.14); }
    48%, 92% { color: #fff; border-color: #05c7bb; }
    96%, 100% { color: #989ea1; border-color: rgba(255, 255, 255, 0.14); }
}

@keyframes skMini {
    0%, 54% { opacity: 0; transform: translateY(4px) rotate(-2deg); }
    60%, 92% { opacity: 1; transform: rotate(-2deg); }
    97%, 100% { opacity: 0; transform: rotate(-2deg); }
}

@keyframes skTag {
    0%, 64% { opacity: 0; }
    68%, 92% { opacity: 1; }
    97%, 100% { opacity: 0; }
}

/* Plays only while on screen (js/home.js adds .is-playing). */
.sk-scene:not(.is-playing) *,
.sk-scene:not(.is-playing) *::before,
.sk-scene:not(.is-playing) *::after { animation-play-state: paused; }

/* ── Reduced motion: the end state, nothing moves ──────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .sk-scene *,
    .sk-scene *::before,
    .sk-scene *::after { animation: none !important; }
    .sk-cell > img, .sk-cell > b, .sk-cell--formats > i, .sk-chip--clip, .sk-insp__box, .sk-mini, .sk-mini__tag { opacity: 1; }
    .sk-bg__after { clip-path: none; }
    .sk-bg__line, .sk-insp__smear { opacity: 0; }
    .sk-prompt > span { max-width: 100%; border-right: 0; }
    .sk-insp__box { border-color: var(--sk-ok); }
    .sk-mini { transform: rotate(-2deg); }
    .sk-step--2 { color: #fff; border-color: var(--sk-accent); }
}
