/* CSS Custom Properties */
:root {
    --primary-bg: #f6f7fb;
    --card-bg: #ffffff;
    --grid-color: #2b2b2b;
    --cell-default: #ffffff;
    --cell-filled: #e8f5e9;
    --cell-invalid: #ffdddd;
    --cell-highlight: #dbeafe;
    --digit-color: #1f2937;
    --highlight-color: #4f46e5;
    --victory-color: #10b981;
    --border-radius: 8px;
    --transition: all 0.3s ease;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--primary-bg);
    color: var(--digit-color);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Container */
.container {
    max-width: min(90vw, 400px);
    margin: 0 auto;
    padding: 1rem;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    padding: 1rem 0;
}

.screen.active {
    display: block;
}

/* Typography */
h1, h2, h3 {
    margin-bottom: 0.5rem;
}

.game-title {
    font-size: clamp(2rem, 8vw, 3rem);
    text-align: center;
    color: var(--highlight-color);
    margin-bottom: 0.5rem;
}

.game-subtitle {
    text-align: center;
    color: #6b7280;
    margin-bottom: 2rem;
    font-size: clamp(0.9rem, 3vw, 1rem);
}

/* Mode Selection */
.modes-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.mode-card {
    background: var(--card-bg);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.mode-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

.mode-card.selected {
    border-color: var(--highlight-color);
    background: linear-gradient(135deg, #dbeafe 0%, #ffffff 100%);
}

.mode-icon {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.mode-name {
    font-size: 1.25rem;
    text-align: center;
    color: var(--digit-color);
    margin-bottom: 0.5rem;
}

.mode-description {
    text-align: center;
    color: #6b7280;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.mode-details {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.detail-item {
    background: #f3f4f6;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    color: #4b5563;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    display: inline-block;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: #4338ca;
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-warning {
    background: #ef4444;
    color: white;
}

.btn-warning:hover {
    background: #dc2626;
}

.btn-action {
    background: var(--card-bg);
    color: var(--digit-color);
    border: 2px solid #e5e7eb;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.btn-action:hover:not(:disabled) {
    border-color: var(--highlight-color);
    color: var(--highlight-color);
}

.btn-large {
    width: 100%;
    padding: 1rem;
    font-size: 1.1rem;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
}

/* Game Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.mode-badge {
    background: var(--highlight-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

/* Stats Panel */
.stats-panel {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--digit-color);
}

/* Game Board */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    background: var(--grid-color);
    padding: 4px;
    border-radius: var(--border-radius);
    margin: 0 auto 1.5rem;
    max-width: min(90vw, 400px);
    aspect-ratio: 1;
}

.cell {
    background: var(--cell-default);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 5vw, 2rem);
    font-weight: 700;
    color: var(--digit-color);
    cursor: pointer;
    transition: var(--transition);
    border-radius: 4px;
    position: relative;
}

.cell:hover {
    background: var(--cell-highlight);
}

.cell.selected {
    background: var(--cell-highlight);
    box-shadow: inset 0 0 0 3px var(--highlight-color);
}

.cell.filled {
    background: var(--cell-filled);
}

.cell.invalid {
    background: var(--cell-invalid);
    animation: shake 0.3s;
}

.cell.hint {
    animation: pulse 0.5s;
}

.cell.shifting {
    animation: slideRight 0.5s;
}

/* Race Mode Layout */
.race-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.board-section {
    flex: 1;
}

.board-title {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    color: #6b7280;
}

.player-section .board-title {
    color: var(--highlight-color);
}

.ai-section .board-title {
    color: #ef4444;
}

/* Hide AI board on mobile for race mode */
@media (max-width: 767px) {
    .ai-section {
        display: none;
    }
}

/* Single Player Container */
.single-player-container {
    margin-bottom: 1.5rem;
}

/* Digit Selector */
.digit-selector {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.digit-btn {
    width: 50px;
    height: 50px;
    border: 2px solid #e5e7eb;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--digit-color);
    cursor: pointer;
    transition: var(--transition);
}

.digit-btn:hover {
    border-color: var(--highlight-color);
    background: var(--cell-highlight);
}

.digit-btn.active {
    background: var(--highlight-color);
    color: white;
    border-color: var(--highlight-color);
}

.clear-btn {
    background: #fee2e2;
    color: #ef4444;
    border-color: #fecaca;
}

.clear-btn:hover {
    background: #fecaca;
    border-color: #ef4444;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Game Over Screen */
.game-over-content {
    text-align: center;
    padding: 2rem 0;
}

.result-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
}

.result-title {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.result-message {
    color: #6b7280;
    margin-bottom: 2rem;
}

.final-stats {
    display: flex;
    justify-content: space-around;
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.final-stat {
    text-align: center;
}

.final-stat-label {
    display: block;
    font-size: 0.9rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.final-stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--digit-color);
}

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.game-over-buttons .btn {
    width: 100%;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 2rem;
    max-width: min(90vw, 400px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    text-align: center;
}

.modal-message {
    color: #6b7280;
    margin-bottom: 1.5rem;
    text-align: center;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
}

.modal-buttons .btn {
    flex: 1;
}

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

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

@keyframes slideRight {
    0% { transform: translateX(-20px); opacity: 0.5; }
    100% { transform: translateX(0); opacity: 1; }
}

@keyframes victory {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.1) rotate(-5deg); }
    75% { transform: scale(1.1) rotate(5deg); }
}

.victory-animation {
    animation: victory 0.5s ease-in-out;
}

/* Tablet and Desktop Enhancements */
@media (min-width: 768px) {
    .container {
        max-width: min(85vw, 600px);
    }

    .modes-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .game-board {
        max-width: min(80vw, 500px);
        gap: 6px;
        padding: 6px;
    }

    .digit-btn {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }

    .race-container {
        flex-direction: row;
    }

    .ai-section {
        display: block !important;
    }

    .game-over-buttons {
        flex-direction: row;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: min(80vw, 800px);
    }

    .game-board {
        max-width: min(70vw, 600px);
        gap: 8px;
        padding: 8px;
    }

    .cell {
        font-size: 2.5rem;
    }

    .modes-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .mode-card {
        padding: 2rem;
    }
}

@media (min-width: 1440px) {
    .container {
        max-width: min(70vw, 1000px);
    }

    .game-board {
        max-width: min(60vw, 700px);
    }
}
