:root {
    --bg-color: #faf8ef;
    --text-color: #776e65;
    --text-light: #f9f6f2;
    --font-family: 'Fredoka One', sans-serif;
    --heading-font: 'Fredoka One', cursive, sans-serif;

    /* Sudoku Specifics */
    --accent-color: #3498db;
    --accent-hover: #2980b9;
    --grid-border: #34495e;
    --cell-border: #bfc9ca;
    --cell-bg: #ffffff;
    --cell-bg-selected: #e8f6f3;
    --cell-bg-highlight: #d6eaf8;
    --cell-bg-hover: #eaecee;
    --card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --error-color: #e74c3c;
    --filled-text: #2c3e50;
    --user-text: #3498db;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

h1 {
    font-family: var(--heading-font);
    font-size: 3rem;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
    text-align: center;
}

/* --- LAYOUT --- */
.game-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

/* Left/Main Column: Game Board */
.game-container {
    position: relative;
    padding: 15px;
    cursor: default;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    touch-action: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 4px solid rgba(255, 255, 255, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Right Column: Controls & Stats */
.scoreboard {
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 15px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 500px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- BOARD STYLES --- */
/* --- BOARD STYLES --- */
#sudoku-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    /* Make it responsive but bounded */
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1 / 1;
    background-color: rgba(255, 255, 255, 0.5);
    padding: 10px;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    gap: 4px;
    user-select: none;
}

.subgrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    padding: 2px;
    border-radius: 8px;
    
    border: 3px solid rgba(108, 145, 166, 0.2);
}

.tile {
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 400;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    transition: all 0.2s ease;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    aspect-ratio: 1/1;
}

/* Cell States */
.tile.selected {
    background-color: var(--cell-bg-selected);
    transform: scale(0.95);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.tile.highlighted {
    background-color: var(--cell-bg-highlight);
}

.tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    z-index: 1;
}

.tile.filled {
    color: var(--filled-text);
    font-weight: 700;
}

.tile.user-input {
    color: var(--user-text);
    font-weight: 600;
}

.tile.error {
    color: var(--error-color);
    background-color: #fadbd8;
    animation: shake 0.4s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }
}

/* --- STATS STYLES --- */
.stats-bar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.stat-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    flex: 1 1 40%;
    color: white;
    font-family: var(--font-family);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
}

.stat-label {
    font-size: 0.8rem;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
    font-family: var(--heading-font);
    color: #eee4da;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    color: white;
}

/* --- CONTROLS --- */
.controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.numpad {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.number {
    width: 45px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.25rem;
    background-color: rgba(255, 255, 255, 0.5);
    color: var(--text-color);
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-family);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.number:hover {
    background-color: var(--accent-color);
    color: white;
    transform: translateY(-2px);
}

.action-buttons {
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
}

.game-btn {
    font-family: var(--font-family);
    font-size: 1.1rem;
    border-radius: 5px;
    transition: all 0.2s;
    background-color: #ff6b6b;
    color: rgb(255, 255, 255);
    padding: 12px 30px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 #d35454;
    transform: translateY(0);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-btn:hover {
    background-color: #ff5252;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #d35454;
}

.game-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #d35454;
}

/* --- DIFFICULTY MENU --- */
.difficulty-options {
    position: absolute;
    bottom: 60px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}

.difficulty-options.hidden {
    display: none;
}

.diff-btn {
    padding: 12px 20px;
    border: none;
    background: white;
    cursor: pointer;
    font-size: 1rem;
    text-align: left;
    transition: background 0.2s;
    width: 140px;
    font-family: var(--font-family);
    color: var(--text-color);
}

.diff-btn:hover {
    background-color: var(--cell-bg-hover);
}

/* --- BACK BUTTON --- */
.back-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    text-decoration: none;
    color: white;
    font-family: var(--font-family);
    font-size: 1.5rem;
    background-color: rgba(0, 0, 0, 0.2);
    padding: 10px 15px;
    border-radius: 5px;
    transition: background-color 0.3s;
    backdrop-filter: none;
    z-index: 10;
    border: none;
    cursor: pointer;
}

.back-btn:hover {
    background-color: rgba(0, 0, 0, 0.4);
}

/* --- MODAL --- */
/* --- OVERLAY FOR GAME OVER / WIN --- */
.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(218, 238, 235, 0.73);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    animation: fade-in 800ms ease 200ms;
    animation-fill-mode: both;
    border-radius: 15px;
    /* Match game-container border radius minus padding if needed, or just inherit */
}

.game-message p {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    font-family: var(--heading-font);
    line-height: 1.2;
    color: #615a53;
}

.game-message .subtext {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 30px;
    color: #6f675e;
    font-family: var(--font-family);
}

.game-message.game-over {
    display: flex;
    background: rgba(218, 237, 238, 0.9);
    /* Slightly more opaque for game over */
}

.game-message.game-won {
    display: flex;
    background: rgba(218, 237, 238, 0.8);
    /* Goldish for win */
    color: #f9f6f2;
}

.game-message.game-won p,
.game-message.game-won .subtext {
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#retry-btn {
    font-family: var(--font-family);
    font-size: 1.2rem;
    border-radius: 5px;
    transition: all 0.2s;
    background-color: #ff6b6b;
    color: white;
    padding: 10px 20px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 #d35454;
    transform: translateY(0);
}

.game-message.game-won #retry-btn {
    background-color: white;
    color: #776e65;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
}

#retry-btn:hover {
    background-color: #ff5252;
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #d35454;
}

.game-message.game-won #retry-btn:hover {
    background-color: #f2f2f2;
}

#retry-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #d35454;
}

@keyframes fade-in {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}

/* --- RESPONSIVENESS --- */
@media screen and (max-width: 899px) {
    .game-container {
        width: min(95vw, 500px);
        max-width: 100%;
        padding: 10px;
        margin: 0 auto;
    }

    .back-btn {
        font-size: 1rem;
        padding: 8px 12px;
    }

    h1 {
        font-size: 2.5rem;
        margin-top: 50px;
    }

    .number {
        width: 35px;
        height: 40px;
    }

    .scoreboard {
        max-width: 100%;
    }
}

/* Medium Screens: Side-by-side, centered as a group */
@media (min-width: 900px) and (max-width: 1349px) {
    .game-content {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: flex-start;
        gap: 40px;
        margin-top: 2rem;
        width: 100%;
        max-width: none;
        padding: 0 20px;
    }

    .scoreboard {
        width: 350px;
        margin-top: 0;
        flex-shrink: 0;
    }

    .game-container {
        min-width: 500px;
    }
}

/* Extra Large Screens: Game perfectly centered, scoreboard on far right */
@media (min-width: 1350px) {
    .game-content {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: flex-start;
        position: relative;
        margin-top: 2rem;
        width: 100%;
        max-width: none;
        padding: 0 20px;
    }

    .scoreboard {
        position: absolute;
        right: 40px;
        top: 0;
        width: 350px;
        margin-top: 0;
    }

    .game-container {
        min-width: 500px;
    }
}

.hidden {
    display: none !important;
}