/* --- Root Design System & Colors --- */
:root {
    --bg-color: #f7fafc;
    --grid-bg: #ffffff;
    --border-black: #000000;
    --border-light: #cbd5e0;
    
    /* Font Colors per Specification */
    --text-system: #0F2C59;  /* Dark Blue for given clues */
    --text-user: #3182CE;    /* Light/Royal Blue for user input */
    --text-error: #E53E3E;   /* Red for wrong answers */
    --text-pencil: #718096;  /* Slate Grey for candidate notes */
    
    /* Highlights */
    --cell-selected: #bee3f8;
    --cell-highlight: #ebf8ff;
    --cell-same-num: #c3dafe;
    --cell-error-bg: #fed7d7;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: none;
}

body {
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 10px;
}

.game-container {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Header & Controls --- */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-header h1 {
    font-size: 1.5rem;
    letter-spacing: 2px;
    color: var(--text-system);
}

.difficulty-container {
    display: flex;
    align-items: center;
    gap: 6px;
}

.difficulty-container select {
    padding: 6px 10px;
    font-size: 0.9rem;
    border-radius: 6px;
    border: 1px solid #a0aec0;
    background-color: #fff;
    cursor: pointer;
}

/* --- Status Bar --- */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-weight: 600;
    font-size: 0.95rem;
}

.status-btn {
    border: none;
    background-color: #edf2f7;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
}

/* --- 9x9 Grid Layout --- */
.grid-container {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: var(--grid-bg);
    border: 3px solid var(--border-black);
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    height: 100%;
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--border-light);
    font-size: clamp(1.2rem, 5vw, 1.8rem);
    font-weight: bold;
    cursor: pointer;
    position: relative;
    background-color: var(--grid-bg);
}

/* Thick 3x3 Block Borders */
.cell[data-col="2"], .cell[data-col="5"] {
    border-right: 3px solid var(--border-black);
}
.cell[data-row="2"], .cell[data-row="5"] {
    border-bottom: 3px solid var(--border-black);
}

/* Cell State Modifier Classes */
.cell.given {
    color: var(--text-system);
    font-weight: 800;
}

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

.cell.error {
    color: var(--text-error);
    background-color: var(--cell-error-bg);
}

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

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

.cell.same-number {
    background-color: var(--cell-same-num) !important;
}

/* Completion Flash Animation */
.cell.completed-flash {
    animation: greenFlash 0.8s ease-in-out;
}

@keyframes greenFlash {
    0% { background-color: #c6f6d5; }
    50% { background-color: #68d391; }
    100% { background-color: var(--grid-bg); }
}

/* Pencil Mini-Grid Notes */
.pencil-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.pencil-digit {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.7rem, 2.5vw, 0.95rem);
    color: var(--text-pencil);
    font-weight: 600;
}

/* --- Toolbar & Keypad --- */
.toolbar, .keypad {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.tool-btn {
    flex: 1;
    padding: 12px 0;
    border: 1px solid #cbd5e0;
    background-color: #fff;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tool-btn.active {
    background-color: #3182ce;
    color: white;
}

.badge {
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 4px;
    background: #e2e8f0;
    color: #2d3748;
}

.tool-btn.active .badge {
    background: #fff;
    color: #3182ce;
}

/* Keypad Button Styles */
.num-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 0;
    gap: 2px;
    border: 1px solid #cbd5e0;
    background-color: #fff;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.num-digit {
    font-size: 1.1rem;
    font-weight: bold;
    line-height: 1;
}

.num-count {
    font-size: 0.7rem;
    color: #718096;
    font-weight: 500;
}

.num-btn.completed {
    opacity: 0.3;
    background-color: #edf2f7;
    cursor: default;
}

/* --- Footer --- */
.game-footer {
    text-align: center;
    color: #718096;
    font-size: 0.75rem;
    padding-top: 4px;
    line-height: 1.3;
}

/* --- Custom Modal Overlay --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-overlay.hidden {
    display: none;
}

.modal-card {
    background-color: #fff;
    padding: 24px 30px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    text-align: center;
    max-width: 320px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-card h2 {
    color: var(--text-system);
    font-size: 1.4rem;
}

.modal-card p {
    color: #4a5568;
    font-size: 1rem;
    line-height: 1.4;
}

.modal-btn {
    background-color: #3182ce;
    color: white;
    border: none;
    padding: 10px 0;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.modal-btn:hover {
    background-color: #2b6cb0;
}