/* =================================
   COTISA - Mobile Responsive Styles
   Completely Redesigned for Better UX
   ================================= */

/* BASE MOBILE OPTIMIZATIONS */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: manipulation;
    scroll-behavior: smooth;
    /* Disable pull-to-refresh on mobile browsers */
    overscroll-behavior-y: contain;
}

html, body {
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
}

/* Prevent horizontal scroll on small screens */
body {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Interactive elements base styles */
button,
a,
input,
select,
textarea,
.btn,
[role="button"],
[onclick] {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* ================================
   SMALL SCREENS (phones)
   Max width: 576px
   ================================ */
@media (max-width: 576px) {
    /* Interactive elements - clickable */
    button, a, input, select, textarea,
    .btn, .btn-primary, .btn-secondary, .btn-block,
    [type="submit"], [type="button"],
    .auth-link a, .nav-menu a, .user-dropdown-btn,
    .hamburger-menu, #google-login-btn, #logout-btn,
    form button {
        position: relative !important;
        z-index: 1 !important;
        pointer-events: auto !important;
        touch-action: manipulation !important;
        cursor: pointer !important;
    }
    
    /* Containers don't block clicks */
    .auth-container, .auth-card, .form-group,
    #app, .card {
        pointer-events: auto !important;
    }
    
    /* BASE TYPOGRAPHY */
    body {
        font-size: 15px;
        line-height: 1.5;
        overflow-x: hidden;
        overflow-y: auto;
    }
    
    #app {
        padding-top: 48px;
        min-height: 100vh;
        overflow-y: auto;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    
    .container {
        padding: 12px 16px;
        width: 100%;
        max-width: 100%;
    }
    
    /* Make first card in container have top margin */
    .container > .card:first-child {
        margin-top: 12px;
    }

    /* ================================
       NAVIGATION
       ================================ */
    .navbar {
        padding: 6px 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--navbar-bg, #1a1a2e);
        min-height: 48px;
    }
    
    .nav-container {
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
    }
    
    .nav-brand {
        font-size: 1rem;
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .nav-brand .chess-icon {
        font-size: 1.2rem;
    }
    
    .nav-brand .brand-text {
        display: inline;
        font-weight: 700;
    }
    
    /* Mobile menu - HIDDEN on mobile, using dropdown instead */
    .nav-menu {
        display: none !important;
    }
    
    /* Hide hamburger on mobile since we use dropdown */
    .hamburger-menu {
        display: none !important;
    }
    
    .nav-menu li {
        width: 100%;
        list-style: none;
    }
    
    .nav-menu a {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 16px;
        text-align: center;
        border-radius: 12px;
        background: rgba(255,255,255,0.08);
        color: var(--navbar-text, white);
        text-decoration: none;
        font-size: 1rem;
        font-weight: 500;
        min-height: 52px;
        transition: background 0.2s;
    }
    
    .nav-menu a:hover,
    .nav-menu a:active {
        background: rgba(255,255,255,0.15);
    }

    /* ================================
       USER INFO & DROPDOWNS
       ================================ */
    .user-info {
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .notifications-container {
        order: 1;
    }
    
    .notification-bell {
        font-size: 1.3rem;
        padding: 10px;
        background: transparent;
        border: none;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .notification-badge {
        position: absolute;
        top: 4px;
        right: 4px;
        font-size: 10px;
        min-width: 18px;
        height: 18px;
        border-radius: 9px;
    }
    
    .user-dropdown-container {
        order: 2;
    }
    
    .user-dropdown-btn {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 6px;
        background: rgba(255,255,255,0.1);
        border: none;
        border-radius: 8px;
        color: var(--navbar-text, white);
    }
    
    #username-display {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .role-badge {
        display: none;
    }
    
    .dropdown-arrow {
        font-size: 0.6rem;
        opacity: 0.7;
    }
    
    /* User dropdown menu */
    .user-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        min-width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        max-height: 80vh;
        overflow-y: auto;
        animation: slideUp 0.3s ease;
        z-index: 1002;
    }
    
    /* Overlay for user dropdown */
    .user-dropdown::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.75);
        z-index: -1;
        animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    @keyframes slideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .user-dropdown-header {
        padding: 20px 16px;
        border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.1));
    }
    
    .user-avatar {
        width: 48px;
        height: 48px;
        font-size: 1.5rem;
    }
    
    .user-details .user-name {
        font-size: 1rem;
        font-weight: 600;
    }
    
    .user-details .user-email {
        font-size: 0.8rem;
        opacity: 0.7;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .user-dropdown-item {
        padding: 16px;
        font-size: 1rem;
        min-height: 52px;
        display: flex;
        align-items: center;
        gap: 12px;
    }
    
    .user-dropdown-item .item-icon {
        font-size: 1.2rem;
    }
    
    /* Show mobile navigation items only on mobile */
    .mobile-nav-item,
    .mobile-nav-divider {
        display: flex !important;
    }
    
    /* Notifications dropdown */
    .notifications-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 60vh;
        border-radius: 20px 20px 0 0;
        animation: slideUp 0.3s ease;
        z-index: 1002;
    }
    
    /* Overlay for notifications dropdown */
    .notifications-dropdown::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.75);
        z-index: -1;
        animation: fadeIn 0.3s ease;
    }
    
    .notifications-header {
        padding: 16px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .notification-item {
        padding: 16px;
        min-height: 60px;
    }

    /* ================================
       AUTH PAGES (Login/Register)
       ================================ */
    .auth-container {
        padding: 20px 16px;
        min-height: calc(100vh - 56px);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .auth-card {
        padding: 24px 20px;
        margin: 0;
        border-radius: 16px;
        width: 100%;
        max-width: 400px;
        background: var(--bg-card);
    }
    
    .auth-header {
        margin-bottom: 24px;
    }
    
    .auth-header h1 {
        font-size: 1.75rem;
        font-weight: 700;
        margin-bottom: 8px;
    }
    
    .auth-header p {
        font-size: 0.95rem;
        opacity: 0.8;
    }
    
    .auth-header .chess-icon {
        font-size: 3rem;
        margin-bottom: 12px;
    }
    
    /* ================================
       FORMS
       ================================ */
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group label {
        display: block;
        margin-bottom: 8px;
        font-weight: 500;
        font-size: 0.95rem;
    }
    
    .form-control {
        padding: 14px 16px;
        font-size: 16px !important; /* Prevents zoom on iOS */
        -webkit-appearance: none;
        appearance: none;
        border-radius: 12px;
        width: 100%;
        border: 2px solid var(--border-color, #e0e0e0);
        background: var(--bg-secondary, #f5f5f5);
        color: var(--text-primary);
        transition: border-color 0.2s, box-shadow 0.2s;
    }
    
    .form-control:focus {
        outline: none;
        border-color: var(--primary, #667eea);
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
    }
    
    select.form-control {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23666' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 16px center;
        background-size: 8px 10px;
        padding-right: 40px;
    }
    
    /* ================================
       BUTTONS
       ================================ */
    .btn {
        padding: 14px 20px;
        font-size: 1rem;
        font-weight: 600;
        min-height: 52px;
        border-radius: 12px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        -webkit-appearance: none;
        appearance: none;
        border: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        transition: transform 0.1s, opacity 0.1s;
    }
    
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .btn-block {
        display: flex;
        width: 100%;
        min-height: 52px;
    }
    
    .btn-primary {
        background: linear-gradient(135deg, var(--primary, #667eea) 0%, var(--secondary, #764ba2) 100%);
        color: white;
    }
    
    .btn-secondary {
        background: var(--bg-secondary);
        color: var(--text-primary);
        border: 2px solid var(--border-color);
    }
    
    /* Social login buttons */
    #google-login-btn,
    #chesscom-login-btn {
        min-height: 52px !important;
        padding: 14px 20px !important;
        font-size: 0.95rem !important;
        border-radius: 12px !important;
    }
    
    form .btn,
    form button[type="submit"],
    .auth-card .btn {
        min-height: 52px !important;
        width: 100%;
    }

    /* ================================
       CARDS
       ================================ */
    .card {
        padding: 16px;
        margin-bottom: 16px;
        border-radius: 16px;
        background: var(--bg-card);
    }
    
    .card-header {
        padding-bottom: 1rem;
        margin-bottom: 1rem;
        border-bottom: 1px solid var(--border-color);
    }
    
    .card-header h2 {
        font-size: 1.25rem;
        font-weight: 700;
        margin-bottom: 0.5rem;
    }
    
    .card-header h3 {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }
    
    .card-header p {
        font-size: 0.9rem;
        color: var(--text-secondary);
        margin: 0;
    }
    
    .card h2, .card h3 {
        font-size: 1.15rem;
        font-weight: 600;
        margin-bottom: 12px;
    }

    /* ================================
       DASHBOARD
       ================================ */
    .dashboard-container {
        padding: 16px;
    }
    
    .dashboard-header {
        margin-bottom: 20px;
    }
    
    .dashboard-header h1 {
        font-size: 1.5rem;
        font-weight: 700;
    }
    
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .stat-card {
        padding: 16px;
        border-radius: 16px;
        text-align: center;
    }
    
    .stat-value {
        font-size: 1.5rem;
        font-weight: 700;
    }
    
    .stat-label {
        font-size: 0.75rem;
        opacity: 0.8;
        margin-top: 4px;
    }
    
    .quick-actions {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .quick-action-btn {
        padding: 20px 16px;
        border-radius: 16px;
        text-align: center;
        min-height: 80px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
    }
    
    .quick-action-btn .icon {
        font-size: 1.5rem;
    }
    
    .quick-action-btn .label {
        font-size: 0.85rem;
        font-weight: 500;
    }

    /* ================================
       TOURNAMENTS
       ================================ */
    .tournament-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    .tournament-card {
        padding: 16px;
        border-radius: 16px;
        background: var(--bg-card);
    }
    
    .tournament-header {
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin-bottom: 12px;
    }
    
    .tournament-name {
        font-size: 1.1rem;
        font-weight: 600;
    }
    
    .tournament-badge {
        display: inline-flex;
        padding: 4px 10px;
        font-size: 0.75rem;
        font-weight: 600;
        border-radius: 20px;
        align-self: flex-start;
    }
    
    .tournament-info {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
        font-size: 0.85rem;
        margin-bottom: 12px;
        opacity: 0.8;
    }
    
    .tournament-info-item {
        display: flex;
        align-items: center;
        gap: 4px;
    }
    
    .tournament-actions {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .tournament-actions .btn {
        width: 100%;
    }

    /* ================================
       TABLES
       ================================ */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    table {
        font-size: 0.85rem;
        width: 100%;
        min-width: 500px;
    }
    
    th, td {
        padding: 12px 8px;
        text-align: left;
    }
    
    th {
        font-weight: 600;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    /* Hide less important columns */
    .hide-mobile {
        display: none !important;
    }

    /* ================================
       CHESS GAME
       ================================ */
    .game-container {
        padding: 12px;
    }
    
    .chess-board-container {
        width: 100%;
        max-width: calc(100vw - 24px);
        margin: 0 auto;
    }
    
    .chess-board {
        width: 100%;
        aspect-ratio: 1;
        max-width: calc(100vw - 24px);
    }
    
    .game-sidebar {
        width: 100%;
        margin-top: 16px;
    }
    
    .player-info {
        padding: 12px;
        border-radius: 12px;
        margin-bottom: 8px;
    }
    
    .player-avatar {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .player-name {
        font-size: 1rem;
        font-weight: 600;
    }
    
    .player-time {
        font-size: 1.25rem;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
    }
    
    .game-controls {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
        margin: 16px 0;
    }
    
    .game-controls .btn {
        flex: 1;
        min-width: 100px;
    }
    
    .move-history {
        max-height: 200px;
        overflow-y: auto;
        padding: 12px;
        border-radius: 12px;
        font-size: 0.85rem;
    }

    /* ================================
       PROFILE
       ================================ */
    .profile-container {
        padding: 16px;
    }
    
    .profile-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 24px 16px;
        border-radius: 16px;
        margin-bottom: 20px;
    }
    
    .profile-avatar {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        margin-bottom: 16px;
        font-size: 3rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .profile-name {
        font-size: 1.5rem;
        font-weight: 700;
        margin-bottom: 4px;
    }
    
    .profile-username {
        font-size: 0.95rem;
        opacity: 0.7;
    }
    
    .profile-stats {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-top: 20px;
        width: 100%;
    }
    
    .profile-stat {
        text-align: center;
        padding: 12px 8px;
        background: rgba(255,255,255,0.1);
        border-radius: 12px;
    }
    
    .profile-stat-value {
        font-size: 1.25rem;
        font-weight: 700;
    }
    
    .profile-stat-label {
        font-size: 0.7rem;
        opacity: 0.7;
        margin-top: 2px;
    }

    /* ================================
       MODALS
       ================================ */
    .modal-overlay {
        padding: 16px;
    }
    
    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
        border-radius: 20px 20px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        animation: slideUp 0.3s ease;
    }
    
    .modal-header {
        padding-bottom: 16px;
        margin-bottom: 16px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .modal-header h2,
    .modal-header h3 {
        font-size: 1.25rem;
        font-weight: 600;
    }
    
    .modal-close {
        width: 44px;
        height: 44px;
        font-size: 1.5rem;
    }
    
    .modal .form-group {
        margin-bottom: 16px;
    }
    
    .modal-footer {
        padding-top: 16px;
        margin-top: 16px;
        border-top: 1px solid var(--border-color);
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .modal-footer .btn {
        width: 100%;
    }

    /* ================================
       PLAYERS LIST
       ================================ */
    .players-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    .player-list-item {
        display: flex;
        align-items: center;
        padding: 12px;
        border-radius: 12px;
        background: var(--bg-card);
        gap: 12px;
    }
    
    .player-list-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        font-size: 1.25rem;
    }
    
    .player-list-info {
        flex: 1;
    }
    
    .player-list-name {
        font-weight: 600;
        font-size: 1rem;
    }
    
    .player-list-rating {
        font-size: 0.85rem;
        opacity: 0.7;
    }

    /* ================================
       ACTION BUTTONS
       ================================ */
    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 8px;
        margin: 16px 0;
    }
    
    .action-buttons .btn {
        width: 100%;
        margin: 0;
    }
    
    .action-buttons.horizontal {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .action-buttons.horizontal .btn {
        flex: 1;
        min-width: calc(50% - 4px);
    }

    /* ================================
       LEADERBOARD
       ================================ */
    .leaderboard-table {
        font-size: 0.85rem;
    }
    
    .leaderboard-table td,
    .leaderboard-table th {
        padding: 12px 8px;
    }
    
    .leaderboard-rank {
        width: 40px;
        text-align: center;
        font-weight: 700;
    }
    
    .leaderboard-player {
        display: flex;
        align-items: center;
        gap: 10px;
    }
    
    .leaderboard-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
    }

    /* ================================
       TOASTS & NOTIFICATIONS
       ================================ */
    .toast-container {
        position: fixed;
        bottom: 20px;
        left: 16px;
        right: 16px;
        z-index: 9999;
    }
    
    .toast {
        width: 100%;
        padding: 16px;
        border-radius: 12px;
        font-size: 0.95rem;
        margin-bottom: 8px;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    /* ================================
       SETTINGS
       ================================ */
    .settings-container {
        padding: 16px;
    }
    
    .settings-section {
        margin-bottom: 24px;
    }
    
    .settings-section h3 {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 12px;
    }
    
    .settings-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px;
        background: var(--bg-card);
        border-radius: 12px;
        margin-bottom: 8px;
    }
    
    .settings-item-label {
        font-weight: 500;
    }
    
    .settings-item-description {
        font-size: 0.85rem;
        opacity: 0.7;
        margin-top: 4px;
    }
    
    /* Theme selector */
    .theme-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .theme-option {
        padding: 16px;
        border-radius: 12px;
        text-align: center;
        min-height: 80px;
        cursor: pointer;
    }

    /* Hide desktop theme selector */
    .theme-selector {
        display: none;
    }
}

/* ================================
   MEDIUM SCREENS (tablets)
   577px - 768px
   ================================ */
@media (max-width: 768px) and (min-width: 577px) {
    #app {
        padding-top: 60px;
    }
    
    .nav-container {
        padding: 0 20px;
    }
    
    .nav-menu {
        gap: 8px;
    }
    
    .nav-menu a {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    .container {
        padding: 0 20px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }
    
    .card {
        padding: 20px;
        border-radius: 16px;
    }
    
    .auth-card {
        max-width: 420px;
        margin: 0 auto;
        padding: 32px;
    }
    
    .modal-content {
        width: 90%;
        max-width: 500px;
        border-radius: 16px;
    }
    
    .tournament-actions {
        flex-direction: row;
    }
    
    .action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .action-buttons .btn {
        flex: 1;
        min-width: 150px;
    }
    
    .profile-stats {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .quick-actions {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ================================
   LANDSCAPE MOBILE
   ================================ */
@media (max-height: 500px) and (orientation: landscape) {
    #app {
        padding-top: 48px;
    }
    
    .navbar {
        padding: 4px 0;
    }
    
    .nav-brand {
        font-size: 1rem;
    }
    
    .auth-container {
        min-height: auto;
        padding: 12px;
        align-items: flex-start;
    }
    
    .auth-card {
        padding: 16px 20px;
    }
    
    .auth-header {
        margin-bottom: 12px;
    }
    
    .auth-header h1 {
        font-size: 1.25rem;
    }
    
    .auth-header .chess-icon {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    .form-group {
        margin-bottom: 10px;
    }
    
    .form-control {
        padding: 10px 14px;
    }
    
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }
    
    .modal-content {
        max-height: 95vh;
    }
}

/* ================================
   TOUCH DEVICE IMPROVEMENTS
   ================================ */
@media (hover: none) and (pointer: coarse) {
    /* Large touch targets */
    .btn, button, 
    input[type="submit"],
    input[type="button"],
    a.nav-link,
    .nav-menu a {
        min-height: 48px !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* All interactive elements clickable */
    .btn-primary, .btn-secondary, .btn-block,
    #google-login-btn, #logout-btn,
    .auth-card button, .auth-card .btn,
    .auth-link a, .nav-menu a,
    form button, form input[type="submit"],
    .hamburger-menu {
        pointer-events: auto !important;
        position: relative;
        z-index: 10;
        touch-action: manipulation;
    }
    
    /* Form controls */
    input, select, textarea {
        touch-action: manipulation;
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    .nav-menu a,
    .user-dropdown-item,
    .notification-item {
        min-height: 52px;
        touch-action: manipulation;
    }
    
    /* Remove hover effects on touch */
    .btn:hover,
    .card:hover,
    .tournament-card:hover {
        transform: none;
    }
    
    /* Active states instead */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
    
    .card:active,
    .tournament-card:active {
        opacity: 0.95;
    }
}

/* ================================
   HAMBURGER MENU BUTTON
   ================================ */
.hamburger-menu {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 48px;
    height: 48px;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 10px;
    padding: 10px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 1001;
    transition: background 0.2s;
}

.hamburger-menu:active {
    background: rgba(255,255,255,0.2);
}

.hamburger-menu span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--white, white);
    margin: 3px 0;
    transition: 0.3s;
    border-radius: 2px;
    pointer-events: none;
}

.hamburger-menu.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.hamburger-menu.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-menu.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

@media (max-width: 576px) {
    .hamburger-menu {
        display: none !important;
    }
}

/* ================================
   SAFE AREA FOR NOTCHED PHONES
   ================================ */
@supports (padding: max(0px)) {
    .navbar {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    
    #app {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .modal-content {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
    
    .user-dropdown,
    .notifications-dropdown {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* ================================
   DARK MODE SPECIFIC MOBILE FIXES
   ================================ */
[data-theme="dark"] {
    .form-control {
        background: var(--bg-secondary);
        border-color: var(--border-color);
    }
    
    select.form-control {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23aaa' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e");
    }
}

/* ================================
   LOADING STATES
   ================================ */
@media (max-width: 576px) {
    .loading-spinner {
        width: 40px;
        height: 40px;
    }
    
    .loading-overlay {
        backdrop-filter: blur(4px);
    }
    
    .skeleton {
        border-radius: 8px;
    }
}

/* ================================
   EMPTY STATES
   ================================ */
@media (max-width: 576px) {
    .empty-state {
        padding: 40px 20px;
        text-align: center;
    }
    
    .empty-state-icon {
        font-size: 3rem;
        margin-bottom: 16px;
        opacity: 0.5;
    }
    
    .empty-state-title {
        font-size: 1.1rem;
        font-weight: 600;
        margin-bottom: 8px;
    }
    
    .empty-state-description {
        font-size: 0.9rem;
        opacity: 0.7;
        margin-bottom: 20px;
    }
}

/* ================================
   HELP PAGE (help.html) MOBILE STYLES
   ================================ */
@media (max-width: 576px) {
    /* Help section mobile styles */
    .help-section {
        margin-bottom: 1.5rem;
    }
    
    .help-section h3 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }
    
    .faq-item {
        margin-bottom: 0.75rem;
        border-radius: 12px;
    }
    
    .faq-question {
        padding: 1rem;
        font-size: 0.95rem;
        gap: 12px;
        min-height: 52px;
        touch-action: manipulation;
        cursor: pointer;
    }
    
    .faq-question:active {
        background: var(--bg-hover);
    }
    
    .faq-arrow {
        font-size: 0.8rem;
        min-width: 20px;
        text-align: center;
    }
    
    .faq-answer {
        font-size: 0.9rem;
        line-height: 1.6;
    }
    
    .faq-answer ul,
    .faq-answer ol {
        padding-left: 1.5rem;
        margin: 0.5rem 0;
    }
    
    .faq-answer li {
        margin-bottom: 0.5rem;
        line-height: 1.5;
    }
    
    .faq-answer p {
        margin-bottom: 0.75rem;
    }
    
    .faq-item.open .faq-answer {
        padding: 0 1rem 1rem;
        max-height: 800px;
    }
    
    .video-tutorial {
        flex-direction: column;
        padding: 1rem;
        text-align: center;
        gap: 0.75rem;
    }
    
    .video-icon {
        font-size: 2.5rem;
    }
    
    .video-info h4 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .video-duration {
        font-size: 0.85rem;
    }
    
    .contact-card {
        padding: 1.5rem;
        border-radius: 12px;
        margin-top: 1.5rem;
    }
    
    .contact-card h3 {
        font-size: 1.2rem;
        margin-bottom: 0.75rem;
    }
    
    .contact-card p {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .contact-card .btn {
        margin-top: 1rem;
        width: 100%;
        max-width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
}

/* ================================
   SETTINGS PAGE (settings.html) MOBILE STYLES
   ================================ */
@media (max-width: 576px) {
    .settings-section {
        margin-bottom: 1.5rem;
        padding-bottom: 1.5rem;
    }
    
    .settings-section h3 {
        font-size: 1.1rem;
        margin-bottom: 1rem;
    }
    
    .settings-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    /* Theme previews */
    .theme-preview {
        padding: 0.75rem;
        border-radius: 10px;
        min-height: 85px;
        touch-action: manipulation;
    }
    
    .theme-preview:active {
        transform: scale(0.98);
    }
    
    .theme-preview-icon {
        font-size: 1.75rem;
        margin-bottom: 0.375rem;
    }
    
    .theme-preview h4 {
        font-size: 0.875rem;
        margin-bottom: 0.25rem;
    }
    
    .theme-preview p {
        font-size: 0.75rem;
    }
    
    /* Chess board and piece styles */
    .chess-style-preview {
        padding: 0.75rem;
        border-radius: 10px;
        touch-action: manipulation;
    }
    
    .chess-style-preview:active {
        transform: scale(0.98);
    }
    
    .chess-board-mini {
        grid-template-columns: repeat(4, 24px);
        grid-template-rows: repeat(4, 24px);
        margin: 0 auto 0.5rem;
    }
    
    .chess-square {
        width: 24px;
        height: 24px;
    }
    
    .piece-examples {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }
    
    .chess-style-preview h4 {
        font-size: 0.875rem;
    }
    
    /* Setting items */
    .setting-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 1rem;
    }
    
    .setting-item.horizontal {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    
    .setting-label {
        width: 100%;
    }
    
    .setting-item.horizontal .setting-label {
        width: auto;
        flex: 1;
    }
    
    .setting-label h4 {
        font-size: 0.95rem;
        margin-bottom: 0.25rem;
    }
    
    .setting-description {
        font-size: 0.85rem;
        line-height: 1.4;
    }
    
    /* Toggle switch */
    .toggle-switch {
        width: 50px;
        height: 28px;
        min-width: 50px;
    }
    
    .toggle-slider {
        border-radius: 28px;
    }
    
    .toggle-slider:before {
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
    }
    
    input:checked + .toggle-slider:before {
        transform: translateX(22px);
    }
    
    /* Select controls */
    .setting-item select,
    select.form-control {
        width: 100%;
        padding: 0.75rem;
        font-size: 1rem;
        border-radius: 8px;
        min-height: 44px;
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-color);
        color: var(--text-primary);
        cursor: pointer;
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='%23999' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 8px 10px;
        padding-right: 2.5rem;
    }
    
    .setting-item select:focus,
    select.form-control:focus {
        outline: 2px solid var(--primary);
        outline-offset: 2px;
    }
    
    /* Auto-save toast for mobile */
    .auto-save-toast {
        bottom: 1rem;
        right: 1rem;
        left: 1rem;
        text-align: center;
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }
    
    .auto-save-toast.show {
        transform: translateY(0);
    }
    
    /* Account section buttons */
    .settings-section .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
        margin-top: 0.5rem;
    }
    
    .settings-section .btn-danger {
        margin-top: 1rem;
    }
}

/* ================================
   TWO-COLUMN LAYOUT FOR TABLETS (settings grid)
   ================================ */
@media (min-width: 577px) and (max-width: 768px) {
    .settings-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

/* ================================
   PRINT STYLES
   ================================ */
@media print {
    .navbar, .user-dropdown, .notifications-dropdown,
    .toast-container, .hamburger-menu, .modal-overlay {
        display: none !important;
    }
    
    #app {
        padding-top: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
