/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light theme colors */
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --background: #ffffff;
    --surface: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    
    /* Grid specific colors */
    --grid-border: #d1d5db;
    --grid-thick-border: #374151;
    --cell-bg: #ffffff;
    --cell-selected: #dbeafe;
    --cell-highlight: #fef3c7;
    --cell-error: #fee2e2;
    --cell-given: #f3f4f6;
    --cell-notes: #9ca3af;
    
    /* Fonts */
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'Consolas', monospace;
}

[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --secondary-color: #9ca3af;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --error-color: #f87171;
    --background: #111827;
    --surface: #1f2937;
    --card-bg: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --border-color: #4b5563;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    
    --grid-border: #4b5563;
    --grid-thick-border: #9ca3af;
    --cell-bg: #374151;
    --cell-selected: #1e3a8a;
    --cell-highlight: #92400e;
    --cell-error: #7f1d1d;
    --cell-given: #4b5563;
    --cell-notes: #6b7280;
}

body {
    font-family: var(--font-family);
    background: var(--background);
    color: var(--text-primary);
    transition: all 0.3s ease;
    overflow-x: hidden;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header */
.header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo i {
    font-size: 1.8rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.language-selector {
    position: relative;
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    min-width: 120px;
    display: none;
    z-index: 200;
}

.language-dropdown.active {
    display: block;
}

.language-dropdown button {
    width: 100%;
    padding: 0.5rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.language-dropdown button:hover {
    background: var(--surface);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn.primary {
    background: var(--primary-color);
    color: white;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.secondary {
    background: var(--surface);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn.secondary:hover {
    background: var(--border-color);
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--border-color);
    border-color: var(--primary-color);
}

.btn-icon.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Screens */
.screen {
    min-height: calc(100vh - 80px);
    padding: 2rem;
}

/* Main Menu */
.main-menu {
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-container {
    max-width: 500px;
    width: 100%;
    text-align: center;
}

.menu-title h2 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.menu-title p {
    color: var(--text-secondary);
    font-size: 1.2rem;
    margin-bottom: 3rem;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.menu-btn {
    width: 100%;
    padding: 1rem 2rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.menu-btn:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.menu-btn.primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.menu-btn i {
    font-size: 1.2rem;
}

/* Game Setup */
.game-setup {
    display: flex;
    align-items: center;
    justify-content: center;
}

.setup-container {
    max-width: 600px;
    width: 100%;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.setup-container h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.setup-option {
    margin-bottom: 2rem;
}

.setup-option label {
    display: block;
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.size-options,
.difficulty-options {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.size-btn,
.difficulty-btn {
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 80px;
    text-align: center;
    font-weight: 500;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 120px;
}

.difficulty-btn small {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.size-btn.active,
.difficulty-btn.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.size-btn:hover,
.difficulty-btn:hover {
    border-color: var(--primary-color);
}

.setup-actions {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
}

.setup-actions .btn {
    flex: 1;
    justify-content: center;
}

/* Game Screen */
.game-screen {
    padding: 1rem;
    padding-bottom: 140px; /* Space for number input bar */
    min-height: calc(100vh - 80px);
    display: flex;
    flex-direction: column;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.game-info {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.timer,
.difficulty-display,
.progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.timer i {
    color: var(--primary-color);
}

.game-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 1rem 0;
}

.grid-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

/* Sudoku Grid */
.sudoku-grid {
    display: grid;
    gap: 1px;
    background: var(--grid-thick-border);
    border: 3px solid var(--grid-thick-border);
    border-radius: 12px;
    padding: 1px;
    max-width: 100%;
    width: 100%;
    aspect-ratio: 1;
    box-shadow: var(--shadow-lg);
}

/* Grid size variations */
.sudoku-grid.size-4 {
    grid-template-columns: repeat(4, 1fr);
}

.sudoku-grid.size-6 {
    grid-template-columns: repeat(6, 1fr);
}

.sudoku-grid.size-9 {
    grid-template-columns: repeat(9, 1fr);
}

.sudoku-grid.size-12 {
    grid-template-columns: repeat(12, 1fr);
}

.sudoku-grid.size-16 {
    grid-template-columns: repeat(16, 1fr);
}

.sudoku-cell {
    aspect-ratio: 1;
    background: var(--cell-bg);
    border: 1px solid var(--grid-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 4vw, 1.5rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.sudoku-cell:active {
    transform: scale(0.95);
}

.sudoku-cell:hover:not(.given) {
    background: var(--surface);
    cursor: pointer;
}

.sudoku-cell.given:hover {
    cursor: default;
}

.sudoku-cell.selected {
    background: var(--cell-selected) !important;
    border-color: var(--primary-color);
    border-width: 2px;
    z-index: 1;
    box-shadow: inset 0 0 0 2px var(--primary-color);
    animation: cellPulse 0.3s ease-out;
}

@keyframes cellPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.sudoku-cell.highlighted {
    background: var(--surface);
}

.sudoku-cell.error {
    background: var(--cell-error) !important;
    color: var(--error-color);
}

.sudoku-cell.given {
    background: var(--cell-given);
    font-weight: 700;
    color: var(--text-primary);
}

.sudoku-cell.notes-mode {
    font-size: clamp(0.5rem, 2vw, 0.8rem);
    color: var(--cell-notes);
    font-weight: 400;
    padding: 2px;
}

/* Box borders for 9x9 grid */
.sudoku-grid.size-9 .sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--grid-thick-border);
}

.sudoku-grid.size-9 .sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-grid.size-9 .sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--grid-thick-border);
}

/* Number Input Bar - Modern Bottom Toolbar */
.number-input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-top: 2px solid var(--border-color);
    padding: 0.75rem;
    box-shadow: 0 -4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

[data-theme="dark"] .number-input-bar {
    background: rgba(55, 65, 81, 0.95);
}

.number-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.control-btn {
    flex: 1;
    max-width: 120px;
    padding: 0.6rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.control-btn.active {
    background: var(--warning-color);
    border-color: var(--warning-color);
    color: white;
}

.control-btn.erase-btn {
    background: var(--error-color);
    border-color: var(--error-color);
    color: white;
}

.control-btn.erase-btn:hover {
    opacity: 0.9;
}

.control-btn i {
    font-size: 1rem;
}

.number-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.number-btn {
    flex: 0 0 calc(11.11% - 0.5rem);
    min-width: 45px;
    aspect-ratio: 1;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.number-btn:active {
    transform: scale(0.92);
}

.number-btn:hover {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
}

.number-btn.selected {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
}

.number-btn.disabled {
    opacity: 0.3;
    pointer-events: none;
}

/* Statistics Screen */
.statistics-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

.stats-container {
    max-width: 800px;
    width: 100%;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.stats-container h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Help Screen */
.help-screen {
    display: flex;
    align-items: center;
    justify-content: center;
}

.help-container {
    max-width: 700px;
    width: 100%;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
}

.help-container h2 {
    font-size: 2rem;
    margin-bottom: 2rem;
    color: var(--text-primary);
    text-align: center;
}

.help-content {
    margin-bottom: 2rem;
}

.help-section {
    margin-bottom: 2rem;
}

.help-section h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.help-section p,
.help-section li {
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.help-section ul {
    padding-left: 2rem;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Success Modal */
.success-content {
    animation: successPulse 0.5s ease-out;
}

.success-animation {
    font-size: 4rem;
    color: var(--success-color);
    margin-bottom: 1rem;
    animation: bounce 1s infinite;
}

.completion-stats {
    display: flex;
    justify-content: space-around;
    margin: 1rem 0 2rem 0;
    padding: 1rem;
    background: var(--surface);
    border-radius: 8px;
}

.completion-time,
.completion-hints {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

@keyframes successPulse {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-content {
        padding: 1rem;
    }
    
    .logo {
        font-size: 1.2rem;
    }
    
    .screen {
        padding: 1rem;
    }
    
    .game-screen {
        padding-bottom: 180px;
    }
    
    .game-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }
    
    .game-info {
        justify-content: space-between;
        gap: 0.75rem;
        font-size: 0.85rem;
    }
    
    .game-actions {
        justify-content: center;
    }
    
    .game-container {
        padding: 0.5rem 0;
    }
    
    .grid-wrapper {
        max-width: 95vw;
    }
    
    .number-input-bar {
        padding: 0.5rem;
    }
    
    .number-btn {
        min-width: 38px;
        font-size: 1.1rem;
    }
    
    .control-btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    
    .control-btn span {
        display: none;
    }
    
    .control-btn i {
        font-size: 1.1rem;
    }
    
    .size-options,
    .difficulty-options {
        flex-direction: column;
    }
    
    .setup-actions {
        flex-direction: column;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .menu-title h2 {
        font-size: 2rem;
    }
    
    .game-screen {
        padding-bottom: 160px;
    }
    
    .number-btn {
        min-width: 32px;
        font-size: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .number-buttons {
        gap: 0.4rem;
    }
}

/* Desktop Enhancements */
@media (min-width: 769px) {
    .number-input-bar {
        max-width: 800px;
        margin: 0 auto;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 16px 16px 0 0;
    }
    
    .number-btn {
        max-width: 60px;
    }
    
    .control-btn {
        max-width: 150px;
    }
    
    .grid-wrapper {
        max-width: 550px;
    }
}

@media (min-width: 1024px) {
    .game-screen {
        padding-bottom: 150px;
    }
    
    .grid-wrapper {
        max-width: 600px;
    }
    
    .number-input-bar {
        max-width: 900px;
        padding: 1rem 1.5rem;
    }
    
    .number-btn {
        font-size: 1.5rem;
        max-width: 70px;
    }
}

/* Animations */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        opacity: 0; 
        transform: translateY(20px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* Utility Classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-primary {
    color: var(--text-primary);
}

.text-secondary {
    color: var(--text-secondary);
}

.bg-primary {
    background-color: var(--primary-color);
}

.bg-surface {
    background-color: var(--surface);
}

.border-primary {
    border-color: var(--primary-color);
}