/* ===== CSS Reset & Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Zen / Calm Color Palette */
    /* Primary: Soft Teal/Mint instead of corporate blue */
    --primary-blue: #2DD4BF;
    /* Teal-400 */
    --primary-blue-dark: #14B8A6;
    /* Teal-500 */
    --primary-blue-light: #5EEAD4;
    /* Teal-300 */
    --accent-blue: #99F6E4;
    /* Teal-200 */

    /* Backgrounds: Deep Slate / Midnight Calm */
    --bg-primary: #0F172A;
    /* Slate-900 */
    --bg-secondary: #1E293B;
    /* Slate-800 */
    --bg-tertiary: #334155;
    /* Slate-700 */
    --bg-glass: rgba(30, 41, 59, 0.75);
    /* Slate-800 with opacity */

    /* Text: Soft Warm White */
    --text-primary: #F1F5F9;
    /* Slate-100 */
    --text-secondary: #94A3B8;
    /* Slate-400 */
    --text-muted: #64748B;
    /* Slate-500 */

    /* Status Colors: Softer tone */
    --success: #34D399;
    /* Emerald-400 */
    --error: #FB7185;
    /* Rose-400 */
    --warning: #FBBF24;
    /* Amber-400 */

    /* UI Elements */
    --border-color: rgba(148, 163, 184, 0.2);
    /* Soft slate border */

    /* Shadows: Diffuse and soft */
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Radii: Friendlier roundness */
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;

    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
    /* Simpler, cleaner gradient */
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
}

/* ===== Container ===== */
.container {
    width: 100%;
    max-width: 700px;
    animation: fadeIn 0.6s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Header ===== */
.header {
    text-align: center;
    margin-bottom: 2rem;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-blue-light) 0%, var(--accent-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 3px;
    background: transparent;
    padding: 12px 0;
    /* Reduced side padding since it's full width */
    width: 100%;
    max-width: 480px;
    /* Matches game board width roughly */
    display: block;
    margin: 1rem auto 0;
    text-align: center;
    border: none;
    border-top: 1px solid rgba(148, 163, 184, 0.3);
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
}

/* ===== Game Area ===== */
.game-area {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

/* ===== Info Panel ===== */
.info-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    text-align: center;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-blue-light);
}

/* ===== Sudoku Container ===== */
.sudoku-container {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
    position: relative;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
    background: var(--bg-secondary);
    padding: 8px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

/* ===== Cell Styles ===== */
.cell {
    width: 60px;
    height: 60px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    color: var(--text-primary);
}

/* Rounded corners for corner cells */
.cell:first-child {
    border-top-left-radius: 16px;
}

.cell:nth-child(6) {
    border-top-right-radius: 16px;
}

.cell:nth-child(31) {
    border-bottom-left-radius: 16px;
}

.cell:last-child {
    border-bottom-right-radius: 16px;
}

.cell:focus {
    outline: none;
}

.cell:not(.prefilled):hover {
    background: rgba(10, 102, 194, 0.1);
    transform: scale(1.05);
    z-index: 1;
}

.cell.selected {
    background: rgba(10, 102, 194, 0.2);
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px var(--primary-blue);
    z-index: 2;
}

.cell.prefilled {
    background: rgba(10, 102, 194, 0.15);
    color: var(--accent-blue);
    font-weight: 700;
    cursor: default;
}

.cell.conflict {
    background: rgba(248, 81, 73, 0.2);
    border-color: var(--error);
    animation: shake 0.3s ease;
}

@keyframes shake {

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

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

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

/* Block borders for 2x3 grid structure */
/* Vertical block borders: thick border after every 3rd column */
.cell:nth-child(6n+3) {
    border-right: 2px solid var(--primary-blue-dark);
}

/* Horizontal block borders: thick border after every 2nd row */
/* Rows 3 and 5 get thick top borders (cells 13-18 and 25-30) */
.cell:nth-child(n+13):nth-child(-n+18),
.cell:nth-child(n+25):nth-child(-n+30) {
    border-top: 2px solid var(--primary-blue-dark);
}

/* Corner radius for grid */
.cell:nth-child(1) {
    border-top-left-radius: 8px;
}

.cell:nth-child(6) {
    border-top-right-radius: 8px;
}

.cell:nth-child(31) {
    border-bottom-left-radius: 8px;
}

.cell:nth-child(36) {
    border-bottom-right-radius: 8px;
}

/* ===== Number Selector ===== */
.number-selector {
    position: absolute;
    width: 200px;
    height: 200px;
    pointer-events: none;
    z-index: 100;
}

.number-selector.hidden {
    display: none;
}

.number-btn {
    position: absolute;
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: 700;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    pointer-events: all;
    animation: buttonPopIn 0.2s ease backwards;
    transform: translate(-50%, -50%);
}

@keyframes buttonPopIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.number-btn:hover {
    background: var(--primary-blue);
    border-color: var(--primary-blue-light);
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 6px 20px rgba(10, 102, 194, 0.6);
    z-index: 10;
}

.number-btn:active {
    transform: translate(-50%, -50%) scale(1.05);
}

.number-btn.delete-btn {
    background: rgba(248, 81, 73, 0.2);
    border-color: var(--error);
    color: var(--error);
    font-size: 1.4rem;
    font-weight: 400;
}

.number-btn.delete-btn:hover {
    background: var(--error);
    color: white;
    border-color: var(--error);
}

/* ===== Controls ===== */
.controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-transform: none;
}

.btn-icon {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
    color: #0F172A;
    /* Dark text for contrast against teal */
    border: none;
    box-shadow: 0 4px 12px rgba(45, 212, 191, 0.3);
    /* Soft teal shadow */
    border-radius: 9999px;
    /* Pill shape */
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(45, 212, 191, 0.4);
    filter: brightness(1.05);
}

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

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    /* Pill shape */
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--primary-blue);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ===== Shine Effect ===== */
@keyframes shine {
    0% {
        background-color: var(--bg-secondary);
        box-shadow: 0 0 0 rgba(255, 215, 0, 0);
    }

    50% {
        background-color: rgba(255, 215, 0, 0.25);
        /* Gold tint */
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
        transform: scale(1.02);
        z-index: 5;
        border-color: #ffd700;
        color: #ffd700;
    }

    100% {
        background-color: var(--bg-secondary);
        box-shadow: 0 0 0 rgba(255, 215, 0, 0);
        transform: scale(1);
    }
}

.cell.shine-effect {
    animation: shine 0.8s ease-in-out;
}

/* Ensure prefilled cells also get the effect */
.cell.prefilled.shine-effect {
    animation: shine 0.8s ease-in-out;
}

/* ===== Victory Modal ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    padding: 3rem 2.5rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    text-align: center;
    max-width: 400px;
    animation: modalSlideUp 0.4s ease;
    box-shadow: var(--shadow-lg);
}

@keyframes modalSlideUp {
    from {
        transform: translateY(50px) scale(0.9);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.victory-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-blue-light) 0%, var(--accent-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.modal-content .victory-time {
    color: var(--primary-blue-light);
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 2rem;
    margin-top: -1rem;
}

/* ===== Responsive Design ===== */
@media (max-width: 600px) {
    .title {
        font-size: 2rem;
    }

    .game-area {
        padding: 1.5rem;
    }

    .cell {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    .info-panel {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .modal-content {
        margin: 0 20px;
        padding: 2rem 1.5rem;
    }
}

@media (max-width: 400px) {
    .cell {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
    }

    .sudoku-grid {
        padding: 6px;
    }
}