/* Videos page covers (pagesVideos.js + videoCovers.js).
   A course-channel cover: a coloured spine and paper wash per topic family,
   watercolour blooms and paper grain like the scenery, a topic kicker, a big
   Lora title, the problem typeset by KaTeX (your own videos) or the family's
   formula drawn faintly (shared lessons), a step badge and a small fox mark.
   Loaded after pages.css; its colour tokens are read, never redefined. */

.video-grid .video-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.video-grid .video-card:hover,
.video-grid .video-card:focus-within {
    transform: translateY(-2px);
    border-color: var(--c-line-strong);
    box-shadow: 0 10px 24px rgba(28, 36, 31, 0.1);
}

/* ---------- family palettes ---------- */

.cover {
    --cv-ink: var(--c-ink);
    --cv-tint: var(--c-accent);
    --cv-wash: var(--c-ivory);
    --cv-chip: rgba(255, 255, 255, 0.72);
    --cv-grain-blend: multiply;
    --cv-grain-opacity: 0.32;
}

.cover--calculus    { --cv-ink: #1d3a2d; --cv-tint: #2f5b47; --cv-wash: #e4ece2; }
.cover--fractions   { --cv-ink: #553c13; --cv-tint: #9b6b22; --cv-wash: #f2e9d7; }
.cover--polynomials { --cv-ink: #46303f; --cv-tint: #8a5f80; --cv-wash: #ede3ea; }
.cover--algebra     { --cv-ink: #22354c; --cv-tint: #4d6a8d; --cv-wash: #e3e9f0; }
.cover--geometry    { --cv-ink: #1e4446; --cv-tint: #4c8183; --cv-wash: #e0ecea; }
.cover--stats       { --cv-ink: #5a2f24; --cv-tint: #b0533b; --cv-wash: #f3e4dc; }

html[data-theme="dark"] .cover {
    --cv-ink: var(--c-ink);
    --cv-wash: #1f2c26;
    --cv-chip: rgba(10, 16, 13, 0.42);
    --cv-grain-blend: soft-light;
    --cv-grain-opacity: 0.5;
}

html[data-theme="dark"] .cover--calculus    { --cv-ink: #e3eee6; --cv-tint: #8fc2a6; --cv-wash: #1e2f27; }
html[data-theme="dark"] .cover--fractions   { --cv-ink: #f3e6cc; --cv-tint: #d8b06c; --cv-wash: #2e281c; }
html[data-theme="dark"] .cover--polynomials { --cv-ink: #f0e2ec; --cv-tint: #cfa1c3; --cv-wash: #2c2229; }
html[data-theme="dark"] .cover--algebra     { --cv-ink: #e2eaf4; --cv-tint: #9db7d8; --cv-wash: #1f2834; }
html[data-theme="dark"] .cover--geometry    { --cv-ink: #ddefee; --cv-tint: #8cc3c2; --cv-wash: #1b2d2d; }
html[data-theme="dark"] .cover--stats       { --cv-ink: #f6e1d9; --cv-tint: #e3917a; --cv-wash: #2f221e; }

/* ---------- the cover ---------- */

.video-grid .video-card > .video-thumb.cover {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    width: 100%;
    min-height: 0;
    aspect-ratio: 16 / 9;
    padding: 14px 16px 40px 22px;
    overflow: hidden;
    isolation: isolate;
    container-type: inline-size;
    border: 0;
    border-bottom: 1px solid var(--c-line);
    color: var(--cv-ink);
    text-align: left;
    cursor: pointer;
    box-sizing: border-box;
    background:
        radial-gradient(120% 95% at 104% -8%, color-mix(in srgb, var(--cv-tint) 26%, transparent) 0%, transparent 58%),
        radial-gradient(70% 80% at -6% 108%, color-mix(in srgb, var(--cv-tint) 16%, transparent) 0%, transparent 62%),
        linear-gradient(180deg, color-mix(in srgb, var(--cv-wash) 88%, #fff) 0%, var(--cv-wash) 100%);
    background-color: var(--cv-wash);
}

/* Paper grain, the same feel as the painted scenery. */
.video-thumb.cover::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: var(--cv-grain-opacity);
    mix-blend-mode: var(--cv-grain-blend);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.35 0 0 0 0 0.3 0 0 0 0 0.22 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
    background-size: 160px 160px;
}

/* The coloured spine down the left edge. */
.video-thumb.cover::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 6px;
    background: linear-gradient(180deg, var(--cv-tint), color-mix(in srgb, var(--cv-tint) 70%, var(--cv-ink)));
}

.cover-kicker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: 100%;
    font: 700 10px/1.2 var(--sans);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--cv-tint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cover-kicker::before {
    content: "";
    flex: none;
    width: 14px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}

.cover-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    max-width: 92%;
    overflow: hidden;
    font: 600 clamp(19px, 9.4cqi, 30px)/1.08 var(--serif);
    letter-spacing: -0.01em;
    text-wrap: balance;
    color: var(--cv-ink);
}

.cover-math {
    display: inline-block;
    max-width: 100%;
    margin-top: 2px;
    padding: 4px 10px 5px;
    overflow: hidden;
    white-space: nowrap;
    border-radius: 7px;
    border: 1px solid color-mix(in srgb, var(--cv-tint) 22%, transparent);
    background: var(--cv-chip);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
    transform: rotate(-0.6deg);
    font: 400 clamp(13px, 6cqi, 18px)/1.3 var(--serif);
    color: var(--cv-ink);
}

.cover-math .katex { font-size: 1em; }

/* The family's formula, drawn large and faint behind the words. */
.cover-motif {
    position: absolute;
    z-index: -1;
    right: 5%;
    bottom: 24%;
    font-size: clamp(22px, 11cqi, 38px);
    line-height: 1;
    color: var(--cv-tint);
    opacity: 0.16;
    transform: rotate(-7deg);
    white-space: nowrap;
    pointer-events: none;
}

/* With the problem typeset, the words and the math share the space. */
.cover.has-math .cover-motif { display: none; }
.cover.has-math .cover-title { font-size: clamp(17px, 7.6cqi, 24px); }
.cover.has-math .cover-math { font-size: clamp(12px, 5.2cqi, 16px); }
.cover-motif .katex { font-size: 1em; color: inherit; }

.cover-foot {
    position: absolute;
    left: 22px;
    right: 12px;
    bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cover-mark {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: 600 11px/1 var(--sans);
    letter-spacing: 0.02em;
    color: color-mix(in srgb, var(--cv-ink) 72%, transparent);
}

.cover-mark img {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex: none;
}

.cover-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px 3px 6px;
    border-radius: 999px;
    background: rgba(18, 24, 20, 0.8);
    color: #fff;
    font: 600 11px/1.2 var(--sans);
    white-space: nowrap;
}

.cover-badge svg,
.cover-play svg {
    fill: currentColor;
    stroke: none;
}

.cover-badge svg { width: 10px; height: 10px; }

.cover-play {
    position: absolute;
    top: 50%;
    left: 50%;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    color: var(--c-accent);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.86);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}

.cover-play svg { width: 20px; height: 20px; margin-left: 3px; }

.video-thumb.cover:hover .cover-play,
.video-thumb.cover:focus-visible .cover-play {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.video-thumb.cover:focus-visible {
    outline: 3px solid var(--c-focus);
    outline-offset: -3px;
}

html[data-theme="dark"] .cover-play { background: rgba(33, 47, 40, 0.94); color: #cfe3d6; }
html[data-theme="dark"] .cover-badge { background: rgba(0, 0, 0, 0.55); }

/* Small covers (narrow grid cells): drop the decoration, keep the words. */
@container (max-width: 230px) {
    .cover-motif { display: none; }
    .cover-kicker { font-size: 9px; }
    .cover-mark span,
    .cover-mark { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .video-grid .video-card,
    .cover-play { transition: none; }
    .video-grid .video-card:hover,
    .video-grid .video-card:focus-within { transform: none; }
}
