/* CSS Variables for Material You Design */
:root {
    --primary-color: #2196F3;
    --secondary-color: #4CAF50;
    --accent-color: #FFC107;
    --error-color: #F44336;
    --tertiary-color: #9C27B0;
    
    --surface-color: #FFFFFF;
    --surface-variant: #F5F5F5;
    --on-surface: #1C1B1F;
    --on-surface-variant: #49454F;
    
    --shadow-color: rgba(0, 0, 0, 0.1);
    --border-color: #E0E0E0;
    
    --border-radius: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-small: 0.875rem;
    --font-size-medium: 1rem;
    --font-size-large: 1.25rem;
    --font-size-xlarge: 1.5rem;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--on-surface);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    background: var(--surface-color);
    padding: 1rem;
    box-shadow: 0 2px 8px var(--shadow-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    color: var(--primary-color);
    font-size: var(--font-size-xlarge);
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-align: center;
}

nav {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.nav-btn {
    background: none;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    font-size: var(--font-size-small);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

/* Main Content */
main {
    flex: 1;
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Game Controls */
.game-controls {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.difficulty-selector {
    margin-bottom: 1rem;
}

.difficulty-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--on-surface-variant);
}

.difficulty-selector select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--surface-color);
    color: var(--on-surface);
    font-size: var(--font-size-medium);
    cursor: pointer;
    transition: var(--transition);
}

.difficulty-selector select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.game-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.action-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: var(--font-size-medium);
    font-weight: 500;
    transition: var(--transition);
    min-width: 100px;
}

.action-btn.primary {
    background: var(--primary-color);
    color: white;
}

.action-btn.primary:hover {
    background: #1976D2;
    transform: translateY(-2px);
}

.action-btn.secondary {
    background: var(--surface-variant);
    color: var(--on-surface);
    border: 2px solid var(--border-color);
}

.action-btn.secondary:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

/* Game Status */
.game-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface-color);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.timer, .difficulty-display, .hints-remaining {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.material-icon {
    font-size: 1.2rem;
}

/* Sudoku Grid */
.sudoku-container {
    margin-bottom: 1rem;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 1px;
    background: var(--on-surface);
    border: 3px solid var(--on-surface);
    border-radius: var(--border-radius);
    padding: 1px;
    aspect-ratio: 1;
    max-width: 100%;
    margin: 0 auto;
}

.sudoku-cell {
    background: var(--surface-color);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(min(4vw, 1.5rem));
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    min-height: calc(min(10vw, 3rem));
}

.sudoku-cell:focus {
    outline: 3px solid var(--primary-color);
    outline-offset: -3px;
    z-index: 10;
}

.sudoku-cell.selected {
    background: var(--primary-color);
    color: white;
}

.sudoku-cell.highlighted {
    background: rgba(33, 150, 243, 0.1);
}

.sudoku-cell.given {
    background: var(--surface-variant);
    color: var(--on-surface);
    cursor: default;
}

.sudoku-cell.error {
    background: var(--error-color);
    color: white;
    animation: shake 0.5s ease-in-out;
}

.sudoku-cell.correct {
    background: var(--secondary-color);
    color: white;
    animation: pulse 0.5s ease-in-out;
}

.sudoku-cell.notes {
    font-size: calc(min(1.5vw, 0.6rem));
    padding: 2px;
    line-height: 1;
}

/* 3x3 Box Borders */
.sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--on-surface);
}

.sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--on-surface);
}

/* Game Tools */
.game-tools {
    margin-bottom: 1rem;
}

.tool-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.tool-btn {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    color: var(--on-surface);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--font-size-small);
    min-width: 80px;
}

.tool-btn:hover {
    background: var(--surface-variant);
    transform: translateY(-2px);
}

.tool-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--on-surface);
}

/* Number Input */
.number-input {
    margin-bottom: 1rem;
}

.number-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    max-width: 300px;
    margin: 0 auto;
}

.number-btn {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    color: var(--on-surface);
    padding: 1rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: var(--font-size-large);
    font-weight: 600;
    transition: var(--transition);
    aspect-ratio: 1;
}

.number-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.number-btn:active {
    transform: scale(0.95);
}

/* Game Messages */
.game-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface-color);
    padding: 1rem 2rem;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px var(--shadow-color);
    z-index: 1000;
    text-align: center;
    font-weight: 500;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.game-message.show {
    opacity: 1;
    visibility: visible;
}

.game-message.success {
    border-left: 4px solid var(--secondary-color);
}

.game-message.error {
    border-left: 4px solid var(--error-color);
}

.game-message.info {
    border-left: 4px solid var(--primary-color);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

.loading-overlay p {
    color: white;
    font-size: var(--font-size-large);
}

/* Pause Overlay */
.pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.pause-overlay.show {
    opacity: 1;
    visibility: visible;
}

.pause-content {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    text-align: center;
    box-shadow: 0 8px 32px var(--shadow-color);
}

.pause-content h2 {
    margin-bottom: 1rem;
    color: var(--on-surface);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px var(--shadow-color);
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    color: var(--on-surface);
    font-size: var(--font-size-large);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--on-surface-variant);
    transition: var(--transition);
}

.close-btn:hover {
    color: var(--error-color);
}

.modal-body {
    padding: 1.5rem;
}

.stats-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--surface-variant);
    border-radius: var(--border-radius);
}

.stat-label {
    font-weight: 500;
    color: var(--on-surface-variant);
}

.stat-value {
    font-weight: 600;
    color: var(--primary-color);
    font-size: var(--font-size-large);
}

/* Footer */
footer {
    background: var(--surface-color);
    padding: 1rem;
    text-align: center;
    color: var(--on-surface-variant);
    font-size: var(--font-size-small);
    box-shadow: 0 -2px 8px var(--shadow-color);
}

/* Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --font-size-small: 0.75rem;
        --font-size-medium: 0.875rem;
        --font-size-large: 1rem;
        --font-size-xlarge: 1.25rem;
    }
    
    main {
        padding: 0.5rem;
    }
    
    .game-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .action-btn {
        min-width: auto;
        padding: 0.5rem 1rem;
    }
    
    .game-status {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
    
    .tool-buttons {
        flex-wrap: wrap;
    }
    
    .tool-btn {
        min-width: 60px;
        padding: 0.5rem;
    }
    
    .number-buttons {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.25rem;
    }
    
    .number-btn {
        padding: 0.75rem;
        font-size: var(--font-size-medium);
    }
}

@media (max-width: 480px) {
    .nav-btn {
        padding: 0.5rem;
        font-size: 0.75rem;
    }
    
    .sudoku-cell {
        font-size: calc(min(3.5vw, 1.2rem));
        min-height: calc(min(9vw, 2.5rem));
    }
    
    .modal-content {
        max-width: 95%;
        margin: 1rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow-color: rgba(0, 0, 0, 0.3);
    }
    
    .sudoku-cell {
        border: 1px solid var(--border-color);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
