/* Study Session styles using CSS layers */
@layer components {
    /* CTA Button (outside nav/hero) */
    .cta-button {
        background: var(--gradient-primary);
        color: var(--bg-primary);
        padding-block: 0.75rem;
        padding-inline: 1.5rem;
        border-radius: 12px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
        font-size: 1rem;

        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px oklch(0.9 0.15 195 / 0.4);
        }

        &:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
    }

    /* Nav Actions (shared with nav) */
    .nav-actions {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    /* Study-specific Nav */
    .study-nav {
        position: fixed;
        inset-block-start: 0;
        inline-size: 100%;
        background: var(--bg-card);
        border-block-end: 1px solid var(--border-color);
        backdrop-filter: blur(20px);
        z-index: 100;
        padding-block: 1rem;

        & .container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        & .nav-left {
            display: flex;
            align-items: center;
            gap: 1.5rem;
        }

        & .nav-right {
            display: flex;
            align-items: center;
            gap: 1.5rem;
        }

        & .back-link {
            color: var(--text-secondary);
            text-decoration: none;
            font-weight: 600;
            transition: color 0.3s ease;

            &:hover {
                color: var(--cyan);
            }
        }

        & .course-name {
            color: var(--text-primary);
            font-weight: 700;
            font-size: 1.1rem;
        }

        & .progress-indicator {
            display: flex;
            align-items: center;
            gap: 1rem;
        }

        & .progress-text {
            color: var(--text-secondary);
            font-weight: 600;
            font-size: 0.95rem;
            min-inline-size: 60px;
            text-align: end;
        }

        & .progress-bar-small {
            inline-size: 120px;
            block-size: 6px;
            background: var(--bg-secondary);
            border-radius: 3px;
            overflow: hidden;

            & .progress-fill {
                block-size: 100%;
                background: var(--gradient-primary);
                border-radius: 3px;
                transition: width 0.6s ease;
            }
        }
    }

    /* User Menu (for study nav) */
    .user-menu {
        position: relative;
    }

    .user-button {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding-block: 0.5rem;
        padding-inline: 1rem;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 50px;
        cursor: pointer;
        transition: all 0.3s ease;
        color: var(--text-primary);

        &:hover {
            border-color: var(--border-hover);
            transform: translateY(-2px);
        }
    }

    .user-avatar {
        inline-size: 32px;
        block-size: 32px;
        border-radius: 50%;
        background: var(--gradient-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 0.9rem;
        color: var(--bg-primary);
    }

    .user-dropdown {
        position: absolute;
        inset-block-start: calc(100% + 0.5rem);
        inset-inline-end: 0;
        min-inline-size: 200px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        box-shadow: 0 20px 60px oklch(0 0 0 / 0.2);
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: all 0.3s ease;
        z-index: 1000;

        &.show {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        & a {
            display: block;
            padding-block: 0.75rem;
            padding-inline: 1.25rem;
            color: var(--text-secondary);
            text-decoration: none;
            transition: all 0.2s ease;

            &:hover {
                background: var(--bg-primary);
                color: var(--cyan);
            }

            &:first-child {
                border-start-start-radius: 12px;
                border-start-end-radius: 12px;
            }

            &:last-child {
                border-end-start-radius: 12px;
                border-end-end-radius: 12px;
            }
        }

        & hr {
            border: none;
            border-block-start: 1px solid var(--border-color);
            margin: 0;
        }
    }

    /* Study Container */
    .study-container {
        margin-block-start: 80px;
        padding-block: 2rem;
        min-block-size: calc(100dvh - 80px); /* dvh accounts for mobile browser chrome */
        padding-block-end: max(2rem, var(--kb-inset)); /* Account for keyboard on mobile */
        background: var(--bg-primary);
        display: flex;
        align-items: flex-start;
        justify-content: center;

        & .container {
            inline-size: 90vi;
            max-inline-size: 1200px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: flex-start;
            padding-block-start: 3rem;
        }
    }

    /* Progress Header */
    .progress-header {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        margin-block-end: 2rem;
        padding: 1.5rem;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: 12px;

        & .progress-bar {
            inline-size: 100%;
            block-size: 8px;
            background: var(--bg-secondary);
            border-radius: 4px;
            overflow: hidden;
        }

        & .progress-fill {
            block-size: 100%;
            background: var(--gradient-primary);
            border-radius: 4px;
            transition: width 0.4s ease;
            min-inline-size: 2px;
        }

        & .progress-text {
            text-align: center;
            font-size: 0.95rem;
            font-weight: 600;
            color: var(--text-secondary);
        }
    }

    /* Study Session Web Component */
    study-session {
        inline-size: 100%;
        max-inline-size: 1000px;
        display: block;
    }

    /* Study Wrapper */
    .study-wrapper {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        inline-size: 100%;
        margin-inline: auto;
        padding-inline: 1rem;
    }

    /* Question Card */
    .question-card {
        inline-size: 100%;
        padding: 1.5rem;
        background: var(--bg-card);
        border: 2px solid var(--border-color);
        border-radius: 16px;
        backdrop-filter: blur(20px);
        transition: all 0.3s ease;

        & .question-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-block-end: 1rem;

            & .question-label {
                font-size: 0.75rem;
                font-weight: 600;
                color: var(--text-secondary);
                text-transform: uppercase;
                letter-spacing: 0.8px;
            }

            & .question-counter {
                font-size: 0.85rem;
                font-weight: 600;
                color: var(--text-tertiary);
            }
        }

        & .question-level {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            margin-block-end: 1rem;
            padding: 0.75rem 1rem;
            background: var(--bg-secondary);
            border: 2px solid var(--border-color);
            border-radius: 12px;

            & .level-icon {
                font-size: 1.5rem;
                line-height: 1;
            }

            & .level-name {
                font-size: 1rem;
                font-weight: 700;
                line-height: 1;
            }
        }

        & .question-text {
            font-size: 1.35rem;
            font-weight: 700;
            color: var(--text-primary);
            line-height: 1.4;

            /* Cloze inline hints - matches .hint-value style */
            & .cloze-hint {
                display: inline;
                white-space: nowrap;
                font-family: monospace;
                font-size: 1rem;
                letter-spacing: 0.08em;
            }

            & .cloze-number {
                color: var(--orange);
                font-weight: 600;
                font-size: 0.65em;
            }

            & .cloze-letter {
                color: var(--cyan);
                font-weight: 600;
            }

            & .cloze-underscores {
                color: var(--cyan);
                font-weight: 600;
            }

            & .cloze-space {
                display: inline-block;
                width: 0.6em;
            }

            /* Code blocks for ASCII diagrams */
            & pre {
                background: var(--bg-secondary);
                border: 1px solid var(--border-color);
                border-radius: 8px;
                padding: 1rem;
                margin: 1rem 0;
                overflow-x: auto;
                font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
                font-size: 0.9rem;
                font-weight: 400;
                line-height: 1.4;
                white-space: pre;
            }

            & code {
                font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
                background: var(--bg-secondary);
                padding: 0.15em 0.4em;
                border-radius: 4px;
                font-size: 0.85em;
                font-weight: 400;
            }

            & pre code {
                background: none;
                padding: 0;
                border-radius: 0;
                font-size: inherit;
            }
        }

        & .hint-text {
            margin-block-start: 1rem;
            padding: 0.75rem 1rem;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 10px;
            display: flex;
            align-items: center;
            gap: 0.6rem;

            & .hint-label {
                font-size: 0.75rem;
                font-weight: 600;
                color: var(--text-secondary);
                text-transform: uppercase;
                letter-spacing: 0.4px;
            }

            & .hint-value {
                font-size: 1rem;
                font-weight: 600;
                color: var(--cyan);
                font-family: monospace;
                letter-spacing: 0.12em;
            }
        }
    }

    /* Answer Section */
    .answer-section {
        inline-size: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;

        & .answer-label {
            font-size: 0.9rem;
            font-weight: 600;
            color: var(--text-secondary);
        }

        & .answer-input {
            inline-size: 100%;
            padding: 0.75rem 1rem;
            background: var(--bg-card);
            border: 2px solid var(--border-color);
            border-radius: 10px;
            color: var(--text-primary);
            font-family: inherit;
            font-size: 16px; /* Prevent iOS auto-zoom (was 1.1rem ~17.6px, now explicitly 16px) */
            scroll-margin-top: 250px; /* Ensure question card stays visible above input */
            scroll-margin-bottom: 24px;
            transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;

            &:focus {
                outline: none;
                border-color: var(--cyan);
                box-shadow: 0 0 0 4px oklch(0.9 0.15 195 / 0.1);
            }

            &::placeholder {
                color: var(--text-tertiary);
            }

            &.correct {
                border-color: var(--green);
                background: oklch(0.8 0.15 150 / 0.1);
                animation: correctPulse 0.5s ease-out;
            }

            &.incorrect {
                border-color: var(--orange);
                background: oklch(0.85 0.19 35 / 0.1);
                animation: incorrectShake 0.4s ease-out;
            }
        }

        @keyframes correctPulse {
            0% {
                transform: scale(1);
            }
            25% {
                transform: scale(1.03);
            }
            50% {
                transform: scale(0.98);
            }
            75% {
                transform: scale(1.02);
            }
            100% {
                transform: scale(1);
            }
        }

        @keyframes incorrectShake {
            0%, 100% {
                transform: translateX(0);
            }
            10%, 30%, 50%, 70%, 90% {
                transform: translateX(-8px);
            }
            20%, 40%, 60%, 80% {
                transform: translateX(8px);
            }
        }

        & .btn-check {
            padding-block: 0.75rem;
            padding-inline: 1.5rem;
            background: var(--gradient-primary);
            color: var(--bg-primary);
            border: none;
            border-radius: 10px;
            font-weight: 600;
            font-size: 0.95rem;
            cursor: pointer;
            /* Removed opacity transition to prevent flicker on mobile when button is clicked */
            transition: transform 0.2s ease;

            &:disabled {
                opacity: 0.5;
                cursor: not-allowed;
            }

            /* Only apply hover effects on devices with hover capability (not touch screens) */
            @media (hover: hover) {
                &:hover:not(:disabled) {
                    transform: translateY(-2px);
                }
            }
        }

        & .answer-feedback {
            padding: 1rem;
            border-radius: 10px;
            display: flex;
            flex-direction: column;
            gap: 0.75rem;

            /* Smooth, gentle entrance animation */
            animation: feedbackSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
            transform-origin: top center;

            &.correct {
                background: oklch(0.8 0.15 150 / 0.15);
                border: 2px solid var(--green);
            }

            &.incorrect {
                background: oklch(0.85 0.19 35 / 0.15);
                border: 2px solid var(--orange);
            }
        }

        @keyframes feedbackSlideIn {
            0% {
                opacity: 0;
                transform: translateY(-20px) scale(0.95);
            }
            100% {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

            & .feedback-header {
                display: flex;
                align-items: center;
                gap: 0.6rem;

                & .feedback-icon {
                    font-size: 1.25rem;
                }

                & .feedback-text {
                    font-size: 1.05rem;
                    font-weight: 700;
                    color: var(--text-primary);
                }
            }

            & .correct-answer {
                display: flex;
                flex-direction: column;
                gap: 0.4rem;
                padding-block-start: 0.5rem;
                border-block-start: 1px solid var(--border-color);

                & .correct-label {
                    font-size: 0.8rem;
                    font-weight: 600;
                    color: var(--text-secondary);
                }

                & .correct-text {
                    font-size: 1.05rem;
                    font-weight: 700;
                    color: var(--text-primary);
                }
            }

            & .explanation {
                display: flex;
                flex-direction: column;
                gap: 0.4rem;
                padding-block-start: 0.5rem;
                border-block-start: 1px solid var(--border-color);

                & .explanation-label {
                    font-size: 0.8rem;
                    font-weight: 600;
                    color: var(--text-secondary);
                }

                & .explanation-text {
                    font-size: 0.95rem;
                    line-height: 1.5;
                    color: var(--text-primary);
                }
            }
        }

        /* Multiple Choice Options Grid */
        & .options-grid {
            display: grid;
            grid-template-columns: 1fr;
            gap: 0.6rem;
            margin-block-end: 0.75rem;
        }

        & .option-button {
            inline-size: 100%;
            padding: 0.7rem 1rem;
            background: var(--bg-card);
            border: 2px solid var(--border-color);
            border-radius: 10px;
            color: var(--text-primary);
            font-family: inherit;
            font-size: 16px; /* Prevent iOS auto-zoom (was 0.95rem ~15.2px) */
            line-height: 1.4;
            text-align: start;
            cursor: pointer;
            scroll-margin-top: 200px; /* Keep question visible when option is tapped */
            transition: border-color 0.25s ease, background 0.25s ease, transform 0.2s ease;

            &:hover:not(:disabled) {
                border-color: var(--cyan);
                transform: translateX(4px);
                background: var(--bg-secondary);
            }

            &.selected {
                border-color: var(--cyan);
                background: oklch(0.9 0.15 195 / 0.1);
            }

            &.correct-option {
                border-color: var(--green);
                background: oklch(0.8 0.15 150 / 0.15);
                font-weight: 600;
                animation: correctOptionPulse 0.5s ease-out;
            }

            &.incorrect-option {
                border-color: var(--orange);
                background: oklch(0.85 0.19 35 / 0.15);
                animation: incorrectOptionShake 0.4s ease-out;
            }

            &:disabled {
                cursor: not-allowed;
                opacity: 0.8;
            }
        }

        @keyframes correctOptionPulse {
            0% {
                transform: scale(1);
            }
            25% {
                transform: scale(1.04);
            }
            50% {
                transform: scale(0.97);
            }
            75% {
                transform: scale(1.02);
            }
            100% {
                transform: scale(1);
            }
        }

        @keyframes incorrectOptionShake {
            0%, 100% {
                transform: translateX(0);
            }
            10%, 30%, 50%, 70%, 90% {
                transform: translateX(-6px);
            }
            20%, 40%, 60%, 80% {
                transform: translateX(6px);
            }
        }
    }

    /* Continue Button */
    .btn-continue {
        inline-size: 100%;
        padding-block: 0.75rem;
        padding-inline: 1.5rem;
        background: var(--gradient-primary);
        border: none;
        border-radius: 10px;
        color: var(--bg-primary);
        font-weight: 700;
        font-size: 1rem;
        cursor: pointer;
        transition: transform 0.2s ease, box-shadow 0.3s ease;
        margin-block-start: 0.75rem;

        /* Smooth entrance animation */
        animation: buttonSlideIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

        &:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px oklch(0.9 0.15 195 / 0.4);
        }

        &:active {
            transform: translateY(0);
        }
    }

    @keyframes buttonSlideIn {
        0% {
            opacity: 0;
            transform: translateY(20px) scale(0.9);
        }
        60% {
            transform: translateY(-5px) scale(1.02);
        }
        100% {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }

    /* Keyboard Shortcuts Hint */
    .shortcuts-hint {
        display: flex;
        gap: 2rem;
        color: var(--text-tertiary);
        font-size: 0.9rem;
        margin-block-start: 1rem;

        & kbd {
            padding: 0.25rem 0.5rem;
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 6px;
            font-family: monospace;
            font-size: 0.85rem;
            font-weight: 600;
        }
    }

    /* Loading Container */
    .loading-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 1.5rem;
        min-block-size: 400px;
        padding: 3rem;
        text-align: center;

        & .loading-spinner {
            inline-size: 48px;
            block-size: 48px;
            border: 4px solid var(--bg-secondary);
            border-block-start-color: var(--cyan);
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        & p {
            font-size: 1.1rem;
            color: var(--text-secondary);
            font-weight: 500;
        }
    }

    @keyframes spin {
        to { transform: rotate(360deg); }
    }

    /* Error Container */
    .error-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2rem;
        min-block-size: 400px;
        padding: 3rem;
        text-align: center;

        & .error-message {
            font-size: 1.25rem;
            color: var(--text-primary);
            font-weight: 600;
            padding: 2rem;
            background: var(--bg-card);
            border: 2px solid var(--border-color);
            border-radius: 16px;
            max-inline-size: 600px;
            line-height: 1.6;
        }

        & .btn-secondary {
            padding-block: 1rem;
            padding-inline: 2rem;
            background: var(--bg-secondary);
            color: var(--text-primary);
            border: 1px solid var(--border-color);
            border-radius: 12px;
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;

            &:hover {
                border-color: var(--cyan);
                transform: translateY(-2px);
                box-shadow: 0 4px 12px oklch(0 0 0 / 0.1);
            }
        }
    }

    /* Completion Screen */
    .completion-screen {
        display: flex;
        align-items: center;
        justify-content: center;
        min-block-size: 500px;
    }

    /* Completion Content */
    .completion-content {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2rem;
        padding: 3rem;
        background: var(--bg-card);
        border: 2px solid var(--border-color);
        border-radius: 24px;
        backdrop-filter: blur(20px);
        text-align: center;
        max-inline-size: 600px;

        & .completion-icon {
            font-size: 5rem;
        }

        & h2 {
            font-size: 2rem;
            color: var(--text-primary);
            margin: 0;
        }

        & .completion-message {
            color: var(--text-secondary);
            font-size: 1.1rem;
            margin: 0;
        }
    }

    .completion-card {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2rem;
        padding: 3rem;
        background: var(--bg-card);
        border: 2px solid var(--border-color);
        border-radius: 24px;
        backdrop-filter: blur(20px);
        text-align: center;
        max-inline-size: 600px;

        & .completion-icon {
            font-size: 5rem;
        }

        & h2 {
            font-size: 2rem;
            color: var(--text-primary);
            margin-block-end: 0.5rem;
        }

        & p {
            color: var(--text-secondary);
            font-size: 1.1rem;
        }
    }

    /* Session Stats */
    .session-stats {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 2rem;
        inline-size: 100%;
        padding-block: 2rem;

        & .stat-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.5rem;
        }

        & .stat-count {
            font-size: 2.5rem;
            font-weight: 700;
        }

        & .stat-label {
            font-size: 0.85rem;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
    }

    /* Completion Actions */
    .completion-actions {
        display: flex;
        gap: 1rem;
        inline-size: 100%;

        & button {
            flex: 1;
            padding-block: 1rem;
            padding-inline: 2rem;
            border-radius: 12px;
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            border: none;
        }

        & .btn-primary {
            background: var(--gradient-primary);
            color: var(--bg-primary);

            &:hover {
                transform: translateY(-2px);
            }
        }

        & .btn-secondary {
            background: var(--bg-secondary);
            color: var(--text-primary);
            border: 1px solid var(--border-color);

            &:hover {
                border-color: var(--border-hover);
            }
        }
    }

    /* Question Pool Container */
    .question-pool-container {
        display: flex;
        flex-direction: column;
        gap: 2rem;
        padding-block: 1rem;
    }

    .pool-lesson-section {
        background: var(--bg-card);
        border: 2px solid var(--border-color);
        border-radius: 16px;
        padding: 1.5rem;
        transition: all 0.3s ease;

        &:hover {
            border-color: var(--border-hover);
        }
    }

    .pool-lesson-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-block-end: 1.5rem;
        padding-block-end: 1rem;
        border-block-end: 2px solid var(--border-color);

        & h3 {
            margin: 0;
            font-size: 1.5rem;
            color: var(--text-primary);
            font-weight: 700;
        }

        & .question-count {
            font-size: 0.9rem;
            color: var(--text-secondary);
            font-weight: 600;
            padding: 0.375rem 0.75rem;
            background: var(--bg-secondary);
            border-radius: 8px;
        }
    }

    .pool-questions-list {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .pool-question-item {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1.5rem;
        padding: 1.25rem;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        transition: all 0.3s ease;

        &:hover {
            background: var(--bg-primary);
            border-color: var(--border-hover);
            transform: translateX(4px);
        }
    }

    .pool-question-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .pool-question-text {
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--text-primary);
        line-height: 1.5;

        & strong {
            color: var(--cyan);
            margin-inline-end: 0.5rem;
        }
    }

    .pool-answer-text {
        font-size: 1rem;
        color: var(--text-secondary);
        line-height: 1.5;

        & strong {
            color: var(--magenta);
            margin-inline-end: 0.5rem;
        }
    }

    .pool-question-badge {
        flex-shrink: 0;
    }

    .pool-srs-badge {
        display: inline-block;
        padding: 0.5rem 1rem;
        border-radius: 12px;
        font-size: 0.85rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        white-space: nowrap;
        border: 2px solid currentColor;
        text-align: center;
        min-inline-size: 140px;
    }
}

@layer overrides {
    [data-theme="dark"] .question-card {
        box-shadow: 0 20px 60px oklch(0.9 0.15 195 / 0.2);
    }

    [data-theme="light"] .question-card {
        box-shadow: 0 20px 60px oklch(0.7 0.12 210 / 0.15);
    }

    [data-theme="dark"] .btn-check {
        box-shadow: 0 0 20px oklch(0.9 0.15 195 / 0.3);

        /* Only apply hover effects on devices with hover capability (not touch screens) */
        @media (hover: hover) {
            &:hover:not(:disabled) {
                box-shadow: 0 0 30px oklch(0.9 0.15 195 / 0.5);
            }
        }
    }

    [data-theme="light"] .btn-check {
        box-shadow: 0 4px 15px oklch(0.7 0.12 210 / 0.2);

        /* Only apply hover effects on devices with hover capability (not touch screens) */
        @media (hover: hover) {
            &:hover:not(:disabled) {
                box-shadow: 0 8px 25px oklch(0.7 0.12 210 / 0.3);
            }
        }
    }

    [data-theme="dark"] .completion-card {
        box-shadow: 0 30px 80px oklch(0.9 0.15 195 / 0.2);
    }

    [data-theme="light"] .completion-card {
        box-shadow: 0 30px 80px oklch(0.7 0.12 210 / 0.15);
    }

    [data-theme="dark"] .btn-primary {
        box-shadow: 0 0 20px oklch(0.9 0.15 195 / 0.3);

        &:hover {
            box-shadow: 0 0 30px oklch(0.9 0.15 195 / 0.5);
        }
    }

    [data-theme="light"] .btn-primary {
        box-shadow: 0 4px 15px oklch(0.7 0.12 210 / 0.2);

        &:hover {
            box-shadow: 0 8px 25px oklch(0.7 0.12 210 / 0.3);
        }
    }
}

/* Responsive */
@media (max-width: 768px) {
    .study-nav {
        & .course-name {
            display: none;
        }

        & .progress-bar-small {
            inline-size: 80px;
        }
    }

    .flashcard-container {
        block-size: 350px;
    }

    .card-face {
        padding: 2rem;

        & .card-text {
            font-size: 2rem;
        }
    }

    .session-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .shortcuts-hint {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }

    .completion-actions {
        flex-direction: column;
    }

    /* Question card mobile optimizations */
    .question-card {
        padding: 1.5rem;

        & .question-level {
            padding: 0.75rem 1rem;
            gap: 0.75rem;
            margin-block-end: 1rem;

            & .level-icon {
                font-size: 1.75rem;
            }

            & .level-name {
                font-size: 1rem;
            }
        }

        & .question-text {
            font-size: 1.1rem;
            line-height: 1.35;
        }

        & .hint-text {
            margin-block-start: 1rem;
            padding: 0.75rem 1rem;
            gap: 0.5rem;

            & .hint-label {
                font-size: 0.75rem;
            }

            & .hint-value {
                font-size: 1rem;
                letter-spacing: 0.1em;
            }
        }
    }
}

@media (max-width: 480px) {
    .card-face .card-text {
        font-size: 1.5rem;
    }

    /* Further reduce on smaller screens */
    .question-card {
        padding: 1.25rem;

        & .question-level {
            padding: 0.5rem 0.75rem;
            gap: 0.5rem;
            margin-block-end: 0.75rem;

            & .level-icon {
                font-size: 1.5rem;
            }

            & .level-name {
                font-size: 0.875rem;
            }
        }

        & .question-text {
            font-size: 1.1rem;
        }

        & .hint-text {
            margin-block-start: 0.75rem;
            padding: 0.625rem 0.875rem;

            & .hint-label {
                font-size: 0.7rem;
            }

            & .hint-value {
                font-size: 0.9rem;
            }
        }
    }
}
        /* View Transitions API support for smoother state changes */
        @supports (view-transition-name: none) {
            ::view-transition-old(answer-feedback),
            ::view-transition-new(answer-feedback) {
                animation-duration: 0.3s;
                animation-timing-function: cubic-bezier(0.34, 1.56, 0.64, 1);
            }
        }

        /* Requeue feedback animations */
        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateX(-50%) translateY(-20px);
            }
            to {
                opacity: 1;
                transform: translateX(-50%) translateY(0);
            }
        }

        @keyframes slideUp {
            from {
                opacity: 1;
                transform: translateX(-50%) translateY(0);
            }
            to {
                opacity: 0;
                transform: translateX(-50%) translateY(-20px);
            }
        }

        /* Typo Warning Dialog */
        .typo-warning-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            backdrop-filter: blur(4px);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            padding: 1rem;
            animation: fadeIn 0.2s ease-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }
            to {
                opacity: 1;
            }
        }

        .typo-warning-dialog {
            background: var(--bg-card);
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 2rem;
            max-width: 400px;
            width: 100%;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
            text-align: center;
            animation: dialogSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
        }

        @keyframes dialogSlideUp {
            from {
                opacity: 0;
                transform: translateY(20px) scale(0.95);
            }
            to {
                opacity: 1;
                transform: translateY(0) scale(1);
            }
        }

        .typo-warning-icon {
            font-size: 3rem;
            margin-bottom: 1rem;
            animation: iconBounce 0.5s ease-out;
        }

        @keyframes iconBounce {
            0% {
                transform: scale(0);
            }
            50% {
                transform: scale(1.1);
            }
            100% {
                transform: scale(1);
            }
        }

        .typo-warning-title {
            font-size: 1.5rem;
            font-weight: 600;
            color: var(--text);
            margin: 0 0 0.75rem 0;
        }

        .typo-warning-message {
            font-size: 1rem;
            color: var(--text-secondary);
            margin: 0 0 1.5rem 0;
            line-height: 1.5;
        }

        .typo-warning-btn {
            width: 100%;
            padding: 0.75rem 1.5rem;
            font-size: 1rem;
            font-weight: 600;
            background: var(--gradient-primary);
            color: var(--bg-primary);
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.2s ease;
        }

        .typo-warning-btn:hover {
            transform: translateY(-2px);
        }

        .typo-warning-btn:active {
            transform: translateY(0);
        }

        /* Mobile adjustments */
        @media (max-width: 480px) {
            .typo-warning-dialog {
                padding: 1.5rem;
                border-radius: 8px;
            }

            .typo-warning-icon {
                font-size: 2.5rem;
            }

            .typo-warning-title {
                font-size: 1.25rem;
            }

            .typo-warning-message {
                font-size: 0.9rem;
            }
        }

        /* Reduce motion for users who prefer it */
        @media (prefers-reduced-motion: reduce) {
            *,
            *::before,
            *::after {
                animation-duration: 0.01ms !important;
                animation-iteration-count: 1 !important;
                transition-duration: 0.01ms !important;
            }
        }

        /* AI Evaluation Markdown Content */
        .ai-evaluation {
            margin-block-start: 1rem;
            padding: 1rem;
            background: var(--bg-secondary);
            border-radius: 8px;
            border: 1px solid var(--border-color);
        }

        .ai-evaluation .evaluation-label {
            display: block;
            font-weight: 600;
            margin-block-end: 0.5rem;
            color: var(--text-primary);
        }

        .ai-evaluation-content {
            line-height: 1.6;
            color: var(--text-primary);
        }

        .ai-evaluation-content p {
            margin-block: 0.5rem 0;
        }

        .ai-evaluation-content p:first-child {
            margin-block-start: 0;
        }

        .ai-evaluation-content code {
            background: var(--bg-tertiary);
            padding: 0.2em 0.4em;
            border-radius: 4px;
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 0.9em;
        }

        .ai-evaluation-content pre {
            background: var(--bg-tertiary);
            padding: 1rem;
            border-radius: 8px;
            overflow-x: auto;
            margin-block: 0.75rem;
        }

        .ai-evaluation-content pre code {
            background: transparent;
            padding: 0;
            font-size: 0.85em;
        }

        .ai-evaluation-content ul,
        .ai-evaluation-content ol {
            margin-block: 0.5rem;
            padding-inline-start: 1.5rem;
        }

        .ai-evaluation-content li {
            margin-block: 0.25rem;
        }

        .ai-evaluation-content strong {
            font-weight: 600;
        }

        .ai-evaluation-content em {
            font-style: italic;
        }

        /* Matching Question Styles */
        .matching-container {
            display: flex;
            flex-direction: column;
            gap: 0.75rem;
        }

        .matching-row {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 1rem;
            padding: 0.75rem 1rem;
            background: var(--bg-card);
            border: 2px solid var(--border-color);
            border-radius: 10px;
            transition: border-color 0.3s ease, background 0.3s ease;
        }

        .matching-row.matching-correct {
            border-color: var(--green);
            background: oklch(0.8 0.15 150 / 0.1);
        }

        .matching-row.matching-incorrect {
            border-color: var(--orange);
            background: oklch(0.85 0.19 35 / 0.1);
        }

        .matching-row.matching-active {
            border-color: oklch(0.6 0.15 140);
            background: oklch(0.95 0.03 140);
            box-shadow: 0 0 0 2px oklch(0.6 0.15 140 / 0.3);
        }

        .matching-left {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            flex: 1;
            min-width: 0;
        }

        .matching-index {
            font-weight: 600;
            color: var(--text-secondary);
            min-width: 1.5rem;
        }

        .matching-term {
            font-weight: 600;
            color: var(--text-primary);
            word-break: break-word;
        }

        .matching-right {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            flex: 1;
            min-width: 0;
        }

        .matching-select {
            flex: 1;
            padding: 0.5rem 0.75rem;
            background: var(--bg-secondary);
            border: 2px solid var(--border-color);
            border-radius: 8px;
            color: var(--text-primary);
            font-family: inherit;
            font-size: 16px;
            cursor: pointer;
            transition: border-color 0.3s ease;
            appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 0.75rem center;
            padding-right: 2rem;
        }

        .matching-select:focus {
            outline: none;
            border-color: var(--cyan);
        }

        .matching-select:disabled {
            cursor: not-allowed;
            opacity: 0.8;
        }

        .matching-select.matching-correct {
            border-color: var(--green);
        }

        .matching-select.matching-incorrect {
            border-color: var(--orange);
        }

        .matching-result-icon {
            font-size: 1.2rem;
            font-weight: 600;
        }

        .matching-correct-answer {
            margin-left: 2rem;
            padding: 0.25rem 0;
            font-size: 0.9rem;
            color: var(--green);
            font-weight: 500;
        }

        .matching-summary {
            margin-top: 0.5rem;
        }

        /* Mobile matching styles */
        @media (max-width: 768px) {
            .matching-row {
                flex-direction: column;
                align-items: stretch;
                gap: 0.5rem;
                padding: 0.75rem;
            }

            .matching-left {
                padding-bottom: 0.5rem;
                border-bottom: 1px solid var(--border-color);
            }

            .matching-right {
                padding-top: 0.25rem;
            }

            .matching-correct-answer {
                margin-left: 0;
                padding-left: 1.5rem;
            }
        }

        @media (max-width: 480px) {
            .matching-select {
                font-size: 14px;
                padding: 0.4rem 0.6rem;
                padding-right: 1.75rem;
            }

            .matching-term {
                font-size: 0.95rem;
            }
        }
