:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --border-color: #e2e8f0;
    --grid-border: #334155;
    --cell-given: #1e293b;
    --cell-user: #0369a1;
    --cell-bg-hover: #f1f5f9;
    --cell-bg-selected: #bae6fd;
    --cell-bg-related: #f1f5f9;
    --error: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.app-container {
    width: 100%;
    max-width: 800px;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

h1 {
    font-weight: 700;
    letter-spacing: -1px;
    font-size: 1.5rem;
}

h1 span {
    color: var(--accent);
}

.game-meta {
    text-align: right;
    font-weight: 600;
}

#timer {
    font-size: 1.2rem;
    color: var(--text-main);
}

#difficulty-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Controls */
.controls-top {
    display: flex;
    gap: 10px;
    margin-bottom: 2rem;
}

select, .btn-primary {
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
}

select {
    background: white;
    flex-grow: 1;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

/* Grid Layout */
.game-area {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    border: 2px solid var(--grid-border);
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
}

.cell {
    border: 0.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 4vw, 1.5rem);
    cursor: pointer;
    background: white;
    user-select: none;
    transition: background 0.1s;
}

/* Thick borders for 3x3 blocks */
.cell:nth-child(3n) { border-right: 2px solid var(--grid-border); }
.cell:nth-child(9n) { border-right: 2px solid var(--grid-border); }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--grid-border);
}
.cell:nth-child(n+73) { border-bottom: none; }
.cell:nth-child(9n) { border-right: none; }

.cell.given {
    font-weight: 700;
    color: var(--cell-given);
}

.cell.user-input {
    color: var(--cell-user);
}

.cell:hover { background: var(--cell-bg-hover); }
.cell.selected { background: var(--cell-bg-selected) !important; }
.cell.related { background: var(--cell-bg-related); }
.cell.error { color: var(--error); background: #fee2e2; }

/* Side Panel & Numpad */
.side-panel {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.num-btn {
    padding: 15px 0;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: white;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.num-btn:hover {
    background: var(--cell-bg-hover);
    border-color: var(--accent);
}

.num-btn.action {
    background: #f1f5f9;
}

/* Toggle Switch */
.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.switch input { display: none; }

.slider {
    width: 40px;
    height: 20px;
    background: #cbd5e1;
    border-radius: 20px;
    position: relative;
    transition: 0.3s;
}

.slider:before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: 0.3s;
}

input:checked + .slider { background: var(--accent); }
input:checked + .slider:before { transform: translateX(20px); }
.label-text { font-size: 14px; color: var(--text-secondary); }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal.active { display: flex; }

.modal-content {
    background: white;
    padding: 3rem;
    border-radius: 24px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: slideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideUp {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-content .icon { font-size: 4rem; margin-bottom: 1rem; }
.modal-content h2 { font-size: 2rem; margin-bottom: 0.5rem; }
.modal-content p { color: var(--text-secondary); margin-bottom: 2rem; }

/* Responsive */
@media (max-width: 600px) {
    .app-container { padding: 1rem; }
    .game-area { flex-direction: column; align-items: center; }
    .grid { max-width: 100%; }
    .side-panel { width: 100%; }
}