.lesson-view-shell {
    max-width: 920px;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem;
}

.lesson-page-title {
    color: #111827;
    font-size: clamp(1.35rem, 2.4vw, 2rem);
    font-weight: 700;
    line-height: 1.3;
    margin: 0 0 1rem;
}

.lesson-page-lang {
    color: var(--primary-blue, #2c68a8);
}

.lesson-app {
    --bg: #f8f7f4;
    --surface: #ffffff;
    --surface2: #f2f0ec;
    --border: rgba(0, 0, 0, 0.09);
    --border-mid: rgba(0, 0, 0, 0.16);
    --text: #1a1916;
    --text-2: #6b6862;
    --text-3: #a09c97;
    --green: #1d9e75;
    --green-light: #e1f5ee;
    --green-dark: #085041;
    --blue: #378add;
    --blue-light: #e6f1fb;
    --blue-dark: #0c447c;
    --red: #e24b4a;
    --red-light: #fcebeb;
    --red-dark: #501313;
    --amber: #ba7517;
    --amber-light: #faeeda;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Courier New", monospace;
    background: var(--bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 1.28rem;
    color: var(--text);
    font-family: var(--font);
}

.lesson-catalog {
    padding: 0;
}

.lesson-catalog-head {
    font-size: 0.95rem;
    font-weight: 700;
    color: #111827;
    margin-bottom: 0.8rem;
}

.lesson-guest-note {
    margin-bottom: 0.75rem;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #92400e;
    font-size: 0.8rem;
}

.lesson-catalog-section {
    margin-top: 1rem;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 0.85rem;
}

.lesson-catalog-section + .lesson-catalog-section {
    margin-top: 0.75rem;
}

.lesson-catalog-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #6b7280;
    margin-bottom: 0.6rem;
}

.lesson-catalog-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.65rem;
}

.lesson-catalog-card {
    border: 1px solid #d1d5db;
    border-radius: 12px;
    background: #ffffff;
    text-align: left;
    padding: 0.75rem;
    min-height: 0;
    cursor: pointer;
    word-break: break-word;
    overflow-wrap: break-word;
}

.lesson-catalog-card:hover {
    border-color: #93c5fd;
    background: #eff6ff;
    transform: translateY(-2px);
}

.lesson-catalog-card {
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.lesson-catalog-card.locked {
    opacity: 0.58;
    background: #f9fafb;
    cursor: not-allowed;
}

.lesson-catalog-card.login-required {
    opacity: 1;
    background: #fff7ed;
    border-color: #fbbf24;
    cursor: pointer;
}

.lesson-catalog-card.login-required:hover {
    background: #fffbeb;
    border-color: #f59e0b;
}

.lesson-catalog-card.done {
    border-color: #10b981;
    background: #ecfdf5;
}

.lesson-catalog-card.failed-attempt {
    border-color: #ef4444;
    background: #fef2f2;
}

.lesson-catalog-card.failed-attempt:hover {
    border-color: #dc2626;
    background: #fee2e2;
}

.lesson-catalog-title {
    font-size: clamp(0.72rem, 2vw, 0.93rem);
    font-weight: 700;
    color: #111827;
    line-height: 1.3;
}

.lesson-catalog-sub {
    margin-top: 0.2rem;
    font-size: clamp(0.65rem, 1.8vw, 0.77rem);
    color: #6b7280;
}

.lesson-catalog-state {
    margin-top: 0.35rem;
    font-size: clamp(0.6rem, 1.6vw, 0.7rem);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #2563eb;
}

.lesson-catalog-card.locked .lesson-catalog-state {
    color: #9ca3af;
}

.lesson-catalog-card.done .lesson-catalog-state {
    color: #059669;
}

.lesson-catalog-card.failed-attempt .lesson-catalog-state {
    color: #dc2626;
}

.lesson-empty-state {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 1.2rem;
}

.lesson-empty-state h3 {
    margin: 0;
    font-size: 1rem;
    color: #111827;
}

.lesson-empty-state p {
    margin-top: 0.45rem;
    font-size: 0.86rem;
    color: #6b7280;
}

.lesson-app * {
    box-sizing: border-box;
}

.lesson-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
    gap: 0.7rem;
    flex-wrap: wrap;
}

.lesson-back {
    border: 1px solid #c8d8ec;
    background: #f0f5fb;
    color: #3a6fa8;
    border-radius: 999px;
    padding: 0.48rem 0.92rem;
    font-size: 0.84rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}

.lesson-back:hover {
    background: #ddeaf7;
    border-color: #a8c4e0;
    color: #1e5394;
}

.lesson-back:active {
    transform: translateY(1px);
}

.lesson-back:focus-visible {
    outline: 2px solid rgba(58, 111, 168, 0.35);
    outline-offset: 2px;
}

.lesson-xp {
    font-size: 0.75rem;
    background: var(--amber-light);
    color: var(--amber);
    border-radius: 999px;
    padding: 0.3rem 0.65rem;
    font-weight: 600;
}

.lesson-header {
    margin-bottom: 0.9rem;
}

.lesson-label {
    font-size: 0.68rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.lesson-title {
    margin-top: 0.22rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.lesson-progress {
    margin-bottom: 0.9rem;
}

.lesson-progress-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.79rem;
    margin-bottom: 0.45rem;
}

.lesson-track {
    height: 6px;
    background: var(--surface2);
    border-radius: 999px;
    overflow: hidden;
}

.lesson-fill {
    height: 100%;
    width: 0;
    background: var(--green);
    transition: width 0.3s ease;
}

.lesson-phase-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0.7rem 0;
}

.lesson-stage {
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lesson-stage > * {
    animation: lessonEnter 0.35s ease;
}

@keyframes lessonEnter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.lesson-actions {
    margin-top: 0.9rem;
    display: flex;
    gap: 0.6rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
    border-radius: 999px;
    padding: 0.68rem 1.25rem;
    font-size: 0.85rem;
    cursor: pointer;
    border: none;
    font-weight: 600;
}

.btn-primary {
    background: var(--green);
    color: #ffffff;
}

.btn-primary:disabled {
    opacity: 0.4;
    pointer-events: none;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-mid);
    color: var(--text-2);
}

.btn-secondary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.flashcard {
    width: 100%;
    max-width: 430px;
    perspective: 1000px;
    cursor: pointer;
}

.flashcard-inner {
    position: relative;
    min-height: 240px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    background: var(--surface);
    transform-style: preserve-3d;
    transition: transform 0.45s ease;
}

.flashcard.is-flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-face {
    position: absolute;
    inset: 0;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    backface-visibility: hidden;
}

.flashcard-back {
    transform: rotateY(180deg);
}

.fc-image {
    width: 112px;
    height: 112px;
    border-radius: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.fc-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.fc-digit {
    font-size: 2.6rem;
    color: var(--text-2);
    font-weight: 700;
}

.fc-english {
    font-size: 1.55rem;
    font-weight: 700;
}

.fc-spanish {
    color: var(--text-2);
    font-size: 1.04rem;
}

.fc-hint {
    margin-top: 0.45rem;
    color: var(--text-3);
    font-size: 0.82rem;
}

/* When the card is flipped hide the front-only hint to avoid mirrored text */
.flashcard.is-flipped .fc-hint {
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear 0s, opacity 0.18s linear;
}

.fc-lang {
    font-size: 0.74rem;
    color: var(--green-dark);
    border-radius: 999px;
    padding: 0.24rem 0.58rem;
    background: var(--green-light);
}

.fc-native {
    color: var(--green);
    font-family: "Times New Roman", Georgia, serif;
    font-size: clamp(2.1rem, 5.7vw, 2.8rem);
    font-weight: 700;
    line-height: 1.05;
    font-variant-ligatures: none;
    letter-spacing: normal;
    text-rendering: optimizeLegibility;
}

.quiz-wrap,
.match-wrap,
.complete-wrap {
    width: 100%;
    max-width: 450px;
}

.quiz-prompt {
    text-align: center;
    margin-bottom: 0.85rem;
    font-weight: 600;
}

.quiz-native-pill {
    margin: 0 auto 0.85rem;
    width: fit-content;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    border-radius: 999px;
    border: 1px solid var(--green);
    padding: 0.45rem 0.75rem;
    background: var(--green-light);
    color: var(--green-dark);
    cursor: pointer;
}

.speaker-badge {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid #86efac;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.quiz-native-word {
    font-weight: 700;
    font-family: "Times New Roman", Georgia, serif;
    line-height: 1.05;
    font-variant-ligatures: none;
    text-rendering: optimizeLegibility;
}

.speaker-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    margin-left: 2px;
}

.speaker-bars span {
    width: 2px;
    height: 7px;
    background: #059669;
    border-radius: 2px;
    opacity: 0.45;
}

.quiz-native-pill.playing .speaker-bars span {
    animation: speakerBounce 0.8s ease-in-out infinite;
    opacity: 1;
}

.quiz-native-pill.playing .speaker-bars span:nth-child(2) {
    animation-delay: 0.1s;
}

.quiz-native-pill.playing .speaker-bars span:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes speakerBounce {
    0%,
    100% {
        transform: scaleY(0.55);
    }
    50% {
        transform: scaleY(1.35);
    }
}

.quiz-native-pill.no-audio {
    border-color: var(--border-mid);
    color: var(--text-3);
    background: var(--surface2);
    cursor: default;
}

.quiz-clue {
    width: 84px;
    height: 84px;
    margin: 0 auto 0.8rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.quiz-clue-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.quiz-clue-digit {
    font-size: 2rem;
    line-height: 1;
    font-weight: 700;
    color: var(--text-2);
}

.quiz-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.quiz-option {
    border: 1px solid var(--border-mid);
    background: var(--surface);
    border-radius: var(--radius-md);
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    flex-direction: column;
    gap: 0.2rem;
}

.quiz-option.image-mode {
    min-height: 104px;
    padding: 0.45rem;
}

.quiz-option-image {
    width: 100%;
    max-width: 128px;
    height: 82px;
    object-fit: contain;
    border-radius: 10px;
}

.quiz-option.image-mode .quiz-option-image {
    max-width: none;
    width: 100%;
    height: 84px;
}

.quiz-option-en {
    font-size: 0.9rem;
    line-height: 1;
}

.quiz-option-es {
    font-size: 0.78rem;
    line-height: 1;
    color: #6b7280;
    font-weight: 600;
}

.quiz-option.correct {
    background: var(--green-light);
    border-color: var(--green);
    color: var(--green-dark);
}

.quiz-option.wrong {
    background: var(--red-light);
    border-color: var(--red);
    color: var(--red-dark);
}

.quiz-feedback {
    margin-top: 0.65rem;
    min-height: 38px;
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.7rem;
    font-size: 0.8rem;
    text-align: center;
}

.quiz-feedback.correct {
    background: var(--green-light);
    color: var(--green-dark);
}

.quiz-feedback.wrong {
    background: var(--red-light);
    color: var(--red-dark);
}

.match-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.match-column {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.match-item {
    border: 1px solid var(--border-mid);
    background: var(--surface);
    border-radius: var(--radius-md);
    min-height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem;
    text-align: center;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
}

.match-item.visual {
    min-height: 66px;
    padding: 0.35rem 0.55rem;
}

.match-item.visual.with-image {
    min-height: 66px;
    padding: 0.35rem;
}

.match-item-image {
    width: 52px;
    height: 52px;
    object-fit: contain;
}

.match-item.native {
    color: var(--green);
    font-family: "Times New Roman", Georgia, serif;
    min-height: 66px;
    padding: 0.35rem 0.55rem;
    line-height: 1.05;
    font-variant-ligatures: none;
    letter-spacing: normal;
    text-rendering: optimizeLegibility;
}

.match-item.native.playing {
    border-color: var(--green);
    background: var(--green-light);
    box-shadow: 0 0 0 3px rgba(47, 168, 111, 0.15);
}

.match-item.selected {
    background: var(--blue-light);
    border-color: var(--blue);
    color: var(--blue-dark);
}

.match-item.matched {
    background: var(--green-light);
    border-color: var(--green);
    color: var(--green-dark);
    pointer-events: none;
}

.match-item.wrong {
    background: var(--red-light);
    border-color: var(--red);
}

.complete-title {
    text-align: center;
    font-size: 1.3rem;
    font-weight: 700;
}

.complete-subtitle {
    margin-top: 0.35rem;
    text-align: center;
    color: var(--text-2);
}

.complete-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.45rem;
    margin-top: 0.95rem;
}

.stat-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    padding: 0.65rem;
    text-align: center;
}

.stat-value {
    font-size: 1.15rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.68rem;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.lesson-pass-warning {
    margin-top: 0.95rem;
    border: 1px solid var(--red);
    border-radius: var(--radius-md);
    background: var(--red-light);
    color: var(--red-dark);
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
    text-align: center;
}

.lesson-repeat-note {
    margin-top: 0.9rem;
    font-size: 0.93rem;
    color: #7c5c10;
    background: #fff7e0;
    border: 1px solid #f2cf75;
    border-radius: 16px;
    padding: 0.65rem 0.85rem;
    text-align: center;
}

.lesson-improved-note {
    margin-top: 0.9rem;
    font-size: 0.9rem;
    color: #065f46;
    background: #ecfdf5;
    border: 1px solid #34d399;
    border-radius: 16px;
    padding: 0.6rem 0.8rem;
    text-align: center;
    font-weight: 600;
}

@media (max-width: 768px) {
    .lesson-view-shell {
        padding: 0.85rem 0.45rem 2rem;
    }

    .lesson-app {
        padding: 0.85rem;
    }

    /* 2-column grid on mobile so cards have enough room */
    .lesson-catalog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.55rem;
    }

    .lesson-catalog-card {
        padding: 0.65rem 0.55rem;
    }

    .lesson-catalog-title {
        font-size: 0.82rem;
    }

    .lesson-catalog-sub {
        font-size: 0.68rem;
    }

    .lesson-catalog-state {
        font-size: 0.62rem;
    }

    .quiz-options,
    .match-grid {
        grid-template-columns: 1fr;
    }

    .complete-stats {
        grid-template-columns: 1fr;
    }
}