:root {
    /* --- Color System (Slate Scale) --- */
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* --- Brand Colors (Indigo) --- */
    --primary: #4f46e5;
    /* Indigo 600 */
    --primary-hover: #4338ca;
    /* Indigo 700 */
    --primary-light: #e0e7ff;
    /* Indigo 100 */
    --accent: #ec4899;
    /* Pink 500 */

    /* --- Semantic Variables --- */
    --bg-app: var(--slate-100);
    --bg-sidebar: var(--slate-900);
    --bg-card: #ffffff;

    --text-main: var(--slate-800);
    --text-muted: var(--slate-500);
    --text-sidebar: var(--slate-400);
    --text-sidebar-active: #ffffff;

    --border-subtle: var(--slate-200);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-float: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    /* --- Dimensions --- */
    --sidebar-width: 280px;
    --header-height: 72px;
}

/* Reset & Base */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', 'Pretendard', sans-serif;
    color: var(--text-main);
    background: var(--bg-app);
    height: 100vh;
    overflow: hidden;
}

/* --- Layout --- */
.app-container {
    display: flex;
    height: 100%;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    padding: 24px;
    border-right: 1px solid var(--slate-800);
    color: var(--text-sidebar);
}

.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 40px;
    padding-left: 8px;
}

.brand i {
    color: var(--primary);
}

.nav-menu {
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
    /* Scrollbar formatting */
}

/* Custom Scrollbar for dark sidebar */
.nav-menu::-webkit-scrollbar {
    width: 4px;
}

.nav-menu::-webkit-scrollbar-thumb {
    background: var(--slate-700);
    border-radius: 4px;
}

.nav-section {
    margin-bottom: 32px;
}

.nav-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--slate-500);
    font-weight: 700;
    margin-bottom: 12px;
    padding-left: 12px;
}

.nav-item {
    display: block;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    color: var(--slate-400);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--slate-200);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 20px;
    border-top: 1px solid var(--slate-800);
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-weight: bold;
    font-size: 0.8rem;
    display: grid;
    place-items: center;
}

.info .name {
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}

.info .status {
    color: var(--slate-500);
    font-size: 0.75rem;
}


/* --- Main Content --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-app);
}

/* Header */
.top-bar {
    height: var(--header-height);
    background: var(--bg-app);
    /* Transparent feel or solid? Solid matches bg */
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    justify-content: space-between;
    padding: 0 32px;
    position: relative;
    z-index: 50;
    /* Ensure it stays above content */
}

.header-left h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--slate-900);
}

.subtitle {
    font-size: 0.85rem;
    color: var(--slate-500);
}

/* Mode Tabs */
.mode-tabs {
    background: white;
    padding: 4px;
    border-radius: 10px;
    display: flex;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--slate-500);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 6px;
    align-items: center;
}

.mode-btn:hover {
    color: var(--slate-700);
    background: var(--slate-50);
}

.mode-btn.active {
    background: var(--slate-900);
    color: white;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}


/* --- Views --- */
.content-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-section {
    position: absolute;
    inset: 0;
    overflow: hidden;
    /* Prevent body scroll */
    display: flex;
    /* Use flex to manage scroll area */
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-out;
}

.view-section.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* -- Study Mode -- */
#study-container {
    flex: 1;
    overflow-y: auto;
    /* Scroll ONLY the content */
    padding: 32px;
    padding-bottom: 120px;
    /* Space for player */
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* Guide Box */
.guide-box {
    background: white;
    border: 1px solid var(--primary-light);
    border-left: 4px solid var(--primary);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.guide-box.hidden {
    display: none;
}

.guide-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    margin-bottom: 12px;
}

.guide-content p {
    margin: 6px 0;
    font-size: 0.95rem;
    line-height: 1.5;
}

.guide-content .intent {
    font-weight: 600;
    color: var(--slate-800);
}

.guide-content .tips {
    color: var(--slate-600);
    background: var(--slate-50);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-top: 10px;
}

/* Toolbar */
.toolbar {
    max-width: 800px;
    margin: 0 auto 16px;
    display: flex;
    justify-content: flex-end;
}

.control-group {
    background: white;
    padding: 4px;
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    display: flex;
    gap: 4px;
}

.icon-btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--slate-600);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.1s;
}

.icon-btn:hover {
    background: var(--slate-50);
    color: var(--slate-900);
}

/* Sentences */
.sent-item {
    background: white;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.sent-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.sent-item.active {
    border-color: var(--primary);
    background: #fdfdff;
    /* very subtle tint */
    box-shadow: 0 0 0 1px var(--primary);
}

.eng-text {
    font-size: 1.05rem;
    font-weight: 500;
    line-height: 1.6;
    color: var(--slate-800);
}

.eng-text.hidden {
    display: none;
}

.kor-text {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--slate-500);
}

.kor-text.hidden {
    display: none;
}

.sent-item.active .eng-text {
    color: var(--primary);
    font-weight: 600;
}

/* Floating Player (Custom) */
.floating-player {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 500px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    padding: 12px 24px;
    border-radius: 100px;
    box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.8);
    z-index: 100;
}

.custom-player-wrapper audio {
    display: none;
}

.custom-controls {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 16px;
}

.progress-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: var(--slate-200);
    border-radius: 10px;
    transition: background 0.2s;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--primary);
    margin-top: -5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.time-display {
    font-size: 0.75rem;
    color: var(--slate-500);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Button overrides for player */
.circle-btn.small {
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.text-btn.small {
    font-size: 0.85rem;
    padding: 6px 12px;
    background: var(--slate-100);
    border-radius: 20px;
    color: var(--slate-700);
}


/* -- Memorize Mode -- */
.memorize-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.card-stack {
    width: 600px;
    height: 360px;
    perspective: 1200px;
    margin-bottom: 30px;
}

.flashcard {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
    cursor: pointer;
}

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

.card-content {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.card-content .front,
.card-content .back {
    position: absolute;
    inset: 0;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    background: white;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.card-content .back {
    transform: rotateY(180deg);
    border: 2px solid var(--primary);
}

.hint-text {
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 1px;
    font-weight: 700;
    color: var(--slate-400);
    margin-bottom: 24px;
}

h3 {
    margin: 0;
    font-size: 1.4rem;
    line-height: 1.5;
    font-weight: 600;
    color: var(--slate-800);
}

.tap-hint {
    margin-top: 32px;
    font-size: 0.8rem;
    color: var(--slate-400);
}

.controls-bar {
    display: flex;
    gap: 24px;
    align-items: center;
    margin-bottom: 16px;
}

.circle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid var(--border-subtle);
    background: white;
    color: var(--slate-600);
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s;
    display: grid;
    place-items: center;
}

.circle-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

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

.pill-btn {
    border: 1px solid var(--border-subtle);
    background: white;
    padding: 10px 24px;
    border-radius: 100px;
    font-weight: 600;
    color: var(--slate-700);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}

.pill-btn:hover {
    background: var(--slate-50);
}

.progress-indicator {
    font-family: monospace;
    color: var(--slate-400);
}


/* -- Shadowing Mode -- */
.shadowing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.active-sentence-display {
    max-width: 700px;
    margin-bottom: 60px;
    padding: 0 20px;
}

#shadow-eng {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--slate-800);
    margin: 0 0 20px 0;
    line-height: 1.4;
}

#shadow-kor {
    font-size: 1.1rem;
    color: var(--slate-500);
}

.player-controls {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
}

.speed-control {
    background: white;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    display: flex;
}

.speed-btn {
    border: none;
    background: transparent;
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--slate-500);
    cursor: pointer;
}

.speed-btn.active {
    background: var(--slate-100);
    color: var(--primary);
}

.circle-btn.large {
    width: 80px;
    height: 80px;
    font-size: 2.5rem;
    background: var(--slate-900);
    color: white;
    border: none;
}

.loop-control {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--slate-600);
}


/* -- Exam Mode -- */
.exam-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.question-card {
    background: white;
    width: 600px;
    padding: 48px;
    border-radius: 24px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    text-align: center;
    margin-bottom: 40px;
}

.ava-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    display: block;
}

.question-card h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--slate-400);
    margin-bottom: 16px;
}

#exam-topic {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--slate-800);
}

.timer-display {
    font-size: 5rem;
    font-weight: 800;
    color: var(--slate-900);
    font-variant-numeric: tabular-nums;
    margin-bottom: 40px;
    letter-spacing: -2px;
}

.record-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: 16px 36px;
    border-radius: 100px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 10px 20px -5px rgba(239, 68, 68, 0.4);
    transition: all 0.2s;
}

.record-btn:active {
    transform: scale(0.96);
}

.record-btn.recording {
    animation: pulse-red 2s infinite;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

#feedback-area {
    margin-top: 20px;
    text-align: center;
    width: 100%;
    max-width: 700px;
}

.answer-box {
    text-align: left;
    background: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    margin: 20px 0;
    max-height: 300px;
    overflow-y: auto;
    font-size: 0.95rem;
    line-height: 1.6;
    border: 1px solid var(--border-subtle);
    white-space: pre-wrap;
}

#btn-show-answer {
    background: none;
    border: none;
    text-decoration: underline;
    cursor: pointer;
    color: var(--slate-500);
}

.hidden {
    display: none !important;
}

/* --- Mobile Responsive --- */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* Layout */
    .app-container {
        flex-direction: column;
    }

    /* Sidebar (Drawer) */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 80%;
        max-width: 300px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 10px 0 25px rgba(0, 0, 0, 0.5);
    }

    /* Overlay */
    .overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
        backdrop-filter: blur(2px);
    }

    .overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Header */
    .top-bar {
        padding: 0 16px;
        justify-content: flex-start;
        gap: 12px;
    }

    .header-left {
        display: flex;
        align-items: center;
        gap: 12px;
        overflow: hidden;
    }

    .header-left h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .subtitle {
        display: none;
        /* Hide subtitle on mobile to save space */
    }

    #btn-hamburger {
        font-size: 1.2rem;
        color: var(--slate-800);
        padding: 8px;
        margin-left: -8px;
    }

    #btn-close-sidebar i {
        font-size: 1.5rem;
    }

    /* View Section */
    .view-section {
        padding: 16px;
    }

    #study-container {
        padding: 16px;
        padding-bottom: 160px;
        /* More space for player + nav */
    }

    /* Bottom Navigation */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: white;
        border-top: 1px solid var(--border-subtle);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: 100;
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .nav-tab {
        flex: 1;
        height: 100%;
        border: none;
        background: transparent;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: var(--slate-400);
        font-size: 0.7rem;
        font-weight: 500;
        cursor: pointer;
    }

    .nav-tab i {
        font-size: 1.4rem;
        margin-bottom: -2px;
    }

    .nav-tab.active {
        color: var(--primary);
    }

    /* Adjust Floating Player */
    .floating-player {
        bottom: 80px;
        /* Above Bottom Nav */
        width: 95%;
        padding: 10px 16px;
    }

    /* Adjust Cards */
    .card-stack {
        width: 100%;
        height: 300px;
    }

    .question-card {
        width: 100%;
        padding: 24px;
    }
}