:root {
    --bg-color: #fdfaf6; /* Warm off-white */
    --text-primary: #3d2b1f; /* Dark brown */
    --text-secondary: #5c4a3d;
    --border-color: #d4c4b7;
    --border-thick: #8a7360;
    --cell-bg: #fffcf8;
    --cell-bg-selected: #e9dec9;
    --cell-bg-highlight: #f2e9d8;
    --cell-bg-error: #f8dcd2;
    --text-error: #a83232;
    --btn-bg: #eae0d5;
    --btn-hover: #dfcebd;
    --font-heading: 'Libre Baskerville', serif;
    --font-ui: 'Source Sans 3', sans-serif;
}

body.dark-mode {
    --bg-color: #1a1512; /* Dark warm charcoal */
    --text-primary: #f5ece5; /* Soft light cream */
    --text-secondary: #d1beb0; /* Soft warm gray */
    --border-color: #4a3e36; /* Darker warm border */
    --border-thick: #9e8570; /* Slightly lighter/softer border */
    --cell-bg: #221c18; /* Dark cell background */
    --cell-bg-selected: #46392f; /* Highlight selected cell */
    --cell-bg-highlight: #352a22; /* Highlight peer cells */
    --cell-bg-error: #52241e; /* Error highlight */
    --text-error: #ff8585; /* Light red for error readability */
    --btn-bg: #2d241f; /* Dark button background */
    --btn-hover: #3d312a; /* Dark button hover */
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-ui);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app-container {
    max-width: 500px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    color: var(--text-primary);
}

.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.timer {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-secondary);
}

button {
    font-family: var(--font-ui);
    background-color: var(--btn-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s, transform 0.1s, color 0.2s, border-color 0.2s;
}

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

button:active:not(:disabled) {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Circular Icon Buttons */
.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
    background-color: var(--btn-bg);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s, color 0.2s, border-color 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background-color: var(--btn-hover);
}

.icon-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.icon-btn.active {
    background-color: var(--border-thick);
    color: var(--bg-color);
    border-color: var(--border-thick);
}

/* Custom Dropdown styling */
.dropdown-wrapper {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    top: 48px;
    left: 0;
    background-color: var(--cell-bg);
    min-width: 120px;
    box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    z-index: 10;
    overflow: hidden;
    flex-direction: column;
}

.dropdown-content.show {
    display: flex;
}

.dropdown-item {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0.75rem 1rem;
    text-align: left;
    width: 100%;
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.2s;
}

.dropdown-item:hover {
    background-color: var(--btn-hover);
}

.dropdown-item.active {
    background-color: var(--border-thick);
    color: var(--bg-color);
    border-color: var(--border-thick);
}

.sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 2px solid var(--border-thick);
    background-color: var(--border-color); /* Grid lines color */
    gap: 1px;
}

.cell {
    background-color: var(--cell-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: var(--font-heading);
    font-size: clamp(1.2rem, 5vw, 2rem);
    cursor: pointer;
    position: relative;
    user-select: none;
    color: var(--text-primary);
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

/* Thicker borders for 3x3 boxes */
.cell:nth-child(3n) { border-right: 2px solid var(--border-thick); }
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { 
    border-bottom: 2px solid var(--border-thick); 
}

.cell.selected { background-color: var(--cell-bg-selected); }
.cell.highlight { background-color: var(--cell-bg-highlight); }
.cell.error { color: var(--text-error); background-color: var(--cell-bg-error); }
.cell.fixed { font-weight: bold; color: var(--text-primary); }
.cell.user-input { color: var(--text-secondary); }

.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    padding: 2px;
}

.note-num {
    font-family: var(--font-ui);
    font-size: clamp(0.5rem, 2vw, 0.7rem);
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    max-width: 320px;
    margin: 0 auto;
    width: 100%;
}

.num-btn {
    position: relative;
    font-family: var(--font-heading);
    font-size: 1.6rem;
    padding: 0.75rem 0;
    border-radius: 8px;
}

.num-counter {
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: var(--border-thick);
    color: var(--bg-color);
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    pointer-events: none;
}

.num-counter.hidden {
    display: none;
}

.num-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

@media (min-width: 600px) {
    .app-container {
        max-width: 600px;
    }
}
