/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Nav-menu isolation fixes */
.site-header,
.site-header *,
.main-nav,
.main-nav *,
.mobile-menu-toggle,
.mobile-menu-toggle * {
    box-sizing: border-box !important;
    font-family: Arial, sans-serif !important;
    user-select: auto !important;
    -webkit-user-select: auto !important;
    -moz-user-select: auto !important;
    -ms-user-select: auto !important;
}

/* Ensure nav has proper layering */
.site-header {
    position: relative !important;
    z-index: 1000 !important;
    margin-bottom: 1.5rem !important;
    width: 100% !important;
}

.main-nav {
    position: relative !important;
    z-index: 999 !important;
}

.mobile-menu-toggle {
    z-index: 1001 !important;
}

/* Mobile nav specific fixes */
@media screen and (max-width: 768px) {
    .site-header {
        padding-top: 4rem !important;
    }
    
    .main-nav {
        position: absolute !important;
        top: 3.5rem !important;
        left: 1rem !important;
        right: 1rem !important;
        width: calc(100% - 2rem) !important;
        background-color: #333 !important;
        border-radius: 0.5rem !important;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2) !important;
        max-width: none !important;
        min-width: auto !important;
    }
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    overflow-x: hidden;
    position: relative;
    margin: 0;
    padding: 0;
}

/* Game container - mobile first */
.game-container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.5rem;
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100);
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Menu styles */
.menu-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
    padding: 1.5rem 1rem;
    margin: 0.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.menu-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #4c1d95;
    margin-bottom: 2rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.difficulty-section {
    margin-bottom: 2rem;
}

.difficulty-label {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #374151;
}

.difficulty-select {
    width: 100%;
    max-width: 280px;
    padding: 0.875rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    font-size: 1rem;
    background: white;
    color: #374151;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1rem;
    padding-right: 2.5rem;
}

.difficulty-select:focus {
    outline: none;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.new-game-btn {
    background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
    color: white;
    font-weight: 600;
    padding: 1rem 2rem;
    border-radius: 0.75rem;
    font-size: 1.125rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
    min-width: 140px;
}

.new-game-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
}

.new-game-btn:active {
    transform: translateY(0);
}

/* Game container styles */
.game-wrapper {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
    padding: 1rem 0.5rem;
    margin: 0.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Stats bar */
.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #475569;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-weight: 600;
    color: #334155;
}

/* Sudoku grid container */
.grid-container {
    width: 100%;
    margin: 0.5rem auto;
    background: #1e293b;
    border-radius: 0.75rem;
    padding: 0.375rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Grid layout - 3x3 clusters */
.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 0.25rem;
    width: 100%;
    max-width: min(85vw, calc(var(--vh, 1vh) * 100 - 250px), 500px);
    max-height: min(85vw, calc(var(--vh, 1vh) * 100 - 250px), 500px);
    aspect-ratio: 1;
}

/* Individual 3x3 cluster */
.cluster {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    background: #334155;
    border-radius: 0.25rem;
    overflow: hidden;
}

/* Individual cells */
.cell {
    aspect-ratio: 1;
    border: none;
    background: white;
    font-size: clamp(0.75rem, 2.5vw, 1.5rem);
    font-weight: 600;
    text-align: center;
    color: #1e293b;
    transition: all 0.15s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.cell::-webkit-outer-spin-button,
.cell::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cell:focus {
    outline: none;
    background: #fef3c7;
    box-shadow: inset 0 0 0 2px #f59e0b;
    z-index: 1;
    position: relative;
}

.cell.original {
    background: #f1f5f9;
    font-weight: 700;
    color: #475569;
    cursor: not-allowed;
}

.cell.correct {
    background: #dcfce7;
    color: #166534;
}

.cell.incorrect {
    background: #fecaca;
    color: #dc2626;
}

.cell.solved {
    background: #fef3c7;
    color: #92400e;
}

.cell:disabled {
    cursor: not-allowed;
}

/* Loading spinner */
.loading-container {
    text-align: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 1.5rem;
    padding: 3rem 2rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.spinner {
    width: 4rem;
    height: 4rem;
    border: 3px solid #e5e7eb;
    border-top: 3px solid #8b5cf6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1.5rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 1.125rem;
    color: #475569;
    font-weight: 500;
}

/* Action buttons */
.actions-container {
    text-align: center;
    margin-top: 0.75rem;
    flex-shrink: 0;
}

.check-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    font-weight: 600;
    padding: 0.875rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    margin-bottom: 0.75rem;
    display: block;
    width: 100%;
    max-width: 200px;
    margin-left: auto;
    margin-right: auto;
}

.check-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

.instructions {
    font-size: 0.875rem;
    color: #64748b;
    margin-bottom: 1rem;
}

.success-message {
    margin-bottom: 1.5rem;
}

.success-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #059669;
    margin-bottom: 0.5rem;
}

.success-subtitle {
    font-size: 1.125rem;
    color: #374151;
    margin-bottom: 0.25rem;
}

.success-score {
    font-size: 1.125rem;
    font-weight: 600;
    color: #7c3aed;
}

.button-group {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.secondary-btn {
    background: #6b7280;
    color: white;
    font-weight: 500;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.secondary-btn:hover {
    background: #4b5563;
    transform: translateY(-1px);
}

.primary-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    font-weight: 500;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Tablet styles */
@media (min-width: 768px) {
    .game-container {
        padding: 2rem;
        max-width: 600px;
    }
    
    .menu-container,
    .game-wrapper {
        padding: 3rem 2.5rem;
    }
    
    .menu-title {
        font-size: 3rem;
    }
    
    .grid-container {
        max-width: 450px;
        padding: 0.75rem;
    }
    
    .cell {
        font-size: 1.375rem;
    }
    
    .stats-bar {
        font-size: 1rem;
        flex-wrap: nowrap;
    }
    
    .button-group {
        flex-wrap: nowrap;
    }
    
    .check-btn {
        display: inline-block;
        width: auto;
        margin-bottom: 0;
        margin-right: 0.75rem;
    }
}

/* Desktop styles */
@media (min-width: 1024px) {
    .game-container {
        max-width: 700px;
        padding: 3rem;
    }
    
    .menu-container,
    .game-wrapper {
        padding: 4rem 3rem;
    }
    
    .menu-title {
        font-size: 3.5rem;
    }
    
    .grid-container {
        max-width: 500px;
        padding: 1rem;
    }
    
    .cell {
        font-size: 1.5rem;
    }
    
    .cluster {
        gap: 2px;
    }
    
    .sudoku-grid {
        gap: 0.5rem;
    }
}

/* Mobile-specific optimizations */
@media screen and (max-width: 480px) {
    .game-container {
        padding: 0.25rem;
        min-height: 100vh;
        min-height: 100dvh; /* Dynamic viewport height for mobile */
    }
    
    .menu-container,
    .game-wrapper {
        margin: 0.25rem;
        padding: 1rem 0.75rem;
    }
    
    .menu-title {
        font-size: 2rem;
        margin-bottom: 1rem;
    }
    
    .sudoku-grid {
        max-width: min(95vw, 95vh, 400px);
        gap: 0.125rem;
    }
    
    .grid-container {
        padding: 0.25rem;
        margin: 0.25rem auto;
    }
    
    .cell {
        font-size: clamp(1.2rem, 4vw, 2rem);
    }
    
    .stats-bar {
        padding: 0.75rem;
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
    
    .actions-container {
        margin-top: 0.5rem;
    }
    
    .check-btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }
    
    .button-group {
        gap: 0.5rem;
        margin-top: 0.5rem;
    }
    
    .primary-btn,
    .secondary-btn {
        padding: 0.6rem 1rem;
        font-size: 0.875rem;
    }
}

/* Extra small mobile screens */
@media screen and (max-width: 360px) {
    .game-container {
        padding: 0.125rem;
    }
    
    .menu-container,
    .game-wrapper {
        margin: 0.125rem;
        padding: 0.75rem 0.5rem;
        border-radius: 1rem;
    }
    
    .sudoku-grid {
        max-width: min(98vw, 98vh, 350px);
        gap: 0.125rem;
    }
    
    .cell {
        font-size: clamp(1rem, 3.5vw, 1.8rem);
    }
    
    .stats-bar {
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem;
    }
    
    .stat-item {
        font-size: 0.8rem;
    }
}

/* Landscape mobile optimization */
@media screen and (max-height: 600px) and (orientation: landscape) {
    .game-container {
        padding: 0.25rem;
        justify-content: flex-start;
        min-height: 100vh;
    }
    
    .menu-container,
    .game-wrapper {
        padding: 0.75rem 1rem;
        margin: 0.25rem;
    }
    
    .menu-title {
        font-size: 1.75rem;
        margin-bottom: 0.75rem;
    }
    
    .sudoku-grid {
        max-width: min(50vw, 85vh, 400px);
    }
    
    .stats-bar {
        padding: 0.5rem;
        margin-bottom: 0.25rem;
    }
    
    .actions-container {
        margin-top: 0.5rem;
    }
}

/* Touch improvements for mobile */
@media (hover: none) and (pointer: coarse) {
    .new-game-btn,
    .check-btn,
    .primary-btn,
    .secondary-btn {
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .difficulty-select {
        min-height: 44px;
    }
    
    .cell {
        touch-action: manipulation;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .cell {
        border: 0.5px solid transparent;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .cell,
    .new-game-btn,
    .check-btn,
    .primary-btn,
    .secondary-btn {
        transition: none;
    }
    
    .spinner {
        animation: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .menu-container,
    .game-wrapper {
        background: rgba(15, 23, 42, 0.95);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    .menu-title {
        color: #e2e8f0;
    }
    
    .difficulty-label,
    .stat-label {
        color: #cbd5e1;
    }
    
    .stats-bar {
        background: #1e293b;
        color: #94a3b8;
    }
    
    .instructions {
        color: #94a3b8;
    }
    
    .success-subtitle {
        color: #cbd5e1;
    }
}