/* ═══════════════════════════════════════════════════════════════════════════════
   NYT CROSSWORD MAKER - COMPREHENSIVE RESPONSIVE SYSTEM
   ═══════════════════════════════════════════════════════════════════════════════
   
   A mobile-first responsive design system with touch-optimized interactions,
   fluid typography, and adaptive layouts for all screen sizes.
   
   Breakpoints:
   - xs: 0 - 479px    (Small phones)
   - sm: 480 - 639px  (Large phones)
   - md: 640 - 899px  (Tablets portrait)
   - lg: 900 - 1199px (Tablets landscape, small laptops)
   - xl: 1200px+      (Desktops)
   
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════════════════════
   1. BASE MOBILE OPTIMIZATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Touch-friendly tap behavior - applies to all but doesn't affect sizing */
@media (max-width: 899px) {
    html {
        -webkit-tap-highlight-color: transparent;
    }
    
    body {
        overflow-x: hidden;
    }
    
    button,
    a,
    input,
    select,
    textarea,
    .btn,
    [role="button"] {
        touch-action: manipulation;
    }
}

/* Hide scrollbars on mobile for cleaner look */
@media (max-width: 899px) {
    body::-webkit-scrollbar {
        width: 0;
        display: none;
    }
    body {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   2. TYPOGRAPHY SCALING (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Only apply fluid typography on smaller screens */
@media (max-width: 639px) {
    h1 {
        font-size: clamp(1.5rem, 5vw, 2rem);
    }

    h2 {
        font-size: clamp(1.25rem, 4vw, 1.5rem);
    }

    h3 {
        font-size: clamp(1.1rem, 3.5vw, 1.25rem);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   3. HEADER - RESPONSIVE NAVIGATION
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Mobile header adjustments - only apply on mobile/tablet */
@media (max-width: 899px) {
    .header-nav.hide-mobile,
    .hide-mobile {
        display: none !important;
    }
    
    .header-nav-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Mobile Navigation Drawer */
.mobile-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background-color: var(--bg-overlay, rgba(0, 0, 0, 0.5));
    z-index: var(--z-modal, 1000);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-nav.active {
    opacity: 1;
    visibility: visible;
}

.mobile-nav-content {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 85vw;
    height: 100%;
    background-color: var(--surface-modal, #ffffff);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.mobile-nav.active .mobile-nav-content {
    transform: translateX(0);
}

[data-theme="dark"] .mobile-nav-content {
    background-color: var(--bg-secondary);
}

.mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-default, #e5e5e5);
}

.mobile-nav-close {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

.mobile-nav-items {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 8px;
    color: var(--text-primary, #121212);
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s ease;
}

.mobile-nav-item:hover,
.mobile-nav-item.active {
    background-color: var(--bg-tertiary, #f0f0f0);
}

.mobile-nav-item.active {
    background-color: rgba(247, 218, 33, 0.2);
}

[data-theme="dark"] .mobile-nav-item.active {
    background-color: rgba(247, 218, 33, 0.15);
}

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

@media (max-width: 899px) {
    .mobile-nav-toggle {
        display: flex !important;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        cursor: pointer;
        font-size: 24px;
        color: var(--text-primary);
    }
}

@media (min-width: 900px) {
    .mobile-nav-toggle,
    .mobile-nav {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   4. PAGE LAYOUTS (Mobile/Tablet Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
    .two-column-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   5. CARDS - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .game-card {
        flex-direction: column;
    }
    
    .game-card-preview {
        width: 100%;
        max-height: 200px;
    }
}

@media (max-width: 479px) {
    .stat-value {
        font-size: 1.5rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   6. BUTTONS - TOUCH OPTIMIZED (Mobile/Tablet Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Touch target sizes only for mobile/tablet */
@media (max-width: 899px) {
    .btn,
    button,
    [role="button"] {
        min-height: 44px;
    }
}

@media (max-width: 479px) {
    .btn-group,
    .button-group {
        flex-direction: column;
        gap: 8px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   7. FORMS - RESPONSIVE (Mobile/Tablet Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Only apply touch-friendly form sizes on mobile/tablet */
@media (max-width: 899px) {
    input,
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

@media (max-width: 639px) {
    .form-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .form-row > * {
        flex: none;
        width: 100%;
    }
}

/* Search inputs - mobile only adjustments */
@media (max-width: 639px) {
    .search-container,
    .filter-bar {
        flex-direction: column;
    }
    
    .search-container input,
    .filter-bar input,
    .filter-bar select {
        width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   8. MODALS - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .modal {
        max-width: 100%;
        width: 95%;
        max-height: 90vh;
        max-height: 90dvh;
    }
    
    .modal-footer .btn {
        flex: 1;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   9. TABLES - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 639px) {
    .leaderboard-table {
        font-size: 14px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   10. TABS - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .tabs,
    .tab-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   11. CROSSWORD GRID - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
    .grid {
        touch-action: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   12. CLUES PANEL - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* No desktop overrides - only mobile adjustments */

/* ═══════════════════════════════════════════════════════════════════════════════
   13. PLAY PAGE LAYOUT (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* No desktop overrides - only mobile adjustments */
@media (max-width: 639px) {
    .toolbar {
        gap: 4px;
        padding: 8px;
        flex-wrap: wrap;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   14. MOBILE KEYBOARD & CONTROLS
   ═══════════════════════════════════════════════════════════════════════════════ */

.mobile-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-sticky, 200);
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    background-color: var(--bg-tertiary, #f0f0f0);
}

@media (max-width: 899px) {
    .mobile-controls {
        display: block;
    }
    
    /* Add padding to body to account for keyboard */
    body.keyboard-active {
        padding-bottom: 200px;
    }
}

.mobile-keyboard {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 500px;
    margin: 0 auto;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
}

.key {
    flex: 1;
    max-width: 44px;
    height: 44px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key.wide {
    flex: 1.5;
    max-width: 66px;
}

.key.delete {
    flex: 1.5;
    max-width: 66px;
}

/* Direction toggle */
.mobile-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    justify-content: center;
}

.mobile-btn {
    flex: 1;
    max-width: 150px;
    height: 44px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   15. AUTH PAGE - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 899px) {
    .auth-container {
        flex-direction: column;
    }
}

@media (max-width: 479px) {
    .puzzle-grid-side {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   16. SETTINGS PAGE - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .setting-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .setting-row .toggle-switch {
        align-self: flex-end;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   17. ADMIN PAGE - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .admin-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   18. GALLERY & COMMUNITY - RESPONSIVE (Mobile Only)
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .puzzle-gallery,
    .community-grid {
        grid-template-columns: 1fr;
    }
    
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   19. UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════════ */

/* Hide on mobile breakpoint */
@media (max-width: 899px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

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

/* Safe area insets for notched devices */
@media (max-width: 899px) {
    .safe-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   20. ANIMATIONS - REDUCED MOTION
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   21. LANDSCAPE PHONE OPTIMIZATIONS
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 899px) and (orientation: landscape) and (max-height: 500px) {
    .mobile-controls {
        padding: 4px;
    }
    
    .key {
        height: 36px;
    }
}

