:root {
    --bg-app: 220 15% 8%;
    --bg-panel: 220 15% 12%;
    --bg-board: 220 15% 15%;
    --border-color: 220 10% 25%;
    --text-primary: 220 20% 98%;
    --text-secondary: 220 10% 70%;
    --text-dim: 220 10% 40%;
    --accent-color: 212 100% 60%;
    --accent-hover: 212 100% 50%;
    --danger-color: 0 80% 60%;
    --cell-selected: 212 70% 25%;
    --cell-highlight: 212 30% 18%;
    --cell-initial-text: 220 20% 95%;
    --cell-user-text: 212 100% 80%;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Outfit', 'Inter', system-ui, sans-serif;
    background-color: hsl(var(--bg-app));
    color: hsl(var(--text-primary));
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 2rem 1rem;
}

#app {
    width: 100%;
    max-width: 650px;
    /* Generous width */
    margin: 0 auto;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    background: hsl(var(--border-color));
    gap: 1.5px;
    /* Slightly thicker gaps for clarity */
    border: 4px solid hsl(var(--text-dim));
    margin: 2rem 0;
    user-select: none;
    width: 100%;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
}

.cell {
    background: hsl(var(--bg-board));
    aspect-ratio: 1 / 1;
    /* FORCES SQUARE */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: min(3rem, 7vw);
    font-weight: 500;
    cursor: pointer;
    position: relative;
    transition: background-color 0.15s ease, transform 0.1s ease;
}

.cell:active {
    transform: scale(0.95);
}

/* Thicker internal borders for 3x3 boxes */
.cell.border-r-thick {
    border-right: 4px solid hsl(var(--text-dim));
}

.cell.border-b-thick {
    border-bottom: 4px solid hsl(var(--text-dim));
}

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

.cell.selected {
    background: hsl(var(--cell-selected));
    z-index: 1;
    outline: 2px solid hsl(var(--accent-color));
    outline-offset: -2px;
}

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

.cell.error-flash {
    background-color: hsl(var(--danger-color)) !important;
    color: white !important;
    animation: shake 0.4s ease-in-out;
}

.cell.initial {
    color: hsl(var(--cell-initial-text));
    font-weight: 900;
}

.cell.user-filled {
    color: hsl(var(--cell-user-text));
    font-weight: 600;
}

.notes-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 90%;
    height: 90%;
    font-size: min(1rem, 2.5vw);
    line-height: 1;
    color: hsl(var(--text-secondary));
}

.note-item {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Helpers & Utils */
.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.gap-1 {
    gap: 0.25rem;
}

.gap-2 {
    gap: 0.5rem;
}

.gap-4 {
    gap: 1rem;
}

.w-full {
    width: 100%;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mb-4 {
    margin-bottom: 2rem;
}

.text-2xl {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
}

.text-xl {
    font-size: 1.5rem;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -0.05em;
}

/* Number Row Responsiveness */
.number-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 0.25rem;
    width: 100%;
    min-width: 0;
    /* Important for flex items to shrink */
    overflow-x: auto;
    padding: 0.5rem 2px;
    margin: 0 -2px;
    /* Offset padding for internal alignment */
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.number-row::-webkit-scrollbar {
    display: none;
}

.number-row .btn {
    flex: 0 0 auto;
    width: calc((100% - (8 * 0.25rem)) / 9);
    min-width: 2.5rem;
    height: 3.5rem;
    padding: 0;
    font-size: 1.2rem;
}

/* UI Buttons */
.btn {
    background: hsl(var(--bg-panel));
    color: hsl(var(--text-primary));
    border: 1px solid hsl(var(--border-color));
    padding: 1rem;
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    background: hsl(var(--border-color));
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: hsl(var(--accent-color));
    color: white;
    border-color: transparent;
}

.btn-primary:hover {
    background: hsl(var(--accent-hover));
}

.flex-1 {
    flex: 1;
}

.complete-btn {
    opacity: 0.5;
    color: hsl(var(--success-color)) !important;
    cursor: default;
    pointer-events: none;
    background: transparent !important;
    box-shadow: none !important;
}

select.btn {
    padding-right: 2.5rem;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

/* Modals */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: hsla(220, 15%, 5%, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(12px);
}

@keyframes shake {

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

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

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

.animate-shake {
    animation: shake 0.4s ease-in-out;
}

.animate-fade-in {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}