/* GRAMMAR ACADEMY - FINAL PRECISION BUILD */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Outfit:wght@600;700;800&display=swap');

:root {
    --primary: #0ea5e9;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
}

/* TRACK THEMES */
body.theme-sprout {
    --primary: #16a34a;
}

body.theme-builder {
    --primary: #ea580c;
}

body.theme-navigator {
    --primary: #ca8a04;
}

body.theme-mastery {
    --primary: #7c3aed;
}

body {
    background: var(--bg-main);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, sans-serif;
    margin: 0;
    padding-top: 64px;
    /* Account for fixed header */
    line-height: 1.5;
}

/* HEADER - SINGLE ROW, 64px */
.app-header {
    height: 64px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 40px 1fr 80px;
    align-items: center;
    padding: 0 4%;
    gap: 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 100;
    transition: transform 0.3s ease;
}

.app-header.hidden {
    transform: translateY(-100%);
}

.header-logo {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
}

.header-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1.1rem;
    text-align: center;
    color: var(--text-main);
    cursor: pointer;
    transition: color 0.2s;
}

.header-title:hover {
    color: var(--primary);
}

.lang-toggle {
    display: flex;
    background: #f1f5f9;
    padding: 2px;
    border-radius: 6px;
    gap: 2px;
}

.lang-opt {
    padding: 4px 8px;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-muted);
    transition: all 0.2s;
}

.lang-opt.active {
    background: white;
    color: var(--primary);
}

/* CONTENT */
.content-area {
    max-width: 900px;
    margin: 0 auto;
    padding: 16px 4% 24px;
    /* Mobile-first: 4% margins, reduced bottom padding for clearer footer visibility */
}

.hero {
    text-align: center;
    padding: 12px 0 16px;
    /* Reduced from 20px 0 30px */
}

.hero p {
    font-size: 0.95rem;
    /* Slightly smaller */
    color: var(--text-muted);
    font-weight: 500;
    margin: 0;
}

/* MODE SELECTOR */
.mode-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 3px;
    /* Reduced from 4px */
    border-radius: 10px;
    /* Reduced from 12px */
    margin-bottom: 20px;
    /* Reduced from 30px */
    gap: 3px;
    /* Reduced from 4px */
}

.mode-btn {
    border: none;
    background: transparent;
    padding: 8px 4px;
    /* Reduced from 10px 4px */
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    /* Reduced from 4px */
    border-radius: 7px;
    /* Reduced from 8px */
    transition: all 0.2s;
}

.mode-btn span:first-child {
    font-size: 1.2rem;
    /* Reduced from 1.3rem */
}

.mode-btn span:last-child {
    font-size: 0.6rem;
    /* Reduced from 0.65rem */
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.mode-btn.active {
    background: white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.mode-btn.active span:last-child {
    color: var(--primary);
}

/* CHAPTER CARDS - GRID */
.chapters-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    /* Reduced from 20px */
}

@media (min-width: 800px) {
    .chapters-grid {
        grid-template-columns: 1fr 1fr;
        gap: 16px;
        /* Reduced from 24px */
    }
}

.chapter-card {
    background: white;
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 10px;
    /* Reduced from 12px */
    padding: 14px;
    /* Reduced from 20px */
    transition: all 0.2s;
}

.chapter-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
    /* Reduced from 6px */
}

.chapter-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    /* Reduced from 1.2rem */
    color: var(--text-main);
    cursor: pointer;
}

.chapter-title:hover {
    color: var(--primary);
}

.status-badge {
    font-size: 0.6rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(14, 165, 233, 0.1);
    color: var(--primary);
    text-transform: uppercase;
}

.chapter-desc {
    font-size: 0.85rem;
    /* Reduced from 0.9rem */
    color: var(--text-muted);
    margin-bottom: 12px;
    /* Reduced from 16px */
}

/* ACTION BAR */
.action-bar {
    display: flex;
    gap: 8px;
    /* Reduced from 12px */
    padding-top: 10px;
    /* Reduced from 12px */
    border-top: 1px solid var(--border);
}

.action-btn {
    flex: 1;
    background: #f8fafc;
    border: 1px solid var(--border);
    padding: 10px 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
}

.action-btn .icon {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}

.action-btn:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

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

/* FOOTER - SLIM SINGLE ROW */
.app-footer {
    background: white;
    border-top: 1px solid var(--border);
    padding: 12px 4%;
    /* Mobile-first: 4% margins */
    max-height: 8vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 99;
    transition: transform 0.3s ease;
    font-size: 0.8rem;
    /* Smaller text */
}

.app-footer.hidden {
    transform: translateY(100%);
}

.footer-links {
    display: flex;
    gap: 16px;
    /* Reduced from 20px */
}

.footer-link {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.footer-link:hover {
    color: var(--primary);
}

/* CAROUSEL OVERLAY */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(12px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 5vh 4%;
    /* Breathing room on all sides */
    box-sizing: border-box;
}

.overlay.active {
    display: flex;
}

.carousel-container {
    background: white;
    width: 100%;
    max-width: 580px;
    /* Contained, not stretched */
    min-height: 400px;
    /* Content-based minimum */
    max-height: 70vh;
    /* Never consume more than 70% of viewport */
    border-radius: 20px;
    padding: 36px 0 28px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Proper internal layout */
}

.carousel-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: #f1f5f9;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-muted);
    z-index: 10;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-close:hover {
    background: #e2e8f0;
    transform: scale(1.05);
}

.carousel-close:active {
    transform: scale(0.95);
}

.carousel-track {
    display: flex;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    flex: 1;
    /* Allow it to grow within container */
    overflow: hidden;
}

.carousel-screen {
    flex: 0 0 100%;
    /* No grow, no shrink, exactly 100% */
    width: 100%;
    text-align: center;
    padding: 24px 40px;
    /* Generous internal padding */
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Center content vertically */
    overflow-y: auto;
    /* Allow scroll if content overflows */
}

.carousel-icon {
    font-size: 4.5rem;
    /* Large but not overwhelming */
    margin-bottom: 20px;
}

.carousel-screen h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    /* Readable, not shouty */
    font-weight: 800;
    margin-bottom: 16px;
    color: var(--text-main);
}

.carousel-screen p {
    color: var(--text-main);
    line-height: 1.7;
    font-size: 1rem;
    margin: 0;
    max-width: 480px;
    /* Constrain line length for readability */
    margin-left: auto;
    margin-right: auto;
}

.carousel-screen p strong {
    color: var(--primary);
    font-weight: 700;
}

.carousel-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 20px 0 16px;
    padding: 0 40px;
    flex-shrink: 0;
    /* Prevent compression */
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e2e8f0;
    transition: all 0.3s;
    cursor: pointer;
}

.dot:hover {
    background: #cbd5e1;
}

.dot.active {
    background: var(--primary);
    width: 24px;
    border-radius: 4px;
}

.carousel-btn {
    width: calc(100% - 80px);
    /* Proper gutters on sides */
    margin: 0 40px 4px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 15px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
    /* Prevent compression */
}

.carousel-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
}

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

@media (max-width: 768px) {
    .overlay {
        padding: 3vh 4%;
        /* Tighter on mobile but still breathing room */
    }

    .carousel-container {
        max-width: 100%;
        max-height: 75vh;
        /* Slightly more space on mobile */
        padding: 28px 0 20px;
        min-height: 360px;
    }

    .carousel-screen {
        padding: 20px 24px;
        /* Reduced but not cramped */
    }

    .carousel-screen h2 {
        font-size: 1.5rem;
    }

    .carousel-icon {
        font-size: 3.5rem;
    }

    .carousel-screen p {
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .carousel-dots {
        padding: 0 24px;
        margin: 16px 0 12px;
    }

    .carousel-btn {
        width: calc(100% - 48px);
        margin: 0 24px 4px;
        padding: 14px;
    }
}

/* PAGE 0 - INTRODUCTION PAGE STYLES */
.page-0-container {
    max-width: 700px;
    margin: 0 auto;
    padding: 12px 0 24px;
}

.page-0-header {
    text-align: center;
    padding: 16px 0 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.page-0-chapter {
    font-family: 'Outfit', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0 0 8px 0;
}

.page-0-subtitle {
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    margin: 0;
}

.page-0-section {
    background: white;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 16px;
    transition: all 0.2s;
}

.page-0-section:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.page-0-section-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 12px 0;
}

.page-0-text {
    line-height: 1.7;
    color: var(--text-main);
    margin: 0;
    font-size: 0.95rem;
}

.page-0-list {
    margin: 0;
    padding-left: 24px;
    line-height: 1.8;
}

.page-0-list li {
    margin-bottom: 8px;
    color: var(--text-main);
    font-size: 0.95rem;
}

.page-0-highlight {
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.05) 0%, rgba(14, 165, 233, 0.1) 100%);
    border-left: 4px solid var(--primary);
}

.page-0-callout {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-left: 4px solid #64748b;
}

.page-0-cta {
    text-align: center;
    padding: 32px 0 20px;
}

.page-0-start-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.page-0-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
}

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

/* Responsive adjustments for Page 0 */
@media (max-width: 768px) {
    .page-0-chapter {
        font-size: 1.5rem;
    }

    .page-0-section-title {
        font-size: 1.1rem;
    }

    .page-0-section {
        padding: 16px;
    }
}

/* NAVIGATION FOOTER BUTTONS */
.reader-footer {
    border-top: 2px solid #f1f5f9;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.95));
}

#view-reader {
    padding-bottom: 88px;
    box-sizing: border-box;
}

#btn-prev, #btn-next {
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
}

#btn-prev {
    border: 2px solid var(--border);
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

#btn-prev:hover:not(:disabled) {
    background: #f8fafc;
    border-color: var(--primary);
    transform: translateX(-2px);
}

#btn-prev:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#btn-next {
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.25);
}

#btn-next:hover:not(:disabled) {
    background: #0891b2;
    transform: translateX(2px);
    box-shadow: 0 4px 10px rgba(14, 165, 233, 0.35);
}

#btn-next:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #94a3b8;
}

#page-indicator {
    font-weight: 700;
    color: var(--text-main);
}

/* DESKTOP MARGINS - Maintain 20px on larger screens */
/* MOBILE FIRST - Optimize for small screens */
@media (max-width: 767px) {
    /* Header improvements */
    .app-header {
        height: 56px;
        padding: 0 3%;
    }
    
    .logo-text {
        font-size: 1.1rem !important;
    }
    
    .lang-toggle {
        padding: 1px;
    }
    
    .lang-opt {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
    
    /* Reader header */
    .reader-header {
        height: 56px !important;
        padding: 0 3% !important;
    }
    
    #reader-chapter {
        font-size: 0.75rem !important;
    }
    
    #reader-title {
        font-size: 0.9rem !important;
    }
    
    /* Mode selector - stack on very small screens */
    .mode-selector {
        gap: 2px;
        padding: 2px;
    }
    
    .mode-btn span:last-child {
        font-size: 0.55rem;
    }
    
    /* Hero section */
    .hero p {
        font-size: 0.9rem;
        padding: 0 10px;
    }
    
    /* Chapter cards */
    .chapter-card {
        padding: 14px;
    }
    
    .chapter-card h3 {
        font-size: 1rem;
    }
    
    .chapter-subtitle {
        font-size: 0.8rem;
    }
    
    /* Quiz carousel */
    .quiz-carousel {
        padding: 14px;
        margin: 20px 0;
    }
    
    .quiz-nav-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }
    
    .quiz-counter {
        font-size: 0.85rem;
    }
    
    .quiz-stem {
        font-size: 0.95rem;
    }
    
    .quiz-option label {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .quiz-explanation {
        padding: 12px;
        margin: 0 12px 12px;
        font-size: 0.85rem;
    }
    
    /* Page 0 */
    .page-0-container {
        padding: 10px 0 20px;
    }
    
    .page-0-header {
        padding: 12px 0 16px;
    }
    
    .page-0-chapter {
        font-size: 1.4rem;
    }
    
    .page-0-subtitle {
        font-size: 0.9rem;
    }
    
    .page-0-section {
        padding: 14px 16px;
        margin-bottom: 14px;
    }
    
    .page-0-section-title {
        font-size: 1.05rem;
    }
    
    .page-0-text {
        font-size: 0.9rem;
    }
    
    /* Footer buttons */
    .reader-footer {
        padding: 16px 3% !important;
    }

    #view-reader {
        padding-bottom: 72px;
    }
    
    #btn-prev, #btn-next {
        padding: 8px 16px !important;
        font-size: 0.9rem !important;
    }
    
    #page-indicator {
        font-size: 0.85rem;
    }
}

/* TABLET & DESKTOP */
@media (min-width: 768px) {
    .app-header {
        padding: 0 20px;
    }

    .app-footer {
        padding: 12px 20px;
    }

    .content-area {
        padding: 16px 20px 24px;
    }

    .reader-header {
        padding: 0 20px !important;
    }

    .reader-footer {
        padding: 24px 20px !important;
    }
}

.hidden {
    display: none !important;
}