/* ========== Reset & Base ========== */
:root {
    --size: 500px;

    /* -- Dark theme (default) -- */
    --bg-primary:    #1a1a2e;
    --bg-secondary:  #16213e;
    --bg-tertiary:   #0f3460;
    --bg-dark:       #0a1a30;

    --text-primary:  #e0e0e0;
    --text-secondary:#aaa;
    --text-disabled: #333;

    --accent:        #e94560;
    --accent-hover:  #c73652;

    --btn-bg:        #0f3460;
    --btn-hover:     #1a4a8a;

    --cell-bg:       #16213e;
    --cell-border:   #0f3460;
    --cell-selected: #4e0b6d;
    --cell-related:  #1a2d52;
    --cell-same:     #1e3a6e;

    --color-given:   #e0e0e0;
    --color-user:    #53a8e2;
    --color-error:   #e94560;
    --color-correct: #2a6e3a;
    --color-notes:   #7fa8d2;

    --overlay-bg:    rgba(0, 0, 0, 0.75);
}

/* -- Light theme -- */
[data-theme="light"] {
    --bg-primary:    #f0f2f5;
    --bg-secondary:  #ffffff;
    --bg-tertiary:   #ccd6e0;
    --bg-dark:       #e8eaed;

    --text-primary:  #2c3e50;
    --text-secondary:#6b7b8d;
    --text-disabled: #b0b8c4;

    --accent:        #e74c3c;
    --accent-hover:  #c0392b;

    --btn-bg:        #d5dde6;
    --btn-hover:     #b8c4d2;

    --cell-bg:       #ffffff;
    --cell-border:   #ccd6e0;
    --cell-selected: #e1d4f9;
    --cell-related:  #eaf1f7;
    --cell-same:     #c5ddf5;

    --color-given:   #1a1a2e;
    --color-user:    #2980b9;
    --color-error:   #e74c3c;
    --color-correct: #27ae60;
    --color-notes:   #5a7a9a;

    --overlay-bg:    rgba(0, 0, 0, 0.5);
}

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

/* ========== Correct Answer Flash Animation ========== */
@keyframes correctFlash {
    0% {
        background-color: var(--color-correct);
        box-shadow: 0 0 12px var(--color-correct);
    }
    100% {
        background-color: var(--cell-bg);
        box-shadow: none;
    }
}

.cell.correct-flash {
    animation: correctFlash 500ms ease-out;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 30px 10px;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: var(--size);
    width: 100%;
}

h1 {
    font-size: 2.4rem;
    font-weight: 300;
    letter-spacing: 12px;
    text-transform: uppercase;
    color: var(--accent);
}

/* ========== Controls ========== */
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.control-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--bg-tertiary);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9rem;
    cursor: pointer;
}

button {
    background: var(--btn-bg);
    color: var(--text-primary);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: var(--btn-hover);
}

.toggle-btn.active {
    background: var(--accent);
}

/* ========== Game Stats ========== */
.game-stats {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: var(--size);
    font-size: 0.95rem;
    color: var(--text-secondary);
}

/* ========== Board ========== */
.board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: var(--size);
    height: var(--size);
    border: 2px solid var(--accent);
    background: var(--bg-tertiary);
    gap: 0;
}

.cell {
    position: relative;
    background: var(--cell-bg);
    border: 1px solid var(--cell-border);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
    font-weight: 500;
}

/* Thicker borders for 3x3 boxes */
.cell.box-top {
    border-top: 2px solid var(--accent);
}

.cell.box-bottom {
    border-bottom: 2px solid var(--accent);
}

.cell.box-left {
    border-left: 2px solid var(--accent);
}

.cell.box-right {
    border-right: 2px solid var(--accent);
}

.cell.given {
    color: var(--color-given);
}

.cell.user-entered {
    color: var(--color-user);
}

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

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

.cell.selected {
    background: var(--cell-selected) !important;
}

.cell.error {
    color: var(--color-error) !important;
}

.cell.correct-flash {
    background: var(--color-correct) !important;
}

/* ========== Pencil Notes ========== */
.cell .notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.cell .notes-grid span {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.65rem;
    color: var(--color-notes);
    line-height: 1;
}

/* ========== Number Pad ========== */
.num-pad {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: var(--size);
}

.num-pad button {
    width: 58px;
    height: 80px;
    font-size: 1.2rem;
    font-weight: 600;
    padding: 0;
    position: relative;
}

.num-pad button .remaining {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.6rem;
    font-weight: 400;
}

.num-pad button:disabled {
    background: var(--bg-dark);
    color: var(--text-disabled);
    cursor: default;
    opacity: 0.6;
}

.num-pad button.pending {
    background: var(--cell-selected) !important;
    border-color: var(--accent) !important;
    box-shadow: 0 0 8px var(--accent);
}

.erase-btn {
    font-size: 0.8rem !important;
    width: auto !important;
    padding: 0 12px !important;
}

/* ========== Overlay ========== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background: var(--bg-secondary);
    padding: 40px 50px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid var(--accent);
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 12px;
}

.overlay-content p {
    margin-bottom: 24px;
    color: var(--text-secondary);
}

.overlay-content button {
    padding: 12px 32px;
    font-size: 1rem;
    background: var(--accent);
}

.overlay-content button:hover {
    background: var(--accent-hover);
}

/* ========== Responsive ========== */
@media (max-width: 480px) {
    .board {
        width: 90vw;
        height: 90vw;
    }

    .cell {
        font-size: 1.2rem;
    }

    h1 {
        font-size: 1.6rem;
    }
}

@media (min-width: 900px) {
    :root {
        --size: 800px;
    }
    html {
        font-size: 24px;
    }
}
