/* ============================================================
   MOBILE RESPONSIVE REDESIGN
   English Master - Complete Mobile Experience
   ============================================================ */

/* --- GLOBAL MOBILE FOUNDATIONS --- */

/* Smooth scrolling & better touch */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

/* Prevent horizontal overflow everywhere */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Better touch targets */
a, button, .option-btn, .portal-nav-item, .roadmap-item, .section-tab {
    min-height: 44px;
    min-width: 44px;
}

/* Fix images from overflowing */
img {
    max-width: 100%;
    height: auto;
}

/* ============================================================
   TABLET BREAKPOINT (max-width: 1024px)
   ============================================================ */
@media (max-width: 1024px) {
    
    /* --- modern.css overrides (Grammar pages) --- */
    .theory-panel {
        padding: 2rem 1.5rem;
        max-width: 50%;
    }

    .practice-panel {
        padding: 2rem 1.5rem;
    }

    .sidebar {
        width: 220px;
    }

    /* --- index.html overrides --- */
    .hero h1 {
        font-size: 2.75rem;
    }

    .features-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 2rem;
    }

    /* --- dashboard.html overrides --- */
    .layout-container {
        gap: 1.5rem;
    }

    .sidebar {
        width: 240px;
    }

    .podium-container {
        gap: 0.75rem;
    }

    .podium-place {
        width: 110px;
    }
}

/* ============================================================
   MOBILE BREAKPOINT (max-width: 768px)
   ============================================================ */
@media (max-width: 768px) {

    /* ---- GLOBAL MOBILE LAYOUT ---- */
    body {
        font-size: 15px;
        overflow-x: hidden;
    }

    /* ---- HAMBURGER MENU SYSTEM ---- */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: none;
        border: 1.5px solid var(--border, #e2e8f0);
        border-radius: 10px;
        cursor: pointer;
        z-index: 200;
        position: relative;
        flex-shrink: 0;
    }

    .mobile-menu-toggle .hamburger-line {
        display: block;
        width: 20px;
        height: 2px;
        background: var(--text-main, #334155);
        border-radius: 2px;
        position: relative;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle .hamburger-line::before,
    .mobile-menu-toggle .hamburger-line::after {
        content: '';
        display: block;
        width: 20px;
        height: 2px;
        background: var(--text-main, #334155);
        border-radius: 2px;
        position: absolute;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle .hamburger-line::before {
        top: -6px;
    }

    .mobile-menu-toggle .hamburger-line::after {
        top: 6px;
    }

    /* Hamburger to X animation */
    .mobile-menu-toggle.active .hamburger-line {
        background: transparent;
    }

    .mobile-menu-toggle.active .hamburger-line::before {
        top: 0;
        transform: rotate(45deg);
    }

    .mobile-menu-toggle.active .hamburger-line::after {
        top: 0;
        transform: rotate(-45deg);
    }

    /* Mobile slide-in menu overlay */
    .mobile-nav-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 150;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-nav-overlay.show {
        display: block;
        opacity: 1;
    }

    .mobile-nav-drawer {
        position: fixed;
        top: 0;
        right: -300px;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        background: white;
        z-index: 160;
        transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 1.5rem;
        padding-top: 5rem;
    }

    .mobile-nav-drawer.open {
        right: 0;
    }

    .mobile-nav-drawer .mobile-nav-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        width: 36px;
        height: 36px;
        border: none;
        background: #f1f5f9;
        border-radius: 50%;
        font-size: 1.25rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #64748b;
    }

    .mobile-nav-drawer a,
    .mobile-nav-drawer button {
        display: block;
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        font-weight: 500;
        color: var(--text-main, #334155);
        text-decoration: none;
        border: none;
        background: none;
        text-align: left;
        border-radius: 10px;
        transition: background 0.2s;
        cursor: pointer;
    }

    .mobile-nav-drawer a:hover,
    .mobile-nav-drawer button:hover {
        background: #f0fdfa;
    }

    /* ---- INDEX.HTML (LANDING PAGE) ---- */

    /* Navbar mobile */
    .navbar {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: rgba(240, 253, 250, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        z-index: 100;
    }

    .nav-links {
        display: none;
    }

    /* Hero section mobile */
    .hero {
        padding: 2.5rem 1.25rem 3rem;
    }

    .hero h1 {
        font-size: 2rem !important;
        line-height: 1.25;
        margin-bottom: 1rem;
    }

    .hero p {
        font-size: 1rem !important;
        margin-bottom: 2rem;
        line-height: 1.7;
    }

    .cta-btn {
        padding: 0.9rem 2rem;
        font-size: 1rem;
        width: 100%;
        max-width: 320px;
        display: inline-block;
        text-align: center;
    }

    /* About section mobile */
    .about {
        padding: 3rem 1.25rem;
    }

    .profile-picture {
        width: 140px;
        height: 140px;
        margin-bottom: 1.5rem;
    }

    .bio-text {
        font-size: 0.95rem;
        text-align: left;
        line-height: 1.75;
        padding: 0;
    }

    /* Features grid mobile */
    .features {
        padding: 3rem 1.25rem;
    }

    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 1.25rem;
    }

    .feature-card {
        padding: 1.5rem;
        text-align: left;
        display: flex;
        gap: 1rem;
        align-items: flex-start;
    }

    .feature-card .feature-icon {
        font-size: 2rem;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .feature-card h3 {
        font-size: 1.15rem;
        margin-bottom: 0.5rem;
    }

    .feature-card p {
        font-size: 0.9rem;
        line-height: 1.6;
    }

    /* Poster / Transformation Preview mobile */
    .transformation-preview {
        padding: 2rem 0.75rem !important;
    }

    .poster-container {
        border-radius: 12px !important;
    }

    .poster-header {
        padding: 1.5rem 1rem !important;
    }

    .poster-header-title {
        font-size: 1.3rem !important;
    }

    .comparison-container {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .before-panel,
    .after-panel {
        width: 100% !important;
        min-width: 0 !important;
    }

    .poster-feature-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    .poster-feature-card {
        padding: 1rem !important;
    }

    .split-section {
        grid-template-columns: 1fr !important;
    }

    .poster-main-content {
        padding: 1rem !important;
    }

    .features-section {
        padding: 1rem !important;
    }

    .features-title {
        font-size: 1.1rem !important;
    }

    /* Footer area */
    .footer {
        padding: 2rem 1.25rem !important;
    }

    /* ---- MODERN.CSS OVERRIDES (GRAMMAR PAGES) ---- */

    /* App header mobile */
    .app-header {
        height: 56px;
        padding: 0 1rem;
    }

    .brand-logo {
        font-size: 1.1rem;
    }

    /* Hide desktop sidebar, show mobile bottom nav */
    .sidebar {
        display: none !important;
    }

    /* Split view → stacked mobile view with tabs */
    .split-view-container {
        flex-direction: column;
    }

    .main-content {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        height: calc(100vh - 56px);
        /* Account for mobile header */
    }

    .theory-panel {
        max-width: 100%;
        border-right: none;
        padding: 1.5rem 1.25rem;
        overflow: visible;
        height: auto;
        flex: none;
    }

    .theory-content {
        max-width: 100%;
    }

    .practice-panel {
        max-width: 100%;
        padding: 1.5rem 1.25rem;
        overflow: visible;
        height: auto;
        flex: none;
        border-top: 2px solid var(--primary-light, #99f6e4);
    }

    .practice-content {
        max-width: 100%;
    }

    /* Grammar topic heading */
    .grammar-topic h1 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .theory-section h3 {
        font-size: 1.1rem;
    }

    /* Exercise cards mobile */
    .exercise-card {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }

    .option-btn {
        padding: 0.85rem 1rem;
        font-size: 0.95rem;
    }

    /* Search modal mobile */
    .search-modal-overlay {
        padding-top: 5vh;
    }

    .search-modal {
        margin: 0 1rem;
        max-width: calc(100vw - 2rem);
    }

    /* Mobile content tabs (theory/practice toggle) */
    .mobile-content-tabs {
        display: flex !important;
        position: sticky;
        top: 56px;
        /* Below app-header */
        z-index: 40;
        background: white;
        border-bottom: 1px solid var(--border, #e2e8f0);
        padding: 0;
    }

    .mobile-content-tab {
        flex: 1;
        padding: 0.85rem;
        text-align: center;
        font-weight: 600;
        font-size: 0.9rem;
        cursor: pointer;
        color: #64748b;
        border: none;
        background: none;
        border-bottom: 3px solid transparent;
        transition: all 0.2s;
    }

    .mobile-content-tab.active {
        color: var(--primary, #0f766e);
        border-bottom-color: var(--primary, #0f766e);
        background: rgba(15, 118, 110, 0.04);
    }

    /* When mobile tabs active, toggle panels */
    .theory-panel.mobile-hidden,
    .practice-panel.mobile-hidden {
        display: none !important;
    }

    /* Web interface (grammar content area) */
    .web-nav {
        padding: 10px 1rem;
    }

    .web-title-section {
        padding: 1rem 1.25rem;
    }

    .web-title {
        font-size: 1.15rem !important;
    }

    .web-content {
        padding: 1.25rem;
    }

    .section-tabs {
        gap: 0.5rem;
    }

    .section-tab {
        padding: 0.4rem 0.9rem;
        font-size: 0.85rem;
    }

    /* ---- DASHBOARD.HTML OVERRIDES ---- */

    /* Dashboard body */
    body {
        padding: 0 !important;
    }

    /* Layout → single column */
    .layout-container {
        flex-direction: column !important;
        gap: 0;
        padding: 0;
        min-height: auto;
    }

    /* Sidebar → horizontal scrollable nav on mobile */
    .layout-container > .sidebar {
        display: flex !important;
        width: 100% !important;
        position: sticky !important;
        top: 0;
        z-index: 90;
        flex-direction: row;
        border-radius: 0;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        height: auto;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        flex-shrink: 0;
        order: -1;
    }

    .layout-container > .sidebar h3 {
        display: none;
    }

    .layout-container > .sidebar .roadmap-list {
        display: none;
    }

    .portal-nav {
        flex-direction: row !important;
        gap: 0.25rem;
        width: 100%;
    }

    .portal-nav-item {
        padding: 0.6rem 1rem;
        white-space: nowrap;
        font-size: 0.85rem;
        gap: 0.5rem;
        border-radius: 20px;
        flex-shrink: 0;
    }

    .portal-nav-item i {
        font-size: 1.1rem;
    }

    .portal-nav-item .nav-text {
        display: inline;
    }

    /* Dashboard app area */
    #app {
        padding: 1.25rem !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    #app h1 {
        font-size: 1.75rem;
    }

    .welcome-text {
        font-size: 0.95rem;
    }

    /* Dashboard header */
    .dashboard-header {
        padding: 1.5rem 1rem !important;
        border-radius: 12px !important;
    }

    .user-profile-summary {
        flex-direction: column !important;
        text-align: center;
        gap: 1rem;
    }

    .user-info {
        text-align: center !important;
    }

    .user-level {
        justify-content: center;
    }

    /* Stats grid mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Course cards mobile */
    .course-cards {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* Podium mobile */
    .podium-container {
        gap: 0.5rem;
        min-height: 200px;
        margin: 1.5rem 0;
    }

    .podium-place {
        width: 100px;
        padding: 0.75rem 0.5rem;
    }

    .podium-1 {
        height: 150px;
    }

    .podium-1 .podium-avatar {
        width: 56px;
        height: 56px;
    }

    .podium-2 {
        height: 115px;
    }

    .podium-3 {
        height: 90px;
    }

    .podium-avatar {
        width: 48px;
        height: 48px;
    }

    .podium-name {
        font-size: 0.8rem;
    }

    .podium-points {
        font-size: 0.75rem;
    }

    .podium-rank {
        width: 24px;
        height: 24px;
        font-size: 0.75rem;
        top: -10px;
    }

    /* Leaderboard table mobile */
    .leaderboard-table th,
    .leaderboard-table td {
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Action cards */
    .action-card {
        padding: 1.25rem;
    }

    .action-btn {
        font-size: 1rem;
        padding: 0.85rem 1.5rem;
    }

    /* Profile section */
    .about-section {
        padding: 1.5rem;
    }

    /* Chart container */
    canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Modal mobile */
    .modal {
        width: 92% !important;
        max-width: 380px;
        padding: 1.5rem;
    }

    .modal h2 {
        font-size: 1.25rem;
    }

    .form-group input {
        padding: 0.85rem;
        font-size: 1rem;
    }

    .auth-submit {
        padding: 0.85rem;
        font-size: 1rem;
    }
}

/* ============================================================
   SMALL PHONE BREAKPOINT (max-width: 480px)
   ============================================================ */
@media (max-width: 480px) {

    /* Even smaller hero text */
    .hero h1 {
        font-size: 1.65rem !important;
    }

    .hero p {
        font-size: 0.9rem !important;
    }

    /* Stats grid → still 2 col but tighter */
    .stats-grid {
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .stat-number {
        font-size: 1.25rem;
    }

    /* Podium even tighter */
    .podium-place {
        width: 85px;
    }

    .podium-1 {
        height: 130px;
    }

    .podium-2 {
        height: 100px;
    }

    .podium-3 {
        height: 80px;
    }

    .podium-1 .podium-avatar {
        width: 44px;
        height: 44px;
    }

    .podium-avatar {
        width: 38px;
        height: 38px;
    }

    /* Profile picture smaller */
    .profile-picture {
        width: 110px;
        height: 110px;
    }

    /* Grammar panels tighter */
    .theory-panel,
    .practice-panel {
        padding: 1rem !important;
    }

    .grammar-topic h1 {
        font-size: 1.3rem;
    }

    .exercise-card {
        padding: 1rem;
    }

    .web-title {
        font-size: 1rem !important;
    }

    .web-content {
        padding: 1rem;
    }

    /* Poster section */
    .poster-header-title {
        font-size: 1.1rem !important;
    }

    .book-page-mockup {
        padding: 0.75rem !important;
    }
}

/* ============================================================
   LANDSCAPE PHONE (orientation fix)
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .hero {
        padding: 1.5rem 1rem;
    }

    .hero h1 {
        font-size: 1.75rem !important;
    }

    /* Grammar pages: allow scroll in landscape */
    body {
        overflow-y: auto !important;
        height: auto !important;
    }

    .app-container {
        height: auto;
    }

    .main-content {
        height: auto;
        overflow: visible;
    }
}

/* ============================================================
   UTILITY: Hide on desktop, show on mobile (and vice versa)
   ============================================================ */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: initial;
}

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

    .desktop-only {
        display: none !important;
    }
}

/* Mobile content tabs hidden by default (shown via media query) */
.mobile-content-tabs {
    display: none;
}

/* Mobile menu toggle hidden on desktop */
.mobile-menu-toggle {
    display: none;
}

/* ============================================================
   SMOOTH TRANSITIONS & POLISH
   ============================================================ */

/* Pull-to-refresh-like overscroll color */
body {
    overscroll-behavior-y: contain;
}

/* Better focus states for touch */
@media (max-width: 768px) {
    *:focus-visible {
        outline: 2px solid var(--primary, #0f766e);
        outline-offset: 2px;
        border-radius: 4px;
    }

    /* Smoother scrolling containers */
    .main-content,
    .theory-panel,
    .practice-panel,
    .layout-container > .sidebar {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Bottom safe area for phones with notches */
    .practice-panel:last-child,
    #app {
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    }
}
