/* ==========================================================================
   WebTUI-based Sudoku Styling
   ========================================================================== */

@layer base, components, utilities;

@import url('https://unpkg.com/@webtui/css@0.1.10/base.css');
@import url('https://unpkg.com/@webtui/css@0.1.10/components/button.css');
@import url('https://unpkg.com/@webtui/css@0.1.10/components/input.css');
@import url('https://unpkg.com/@webtui/css@0.1.10/components/table.css');
@import url('https://unpkg.com/@webtui/css@0.1.10/components/badge.css');

/* ==========================================================================
   CSS Variables
   ========================================================================== */

:root {
    /* Animation durations */
    --anim-duration-fast: 0.15s;
    --anim-duration-normal: 0.2s;
    --anim-duration-slow: 0.3s;
    --anim-duration-hint: 0.5s;
    
    /* Grid dimensions */
    --grid-size: 9;
    --grid-gap: 1px;
    --grid-border: 2px;
    --cell-border: 1px;
    
    /* Colors */
    --color-ambiguous: #ffcc00;
    --color-invalid: #ff4444;
    --color-hint: #44ff44;
    --color-strike: #ff4444;
    --color-strike-empty: #999;
}


/* Force dark mode colors */
[data-webtui-theme="dark"] {
    --background0: #1a1a1a;
    --background1: #2a2a2a;
    --background2: #3a3a3a;
    --foreground0: #ffffff;
    --foreground1: #cccccc;
    --foreground2: #4a4a4a;
    --grid-border: #555555;
}

/* Ensure dark mode on mobile */
@media (max-width: 768px) {
    [data-webtui-theme="dark"] {
        --background0: #1a1a1a !important;
        --background1: #2a2a2a !important;
        --background2: #3a3a3a !important;
        --foreground0: #ffffff !important;
        --foreground1: #cccccc !important;
        --foreground2: #4a4a4a !important;
        --grid-border: #555555 !important;
    }
}

/* ==========================================================================
   Sudoku Grid
   ========================================================================== */

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: var(--grid-gap);
    margin: 20px auto;
    background: var(--foreground2, #999);
    border: var(--grid-border) solid var(--foreground0);
    max-width: 450px;
}

.cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--foreground1);  /* User-entered numbers: light grey */
    background: var(--background0);
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    cursor: pointer;
    user-select: none;
    border: var(--cell-border) solid var(--background2);
    transition: all var(--anim-duration-fast) ease;
    position: relative;
}

.cell:hover {
    background: var(--background1, #222);
}

/* Selected cell - prominent highlight */
.cell.selected {
    background: var(--foreground0);
    color: var(--background0);
    box-shadow: inset 0 0 0 3px var(--foreground2);
    transform: scale(0.95);
}

/* Invalid move - red flash */
.cell.invalid {
    background: var(--color-invalid) !important;
    color: #fff !important;
    animation: invalid-flash var(--anim-duration-slow) ease;
}

@keyframes invalid-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.9); }
}

/* Processing state - yellow flash */
.cell.processing {
    background: var(--background2);
    animation: processing-flash var(--anim-duration-normal) ease;
}

@keyframes processing-flash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.cell.original {
    color: var(--foreground0);  /* Pre-filled numbers: bright white */
    background: var(--background1, #222);
    font-weight: var(--font-weight-bold);
}

/* 3x3 box styling - alternating background colors for visual separation */
/* Box 1 (top-left) */
.cell[data-row="0"][data-col="0"],
.cell[data-row="0"][data-col="1"],
.cell[data-row="0"][data-col="2"],
.cell[data-row="1"][data-col="0"],
.cell[data-row="1"][data-col="1"],
.cell[data-row="1"][data-col="2"],
.cell[data-row="2"][data-col="0"],
.cell[data-row="2"][data-col="1"],
.cell[data-row="2"][data-col="2"] {
    background: var(--background1);
}

/* Box 2 (top-middle) */
.cell[data-row="0"][data-col="3"],
.cell[data-row="0"][data-col="4"],
.cell[data-row="0"][data-col="5"],
.cell[data-row="1"][data-col="3"],
.cell[data-row="1"][data-col="4"],
.cell[data-row="1"][data-col="5"],
.cell[data-row="2"][data-col="3"],
.cell[data-row="2"][data-col="4"],
.cell[data-row="2"][data-col="5"] {
    background: var(--background0);
}

/* Box 3 (top-right) */
.cell[data-row="0"][data-col="6"],
.cell[data-row="0"][data-col="7"],
.cell[data-row="0"][data-col="8"],
.cell[data-row="1"][data-col="6"],
.cell[data-row="1"][data-col="7"],
.cell[data-row="1"][data-col="8"],
.cell[data-row="2"][data-col="6"],
.cell[data-row="2"][data-col="7"],
.cell[data-row="2"][data-col="8"] {
    background: var(--background1);
}

/* Box 4 (middle-left) */
.cell[data-row="3"][data-col="0"],
.cell[data-row="3"][data-col="1"],
.cell[data-row="3"][data-col="2"],
.cell[data-row="4"][data-col="0"],
.cell[data-row="4"][data-col="1"],
.cell[data-row="4"][data-col="2"],
.cell[data-row="5"][data-col="0"],
.cell[data-row="5"][data-col="1"],
.cell[data-row="5"][data-col="2"] {
    background: var(--background0);
}

/* Box 5 (center) */
.cell[data-row="3"][data-col="3"],
.cell[data-row="3"][data-col="4"],
.cell[data-row="3"][data-col="5"],
.cell[data-row="4"][data-col="3"],
.cell[data-row="4"][data-col="4"],
.cell[data-row="4"][data-col="5"],
.cell[data-row="5"][data-col="3"],
.cell[data-row="5"][data-col="4"],
.cell[data-row="5"][data-col="5"] {
    background: var(--background1);
}

/* Box 6 (middle-right) */
.cell[data-row="3"][data-col="6"],
.cell[data-row="3"][data-col="7"],
.cell[data-row="3"][data-col="8"],
.cell[data-row="4"][data-col="6"],
.cell[data-row="4"][data-col="7"],
.cell[data-row="4"][data-col="8"],
.cell[data-row="5"][data-col="6"],
.cell[data-row="5"][data-col="7"],
.cell[data-row="5"][data-col="8"] {
    background: var(--background0);
}

/* Box 7 (bottom-left) */
.cell[data-row="6"][data-col="0"],
.cell[data-row="6"][data-col="1"],
.cell[data-row="6"][data-col="2"],
.cell[data-row="7"][data-col="0"],
.cell[data-row="7"][data-col="1"],
.cell[data-row="7"][data-col="2"],
.cell[data-row="8"][data-col="0"],
.cell[data-row="8"][data-col="1"],
.cell[data-row="8"][data-col="2"] {
    background: var(--background1);
}

/* Box 8 (bottom-middle) */
.cell[data-row="6"][data-col="3"],
.cell[data-row="6"][data-col="4"],
.cell[data-row="6"][data-col="5"],
.cell[data-row="7"][data-col="3"],
.cell[data-row="7"][data-col="4"],
.cell[data-row="7"][data-col="5"],
.cell[data-row="8"][data-col="3"],
.cell[data-row="8"][data-col="4"],
.cell[data-row="8"][data-col="5"] {
    background: var(--background0);
}

/* Box 9 (bottom-right) */
.cell[data-row="6"][data-col="6"],
.cell[data-row="6"][data-col="7"],
.cell[data-row="6"][data-col="8"],
.cell[data-row="7"][data-col="6"],
.cell[data-row="7"][data-col="7"],
.cell[data-row="7"][data-col="8"],
.cell[data-row="8"][data-col="6"],
.cell[data-row="8"][data-col="7"],
.cell[data-row="8"][data-col="8"] {
    background: var(--background1);
}

/* Ensure selected cell stands out above box background */
.cell.selected {
    background: var(--foreground0) !important;
    color: var(--background0);
}

/* Ensure hover state works */
.cell:hover {
    background: var(--background2) !important;
}

.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: var(--grid-border) solid var(--foreground0);
}

/* ==========================================================================
   Game Info Panel
   ========================================================================== */

.game-info {
    display: flex;
    justify-content: space-between;
    padding: 15px;
    margin-bottom: 20px;
    background: var(--background1, #222);
    border: var(--grid-border) solid var(--foreground2);
    border-radius: 4px;
}

#setup-panel {
    text-align: center;
    padding: 20px;
    margin-bottom: 20px;
    background: var(--background1, #222);
    border: var(--grid-border) solid var(--foreground2);
    border-radius: 4px;
}

#setup-panel select {
    margin: 0 10px;
    padding: 8px 16px;
}

/* ==========================================================================
   Dialog/Modal
   ========================================================================== */

.dialog {
    display: none;
    z-index: 1002;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--background1, #222);
    padding: 30px;
    border: var(--grid-border) solid var(--foreground0);
    border-radius: 8px;
    text-align: center;
    max-width: 400px;
}

.dialog h2 {
    margin-bottom: 20px;
    color: var(--foreground0);
}

.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
}

/* ==========================================================================
   Leaderboard
   ========================================================================== */

#leaderboard-panel {
    margin-top: 30px;
    padding: 20px;
    background: var(--background1, #222);
    border: var(--grid-border) solid var(--foreground2);
    border-radius: 4px;
}

#leaderboard-table {
    width: 100%;
    margin-top: 15px;
}

#initials {
    margin: 15px 0;
    padding: 10px;
    font-size: 1.2rem;
    text-transform: uppercase;
    text-align: center;
    letter-spacing: 5px;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
}

#score-display {
    font-size: 2rem;
    margin: 20px 0;
}

/* ==========================================================================
   Game State Indicators
   ========================================================================== */

/* Ambiguous cells - thin orange border */
.cell.ambiguous {
    border: 3px solid var(--color-ambiguous) !important;
}

/* Strike system styling */
.strikes-container {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 8px;
    background: var(--background1, #222);
    border-radius: 4px;
    transition: all var(--anim-duration-slow) ease;
}

.strikes-container.strike-flash {
    background: var(--color-strike);
    animation: strike-flash var(--anim-duration-slow) ease;
}

@keyframes strike-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.strike-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-strike-empty);
    border: var(--cell-border) solid var(--foreground1, #ccc);
    transition: all var(--anim-duration-fast) ease;
}

.strike-dot.filled {
    background: var(--color-strike);
    border-color: var(--color-strike);
    box-shadow: 0 0 8px var(--color-strike);
}

.strike-dot.infinity {
    font-size: 1rem;
    font-weight: bold;
    color: #44ff44;
    background: transparent;
    border: none;
}



/* Hint used - green flash */
.cell.hint-used {
    background: var(--color-hint) !important;
    color: #000 !important;
    animation: hint-flash var(--anim-duration-hint) ease;
}

@keyframes hint-flash {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ==========================================================================
   Mobile Number Pad
   ========================================================================== */

.number-pad {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--background1, #222);
    border: var(--grid-border) solid var(--foreground0);
    border-radius: 12px;
    padding: 15px;
    z-index: 1001;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.number-pad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.number-btn {
    aspect-ratio: 1;
    min-width: 60px;
    font-size: 1.5rem;
    font-weight: var(--font-weight-bold);
    background: var(--background0);
    color: var(--foreground0);
    border: var(--grid-border) solid var(--foreground2);
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--anim-duration-fast) ease;
}

.number-btn:hover {
    background: var(--background1, #222);
    border-color: var(--foreground0);
    transform: scale(1.05);
}

.number-btn:active {
    transform: scale(0.95);
    background: var(--foreground0);
    color: var(--background0);
}

.number-btn.clear {
    background: var(--color-strike);
    color: #fff;
    border-color: #ff6666;
}

.number-btn.clear:hover {
    background: #ff6666;
}

.number-btn.clear:active {
    background: #cc0000;
}

/* ==========================================================================
   Mobile Responsiveness
   ========================================================================== */

/* Mobile devices */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        max-width: 100%;
    }
    
    h1 {
        font-size: 1.5rem;
        margin-bottom: 20px;
    }
    
    /* Ensure minimum touch target size for cells */
    .cell {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.2rem;
    }
    
    /* Adjust grid for smaller screens */
    .sudoku-grid {
        max-width: 100%;
        margin: 10px auto;
        gap: 2px;
    }
    
    /* Game info panel - stack on mobile */
    .game-info {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    /* Number pad - fixed at bottom, full width */
    .number-pad {
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 40px);
        max-width: 400px;
        padding: 10px;
        border-radius: 8px;
    }
    
    .number-pad-grid {
        gap: 6px;
    }
    
    .number-btn {
        min-width: 44px;
        min-height: 44px;
        font-size: 1.2rem;
    }
    
    /* Ensure selected cell is highly visible */
    .cell.selected {
        background: var(--foreground0);
        color: var(--background0);
        box-shadow: inset 0 0 0 3px var(--foreground2);
        transform: scale(0.95);
    }
    
    /* Dialog positioning on mobile */
    .dialog {
    display: none;
        width: calc(100% - 40px);
        max-width: none;
        padding: 20px;
    }
    
    /* Timer and score display */
    #timer, #score-display {
        font-size: 1rem;
    }
    
    /* Strikes container */
    .strikes-container {
        padding: 8px;
    }
    
    .strike-dot {
        width: 10px;
        height: 10px;
    }
}

/* Small mobile devices */
@media (max-width: 400px) {
    .cell {
        min-width: 40px;
        min-height: 40px;
        font-size: 1rem;
    }
    
    .number-btn {
        min-width: 40px;
        min-height: 40px;
        font-size: 1.1rem;
    }
    
    h1 {
        font-size: 1.2rem;
    }
}

/* Tablet devices */
@media (min-width: 769px) and (max-width: 1024px) {
    .cell {
        min-width: 48px;
        min-height: 48px;
        font-size: 1.3rem;
    }
    
    .sudoku-grid {
        max-width: 500px;
    }
    
    .number-btn {
        min-width: 50px;
        min-height: 50px;
        font-size: 1.3rem;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .number-pad {
        bottom: 5px;
        padding: 8px;
    }
    
    .number-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .sudoku-grid {
        margin: 5px auto;
    }
}

/* ==========================================================================
   Solution Notice
   ========================================================================== */

.solution-notice {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(68, 255, 68, 0.95);
    color: #000;
    padding: 20px 40px;
    border-radius: 8px;
    font-size: 1.5rem;
    font-weight: bold;
    z-index: 1003;
    box-shadow: 0 4px 20px rgba(68, 255, 68, 0.5);
    animation: fade-in-out 2s ease-in-out;
    pointer-events: none;
}

@keyframes fade-in-out {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    10% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    90% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* Mobile responsiveness for solution notice */
@media (max-width: 768px) {
    .solution-notice {
        padding: 15px 30px;
        font-size: 1.2rem;
        width: calc(100% - 40px);
        text-align: center;
    }
}

/* Solution found notice */
.solution-notice {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 40px;
    border-radius: 12px;
    font-size: 1.5rem;
    font-weight: bold;
    box-shadow: 0 10px 40px rgba(102, 126, 234, 0.4);
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.solution-notice.show {
    opacity: 1;
    animation: notice-pop 0.3s ease-out;
}

@keyframes notice-pop {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
    }
    50% {
        transform: translate(-50%, -50%) scale(1.05);
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}
