:root {
    --primary: #4f46e5;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.05);
    --card-bg: #f9fafb;
    --header-bg: #4f46e5;
    --option-bg: #ffffff;
    --question-bg: #ffffff;
    --border-strong: #1f2937;
    /* New for detail layout borders */
}

[data-theme="dark"] {
    --primary: #6366f1;
    --success: #10b981;
    --danger: #ef4444;
    --bg: #111827;
    --card: #1f2937;
    --text: #f9fafb;
    --text-light: #9ca3af;
    --border: #374151;
    --shadow: rgba(0, 0, 0, 0.3);
    --card-bg: #374151;
    --header-bg: #1f2937;
    --option-bg: #374151;
    --question-bg: #1f2937;
    --border-strong: #e5e7eb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Roboto', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    justify-content: center;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    width: 100%;
    max-width: 480px;
    background: var(--card);
    height: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px var(--shadow);
    position: relative;
    transition: background-color 0.3s ease;
}

/* HEADER */
header {
    padding: 15px;
    background: var(--header-bg);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px var(--shadow);
    z-index: 10;
    transition: background-color 0.3s ease;
}

.logo {
    font-weight: 700;
    font-size: 1.1rem;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

#status-bar {
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    gap: 10px;
}

#btn-back {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

#btn-back:hover {
    background: rgba(255, 255, 255, 0.3);
}

#btn-theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 1.2rem;
}

#btn-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(20deg);
}

#btn-theme-toggle:active {
    transform: scale(0.9) rotate(20deg);
}

/* MAIN CONTENT */
main {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    position: relative;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

main::-webkit-scrollbar {
    display: none;
}

/* VIEWS */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
    height: 100%;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* COMPONENTS */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px var(--shadow);
    transition: all 0.3s ease;
}

.hero {
    text-align: center;
    margin-bottom: 20px;
    padding: 20px 0;
}

.hero h1 {
    color: var(--primary);
    margin-bottom: 5px;
}

/* FORM */
.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s ease;
}

/* BUTTONS */
.btn {
    border: none;
    padding: 12px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 1rem;
}

.btn:active {
    transform: scale(0.98);
}

.full-width {
    width: 100%;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

/* LEARNING GRID */
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.tab-btn {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--primary);
    background: var(--card);
    color: var(--primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

.guide-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 15px;
    text-align: center;
    font-style: italic;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 10px;
    padding-bottom: 20px;
}

.char-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.char-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow);
}

.char-card:active {
    transform: scale(0.95);
    background: var(--primary);
    border-color: var(--primary);
}

.char-card:active .korean,
.char-card:active .romaji,
.char-card:active .name {
    color: white;
}

.char-card .korean {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    transition: color 0.2s ease;
}

.char-card .romaji {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 500;
    transition: color 0.2s ease;
}

.char-card .name {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: 2px;
    transition: color 0.2s ease;
}

/* === NEW DETAIL LESSON LAYOUT (CSS Grid) === */
#view-detail {
    height: 100%;
    padding-bottom: 0;
    /* Remove padding bottom to fit footer exactly */
}

.detail-layout {
    display: grid;
    grid-template-rows: auto 1fr auto;
    /* Header, Body (flexible), Footer */
    height: 100%;
    gap: 15px;
}

.detail-header {
    text-align: center;
    font-weight: bold;
    padding: 12px;
    background: var(--card-bg);
    border: 2px solid var(--border-strong);
    /* Strong border per request */
    border-radius: 8px;
    color: var(--text);
}

.detail-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* Two equal columns */
    gap: 0;
    /* No gap between columns, border handles it */
    border: 2px solid var(--border-strong);
    background: var(--card);
    border-radius: 8px;
    overflow: hidden;
    /* For corner radius */
}

.detail-left-col,
.detail-right-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    /* Remove padding here, add to children */
    height: 100%;
}

.detail-left-col {
    border-right: 2px solid var(--border-strong);
    /* Middle separator */
    background: var(--bg);
    /* Slightly different background for contrast */
}

.stroke-area {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 2px solid var(--border-strong);
}

.video-area {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

/* VIDEO LOOP CONTAINER */
.video-loop-container {
    width: 100%;
    max-width: 150px;
    /* Adjust size as needed */
    aspect-ratio: 1/1;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px var(--shadow);
}

.video-loop-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail-char-large {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 6rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.detail-romaji {
    font-size: 1.8rem;
    color: var(--primary);
    font-weight: 500;
    margin: 15px 0;
}

.btn-speak-icon {
    background: none;
    border: none;
    font-size: 3rem;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.btn-speak-icon:hover {
    transform: scale(1.1);
}

.btn-speak-icon:active {
    transform: scale(0.9);
}

.detail-footer {
    border: 2px solid var(--border-strong);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    background: var(--card);
    border-radius: 8px;
    overflow: hidden;
    min-height: 150px;
    /* Ensure enough space for text */
}

.detail-info-box {
    padding: 15px;
    flex: 1;
    /* Takes up remaining vertical space */
    overflow-y: auto;
    /* Scroll if text is too long */
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text);
}

.detail-info-box strong {
    color: var(--primary);
}

.detail-nav-buttons {
    display: flex;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 2px solid var(--border-strong);
    background: var(--card-bg);
}

.btn-nav-text {
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--primary);
    transition: color 0.2s ease;
}

.btn-nav-text:hover {
    color: var(--text);
}

/* === END NEW DETAIL LAYOUT === */


/* QUIZ STYLES */
.quiz-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    height: 100%;
}

#quiz-progress {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.question-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--question-bg);
    border-radius: 12px;
    margin-bottom: 20px;
    min-height: 150px;
    box-shadow: inset 0 0 10px var(--shadow);
    transition: all 0.3s ease;
}

#q-content {
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 4rem;
    font-weight: 700;
    color: var(--text);
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 10px;
}

.option-btn {
    background: var(--option-bg);
    border: 2px solid var(--border);
    padding: 15px;
    border-radius: 12px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 60px;
    font-family: 'Noto Sans KR', sans-serif;
    color: var(--text);
    transition: all 0.3s ease;
}

.option-btn:hover {
    background: var(--card-bg);
    transform: translateY(-2px);
}

.option-btn.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.option-btn.wrong {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.option-btn:disabled {
    opacity: 0.8;
    pointer-events: none;
}

.feedback {
    height: 24px;
    font-weight: bold;
    margin-top: 10px;
}

#btn-audio-replay {
    margin-top: 10px;
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

#btn-audio-replay:hover {
    background: var(--primary);
    color: white;
}

/* RESULT */
.result-card {
    text-align: center;
    padding-top: 40px;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--success);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    margin: 20px auto;
}

#final-time {
    margin-bottom: 30px;
    font-size: 1.1rem;
}

/* FOOTER */
footer {
    padding: 15px;
    text-align: center;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-light);
    transition: all 0.3s ease;
}

@media (max-width: 480px) {
    footer {
        display: none;
    }
}

/* AUDIO INDICATOR */
.audio-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    z-index: 9999;
    pointer-events: none;
    animation: pulse 0.8s ease-in-out;
}

.audio-indicator.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

@keyframes pulse {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.8;
    }
}

/* UX IMPROVEMENTS */
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.btn:active {
    transform: translateY(0) scale(0.98);
}

.btn-primary:hover {
    background: #4338ca;
}

.btn-success:hover {
    background: #059669;
}

/* Ripple effect on cards */
.char-card {
    position: relative;
    overflow: hidden;
}

.char-card::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.char-card:active::before {
    width: 200%;
    height: 200%;
}

/* Animations */
.feedback {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.score-circle {
    animation: scaleIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* UTILS */
.hidden {
    display: none !important;
}