/* ============================================
   CHINESE MASTER - Responsive & Mobile-First
   Typography + responsive layout + mobile nav
   ============================================ */

/* === BASE TYPOGRAPHY (bigger, more readable) === */
html {
    font-size: 16px;
}

body {
    font-size: 1rem;
    line-height: 1.7;
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

.module-header h1 {
    font-size: 2rem;
    line-height: 1.3;
}

.module-subtitle {
    font-size: 1.05rem;
    line-height: 1.6;
}

h2 {
    font-size: 1.35rem;
}

h3 {
    font-size: 1.15rem;
}

.cn-text,
.chinese-char,
.flashcard-character {
    font-size: 1.25rem;
    letter-spacing: 0.03em;
}

.activity-title {
    font-size: 1.5rem;
}

.activity-subtitle {
    font-size: 0.95rem;
}

.activity-eyebrow {
    font-size: 0.7rem;
}

.btn {
    font-size: 0.95rem;
    min-height: 44px;
    padding: 0.7rem 1.5rem;
}


/* =============================================
   TOUCH TARGET OPTIMIZATIONS (pointer: coarse)
   ============================================= */
@media (pointer: coarse) {
    .btn,
    button,
    [role="button"],
    .action-card,
    .exercise-type-card,
    .level-card,
    .nav-link,
    .back-btn,
    .word-card,
    .matching-card,
    .fill-blank-option,
    .grammar-lesson-item,
    .rating-btn,
    .srs-btn,
    .exercise-controls .btn {
        min-height: 48px;
    }

    .action-card {
        padding: 20px 18px;
    }

    .exercise-type-card {
        padding: 20px 16px;
    }

    .nav-link {
        padding: 14px 20px;
    }

    .back-btn {
        padding: 12px 18px;
    }

    .modal-close {
        width: 56px;
        height: 56px;
        font-size: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-nav-toggle {
        width: 48px;
        height: 48px;
    }

    .search-input,
    input[type="text"],
    input[type="search"],
    textarea {
        min-height: 48px;
    }
}


/* =============================================
   INPUT & FORM ACCESSIBILITY
   ============================================= */

/* Prevent iOS zoom on focus (16px minimum) */
input,
textarea,
select,
.dictation-input,
.search-input {
    font-size: 16px;
}

/* Global focus-visible for keyboard accessibility
   (reinforced here since this loads last) */
:focus-visible {
    outline: 2px solid #f1c40f;
    outline-offset: 2px;
}

input:focus,
textarea:focus,
select:focus,
.search-input:focus,
.dictation-input:focus {
    outline: 2px solid var(--primary, #fca5a5);
    outline-offset: 2px;
    border-color: var(--primary, #fca5a5);
}


/* =============================================
   FOOTER
   ============================================= */
.site-footer {
    margin-left: 260px;
    padding: 18px 32px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.15);
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 260px);
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 1300px;
    margin: 0 auto;
}

.footer-brand {
    color: var(--text-muted, #64748b);
    font-size: 0.8rem;
}

.footer-links {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--text-secondary, #cbd5e1);
    font-size: 0.8rem;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--color-primary, #fca5a5);
}


/* =============================================
   MOBILE HAMBURGER TOGGLE
   ============================================= */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    z-index: 200;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: background 0.2s, transform 0.2s;
}

.mobile-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.14);
}

.mobile-nav-toggle:active {
    transform: scale(0.92);
}

.mobile-nav-toggle:focus-visible {
    outline: 2px solid #f1c40f;
    outline-offset: 2px;
}

/* Hamburger icon animation */
.mobile-nav-toggle span {
    display: inline-block;
    transition: transform 0.3s ease, opacity 0.2s;
}

/* When nav is open, rotate the icon (JS toggles aria-expanded) */
.mobile-nav-toggle[aria-expanded="true"] span {
    transform: rotate(90deg);
    opacity: 0.8;
}


/* =============================================
   MOBILE NAV OVERLAY
   ============================================= */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 150;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.mobile-nav-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}


/* =============================================
   SWIPE-TO-CLOSE HINT
   ============================================= */
.main-nav::after {
    content: '';
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 44px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 2px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

@media (max-width: 768px) {
    .main-nav.mobile-open::after {
        opacity: 1;
        animation: swipeHintPulse 2.5s ease-in-out 0.6s 1 forwards;
    }
}

@keyframes swipeHintPulse {
    0%   { opacity: 0.15; }
    30%  { opacity: 0.55; }
    60%  { opacity: 0.15; }
    80%  { opacity: 0.45; }
    100% { opacity: 0.15; }
}


/* =============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================= */

/* Performance: active module renders visible; inactive hidden via display:none (modern-theme.css) */

/* Use transform for animations (not top/left) */
@keyframes slideInToast {
    from { transform: translateX(120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}


/* =============================================
   PRINT STYLES
   ============================================= */
@media print {
    .main-nav,
    .mobile-nav-toggle,
    .mobile-nav-overlay,
    .site-footer,
    .toast-container,
    .modal,
    .theme-toggle,
    .loading-screen,
    .mobile-nav-toggle {
        display: none !important;
    }

    #app {
        display: block !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        background: white !important;
        max-width: 100% !important;
    }

    body,
    .main-content,
    .module,
    #app,
    .module-header {
        background: white !important;
        color: black !important;
    }

    .module-header h1,
    .module-header h2,
    h1, h2, h3, h4,
    .greeting,
    .module-subtitle {
        color: black !important;
    }

    .card,
    .stats-card,
    .action-card,
    .exercise-type-card,
    .smart-review-section,
    .analytics-dashboard,
    .level-card,
    .word-card {
        background: white !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        break-inside: avoid;
        color: black !important;
    }

    .stats-card::after {
        display: none !important;
    }

    .stats-value,
    .stats-label,
    .action-card h3,
    .action-card p {
        color: black !important;
    }

    .btn {
        background: white !important;
        color: black !important;
        border: 1px solid #999 !important;
        box-shadow: none !important;
    }

    a {
        color: #0000EE !important;
        text-decoration: underline;
    }

    .cn-text,
    .chinese-char,
    .flashcard-character,
    .word-card-character {
        color: black !important;
    }

    .dashboard-grid,
    .action-cards,
    .level-cards {
        break-inside: avoid;
    }

    /* Ensure all visible content fits */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}


/* =============================================
   RESPONSIVE BREAKPOINTS
   ============================================= */

/* -- Tablet: 769-1024px -- */
@media (max-width: 1024px) {
    /* Dashboard insight row stacks on tablet */
    .dashboard-insight-row {
        grid-template-columns: 1fr;
    }
    
    .greeting { font-size: 24px; }
    
    .main-nav {
        width: 240px;
    }

    .main-content {
        margin-left: 240px;
        padding: 24px 20px;
        max-width: calc(100vw - 240px);
    }

    .site-footer {
        margin-left: 240px;
        padding: 16px 20px 20px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        max-width: calc(100vw - 240px);
    }

    .action-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
    .listening-menu, .reading-menu, .speaking-menu { grid-template-columns: repeat(2, 1fr); }
    .achievements-grid { grid-template-columns: repeat(2, 1fr); }

    .flashcard {
        width: 280px;
        height: 360px;
        margin: 0 auto;
    }

    .flashcard-character {
        font-size: 48px;
    }

    .minimal-pair-cards {
        grid-template-columns: 1fr 1fr;
    }

    .comprehension-options,
    .grammar-options,
    .passage-options,
    .sentence-options,
    .context-options {
        grid-template-columns: 1fr 1fr;
    }

    /* Dashboard snapshot stacks on tablet */
    .dashboard-snapshot {
        grid-template-columns: 1fr;
    }
    .dashboard-snapshot .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .weekly-chart-section {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-md);
    }
    .weekly-summary {
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
}

/* -- Phone: max-width 768px -- */
@media (max-width: 768px) {
    .dashboard-hero { margin-bottom: 24px; padding: 16px 16px; }
    .hero-top-row { flex-direction: column; gap: var(--spacing-md); }
    .hero-metrics { flex-direction: row; gap: var(--spacing-sm); justify-content: center; }
    .hero-metric { min-width: 70px; padding: 8px 12px; }
    .hero-greeting .greeting { font-size: 20px; }
    .greeting { font-size: 22px; }
    .greeting-subtitle { font-size: 14px; }
    .hero-level-bar { padding: 8px 12px; }
    .hero-level-title { font-size: 12px; }
    .dashboard-snapshot { grid-template-columns: 1fr; gap: var(--spacing-md); }
    .dashboard-snapshot .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-snapshot .daily-goal-section { padding: var(--spacing-md); }
    .weekly-chart-section { flex-direction: column; align-items: stretch; gap: var(--spacing-md); padding: var(--spacing-md); }
    .weekly-chart { height: 100px; }
    .weekly-summary { display: flex; align-items: center; justify-content: space-around; }
    .weekly-summary-num { font-size: 22px; }
    .skills-stat-row { grid-template-columns: repeat(3, 1fr); gap: 6px; }
    .skills-stat-pill { padding: 6px 8px; }
    .skills-stat-pill .pill-value { font-size: 14px; }
    .proverb-chinese { font-size: 18px; }
    
    /* Show hamburger */
    .mobile-nav-toggle {
        display: flex;
    }

    .mobile-nav-overlay {
        display: block;
    }

    /* Slide-out nav */
    .main-nav {
        width: 280px;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
        transition: transform 0.3s ease;
        z-index: 160;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .main-nav.mobile-open {
        transform: translateX(0);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        background: rgba(10, 10, 15, 0.97);
    }

    .main-content {
        margin-left: 0;
        padding: 16px 12px calc(80px + env(safe-area-inset-bottom, 16px));
        padding-top: 72px;
        max-width: 100%;
    }

    .site-footer {
        margin-left: 0;
        padding: 16px 12px 20px;
        padding-bottom: calc(88px + env(safe-area-inset-bottom, 16px));
        max-width: 100%;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .footer-links {
        justify-content: center;
    }

    /* Stack everything */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .goal-progress {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }

    .goal-ring {
        width: 120px;
        height: 120px;
    }

    .action-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .action-card {
        padding: 20px 16px;
        min-height: 110px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .action-card:active {
        transform: scale(0.96);
    }

    .action-card h3 {
        font-size: 0.9rem;
    }

    .action-card p {
        font-size: 0.75rem;
    }

    /* Exercise type cards */
    .listening-menu,
    .reading-menu,
    .speaking-menu,
    .grammar-menu,
    .vocab-menu {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .exercise-type-card {
        padding: 20px 16px;
    }

    .exercise-type-card:active {
        transform: scale(0.97);
    }

    .exercise-type-card .type-icon {
        font-size: 28px;
    }

    /* Stats cards */
    .stats-card {
        padding: 16px 12px;
    }

    .stats-card:active {
        transform: scale(0.96);
    }

    .stats-icon {
        font-size: 24px;
    }

    .stats-value {
        font-size: 26px;
    }

    .stats-label {
        font-size: 0.65rem;
    }

    /* Flashcard */
    .flashcard {
        width: 260px;
        height: 340px;
    }

    .flashcard-character {
        font-size: 40px;
    }

    /* Reading passage */
    .reading-passage {
        font-size: 1.1rem;
        padding: 16px;
    }

    /* Grammar */
    .grammar-pattern {
        font-size: 1.1rem;
        padding: 16px;
    }

    .grammar-examples li {
        font-size: 0.95rem;
    }

    /* Speaking */
    .speaking-text {
        font-size: 1.4rem;
    }

    /* Exercise container */
    .exercise-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .exercise-container {
        padding: 0 var(--spacing-sm);
    }

    /* Activity cards */
    .activity-card {
        padding: 16px;
        margin-left: auto;
        margin-right: auto;
    }

    .audio-hero {
        padding: 16px;
    }

    .audio-hero .audio-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }

    .dictation-input {
        font-size: 20px;
        padding: 16px 14px;
        min-height: 56px;
    }

    /* Back button - larger touch target on mobile */
    .back-btn {
        min-height: 48px;
        padding: 10px 18px;
        font-size: 1rem;
        border-radius: 8px;
    }

    /* Comprehension */
    .comprehension-options,
    .passage-options,
    .grammar-options,
    .sentence-options,
    .context-options {
        grid-template-columns: 1fr;
    }

    /* Minimal pairs */
    .minimal-pair-cards {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .minimal-pair-card .pair-char {
        font-size: 44px;
    }

    /* Matching grid */
    .match-grid {
        grid-template-columns: 1fr;
    }

    .matching-card {
        font-size: 0.9rem;
        min-height: 48px;
    }

    /* Achievement grid */
    .achievements-grid {
        grid-template-columns: 1fr;
    }

    /* SRS buttons */
    .srs-buttons {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .srs-btn {
        width: 100%;
        max-width: 300px;
        min-height: 48px;
    }

    /* Rating grid */
    .rating-grid {
        flex-wrap: wrap;
        gap: 8px;
    }

    .rating-btn {
        width: 64px;
        padding: 8px 4px;
        min-height: 48px;
    }

    .rating-number {
        font-size: 20px;
    }

    /* Level cards */
    .level-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .level-card {
        padding: 14px 10px;
        min-height: 90px;
    }

    .level-card:active {
        transform: scale(0.95);
    }

    .level-number {
        font-size: 24px;
    }

    /* Word browser grid */
    .browser-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    /* Speaking */
    .shadowing-display .sh-cn,
    .speaking-display .sp-cn {
        font-size: 2rem;
    }

    /* Tone display */
    .tone-display .tone-number {
        width: 50px;
        height: 50px;
    }

    .tone-display .tone-number .tone-num {
        font-size: 18px;
    }

    /* Dialogue */
    .dialogue-turn {
        flex-direction: column !important;
        align-items: flex-start;
    }

    .dialogue-bubble {
        max-width: 100%;
    }

    /* Smart review: stack buttons vertically on mobile */
    .review-actions {
        flex-direction: column;
        gap: 8px;
    }

    .review-actions .btn {
        width: 100%;
        min-width: unset;
        flex: unset;
    }

    /* Toast */
    .toast-container {
        top: auto;
        bottom: 60px;
        right: 10px;
        left: 10px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .toast {
        min-width: auto;
        font-size: 0.85rem;
    }

    /* Modal */
    .modal-content {
        padding: 24px 20px 20px;
        max-height: 85vh;
        max-height: 85dvh;
        overflow-y: auto;
        margin: 10px;
        border-radius: 16px;
    }

    .modal-close {
        width: 56px;
        height: 56px;
        font-size: 30px;
        top: 4px;
        right: 4px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255, 255, 255, 0.05);
    }

    .modal-close:active {
        background: rgba(255, 255, 255, 0.12);
    }

    /* Profile button in nav */
    .profile-name {
        max-width: 120px;
    }

    /* Analytics adjustments */
    .analytics-dashboard .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .analytics-dashboard .category-grid {
        grid-template-columns: 1fr 1fr;
    }

    /* Speed reading */
    .speed-timer .timer-value {
        font-size: 28px;
    }

    /* Exercise controls */
    .exercise-controls {
        flex-direction: column;
        align-items: center;
        gap: 8px;
    }

    .exercise-controls .btn {
        width: 100%;
        max-width: 320px;
        justify-content: center;
        min-height: 48px;
    }

    /* Module header on mobile */
    .module-header {
        margin-bottom: 20px;
    }

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

    .greeting {
        font-size: 1.4rem;
    }

    /* Hide nav when hidden on mobile — kept off-screen and out of tab order */
    .main-nav.hidden {
        visibility: hidden;
    }

    /* Recent activity */
    .activity-item {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .activity-icon {
        font-size: 18px;
    }

    /* Level progress card */
    .level-info {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
    }

    .level-badge-large {
        min-width: auto;
        padding: 16px 24px;
    }

    /* Chart bars */
    .chart-bars {
        height: 100px;
    }

    /* Word cards */
    .word-card-character {
        font-size: 24px;
    }

    /* Fill-in-blank */
    .fill-blank-options {
        flex-direction: column;
        align-items: center;
    }

    .fill-blank-option {
        width: 100%;
        max-width: 280px;
        text-align: center;
        min-height: 48px;
    }

    /* Grammar lesson item */
    .grammar-lesson-item {
        padding: 12px 14px;
        min-height: 48px;
    }

    .grammar-lesson-info h3 {
        font-size: 0.9rem;
    }

    .grammar-lesson-info p {
        font-size: 0.75rem;
    }

    /* Vocab header */
    .vocab-header h2 {
        font-size: 1.4rem;
    }

    .vocab-header p {
        font-size: 0.9rem;
    }

    /* Word cards on mobile - better touch */
    .word-card {
        padding: 14px 10px;
        min-height: 80px;
    }

    .word-card:active {
        transform: scale(0.95);
    }

    /* Ensure nav links have generous tap targets */
    .nav-link {
        min-height: 48px;
        padding: 14px 20px;
    }

    /* Nav footer on mobile */
    .nav-footer {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .gallery-grid { grid-template-columns: 1fr; }
    .activity-card { padding: 20px; border-radius: 14px; }
    .audio-hero .audio-btn { width: 70px; height: 70px; font-size: 28px; }
    .dictation-input { font-size: 20px; padding: 14px; }
    .shadowing-display .sh-cn { font-size: 36px; }
    .speaking-display .sp-cn { font-size: 38px; }
    .radical-grid { grid-template-columns: repeat(2, 1fr); }
    .activity-eyebrow { font-size: 10px; }
    .activity-title { font-size: 18px; }
    .passage-card .passage-body { font-size: 18px; }
    .grammar-question-card .q-cn { font-size: 22px; }
}

/* -- Small phone: max-width 480px -- */
@media (max-width: 480px) {
    .greeting { font-size: 19px; }
    .hero-metrics { gap: 8px; }
    .hero-metric { min-width: 60px; padding: 6px 10px; }
    .hero-metric-value { font-size: 16px; }
    .dashboard-snapshot .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .weekly-chart { height: 80px; gap: 4px; }
    .weekly-bar-label { font-size: 9px; }
    .weekly-bar-value { font-size: 9px; }
    .skills-stat-row { grid-template-columns: repeat(3, 1fr); }
    .proverb-card { padding: var(--spacing-md); }
    .proverb-chinese { font-size: 16px; }
    
    .main-nav {
        width: 100%;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .stats-value {
        font-size: 22px;
    }

    .action-cards {
        grid-template-columns: 1fr;
    }

    .action-card {
        padding: 22px 18px;
        min-height: 100px;
    }

    .level-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .browser-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .match-grid {
        grid-template-columns: 1fr;
    }

    .flashcard {
        width: 240px;
        height: 300px;
    }

    .flashcard-character {
        font-size: 34px;
    }

    .dictation-answer-reveal .answer-cn {
        font-size: 22px;
    }

    .rating-grid {
        justify-content: center;
    }

    /* Exercise type cards - full width on tiny screens */
    .exercise-type-card {
        padding: 22px 16px;
    }
}


/* =============================================
   DESKTOP NAV FIX
   ============================================= */
@media (min-width: 845px) {
    .mobile-nav-toggle {
        display: none;
    }

    .mobile-nav-overlay {
        display: none !important;
    }

    .main-nav {
        transform: translateX(0) !important;
    }

    .main-nav.hidden {
        transform: translateX(-100%) !important;
        visibility: hidden;
    }
}

/* Extra small phones (320-380px) */
@media (max-width: 380px) {
    .dashboard-grid { grid-template-columns: 1fr; gap: 8px; }
    .exercise-type-card, .vocab-mode-card, .game-card { padding: 14px; }
    .greeting { font-size: 20px; }
    .module-header h1 { font-size: 20px; }
    .flashcard-character { font-size: 40px; }
    .speaking-text { font-size: 28px; }
    .main-content { padding: var(--spacing-md); padding-bottom: calc(80px + env(safe-area-inset-bottom, 16px)); }
}

/* Small phone: max-width 360px */
@media (max-width: 360px) {
    .dashboard-grid { grid-template-columns: 1fr; gap: 8px; }
    .dashboard-hero { padding: 12px 8px; }
    .hero-metrics { gap: 4px; }
    .hero-metric { min-width: 52px; padding: 4px 8px; }
    .hero-metric-value { font-size: 14px; }
    .hero-greeting .greeting { font-size: 17px; }
    .greeting { font-size: 17px; }
    .greeting-subtitle { font-size: 12px; }
    .action-cards { grid-template-columns: 1fr; }
    .action-card { padding: 16px 12px; min-height: 92px; }
    .level-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .level-card { padding: 12px 8px; min-height: 80px; }
    .level-number { font-size: 20px; }
    .match-grid { grid-template-columns: 1fr; }
    .browser-grid { grid-template-columns: 1fr; }
    .flashcard { width: 220px; height: 280px; }
    .flashcard-character { font-size: 32px; }
    .stats-card { padding: 12px 8px; }
    .stats-value { font-size: 20px; }
    .stats-label { font-size: 0.6rem; }
    .stats-icon { font-size: 20px; }
    .module-header h1 { font-size: 18px; }
    .speaking-text { font-size: 24px; }
    .dictation-input { font-size: 18px; padding: 12px 8px; min-height: 52px; }
    .audio-hero .audio-btn { width: 60px; height: 60px; font-size: 24px; }
    .rating-btn { width: 56px; padding: 8px 4px; min-height: 44px; }
    .rating-number { font-size: 18px; }
    .comprehension-options,
    .passage-options,
    .sentence-options,
    .context-options,
    .grammar-options { gap: 8px; }
    .main-content { padding: 12px 8px calc(80px + env(safe-area-inset-bottom, 16px)); padding-top: 64px; }
}

/* Landscape phone: short viewport */
@media (orientation: landscape) and (max-height: 500px) {
    .ambient-bg { display: none; }
    .dashboard-hero { padding: 10px 14px; margin-bottom: 10px; }
    .hero-top-row { flex-direction: row; gap: 10px; }
    .hero-greeting .greeting { font-size: 18px; }
    .hero-greeting .greeting-subtitle { font-size: 12px; display: none; }
    .hero-metrics { gap: 6px; }
    .hero-metric { min-width: 50px; padding: 4px 8px; }
    .hero-metric-value { font-size: 14px; }
    .hero-metric-label { font-size: 9px; }
    .hero-level-bar { padding: 6px 10px; }
    .module-header { margin-bottom: 10px; }
    .module-header h1 { font-size: 1.2rem; }
    .module-subtitle { font-size: 0.85rem; }
    .main-content { padding-top: 60px; padding-bottom: calc(80px + env(safe-area-inset-bottom, 16px)); }
    .flashcard { width: 220px; height: 260px; margin: 0 auto; }
    .flashcard-character { font-size: 32px; }
    .modal-content { max-height: 90vh; max-height: 90dvh; overflow-y: auto; padding: 16px 14px; }
    .main-nav { padding-top: 8px; }
    .nav-link { min-height: 40px; padding: 10px 16px; font-size: 0.85rem; }
    .site-footer { display: none; }
    .gallery-grid { grid-template-columns: repeat(2, 1fr); }
}