:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #f3f4f6;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --card-bg: #ffffff;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Noto Sans TC', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    overflow: hidden;
    /* App feel */
}

/* Base Layout */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

.unit-list {
    list-style: none;
    padding: 1rem 0;
    flex-grow: 1;
    overflow-y: auto;
}

.unit-item {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    border-left: 3px solid transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
}

.unit-item:hover {
    background-color: var(--secondary-color);
}

.unit-item.active {
    background-color: #eff6ff;
    border-left-color: var(--primary-color);
    color: var(--primary-color);
}

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}

.main-header {
    padding: 2rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(248, 250, 252, 0.8);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 5;
}

.main-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
}

/* Buttons */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background-color: var(--secondary-color);
    color: var(--primary-color);
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.875rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(99, 102, 241, 0.4);
}

.primary-btn:disabled {
    background-color: var(--text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.6;
}

.secondary-btn {
    background-color: var(--secondary-color);
    color: var(--text-main);
    border: none;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.secondary-btn:hover {
    background-color: #e5e7eb;
}

/* Flashcard Area */
.flashcard-container {
    padding: 2rem 3rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-grow: 1;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.empty-icon {
    font-size: 4rem;
    opacity: 0.5;
    margin-bottom: 1rem;
}

.empty-subtext {
    font-size: 0.875rem;
    opacity: 0.8;
}

/* Flipping Card CSS */
.flashcard-carousel {
    perspective: 1000px;
    width: 100%;
    max-width: 600px;
    height: 480px;
    position: relative;
    margin-bottom: 2rem;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}

.flashcard-carousel:not(.hidden) .card-inner:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    /* Safari */
    backface-visibility: hidden;
    background-color: var(--card-bg);
    border-radius: var(--radius-xl);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.8);
}

.card-front {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
}

.card-front .word {
    font-size: 4rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.02em;
}

.card-back {
    transform: rotateY(180deg);
    background: #ffffff;
}

.card-image-wrapper {
    width: 100%;
    height: 55%;
    position: relative;
    overflow: hidden;
    background-color: #e2e8f0;
    /* skeleton */
}

.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.is-flipped .card-image {
    transform: scale(1.05);
    /* subtle zoom on reveal */
}

.card-content {
    padding: 2rem;
    height: 45%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    text-align: left;
}

.card-meaning {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.75rem;
}

.card-example {
    font-size: 1rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.6;
}

/* Carousel Controls */
.carousel-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 600px;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    box-shadow: var(--shadow-md);
}

.tts-btn {
    background-color: white;
    box-shadow: var(--shadow-md);
    width: 48px;
    height: 48px;
    color: var(--primary-color);
}

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

.card-counter {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 40px;
    text-align: center;
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.large-modal {
    max-width: 600px;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-backdrop.hidden .modal {
    transform: scale(0.95);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.25rem 1.5rem;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Inputs & Form */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 500;
    font-size: 0.875rem;
}

input[type="text"],
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition);
}

input[type="text"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea {
    resize: vertical;
    min-height: 120px;
}

.instruction {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.format-example {
    background: #eff6ff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #1e3a8a;
    margin-bottom: 1rem;
}

.format-example code {
    font-weight: 600;
    font-family: monospace;
}

/* ProgressBar */
.import-progress {
    margin-top: 1rem;
}

.import-progress.hidden {
    display: none;
}

.import-progress p {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}

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

/* Responsive Design (Mobile Support) */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        box-shadow: none;
    }

    .unit-list {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        padding: 0.5rem;
        white-space: nowrap;
    }

    .unit-item {
        border-left: none;
        border-bottom: 3px solid transparent;
        padding: 0.5rem 1rem;
        border-radius: var(--radius-md);
        margin-right: 0.5rem;
    }

    .unit-item.active {
        border-left-color: transparent;
        border-bottom-color: var(--primary-color);
        background-color: #eff6ff;
    }

    .main-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 1rem;
    }

    .main-header h1 {
        font-size: 1.5rem;
    }

    .header-actions {
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
        width: 100%;
    }

    .header-actions button {
        flex: 1;
        justify-content: center;
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    .flashcard-container {
        padding: 1rem;
    }

    .flashcard-carousel {
        height: 65vh;
        max-height: 480px;
    }

    .card-front .word {
        font-size: 2.5rem;
    }

    .card-meaning {
        font-size: 1.25rem;
    }

    .card-example {
        font-size: 0.9rem;
    }

    .nav-controls {
        padding: 0.5rem;
        gap: 0.75rem;
    }

    .carousel-controls {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Make tts and complete buttons fit better in mobile */
    .icon-btn.tts-btn {
        width: 48px;
        height: 48px;
    }
}

/* Practice Mode (Immersive View) */
body.practice-active {
    overflow: hidden;
}

body.practice-active .sidebar,
body.practice-active .main-header {
    display: none !important;
}

body.practice-active .app-container {
    display: flex;
    flex-direction: column;
}

body.practice-active .flashcard-container {
    padding: 0;
    justify-content: center;
    align-items: center;
}

/* Practice Mobile Adjustments */
@media (max-width: 768px) {
    body.practice-active .flashcard-carousel {
        height: 70vh;
        max-height: 70vh;
        width: 90vw;
    }

    body.practice-active .card-content {
        justify-content: center;
        padding: 1rem;
    }

    body.practice-active .card-front .word {
        font-size: 3rem;
    }

    body.practice-active .card-meaning {
        font-size: 1.8rem;
    }

    body.practice-active .card-example {
        font-size: 1.2rem;
    }

    body.practice-active .nav-controls {
        display: none !important;
        /* Hide left/right arrows for touch */
    }

    body.practice-active .carousel-controls {
        gap: 2rem;
        margin-top: 1rem;
    }

    body.practice-active .icon-btn.tts-btn {
        width: 64px;
        height: 64px;
        box-shadow: var(--shadow-lg);
    }

    body.practice-active .icon-btn.tts-btn .material-icons-round {
        font-size: 2rem;
    }
}