:root {
    --primary-hue: 260;
    /* Deep Violet */
    --primary: hsl(var(--primary-hue), 60%, 50%);
    --primary-dark: hsl(var(--primary-hue), 60%, 30%);
    --accent: hsl(320, 80%, 60%);
    /* Pinkish */
    --bg-gradient: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
    --success: #4ade80;
    --error: #f87171;
    --font-serif: 'Noto Serif SC', serif;
    --font-sans: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0; /* Add padding for scrolling space */
}

/* Background Blobs for Atmosphere */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
    animation: float 20s infinite alternate;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: var(--primary);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 300px;
    height: 300px;
    background: var(--accent);
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.blob-3 {
    width: 200px;
    height: 200px;
    background: blue;
    top: 40%;
    left: 40%;
    animation-delay: -10s;
    opacity: 0.4;
}

@keyframes float {
    0% {
        transform: translate(0, 0);
    }

    100% {
        transform: translate(30px, 30px);
    }
}

/* Main Container */
.main-container {
    width: 100%;
    max-width: 600px;
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 1; /* Ensure content is above blobs */
    transition: max-width 0.4s ease; /* Smooth transition for width change */
}

/* Adaptive Width for Book Mode on Desktop */
body.book-mode-active .main-container {
    max-width: 1200px;
}

header {
    text-align: center;
    margin-bottom: 10px;
}

h1 {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    margin-bottom: 5px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Mode Switcher */
.mode-switcher {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 30px;
    padding: 5px;
    border: 1px solid var(--glass-border);
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 10px 25px;
    border-radius: 25px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: var(--font-sans);
}

.mode-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.mode-btn:hover:not(.active) {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

/* Auto-next Progress Bar */
.auto-next-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin: 10px 0 15px 0;
    overflow: hidden;
}

.auto-next-progress {
    height: 100%;
    background: var(--success);
    width: 100%;
    transition: width 3s linear;
}

/* No Results Mode */
.no-results-mode .card-scene {
    cursor: default;
}

.no-results-mode .card {
    border: 2px dashed rgba(255, 255, 255, 0.2);
    box-shadow: none;
    background: rgba(255, 255, 255, 0.02);
}

.no-results-mode .card-front {
    background: transparent;
}

.no-results-mode #question-text {
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
}

.no-results-mode #answer-text {
    font-size: 1.1rem;
    color: var(--primary);
}

.no-results-mode .hint,
.no-results-mode .controls,
.no-results-mode .action-buttons {
    display: none !important;
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

#flashcard-section,
#quiz-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    animation: fadeIn 0.5s ease;
}

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

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

/* 3D Card Scene */
.card-scene {
    width: 100%;
    height: 400px; /* Slightly taller for longer content */
    perspective: 1000px;
    cursor: pointer;
}

.card {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 5px;
    text-align: center;
}

.card-front {
    /* distinct border or gradient for front */
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    color: var(--text-main);
}

.card-back {
    transform: rotateY(180deg);
    background: linear-gradient(145deg, rgba(76, 29, 149, 0.4), rgba(88, 28, 135, 0.2));
}

.card-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 5px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

#question-text,
#answer-text {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    line-height: 1.5;
}

#answer-text {
    color: #e0e7ff;
    font-weight: 700;
}

.hint {
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
    opacity: 0.6;
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 30px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

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

.progress-display {
    font-size: 1.2rem;
    font-variant-numeric: tabular-nums;
    font-family: var(--font-sans);
    color: var(--text-muted);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 30px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(100, 50, 200, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-primary:hover {
    background: hsl(var(--primary-hue), 70%, 55%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(100, 50, 200, 0.6);
}

footer {
    font-size: 0.85rem;
    color: var(--text-muted);
    opacity: 0.5;
    margin-top: 10px;
}

/* Quiz Styles */
.quiz-card {
    width: 100%;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    border-radius: 24px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
    margin-bottom: 5px;
}

#quiz-question {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    min-height: 80px;
    margin-bottom: 10px;
}

.quiz-hint {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: -10px;
    margin-bottom: 10px;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 15px 20px;
    border-radius: 12px;
    color: var(--text-main);
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    position: relative;
    overflow: hidden;
}

.option-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.option-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

.option-btn.correct {
    background: rgba(74, 222, 128, 0.2);
    border-color: var(--success);
    color: #86efac;
}

.option-btn.wrong {
    background: rgba(248, 113, 113, 0.2);
    border-color: var(--error);
    color: #fca5a5;
}

.quiz-feedback {
    margin-top: 10px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    animation: fadeIn 0.3s;
}

.feedback-status {
    font-weight: bold;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.feedback-status.success {
    color: var(--success);
}

.feedback-status.error {
    color: var(--error);
}

.feedback-rationale {
    font-size: 0.95rem;
    color: #e0e7ff;
    line-height: 1.5;
    margin-bottom: 15px;
}

/* Book Content Styles */
/* Book Content Styles */
#book-section {
    width: 100%;
    max-width: 1200px;
}

.book-container {
    display: flex;
    gap: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    border-radius: 20px;
    height: 80vh; 
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
}

#book-back-btn {
    display: none; /* Hidden by default (desktop) */
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: white; /* Changed from var(--primary) for better visibility */
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 15px;
    padding: 0;
    font-family: var(--font-sans);
}

#book-back-btn:hover {
    text-decoration: underline;
    color: var(--accent);
}

.book-toc {
    width: 320px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

/* ... existing TOC styles ... */ 

.book-toc h3 {
    padding: 20px 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-family: var(--font-serif);
    font-size: 1.3rem;
    color: var(--text-main);
    letter-spacing: 1px;
}

#toc-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    padding: 15px;
}

.toc-item {
    padding: 15px 20px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    transition: all 0.2s ease;
    margin-bottom: 8px;
    line-height: 1.4;
    border: 1px solid transparent;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

.toc-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.book-content {
    flex: 1;
    overflow-y: auto;
    padding: 50px 60px; /* More breathing room */
    scroll-behavior: smooth;
    background: rgba(255, 255, 255, 0.02);
}

#book-title {
    font-family: var(--font-serif);
    font-size: 2.4rem; /* Larger title */
    margin-bottom: 15px;
    color: var(--text-main);
    line-height: 1.3;
}

.book-meta {
    margin-bottom: 40px;
    color: var(--accent); /* Changed from var(--primary) for better contrast */
    font-weight: 500;
    font-family: var(--font-sans);
    text-transform: uppercase;
    font-size: 0.95rem;
    letter-spacing: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 20px;
}

/* Hierarchical TOC */
.chapter-group {
    list-style: none;
    margin-bottom: 20px;
}

.chapter-header {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    color: var(--accent);
    font-weight: 600;
    padding: 10px 15px;
    margin-bottom: 5px;
    letter-spacing: 1px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.chapter-articles {
    list-style: none;
    padding-left: 0;
}

.chapter-articles .toc-item {
    margin-left: 15px; /* Indent sub-items */
    font-size: 0.95rem; /* Slightly smaller text for sub-items */
    border-left: 2px solid rgba(255, 255, 255, 0.05); /* Visual guide */
    border-radius: 0 12px 12px 0; /* Only round right side */
}

.chapter-articles .toc-item:hover {
    border-left-color: var(--primary);
}

.chapter-articles .toc-item.active {
    border-left-color: var(--accent);
}

.article-body {
    font-family: var(--font-serif);
    font-size: 1.35rem; /* Increased from 1.2rem */
    line-height: 2; /* Increased from 1.8 */
    color: #e2e8f0;
    max-width: 800px;
    margin: 0 auto; /* Center content for readability */
}

.article-body p {
    margin-bottom: 25px;
    text-align: justify;
}

/* Scrollbar Styling */
.book-toc ::-webkit-scrollbar,
.book-content::-webkit-scrollbar {
    width: 6px;
}

.book-toc ::-webkit-scrollbar-thumb,
.book-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.book-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsive Book Mode */
@media (max-width: 900px) {
    #book-section {
        max-width: 100%;
        padding: 0 10px;
    }

    .book-container {
        flex-direction: column;
        height: 85vh;
        position: relative;
    }

    /* Logic for Master-Detail View */
    .book-toc {
        width: 100%;
        height: 100%; /* Take full height initially */
        border-right: none;
        max-height: none; /* Reset constraint */
        position: absolute;
        top: 0;
        left: 0;
        z-index: 10;
        transition: transform 0.3s ease-in-out;
    }

    .book-content {
        padding: 25px 20px;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 5;
        background: var(--glass-bg); /* Ensure background covers TOC */
        transform: translateX(100%); /* Initially hidden to right */
        transition: transform 0.3s ease-in-out;
    }
    
    /* When in reading mode */
    .book-container.mobile-reading-mode .book-toc {
        transform: translateX(-100%); /* Slide TOC away */
    }

    .book-container.mobile-reading-mode .book-content {
        transform: translateX(0); /* Slide content in */
        z-index: 15; /* Be on top */
    }
    
    #book-back-btn {
        display: flex; /* Show back button on mobile content view */
    }

    .book-toc h3 {
        padding: 15px;
        font-size: 1.1rem;
    }

    #toc-list {
        padding: 10px;
    }

    .toc-item {
        padding: 12px 15px;
        font-size: 1rem;
        margin-bottom: 5px;
    }

    #book-title {
        font-size: 1.8rem;
    }

    .article-body {
        font-size: 1.15rem; 
        line-height: 1.8;
    }
}

/* Responsive */
@media (max-width: 600px) {
    body {
        padding: 20px 0;
        align-items: flex-start;
    }

    .card-scene {
        height: 450px;
    }

    h1 {
        font-size: 1.8rem;
    }

    #question-text,
    #answer-text {
        font-size: 1.25rem;
    }

    .quiz-card {
        padding: 20px;
    }

    #quiz-question {
        font-size: 1.2rem;
    }
    
    .main-container {
        max-width: 100%;
    }
}