/* app/static/css/style.css */

:root {
    --brand-color: #07566a;
    --brand-color-2: #30bfd7;
    --accent-color: #f0b23b;
    --mint-surface: #edf8f3;
    --sky-surface: #dff7fb;
    --sand-surface: #fdf2dc;
    --ink-surface: #073f4e;
    --text-color-primary: #212529;
    --text-color-secondary: #6c757d;
    --background-color: #fbfcfd;
    --border-color: #dfe7ea;
    --card-background: #ffffff;
    --card-shadow: 0 10px 30px rgba(7, 86, 106, 0.06);
    --card-shadow-hover: 0 16px 38px rgba(7, 86, 106, 0.12);
    --card-border-radius: 8px;
    --module-header-bg: #f2f7f8;
    --transition-speed: 0.2s;
    --card-aspect-ratio: 4 / 3;  
    --badge-bg: #dff7fb;
    --badge-fg: #07566a;
    --code-bg: #0f172a;
    --code-fg: #e2e8f0;
}

[data-theme="dark"] {
    --brand-color: #7fdff0;
    --brand-color-2: #30bfd7;
    --accent-color: #f4c15c;
    --mint-surface: #10251f;
    --sky-surface: #10282e;
    --sand-surface: #2a2113;
    --ink-surface: #082f39;
    --text-color-primary: #e9ecef;
    --text-color-secondary: #adb5bd;
    --background-color: #0b0f14;
    --border-color: #1b2936;
    --card-background: #0f151c;
    --card-shadow: 0 1px 2px rgba(0,0,0,0.4);
    --card-shadow-hover: 0 6px 20px rgba(0,0,0,0.35);
    --module-header-bg: #0f1a24;
    --badge-bg: #0f2a32;
    --badge-fg: #7fdff0;
    --code-bg: #0b1220;
    --code-fg: #cfe3ff;
}


body {
    background-color: var(--background-color);
    color: var(--text-color-primary);
    overflow-x: hidden;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

main.container {
    padding-top: 2.4rem;
    padding-bottom: 4rem;
}

/* Wider container for lesson pages to accommodate camera and video side-by-side */
main.container.lesson-page {
    max-width: 1800px;
}

main.container.landing-page {
    max-width: 1320px;
}

main.container.dashboard-page,
main.container.chapter-page,
main.container.lesson-page,
main.container.contents-page {
    max-width: none;
    padding-left: .75rem;
    padding-right: .75rem;
}

main.container.lesson-page {
    padding-top: 1.2rem;
}

.hero {
    background: linear-gradient(135deg, rgba(13,110,253,0.12), rgba(102,16,242,0.12));
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
}
.hero h1 { margin-bottom: .25rem; }
.hero .actions { display:flex; gap:.55rem; flex-wrap:wrap; }

.landing-shell,
.curriculum-shell,
.chapter-shell {
    display: grid;
    gap: 2rem;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.landing-header,
.curriculum-header,
.chapter-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1.5rem;
}

.landing-header {
    justify-content: flex-start;
    align-items: flex-end;
    gap: clamp(1.25rem, 5vw, 3rem);
}

.landing-eyebrow,
.choice-kicker {
    margin: 0 0 .35rem 0;
    color: var(--brand-color);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.landing-header h1,
.curriculum-header h1,
.chapter-header h1 {
    margin: 0;
    color: var(--brand-color);
    font-size: clamp(2.8rem, 7vw, 5.4rem);
    line-height: .95;
}

.language-switcher {
    display: grid;
    grid-template-columns: minmax(150px, 1fr);
    gap: .55rem;
    max-width: 170px;
}

.language-tile {
    display: flex;
    align-items: center;
    gap: .55rem;
    min-height: 4.25rem;
    padding: .65rem .75rem;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
    color: inherit;
    text-decoration: none;
}

.language-tile strong,
.language-tile small {
    display: block;
    line-height: 1.15;
}

.language-tile small {
    color: var(--text-color-secondary);
    font-size: .76rem;
}

.language-tile.is-active {
    border-color: rgba(48, 191, 215, .75);
    box-shadow: 0 0 0 3px rgba(48, 191, 215, .16), var(--card-shadow);
}

.language-tile.is-disabled {
    opacity: .52;
    cursor: not-allowed;
}

.flag-mark {
    width: 2.1rem;
    height: 2.1rem;
    flex: 0 0 auto;
    border-radius: 50%;
    border: 1px solid rgba(7, 86, 106, .25);
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.65);
}

.flag-gsl {
    background: repeating-linear-gradient(0deg, #0d5eaf 0 5px, #fff 5px 10px);
}

.flag-dgs {
    background: linear-gradient(180deg, #111 0 33%, #dd0000 33% 66%, #ffce00 66%);
}

.flag-isl {
    background: linear-gradient(90deg, #169b62 0 33%, #fff 33% 66%, #ff883e 66%);
}

.flag-ngt {
    background: linear-gradient(180deg, #ae1c28 0 33%, #fff 33% 66%, #21468b 66%);
}

.start-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, .95fr);
    gap: .45rem;
    min-height: 500px;
}

.start-media-panel,
.start-choice-panel {
    border-radius: var(--card-border-radius);
    min-width: 0;
}

.start-media-panel {
    position: relative;
    display: grid;
    place-items: center;
    background: var(--mint-surface);
    overflow: hidden;
}

.landing-demo-video {
    width: min(66%, 430px);
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 50%;
    background: #000;
    box-shadow: 0 24px 60px rgba(7, 86, 106, .18);
}

.start-choice-panel {
    display: grid;
    align-content: center;
    gap: 1.2rem;
    padding: clamp(1.5rem, 4vw, 3rem);
    background: var(--sky-surface);
}

.start-choice-panel h2 {
    margin: 0;
    max-width: 12ch;
    color: var(--brand-color);
    font-size: clamp(2.1rem, 3.6vw, 3.8rem);
    line-height: 1;
}

.choice-actions {
    display: grid;
    gap: .8rem;
}

.choice-card {
    display: grid;
    gap: .2rem;
    padding: 1rem 1.1rem;
    border-radius: var(--card-border-radius);
    background: rgba(255,255,255,.72);
    border: 1px solid rgba(7, 86, 106, .15);
    color: inherit;
    text-decoration: none;
    transition: transform var(--transition-speed), box-shadow var(--transition-speed), background var(--transition-speed);
}

.choice-card:hover,
.choice-card:focus {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
    background: #fff;
}

.language-tile:focus-visible,
.choice-card:focus-visible,
.topic-card:focus-visible,
.chapter-lesson-row:focus-visible,
.chapter-back:focus-visible {
    outline: 3px solid rgba(240, 178, 59, .72);
    outline-offset: 4px;
}

.choice-card span {
    color: var(--brand-color);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.choice-card strong {
    color: var(--brand-color);
    font-size: 1.45rem;
    line-height: 1.1;
}

.choice-card small {
    color: var(--text-color-secondary);
}

.choice-card-primary {
    background: var(--ink-surface);
    color: #fff;
    border-color: var(--ink-surface);
}

.choice-card-primary span,
.choice-card-primary strong,
.choice-card-primary small {
    color: #fff;
}

.landing-footnote {
    margin: -.75rem 0 0 0;
    max-width: 58ch;
    color: var(--text-color-secondary);
}

.badge {
    display: inline-block;
    background: var(--badge-bg);
    color: var(--badge-fg);
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
}

a.badge.badge-link {
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}

a.badge.badge-link:hover,
a.badge.badge-link:focus-visible {
    background: var(--brand-color);
    color: #fff;
}

pre, code, kbd, samp {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
pre {
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: 12px;
    padding: .75rem;
    border: 1px solid var(--border-color);
}

pre.code-block {
    margin: 0;
    font-size: .9rem;
    line-height: 1.5;
}

.card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    box-shadow: var(--card-shadow);
    padding: 1rem 1.25rem;
}


.message {
    padding: 1rem;
    margin-bottom: 1rem;
    border-left: 4px solid;
    border-radius: 4px;
}
.message.success {
    border-color: #198754;
    background-color: rgba(25, 135, 84, 0.1);
}
.message.danger {
    border-color: #dc3545;
    background-color: rgba(220, 53, 69, 0.1);
}

/* ==========================================================================
   2. DASHBOARD: MODULE ACCORDION
   ========================================================================== */

.module-details {
    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    margin-bottom: 1rem;
    box-shadow: var(--card-shadow);
}


.module-details summary {
    list-style: none; 
    cursor: pointer;
    padding: .75rem 1.1rem;
    font-size: 1.25rem;
    font-weight: 600;
    position: relative;
    user-select: none; 
    transition: background-color var(--transition-speed) ease;
}
.module-details summary::-webkit-details-marker {
    display: none; 
}


.module-details summary::after {
    content: '';
    position: absolute;
    right: 1.5rem;
    top: 50%;
    width: 0.6rem;
    height: 0.6rem;
    border-style: solid;
    border-color: var(--text-color-secondary);
    border-width: 0 2px 2px 0; 
    transform: translateY(-75%) rotate(45deg);
    transition: transform var(--transition-speed) ease;
}


.module-details[open] > summary {
    border-bottom: 1px solid var(--border-color);
}
.module-details[open] > summary::after {
    transform: translateY(-50%) rotate(225deg);
}

.module-progress {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin-left: 1rem;
}
.module-progress progress {
    width: 160px;
    height: 10px;
}


/* ==========================================================================
   3. DASHBOARD: LESSON GRID & CARDS
   ========================================================================== */


.lesson-grid {
    display: grid;
    /* Create responsive columns: they will be at least 200px wide,
       and the grid will fit as many as possible per row. */
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    padding: 1rem;
}


.lesson-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}


.lesson-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    overflow: hidden; 
    transition: transform var(--transition-speed) ease, box-shadow var(--transition-speed) ease;
    display: flex;
    flex-direction: column; 
}
.lesson-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--card-shadow-hover);
}

.lesson-card.completed {
    box-shadow: 0 0 0 2px rgba(25, 135, 84, 0.3), var(--card-shadow);
}


/* ==========================================================================
   4. API EXPLORER
   ========================================================================== */

.api-explorer-hero {
    background: linear-gradient(135deg, rgba(13,110,253,0.12), rgba(102,16,242,0.08));
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.75rem 1.5rem;
    margin-bottom: 1.8rem;
    box-shadow: var(--card-shadow);
}

.api-explorer-hero h1 {
    margin-bottom: .5rem;
}

.api-explorer-hero p {
    max-width: 60ch;
    color: var(--text-color-secondary);
}

.api-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: .75rem;
    margin-top: 1.25rem;
}

.api-meta-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: .9rem 1.1rem;
    box-shadow: var(--card-shadow);
}

.api-meta-card h3 {
    margin-bottom: .35rem;
    font-size: 1rem;
}

.api-meta-card p {
    margin: 0;
    font-size: .95rem;
    color: var(--text-color-secondary);
}

.api-explorer-layout {
    display: grid;
    grid-template-columns: minmax(0, 270px) minmax(0, 1fr);
    gap: 1.6rem;
    align-items: start;
}

.api-explorer-nav {
    position: sticky;
    top: 5rem;
    display: flex;
    flex-direction: column;
    gap: .7rem;
}

.api-explorer-nav h2 {
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-color-secondary);
    margin: 0;
}

.api-explorer-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.api-explorer-nav a {
    display: block;
    padding: .45rem .6rem;
    border-radius: 8px;
    color: inherit;
    border: 1px solid transparent;
    transition: border-color var(--transition-speed) ease, background-color var(--transition-speed) ease;
}

.api-explorer-nav .nav-label {
    font-weight: 600;
    display: block;
}

.api-explorer-nav a:hover,
.api-explorer-nav a:focus {
    border-color: var(--border-color);
    background: rgba(13, 110, 253, 0.08);
    outline: none;
}

.api-explorer-nav small {
    display: block;
    color: var(--text-color-secondary);
}

.api-section {
    margin-bottom: 1.75rem;
}

.api-section > h2 {
    margin-bottom: .35rem;
}

.api-section > p {
    color: var(--text-color-secondary);
    margin-bottom: 1rem;
}

.endpoint-grid {
    display: grid;
    gap: 1rem;
}

.endpoint-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.endpoint-header {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem .55rem;
    align-items: center;
}

.method-badge {
    font-size: .85rem;
    font-weight: 600;
    text-transform: uppercase;
    padding: .3rem .55rem;
    border-radius: 6px;
    letter-spacing: .05em;
    color: #fff;
}

.method-badge.get { background: #2563eb; }
.method-badge.post { background: #22c55e; }

.endpoint-path {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 1rem;
    background: rgba(15,23,42,0.08);
    padding: .2rem .5rem;
    border-radius: 6px;
}

.endpoint-tag {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    background: var(--badge-bg);
    color: var(--badge-fg);
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.endpoint-body {
    display: grid;
    gap: .7rem;
}

@media (min-width: 960px) {
    .endpoint-body.two-column {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.endpoint-body h3 {
    margin-bottom: .2rem;
    font-size: .95rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.endpoint-body label {
    font-weight: 600;
    font-size: .9rem;
    color: var(--text-color-primary);
}

.endpoint-body input,
.endpoint-body select,
.endpoint-body textarea {
    width: 100%;
}

.api-callout {
    border-left: 4px solid var(--brand-color);
    padding: .75rem 1rem;
    background: rgba(13,110,253,0.08);
    border-radius: 12px;
    color: var(--text-color-secondary);
}

[data-theme="dark"] .api-callout {
    background: rgba(13,110,253,0.18);
}

.try-it-btn {
    align-self: flex-start;
}

.output-area {
    min-height: 2.5em;
    max-height: 260px;
    overflow: auto;
    background: #0b1220;
    color: #cfe3ff;
    border-radius: 12px;
    padding: .75rem;
    border: 1px solid rgba(148, 163, 184, 0.25);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: .9rem;
}

.output-area.empty {
    display: flex;
    align-items: center;
    color: var(--text-color-secondary);
    background: var(--card-background);
}

@media (max-width: 1100px) {
    .api-explorer-layout {
        grid-template-columns: 1fr;
    }

    .api-explorer-nav {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1rem;
        background: var(--card-background);
        box-shadow: var(--card-shadow);
    }

    .api-explorer-nav h2 {
        width: 100%;
    }

    .api-explorer-nav ul {
        flex-direction: row;
        flex-wrap: wrap;
        gap: .35rem;
    }

    .api-explorer-nav a {
        padding: .35rem .5rem;
    }
}


.page-header {
    display: flex;
    flex-direction: column;
    gap: .25rem;
    margin-bottom: 1.2rem;
}

.page-header h1,
.page-header h2 {
    margin: 0;
}

.page-header p {
    color: var(--text-color-secondary);
    max-width: 70ch;
}

.badge-group {
    display: inline-flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}

.metric-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.curriculum-header {
    align-items: end;
}

.curriculum-header p {
    margin: .8rem 0 0 0;
    max-width: 58ch;
    color: var(--text-color-secondary);
}

.topic-levels {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .35rem;
    align-items: stretch;
}

.topic-level {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 1rem;
    min-width: 0;
    padding: .75rem;
    border-radius: var(--card-border-radius);
}

.level-tone-1 {
    background: var(--mint-surface);
}

.level-tone-2 {
    background: var(--sky-surface);
}

.level-tone-3 {
    background: var(--sand-surface);
}

.level-heading {
    display: flex;
    gap: .9rem;
    align-items: flex-start;
}

.level-heading h2 {
    margin: .1rem 0 .2rem 0;
    font-size: clamp(1.6rem, 3vw, 2.4rem);
    line-height: 1;
}

.level-heading p {
    margin: 0;
    color: var(--text-color-secondary);
    line-height: 1.45;
}

.level-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 3.4rem;
    height: 3.4rem;
    border-radius: 50%;
    background: var(--brand-color-2);
    color: #fff;
    font-size: 1.45rem;
    font-weight: 900;
    line-height: 1;
}

.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    grid-auto-rows: 1fr;
    align-content: start;
    gap: .55rem;
}

.topic-card {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: .8rem;
    padding: 1rem;
    min-height: 20rem;
    height: 100%;
    background: var(--card-background);
    border: 1px solid rgba(7, 86, 106, .14);
    border-radius: var(--card-border-radius);
    color: inherit;
    text-decoration: none;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.topic-card-body {
    align-self: end;
}

.topic-card:hover,
.topic-card:focus {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
}

.topic-card-media {
    display: grid;
    place-items: center;
    width: 7rem;
    height: 7rem;
    justify-self: center;
    align-self: center;
    overflow: hidden;
    border-radius: 50%;
    background: var(--brand-color-2);
}

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

.topic-card-placeholder {
    color: #fff;
    font-size: 2.4rem;
    font-weight: 900;
}

.topic-card-body {
    display: grid;
    gap: .35rem;
}

.topic-card small {
    color: var(--text-color-secondary);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.topic-card strong {
    font-size: 1.25rem;
    line-height: 1.15;
}

.topic-progress-line,
.chapter-progress-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: .6rem;
}

.topic-progress-line progress,
.chapter-progress-line progress {
    height: .55rem;
    margin: 0;
}

.topic-progress-line span,
.chapter-progress-line span {
    color: var(--text-color-secondary);
    font-size: .82rem;
    font-weight: 700;
    white-space: nowrap;
}

.topic-context-tile {
    display: block;
    width: calc(100% + 2rem);
    aspect-ratio: 16 / 9;
    margin: .55rem -1rem -1rem;
    overflow: hidden;
    border-radius: 0 0 calc(var(--card-border-radius) - 1px) calc(var(--card-border-radius) - 1px);
    background: var(--module-header-bg);
}

.topic-context-tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chapter-back {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    justify-self: start;
    width: fit-content;
    padding: .35rem .65rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--card-background);
    color: var(--brand-color);
    font-weight: 700;
    text-decoration: none;
    box-shadow: var(--card-shadow);
}

.chapter-back:hover {
    border-color: rgba(48, 191, 215, .75);
    color: var(--brand-color);
}

.chapter-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    width: 100%;
}

.chapter-progress-summary {
    display: grid;
    justify-items: end;
    gap: .2rem;
    min-width: 10rem;
    padding: .9rem 1rem;
    background: var(--mint-surface);
    border-radius: var(--card-border-radius);
    color: var(--brand-color);
}

.chapter-progress-summary strong {
    font-size: 2rem;
    line-height: 1;
}

.chapter-progress-summary small {
    color: var(--text-color-secondary);
}

.chapter-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}

.lesson-progress-list {
    display: grid;
    gap: .8rem;
}

.chapter-lesson-row {
    display: grid;
    grid-template-columns: 6.5rem minmax(0, 1fr);
    align-items: center;
    gap: 1rem;
    padding: .8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    background: var(--card-background);
    color: inherit;
    text-decoration: none;
    box-shadow: var(--card-shadow);
    transition: transform var(--transition-speed), box-shadow var(--transition-speed);
}

.chapter-lesson-row:hover,
.chapter-lesson-row:focus {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.chapter-lesson-media {
    width: 6.5rem;
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: hidden;
    background: #000;
}

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

.chapter-lesson-main {
    display: grid;
    gap: .6rem;
    min-width: 0;
}

.chapter-lesson-topline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .8rem;
}

.chapter-lesson-topline strong {
    min-width: 0;
    font-size: 1.2rem;
    line-height: 1.2;
}

.empty-state {
    margin: 0;
    padding: 1rem;
    color: var(--text-color-secondary);
}

@media (max-width: 1080px) {
    .landing-header,
    .curriculum-header,
    .chapter-header {
        flex-direction: column;
        align-items: stretch;
    }

    .language-switcher {
        max-width: 260px;
        grid-template-columns: minmax(150px, 1fr);
    }

    .start-board,
    .chapter-board {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .start-media-panel {
        min-height: 420px;
    }

    .topic-levels {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    nav.container-fluid {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: .4rem;
    }

    nav.container-fluid ul {
        flex-wrap: wrap;
        gap: .35rem .65rem;
    }

    nav.container-fluid > ul {
        width: 100%;
    }

    nav.container-fluid > ul:last-child {
        justify-content: flex-start;
    }

    nav.container-fluid a {
        font-size: .88rem;
    }

    main.container {
        padding-top: 1.35rem;
        padding-bottom: 2.4rem;
    }

    .landing-header h1,
    .curriculum-header h1,
    .chapter-header h1 {
        font-size: clamp(2.25rem, 11vw, 3rem);
    }

    .language-switcher {
        grid-template-columns: minmax(0, 1fr);
    }

    .language-tile {
        min-height: 3.6rem;
        padding: .55rem;
    }

    .flag-mark {
        width: 1.8rem;
        height: 1.8rem;
    }

    .start-media-panel {
        min-height: 340px;
    }

    .landing-demo-video {
        width: min(74%, 300px);
    }

    .start-choice-panel h2 {
        max-width: 11ch;
    }

    .topic-level {
        padding: 1rem;
    }

    .chapter-title-row {
        flex-direction: column;
        align-items: stretch;
    }

    .chapter-progress-summary {
        justify-items: start;
    }

    .chapter-lesson-row {
        grid-template-columns: 4.6rem minmax(0, 1fr);
        gap: .75rem;
    }

    .chapter-lesson-media {
        width: 4.6rem;
    }

    .chapter-lesson-topline {
        flex-direction: column;
        align-items: flex-start;
        gap: .45rem;
    }
}

.metric-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1.1rem;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.metric-card h3 {
    margin: 0;
    font-size: .95rem;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--text-color-secondary);
}

.metric-card strong {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--text-color-primary);
}

.metric-card small {
    color: var(--text-color-secondary);
}

.split-layout {
    display: grid;
    gap: 1.25rem;
}

@media (min-width: 992px) {
    .split-layout.two-column {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
}

.section-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    padding: 1.1rem;
    box-shadow: var(--card-shadow);
}

.section-card h3 {
    margin-top: 0;
}

.video-container {
    position: relative;
    border-radius: var(--card-border-radius);
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border-color);
}

.video-container video,
.video-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.video-container canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.control-group {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}

.control-group label {
    font-weight: 600;
    font-size: .9rem;
}

.form-card {
    max-width: 420px;
    margin: 0 auto;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
}

.form-card form {
    display: grid;
    gap: .75rem;
    margin-top: 1rem;
}

.form-card form > div {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}

.form-card button[type="submit"] {
    margin-top: .3rem;
}

.form-card footer {
    margin-top: .8rem;
    color: var(--text-color-secondary);
}

.form-card .form-intro {
    margin: .4rem 0 0 0;
    color: var(--text-color-secondary);
}

.page-section {
    margin-top: 1.4rem;
}

.help-text {
    margin-top: .5rem;
    color: var(--text-color-secondary);
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .25rem .65rem;
    border-radius: 999px;
    background: var(--badge-bg);
    color: var(--badge-fg);
    font-size: .8rem;
    font-weight: 600;
}

.pill.success {
    background: rgba(25, 135, 84, 0.18);
    color: #0f5132;
}

[data-theme="dark"] .pill.success {
    color: #74f0b0;
}

.live-status-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.live-status-pill {
    min-width: 5.5rem;
    justify-content: center;
}

.live-status-pill.is-good {
    background: rgba(25, 135, 84, 0.18);
    color: #0f5132;
}

.live-status-pill.is-on-track {
    background: rgba(255, 193, 7, 0.22);
    color: #664d03;
}

.live-status-pill.is-late {
    background: rgba(253, 126, 20, 0.2);
    color: #7a3b00;
}

.live-status-pill.is-off-path {
    background: rgba(220, 53, 69, 0.18);
    color: #842029;
}

[data-theme="dark"] .live-status-pill.is-good {
    color: #74f0b0;
}

[data-theme="dark"] .live-status-pill.is-on-track {
    color: #ffe08a;
}

[data-theme="dark"] .live-status-pill.is-late {
    color: #ffba75;
}

[data-theme="dark"] .live-status-pill.is-off-path {
    color: #ff9aa5;
}

.live-score-details {
    margin-top: .55rem;
    color: var(--text-color-secondary);
    font-size: .85rem;
}

.live-score-details summary {
    cursor: pointer;
    font-weight: 600;
}

.live-score-values {
    display: flex;
    gap: .85rem;
    flex-wrap: wrap;
    margin-top: .35rem;
}

.reference-pose-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: .1rem;
}

.reference-pose-controls .pill {
    min-width: 6rem;
    justify-content: center;
    flex: 0 0 auto;
}

.reference-keyframe-controls {
    display: inline-flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    overflow: hidden;
    background: var(--card-background);
}

.reference-keyframe-controls button {
    width: auto;
    margin: 0;
    border: 0;
    border-right: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-color-primary);
    padding: .32rem .65rem;
    border-radius: 0;
    font-size: .8rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
}

.reference-keyframe-controls button:last-child {
    border-right: 0;
}

.reference-keyframe-controls button[aria-pressed="true"] {
    background: rgba(13, 110, 253, 0.16);
    color: #084298;
}

[data-theme="dark"] .reference-keyframe-controls button[aria-pressed="true"] {
    color: #9ec5fe;
}

.segment-timeline {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: -.15rem 0 .75rem 0;
    min-height: 2rem;
}

.segment-gate {
    position: relative;
    flex: 1 1 0;
    min-width: 1.8rem;
    height: .6rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(108, 117, 125, 0.18);
    transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.segment-gate::after {
    content: attr(data-label);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, .2rem);
    color: var(--text-color-secondary);
    font-size: .68rem;
    font-weight: 700;
    line-height: 1;
}

.segment-gate.is-active {
    border-color: rgba(13, 110, 253, 0.7);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.18);
    transform: translateY(-1px);
}

.segment-gate.is-good {
    background: rgba(25, 135, 84, 0.8);
    border-color: rgba(25, 135, 84, 0.95);
}

.segment-gate.is-on-track {
    background: rgba(255, 193, 7, 0.78);
    border-color: rgba(255, 193, 7, 0.95);
}

.segment-gate.is-late {
    background: rgba(253, 126, 20, 0.78);
    border-color: rgba(253, 126, 20, 0.95);
}

.segment-gate.is-off-path {
    background: rgba(220, 53, 69, 0.72);
    border-color: rgba(220, 53, 69, 0.9);
}

.status-table {
    margin-top: 1.25rem;
}

.status-table th,
.status-table td {
    vertical-align: top;
}


.lesson-card-header {
    position: relative; 
    background-color: #000;
    aspect-ratio: var(--card-aspect-ratio);
}

.status-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #198754;
    color: #fff;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    z-index: 2;
}

/* Tables (Status page) */
table { border: 1px solid var(--border-color); border-radius: 12px; overflow: hidden; }
thead tr { background: var(--module-header-bg); }

.lesson-thumbnail-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lesson-thumbnail-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Show video and hide image on hover */
.lesson-card:hover .lesson-thumbnail-video {
    opacity: 1;
}

.lesson-card:hover .lesson-thumbnail-img {
    opacity: 0;
}


.lesson-card footer {
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto; 
}


/* ==========================================================================
   4. LESSON PAGE STYLES (Kept for consistency)
   ========================================================================== */

#live-view {
    min-height: 480px;
    background: #111;
}
#webcam, #overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    transform: rotateY(180deg);
}
#feedback-panel {
    margin-top: 1em;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    background-color: var(--background-color);
}
#avatar-frame {
    width: 100%;
    height: 480px;
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    background-color: var(--background-color);
}

/* Compact buttons inside control-groups (overrides Pico's full-width default) */
.control-group > button,
.control-group > .button {
    width: auto;
    margin: 0;
    padding: .35rem .8rem;
    font-size: .9rem;
    line-height: 1.2;
}

.panel-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .65rem;
}

.panel-title-row h3 {
    margin: 0;
}

/* ==========================================================================
   5. COACH CHAT INTERFACE
   ========================================================================== */

/* Floating chat button */
.coach-chat-button {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand-color), var(--brand-color-2));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 1000;
}

.coach-chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.lesson-page .coach-chat-button {
    position: static;
    margin: .75rem 0 0 .25rem;
}

/* Chat panel */
.coach-chat-panel {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 380px;
    max-width: calc(100vw - 4rem);
    height: 500px;
    max-height: calc(100vh - 8rem);
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    z-index: 1001;
    overflow: hidden;
}

/* Chat header */
.coach-chat-header {
    background: linear-gradient(135deg, var(--brand-color), var(--brand-color-2));
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.coach-chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.coach-chat-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.coach-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Chat messages */
.coach-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.coach-message {
    display: flex;
    gap: 0.5rem;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.coach-message.bot {
    align-self: flex-start;
}

.coach-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.coach-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2rem;
}

.coach-message.bot .coach-message-avatar {
    background: linear-gradient(135deg, var(--brand-color), var(--brand-color-2));
    color: white;
}

.coach-message.user .coach-message-avatar {
    background: var(--badge-bg);
    color: var(--badge-fg);
}

.coach-message-content {
    background: var(--background-color);
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    max-width: 75%;
    border: 1px solid var(--border-color);
}

.coach-message.user .coach-message-content {
    background: var(--badge-bg);
    color: var(--badge-fg);
}

.coach-message-content p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.coach-message-content strong {
    color: var(--brand-color);
}

/* Chat input */
.coach-chat-input {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    background: var(--background-color);
}

.coach-chat-input input {
    flex: 1;
    padding: 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-background);
    color: var(--text-color-primary);
    font-size: 0.9rem;
}

.coach-chat-input input:focus {
    outline: none;
    border-color: var(--brand-color);
}

.coach-chat-input button {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--brand-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.coach-chat-input button:hover {
    background: var(--brand-color-2);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .coach-chat-panel {
        width: calc(100vw - 2rem);
        height: calc(100vh - 10rem);
        right: 1rem;
        bottom: 1rem;
    }

    .coach-chat-button {
        right: 1rem;
        bottom: 1rem;
    }
}

/* Compact icon-sized theme toggle in the nav */
.theme-toggle-btn {
    width: 2rem;
    height: 2rem;
    margin-left: .5rem;
    padding: 0;
    border-radius: 8px;
    line-height: 1;
    font-size: .95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   KEYFRAME PICKER
   ========================================================================== */

main.container.keyframe-picker-page {
    max-width: none;
    padding-top: 6rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.kf-admin-shell,
.kf-picker {
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

article.kf-admin-shell,
article.kf-picker {
    margin-left: 0;
    margin-right: 0;
    padding: 0;
}

.kf-page-header {
    display: grid;
    gap: .15rem;
    margin-bottom: .85rem;
}

.kf-page-intro {
    margin: .15rem 0 0 0;
    color: var(--text-color-secondary);
    max-width: 58ch;
}

.kf-landing-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .55rem;
    margin-top: 1rem;
}
.kf-landing-item {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    min-height: 6.25rem;
    padding: .8rem .9rem;
    background: var(--mint-surface);
    border: 1px solid transparent;
    border-radius: var(--card-border-radius);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed), transform var(--transition-speed);
}
.kf-landing-item:hover,
.kf-landing-item:focus-visible {
    border-color: var(--brand-color);
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-1px);
}
.kf-landing-title {
    color: var(--brand-color);
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
}
.kf-landing-meta {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}
.pill.pill-ok {
    background: rgba(25, 135, 84, 0.18);
    color: #0f5132;
}
.pill.pill-warn {
    background: rgba(220, 53, 69, 0.18);
    color: #842029;
}
[data-theme="dark"] .pill.pill-ok { color: #74f0b0; }
[data-theme="dark"] .pill.pill-warn { color: #ffb3bd; }

.badge.badge-link {
    text-decoration: none;
}

/* Pico ships button { width:100%; display:block }, which makes every
   button inside a flex row stack full-width. Override locally. */
.kf-picker button,
.kf-picker .pill {
    width: auto;
}
.kf-picker .kf-pick-pill {
    display: inline-flex;
}

.kf-picker {
    outline: none;
}
.kf-picker:focus,
.kf-picker:focus-within {
    /* shortcut hint becomes active state — see .kf-shortcut-hint */
}

.kf-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: .75rem;
    padding: 0;
    margin-bottom: .75rem;
    background: transparent;
    border: 0;
    border-radius: 0;
}

header.kf-toolbar {
    margin-left: 0;
    margin-right: 0;
}

.kf-toolbar-heading {
    display: grid;
    gap: .15rem;
    min-width: 0;
}

.kf-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: .45rem;
}

.kf-toolbar-title {
    margin: 0;
    color: var(--brand-color);
    font-size: clamp(2.2rem, 5vw, 3.3rem);
    font-weight: 800;
    line-height: 1.2;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kf-toolbar-spacer { flex: 1 1 auto; }
.kf-status-pill[data-state="loading"]  { background: rgba(255,193,7,0.18);  color: #856404; }
.kf-status-pill[data-state="ready"]    { background: rgba(25,135,84,0.18);  color: #0f5132; }
.kf-status-pill[data-state="dirty"]    { background: rgba(220,53,69,0.18);  color: #842029; }
[data-theme="dark"] .kf-status-pill[data-state="loading"] { color: #ffe082; }
[data-theme="dark"] .kf-status-pill[data-state="ready"]   { color: #74f0b0; }
[data-theme="dark"] .kf-status-pill[data-state="dirty"]   { color: #ffb3bd; }

.kf-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--card-border-radius);
    background: var(--module-header-bg);
    color: var(--brand-color);
    text-decoration: none;
    font-weight: 800;
}

.kf-icon-link:hover,
.kf-icon-link:focus-visible {
    background: var(--brand-color);
    color: #fff;
}

.kf-publish {
    margin: 0;
    width: auto;
    padding: .35rem .85rem;
    font-size: .85rem;
    line-height: 1.2;
}
.kf-publish:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.pill.pill-muted {
    background: var(--module-header-bg);
    color: var(--text-color-secondary);
    font-weight: 500;
    font-size: .72rem;
}

.kf-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.58fr) minmax(360px, .95fr);
    gap: .45rem;
    align-items: start;
    min-width: 0;
}
.kf-stage > * { min-width: 0; }

.kf-frame-view {
    grid-column: 1;
    grid-row: 1 / span 3;
    display: grid;
    gap: .55rem;
    padding: .75rem;
    background: var(--mint-surface);
    border: 0;
    border-radius: var(--card-border-radius);
    overflow: hidden;
}
.kf-transport[data-disabled="true"] {
    opacity: .65;
}
.kf-video-wrap {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 8.6;
    background: #000;
    border-radius: var(--card-border-radius);
    position: relative;
    overflow: hidden;
}
.kf-video-wrap video,
.kf-frame-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.kf-transport {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
    padding: 0;
    border-top: 0;
    background: transparent;
}
.kf-transport button {
    width: auto;
    margin: 0;
    padding: .25rem .6rem;
    line-height: 1.2;
    min-width: 2.25rem;
    border-radius: 6px;
}
.kf-transport .kf-pick-btn {
    padding: .25rem .85rem;
}
.kf-transport .kf-sep {
    width: 1px;
    align-self: stretch;
    background: var(--border-color);
    margin: 0 .35rem;
}
.kf-picker .kf-counter {
    display: inline-flex;
    align-items: center;
    gap: .85rem;
    margin-left: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .85rem;
    color: var(--text-color-secondary);
    white-space: nowrap;
}
.kf-picker .kf-counter strong {
    color: var(--text-color-primary);
    font-weight: 600;
}
.kf-picker .kf-counter-fps {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}
.kf-picker .kf-fps-input {
    width: 3.25rem;
    padding: .1rem .35rem;
    margin: 0;
    font-family: inherit;
    font-size: .8rem;
    height: auto;
    line-height: 1.2;
}

.kf-analysis {
    grid-column: 2;
    grid-row: 1;
    background: var(--sky-surface);
    color: var(--text-color-primary);
    border: 1px solid rgba(7, 86, 106, .08);
    border-radius: var(--card-border-radius);
    padding: .65rem .8rem;
}
.kf-analysis > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .25rem 0;
    color: var(--text-color-secondary);
    font-size: .85rem;
}
.kf-analysis > summary::-webkit-details-marker { display: none; }
.kf-analysis > summary::before {
    content: '▾';
    font-size: .7rem;
    color: var(--text-color-secondary);
    transition: transform var(--transition-speed);
    margin-right: .15rem;
}
.kf-analysis:not([open]) > summary::before { transform: rotate(-90deg); }
.kf-analysis-title { color: var(--brand-color); font-weight: 800; }
.kf-timeline {
    display: block;
    width: 100%;
    height: 110px;
    margin-top: .15rem;
    border-radius: var(--card-border-radius);
    background: rgba(255, 255, 255, .72);
}
.kf-timeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding-top: .35rem;
    font-size: .75rem;
    color: var(--text-color-secondary);
}
.kf-timeline-legend .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: .35rem;
    vertical-align: middle;
}
.kf-timeline-legend .dot-motion   { background: rgba(13,110,253,0.55); }
.kf-timeline-legend .dot-auto     { background: rgba(120,120,120,0.85); transform: rotate(45deg); border-radius: 0; }
.kf-timeline-legend .dot-manual   { background: rgba(220,53,69,0.95); }
.kf-timeline-legend .dot-playhead { background: rgba(25,135,84,0.95); width: 3px; }

.kf-thumbstrip-wrap {
    grid-column: 1 / -1;
    grid-row: 4;
    background: var(--mint-surface);
    border: 0;
    border-radius: var(--card-border-radius);
    padding: .45rem;
    min-width: 0;
    overflow: hidden;
}
.kf-thumbstrip {
    display: flex;
    gap: .35rem;
    overflow-x: auto;
    padding-bottom: .25rem;
    scrollbar-width: thin;
    max-width: 100%;
}
.kf-picker .kf-thumb {
    flex: 0 0 auto;
    width: 96px;
    height: 64px;
    padding: 0;
    margin: 0;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--module-header-bg);
    color: var(--text-color-secondary);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.kf-thumb:hover    { border-color: var(--brand-color); }
.kf-thumb.is-pick     { border-color: rgba(220,53,69,0.95); }
.kf-thumb.is-current  { box-shadow: 0 0 0 2px rgba(25,135,84,0.95); }
.kf-thumb.has-image   { background: #1a1a1a; color: #fff; border-color: transparent; }
.kf-thumb.has-image.is-pick    { border-color: rgba(220,53,69,0.95); }
.kf-thumb-img {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
}
.kf-thumb-lbl {
    position: absolute;
    bottom: 3px;
    right: 4px;
    font-size: .7rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    padding: 0 .25rem;
    border-radius: 3px;
}
.kf-thumb.has-image .kf-thumb-lbl {
    background: rgba(0,0,0,0.55);
    color: #fff;
}

.kf-picks-row {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .65rem;
    background: var(--sky-surface);
    color: var(--text-color-primary);
    border: 1px solid rgba(7, 86, 106, .08);
    border-radius: var(--card-border-radius);
    padding: .65rem .8rem;
}
.kf-picks-label {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}
.kf-picks-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5rem;
    height: 1.4rem;
    padding: 0 .4rem;
    border-radius: 999px;
    background: rgba(7, 86, 106, .1);
    color: var(--brand-color);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .8rem;
    font-weight: 500;
}
.kf-picks-list {
    display: inline-flex;
    flex-wrap: wrap;
    gap: .35rem;
    flex: 1 1 auto;
}
.kf-picks-list em {
    color: var(--text-color-secondary);
}
.kf-pick-pill {
    border: 1px solid transparent;
    cursor: pointer;
    background: rgba(220,53,69,0.14);
    color: #842029;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    padding: .15rem .55rem;
    font-size: .78rem;
    line-height: 1.3;
}
.kf-pick-pill:hover { background: rgba(220,53,69,0.28); }
.kf-pick-pill.is-current {
    border-color: rgba(25,135,84,0.85);
    background: rgba(220,53,69,0.28);
}
.kf-pick-pill .pill-n { font-weight: 700; }
.kf-pick-pill .pill-sep { opacity: .55; padding: 0 .2rem; }
.kf-pick-pill .pill-t { color: var(--text-color-secondary); }
[data-theme="dark"] .kf-pick-pill   { color: #ffb3bd; }
[data-theme="dark"] .kf-pick-pill .pill-t { color: #c9b9bb; }

.kf-mini {
    padding: .2rem .65rem;
    margin: 0;
    font-size: .8rem;
}

.kf-shortcuts {
    position: relative;
    display: inline-flex;
    background: transparent;
    color: var(--text-color-primary);
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
}

.kf-shortcuts-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 2rem;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-color-secondary);
    cursor: pointer;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
    box-shadow: none;
    transition: color .15s ease;
}

.kf-shortcuts-toggle:hover,
.kf-shortcuts-toggle:focus-visible,
.kf-shortcuts-toggle[aria-expanded="true"] {
    background: transparent;
    color: var(--brand-color);
    box-shadow: none;
}

.kf-shortcuts-panel {
    position: absolute;
    top: calc(100% + .4rem);
    right: 0;
    z-index: 20;
    width: min(19rem, calc(100vw - 2rem));
    margin: 0;
    padding: .7rem .9rem .7rem 1.45rem;
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    background: var(--card-background);
    box-shadow: var(--card-shadow-hover);
    font-size: .85rem;
    color: var(--text-color-secondary);
}

.kf-shortcuts-panel[hidden] {
    display: none;
}

.kf-shortcuts-panel kbd {
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: 4px;
    padding: .05rem .35rem;
    font-size: .75rem;
}

.kf-analysis .pill-muted {
    background: rgba(7, 86, 106, .1);
    color: var(--text-color-secondary);
}

@media (max-width: 1080px) {
    .kf-toolbar {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .kf-toolbar-actions {
        justify-content: flex-start;
    }

    .kf-stage {
        grid-template-columns: 1fr;
    }

    .kf-frame-view,
    .kf-analysis,
    .kf-picks-row,
    .kf-thumbstrip-wrap {
        grid-column: 1;
        grid-row: auto;
    }

    .kf-video-wrap {
        aspect-ratio: 16 / 9;
    }
}

/* ==========================================================================
   6. TOPIC COMPLETION STATE
   ========================================================================== */

.topic-card.is-complete {
    border-color: rgba(25, 135, 84, .45);
    box-shadow: 0 0 0 2px rgba(25, 135, 84, .25), var(--card-shadow);
}

.topic-card.is-complete .topic-card-media {
    box-shadow: 0 0 0 3px rgba(25, 135, 84, .35);
}

/* ==========================================================================
   7. LESSON STAGE (sketch p6a: mint reference / dark teal practice)
   ========================================================================== */

.lesson-shell {
    display: grid;
    gap: .75rem;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.lesson-stage-header {
    display: grid;
    gap: .15rem;
    margin-bottom: .1rem;
}

.lesson-context {
    margin: 0;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .35rem .9rem;
    color: var(--text-color-secondary);
    font-size: .82rem;
    letter-spacing: .02em;
}

.lesson-context-back {
    color: var(--text-color-secondary);
    text-decoration: none;
    font-weight: 600;
}

.lesson-context-back:hover,
.lesson-context-back:focus-visible {
    color: var(--brand-color);
    text-decoration: underline;
}

.lesson-context-pos {
    color: var(--text-color-secondary);
    font-weight: 500;
}

.lesson-title {
    margin: 0;
    color: var(--brand-color);
    font-size: clamp(2.2rem, 5vw, 3.3rem);
    line-height: 1;
}

.lesson-stage {
    display: grid;
    grid-template-columns: minmax(0, 1.58fr) minmax(360px, .95fr);
    gap: .4rem;
    align-items: start;
}

.lesson-reference {
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: .6rem;
    padding: .75rem;
    background: var(--mint-surface);
    border-radius: var(--card-border-radius);
}

.lesson-practice {
    display: grid;
    grid-template-rows: auto auto auto auto auto;
    gap: .45rem;
    padding: .75rem;
    background: var(--ink-surface);
    color: #fff;
    border-radius: var(--card-border-radius);
}

/* Reference toggle (tabs) */
.reference-toggle {
    display: inline-flex;
    align-items: center;
    background: rgba(7, 86, 106, .1);
    border-radius: 999px;
    padding: .2rem;
    gap: .15rem;
    justify-self: start;
    flex-wrap: wrap;
}

.reference-tab {
    appearance: none;
    width: auto;
    margin: 0;
    border: 0;
    background: transparent;
    color: var(--brand-color);
    font-weight: 700;
    padding: .28rem .75rem;
    border-radius: 999px;
    cursor: pointer;
    font-size: .85rem;
    line-height: 1.2;
    transition: background .15s ease, color .15s ease;
}

.reference-tab:hover,
.reference-tab:focus-visible {
    background: rgba(7, 86, 106, .12);
}

.reference-tab.is-active {
    background: var(--brand-color);
    color: #fff;
}

.reference-tab:disabled {
    opacity: .52;
    cursor: not-allowed;
}

.reference-tab:disabled:hover,
.reference-tab:disabled:focus-visible {
    background: transparent;
}

.reference-avatar-status {
    display: inline-flex;
    align-items: center;
    min-height: 1.7rem;
    margin-left: .35rem;
    color: var(--brand-color);
    font-size: .78rem;
    font-weight: 700;
}

.reference-avatar-status[data-state="loading"] {
    color: var(--text-color-secondary);
}

.reference-avatar-status[data-state="error"] {
    padding: .18rem .55rem;
    border-radius: 999px;
    background: rgba(7, 86, 106, .1);
    color: var(--text-color-secondary);
}

[data-theme="dark"] .reference-avatar-status[data-state="error"] {
    color: #adb5bd;
}

.reference-avatar-status[data-state="ready"] {
    display: none;
}

.reference-avatar-status[hidden] {
    display: none;
}

.reference-keyframe-controls[hidden] {
    display: none;
}

.segment-timeline[hidden] {
    display: none;
}

/* Reference media area */
.reference-media-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 8.6;
    background: #000;
    border-radius: var(--card-border-radius);
    overflow: hidden;
}

.reference-pane {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease;
}

.reference-pane.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.reference-pane video,
.reference-pane iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.reference-pane video {
    object-fit: contain;
}

.reference-pane iframe {
    object-fit: cover;
}

#avatar-root {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: var(--card-background);
}

/* Reference controls below media */
.reference-controls {
    display: grid;
    gap: .5rem;
}

.reference-control-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}

.speed-label {
    display: inline-flex;
    flex-direction: column;
    gap: .15rem;
    font-size: .8rem;
    font-weight: 600;
}

.speed-label > span {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

/* Practice (right-side dark teal) */
.practice-camera-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 8.9;
    min-height: 0;
    background: #000;
    border-radius: var(--card-border-radius);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .08);
}

#live-view.practice-camera-stage {
    min-height: 0;
}

.practice-camera-stage video,
.practice-camera-stage canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.practice-camera-stage #webcam,
.practice-camera-stage #overlay {
    height: 100%;
}

.practice-camera-stage canvas {
    pointer-events: none;
}

.practice-controls {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    align-items: center;
}

.practice-controls button,
.reference-control-row button {
    width: auto;
    margin: 0;
    padding: .35rem .75rem;
    font-size: .86rem;
    line-height: 1.2;
}

.lesson-practice .segment-timeline {
    background: rgba(255, 255, 255, .07);
    border-radius: var(--card-border-radius);
    min-height: 1.6rem;
    padding: .25rem;
}

.practice-feedback {
    display: grid;
    gap: .32rem;
    padding: .62rem .8rem;
    border-radius: var(--card-border-radius);
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .1);
}

.practice-feedback-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.practice-feedback-label {
    color: rgba(255, 255, 255, .68);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.practice-feedback-message {
    margin: 0;
    color: rgba(255, 255, 255, .85);
    font-size: .85rem;
    line-height: 1.4;
}

.practice-feedback .live-score-details {
    color: rgba(255, 255, 255, .7);
}

.practice-feedback .live-score-details summary {
    color: rgba(255, 255, 255, .82);
}

.practice-complete-row {
    display: flex;
    justify-content: stretch;
}

.practice-mark-complete {
    appearance: none;
    width: 100%;
    padding: .65rem 1rem;
    border-radius: var(--card-border-radius);
    border: 1px solid #fff;
    background: #fff;
    color: var(--brand-color);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: background .15s ease, transform .1s ease;
}

.practice-mark-complete:hover,
.practice-mark-complete:focus-visible {
    background: var(--mint-surface);
    transform: translateY(-1px);
}

@media (max-width: 1080px) {
    .lesson-stage {
        grid-template-columns: 1fr;
    }
    .reference-media-wrap {
        aspect-ratio: 16 / 9;
    }
    .practice-camera-stage {
        aspect-ratio: 16 / 9;
    }
}

/* ==========================================================================
   8. CAMERA PROMPT OVERLAY
   ========================================================================== */

.camera-prompt-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: linear-gradient(180deg, rgba(7, 86, 106, .55), rgba(7, 86, 106, .82));
    color: #fff;
    text-align: center;
    z-index: 2;
    transition: opacity .25s ease, visibility .25s ease;
}

.camera-prompt-overlay.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.camera-prompt-card {
    max-width: 22ch;
    display: grid;
    justify-items: center;
    gap: .45rem;
}

.camera-prompt-card strong {
    font-size: 1.1rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .82);
}

.camera-prompt-card p {
    margin: 0;
    color: #fff;
    font-size: .95rem;
    line-height: 1.4;
}

.camera-prompt-error {
    max-width: 24ch;
    padding: .3rem .55rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
}

.camera-start-primary {
    appearance: none;
    width: auto;
    margin: .2rem 0 0 0;
    padding: .48rem .9rem;
    border-radius: 999px;
    border: 1px solid #fff;
    background: #fff;
    color: var(--brand-color);
    font-weight: 800;
    font-size: .9rem;
    line-height: 1.1;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .16);
}

.camera-start-primary:hover,
.camera-start-primary:focus-visible {
    background: var(--mint-surface);
}

.camera-start-primary.is-hidden {
    display: none;
}

/* Prominent live-status pill (used inside practice-feedback) */
.live-status-pill-prominent {
    min-width: 7.5rem;
    padding: .4rem 1rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}

/* Accessible visually-hidden helper (used on lesson page status liveregion) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   10. CONTENTS / LIBRARY PAGE
   ========================================================================== */

.contents-toc {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.contents-toc-chip {
    display: inline-flex;
    align-items: center;
    padding: .35rem .85rem;
    border-radius: 999px;
    background: var(--mint-surface);
    color: var(--brand-color);
    font-weight: 600;
    font-size: .85rem;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

.contents-toc-chip:hover,
.contents-toc-chip:focus-visible {
    background: var(--sky-surface);
    border-color: var(--brand-color);
}

.contents-preview-sticky {
    position: fixed;
    top: 4.6rem;
    right: 1rem;
    z-index: 60;
    width: min(22rem, 30vw);
    display: grid;
    gap: .35rem;
    padding: .55rem;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: var(--card-border-radius);
    box-shadow: 0 14px 36px rgba(7, 86, 106, .22);
}

.contents-preview-video {
    width: 100%;
    max-height: 220px;
    border-radius: calc(var(--card-border-radius) - 2px);
    background: #000;
    display: block;
}

.contents-preview-title {
    margin: 0;
    text-align: center;
    color: var(--text-color-secondary);
    font-size: .78rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contents-course {
    display: grid;
    gap: .65rem;
}

.contents-course + .contents-course {
    margin-top: .6rem;
}

.contents-course-header {
    display: grid;
    gap: .15rem;
    padding-bottom: .35rem;
    border-bottom: 2px solid var(--brand-color);
}

.contents-course-header h2 {
    margin: 0;
    color: var(--brand-color);
    font-size: clamp(1.4rem, 2.2vw, 1.85rem);
    line-height: 1.05;
}

.contents-course-header p {
    margin: 0;
    color: var(--text-color-secondary);
    max-width: 70ch;
    font-size: .9rem;
}

.contents-module {
    display: grid;
    gap: .4rem;
    margin-top: .25rem;
}

.contents-module-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .55rem;
}

.contents-module-header h3 {
    margin: 0;
    color: var(--brand-color);
    font-size: .85rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.contents-thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .4rem;
}

.contents-thumb {
    appearance: none;
    position: relative;
    display: block;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--card-border-radius);
    color: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition: transform var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed);
}

.contents-thumb:hover,
.contents-thumb:focus-visible {
    transform: translateY(-2px);
    border-color: var(--brand-color);
    box-shadow: var(--card-shadow-hover);
    outline: none;
}

.contents-thumb-media {
    display: block;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    border-radius: var(--card-border-radius);
    background: #f3f4f6;
}

[data-theme="dark"] .contents-thumb-media {
    background: #1a2630;
}

.contents-thumb-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--transition-speed);
}

.contents-thumb:hover .contents-thumb-media img,
.contents-thumb:focus-visible .contents-thumb-media img {
    transform: scale(1.04);
}

.contents-thumb-title {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    padding: 1.5rem .55rem .45rem;
    color: #fff;
    font-size: .82rem;
    font-weight: 600;
    line-height: 1.2;
    background: linear-gradient(180deg, rgba(7, 86, 106, 0) 0%, rgba(7, 86, 106, .85) 80%);
    word-break: break-word;
}

@media (max-width: 900px) {
    .contents-preview-sticky {
        top: auto;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        width: auto;
    }

    .contents-preview-video {
        max-height: 180px;
    }

    main.container.contents-page {
        padding-bottom: calc(180px + 4rem);
    }
}

@media (max-width: 720px) {
    .contents-thumb-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}
