:root {
    --board-size: min(90vw, 500px);
    --border-radius: 10px;
    --light-bg-primary: #f0f4f8;
    --light-bg-secondary: #dbe3eb;
    --light-bg-tertiary: #c2ccd4;
    --light-accent-color: #4a90e2;
    --light-text-color: #333333;
    --light-editable-bg: #ffffff;
    --light-hint-bg: #a7f3d0;
    --dark-bg-primary: #121212;
    --dark-bg-secondary: #1e1e1e;
    --dark-bg-tertiary: #2c2c2c;
    --dark-accent-color: #bb86fc;
    --dark-text-color: #ffffff;
    --dark-editable-bg: #2a2a2a;
    --dark-hint-bg: #2f5d50;
}

body {
    font-family: 'Poppins', sans-serif;
}

.sudoku-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: calc(100vh - 80px);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: var(--board-size);
    margin-bottom: 15px;
}

.info-group {
    display: flex;
    gap: 20px;
}

.timer-container, .score-container, .control-group label {
    font-size: 1.1rem;
    font-weight: bold;
}

.game-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
    align-items: center;
}

#game-board {
    width: var(--board-size);
    height: var(--board-size);
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 3px solid var(--light-text-color);
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

html.dark #game-board {
    border-color: var(--dark-text-color);
}

.cell {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: clamp(1rem, 5vw, 2rem);
    font-weight: bold;
    border: 1px solid var(--light-bg-tertiary);
    background-color: var(--light-bg-secondary);
    color: var(--light-text-color);
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    cursor: not-allowed;
    transition: background-color 0.4s ease;
}

html.dark .cell {
    border-color: var(--dark-bg-tertiary);
    background-color: var(--dark-bg-secondary);
    color: var(--dark-text-color);
}

.cell.editable {
    background-color: var(--light-editable-bg);
    color: var(--light-accent-color);
    cursor: pointer;
}

html.dark .cell.editable {
    background-color: var(--dark-editable-bg);
    color: var(--dark-accent-color);
}

.cell.selected {
    background-color: var(--light-hint-bg) !important;
}

html.dark .cell.selected {
    background-color: var(--dark-hint-bg) !important;
}

.cell.hint {
    background-color: var(--light-hint-bg);
}

html.dark .cell.hint {
    background-color: var(--dark-hint-bg);
}

/* --- 3x3 Subgrid Borders --- */
.cell:nth-child(3n):not(:nth-child(9n)) {
    border-right: 2px solid var(--light-text-color);
}
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--light-text-color);
}

html.dark .cell:nth-child(3n):not(:nth-child(9n)) {
    border-right-color: var(--dark-text-color);
}
html.dark .cell:nth-child(n+19):nth-child(-n+27),
html.dark .cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom-color: var(--dark-text-color);
}

#number-palette {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.palette-number {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--light-bg-tertiary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5rem;
    font-weight: bold;
    transition: background-color 0.2s, color 0.2s;
}

html.dark .palette-number {
    border-color: var(--dark-bg-tertiary);
}

.palette-number.selected {
    background-color: var(--light-accent-color);
    color: white;
}

html.dark .palette-number.selected {
    background-color: var(--dark-accent-color);
    color: var(--dark-bg-primary);
}

#difficulty {
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid var(--light-bg-tertiary);
    background-color: var(--light-editable-bg);
    font-weight: bold;
}

html.dark #difficulty {
    background-color: var(--dark-editable-bg);
    color: var(--dark-text-color);
    border-color: var(--dark-bg-tertiary);
}


#winningMessage {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 3rem;
    flex-direction: column;
    backdrop-filter: blur(5px);
    z-index: 100;
}

#winningMessage.show {
    display: flex;
}

.watermark {
    position: fixed;
    bottom: 10px;
    right: 10px;
    font-size: 1rem;
    color: rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

html.dark .watermark {
    color: rgba(255, 255, 255, 0.3);
}

@media (max-width: 480px) {
    #number-palette {
        flex-wrap: wrap;
        width: var(--board-size);
        gap: 8px;
    }

    .palette-number {
        width: calc(20% - 8px); /* 5 items per row with gap */
        height: auto;
        aspect-ratio: 1 / 1;
        font-size: 1.2rem;
    }
}