/* ============================================
   Calcudoku Game Styles
   Professional styling for desktop and mobile
   ============================================ */

/* CSS Variables for theming */
:root {
    --calcudoku-cell-bg: #ffffff;
    --calcudoku-cell-border: #d1d5db;
    /* High contrast black */
    --calcudoku-cage-border: #000000;
    --calcudoku-text: #1f2937;
    --calcudoku-selected: #3b82f6;
    --calcudoku-selected-bg: #dbeafe;
    --calcudoku-correct: #059669;
    --calcudoku-incorrect: #dc2626;
    --calcudoku-hint-text: #6b7280;
}

#game-interface-wrapper {
    /* Base styles if needed, but primarily for desktop */
}

.dark {
    --calcudoku-cell-bg: #374151;
    --calcudoku-cell-border: #334155;
    --calcudoku-cage-border: #ffffff;
    --calcudoku-text: #f9fafb;
    --calcudoku-selected: #60a5fa;
    --calcudoku-selected-bg: #1e3a5f;
    --calcudoku-correct: #34d399;
    --calcudoku-incorrect: #f87171;
    --calcudoku-hint-text: #9ca3af;
}

/* ============================================
   GRID CONTAINER
   ============================================ */
#calcudoku-grid {
    width: 100%;
    margin-bottom: 2rem;
    position: relative;
    aspect-ratio: 1 / 1 !important;
}

#puzzle-grid {
    display: grid;
    width: 100%;
    height: 100%;
    background-color: transparent;
    border-radius: 0.5rem;
    overflow: hidden;
    position: relative;
    aspect-ratio: 1 / 1 !important;
    grid-auto-rows: 1fr !important;
}

/* Grid size adaptations - columns set by JS */
/* Grid size adaptations - Scaled up for Desktop Overhaul */
#puzzle-grid[style*="grid-template-columns: repeat(4"] {
    max-width: 100%;
    /* Filled by container */
}

#puzzle-grid[style*="grid-template-columns: repeat(6"] {
    max-width: 100%;
}

#puzzle-grid[style*="grid-template-columns: repeat(9"] {
    max-width: 100%;
}

/* ============================================
   CELL STYLING
   ============================================ */
.calcudoku-cell {
    position: relative;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background-color: #ffffff !important;
    color: #000000 !important;
    aspect-ratio: 1 / 1 !important;
    border: 1px solid var(--calcudoku-cell-border);
    font-weight: 700;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    outline: none;
    cursor: pointer;
    box-sizing: border-box;
}

/* Force Dark Mode Cell Colors */
.dark .calcudoku-cell {
    background-color: #1e293b !important;
    /* Deep Navy/Slate */
    color: #f8fafc !important;
    /* Off-white text */
    /* Dark Slate border */
}

/* Cell hover state */
.calcudoku-cell:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

.dark .calcudoku-cell:hover {
    background-color: rgba(96, 165, 250, 0.15);
}

/* Cell value text */
.cell-value {
    font-weight: 700;
    font-size: 2.75rem;
    line-height: 1;
    color: var(--calcudoku-text);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

/* Smaller text for larger grids */
#puzzle-grid[style*="repeat(6"] .cell-value {
    font-size: 2.15rem;
}

#puzzle-grid[style*="repeat(9"] .cell-value {
    font-size: 1.75rem !important;
}

/* ============================================
   SELECTED STATE
   ============================================ */
.calcudoku-cell.selected {
    background-color: var(--calcudoku-selected-bg) !important;
    box-shadow: inset 0 0 0 3px var(--calcudoku-selected);
    z-index: 2;
}

#game-content-area #puzzle-grid .cage-top {
    border-top: 4px solid var(--calcudoku-cage-border) !important;
}

#game-content-area #puzzle-grid .cage-bottom {
    border-bottom: 4px solid var(--calcudoku-cage-border) !important;
}

#game-content-area #puzzle-grid .cage-left {
    border-left: 4px solid var(--calcudoku-cage-border) !important;
}

#game-content-area #puzzle-grid .cage-right {
    border-right: 4px solid var(--calcudoku-cage-border) !important;
}


/* ============================================
   CAGE HINT (Target + Operation Label)
   ============================================ */
.cage-label,
.cage-hint {
    position: absolute;
    padding-top: 3px !important;
    padding-left: 3px !important;
    top: 0 !important;
    left: 0 !important;
    font-size: 14px !important;
    font-weight: 800 !important;
    line-height: 1;
    color: var(--calcudoku-hint-text);
    pointer-events: none;
    z-index: 3;
    opacity: 0.9;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

/* Consistent hints across all grid sizes */

/* ============================================
   NUMBER PAD (Dynamic Grid)
   ============================================ */
#number-pad {
    max-width: 450px;
    padding: 0;
    /* margin: 0 auto; Removed for left align */
}

.numpad-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.numpad-btn {
    min-width: unset;
    /* Remove fixed width */
    width: calc(20% - 8px);
    height: 52px;
    /* Taller touch targets */
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: 0.5rem;
    background-color: #e5e7eb;
    color: #1f2937;
    border: none;
    cursor: pointer;
    transition: all 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    flex: 0 0 auto;
    margin: 2px;
    box-sizing: border-box;
}


/* Clear/Delete button styling */
.numpad-btn.clear-btn {
    background-color: #fecaca;
    color: #991b1b;
}

.dark .numpad-btn.clear-btn {
    background-color: #7f1d1d;
    color: #fecaca;
}

/* Duplicate Number Conflict State */
.calcudoku-cell.conflict {
    background-color: #fee2e2 !important;
}

.calcudoku-cell.conflict .cell-value {
    color: #991b1b !important;
}

.dark .calcudoku-cell.conflict {
    background-color: #7f1d1d !important;
}

.dark .calcudoku-cell.conflict .cell-value {
    color: #fca5a5 !important;
}

/* ============================================
   GAME BUTTONS (New Game, Check, Hint)
   ============================================ */
#new-game,
#check-btn,
#hint-btn {
    min-height: 44px;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.5rem 1.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Action Buttons - Standardized Height for Mobile */
.action-btn {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Specific overrides for desktop buttons to maintain width but fix height */
#new-game,
#check-btn,
#hint-btn {
    height: 44px !important;
}

#new-game:hover {
    background-color: #eff6ff;
}

.dark #new-game {
    border-color: #60a5fa;
    color: #60a5fa;
}

.dark #new-game:hover {
    background-color: rgba(96, 165, 250, 0.1);
}

#check-btn {
    background-color: #3b82f6;
    color: white;
    border: none;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.5);
}

#check-btn:hover {
    background-color: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 6px 8px -1px rgba(59, 130, 246, 0.6);
}

#new-game:active,
#check-btn:active,
#hint-btn:active {
    transform: scale(0.98);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.calcudoku-toast {
    animation: toastSlideUp 0.3s ease-out;
    font-weight: 500;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }

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

/* ============================================
   FAQ SECTION
   ============================================ */
#calcudoku-faq h2 {
    color: var(--calcudoku-text);
}

#calcudoku-faq h3 {
    color: #374151;
}

.dark #calcudoku-faq h3 {
    color: #f3f4f6;
}

#calcudoku-faq p {
    color: #6b7280;
}

.dark #calcudoku-faq p {
    color: #9ca3af;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Smaller screens */
@media (max-width: 400px) {

    #calcudoku-grid,
    #puzzle-grid {
        max-width: 100%;
        height: auto;
        aspect-ratio: auto;
    }

    .cage-label,
    .cage-hint {
        font-size: 10px !important;
    }

    /* Base 4x4 Grid Mobile Size */
    .cell-value {
        font-size: 2.25rem !important;
    }

    /* 6x6 Grid Mobile Size */
    #puzzle-grid[style*="repeat(6"] .cell-value {
        font-size: 1.75rem !important;
    }

    /* 9x9 Grid Mobile Size */
    #puzzle-grid[style*="repeat(9"] .cell-value {
        font-size: 1.25rem !important;
    }

    .numpad-btn {
        min-width: 32px;
        min-height: 42px;
        font-size: 1.25rem;
    }
}

/* Very small screens */
@media (max-width: 320px) {
    #calcudoku-grid {
        max-width: 260px;
    }

    .cell-value {
        font-size: 1.75rem !important;
    }

    #puzzle-grid[style*="repeat(6"] .cell-value {
        font-size: 1.5rem !important;
    }

    .numpad-btn {
        min-width: 28px;
        min-height: 38px;
        font-size: 1.1rem;
    }
}

/* Tablet and up - slightly fade numpad (keyboard available) */
@media (min-width: 768px) {
    #number-pad {
        opacity: 0.85;
        transition: opacity 0.2s ease;
    }

    #number-pad:hover,
    #number-pad:focus-within {
        opacity: 1;
    }
}

/* ============================================
   DESKTOP OVERHAUL (>= 1024px)
   ============================================ */
@media (min-width: 1024px) {
    #game-interface-wrapper {
        display: grid !important;
        grid-template-columns: 1fr 260px !important;
        grid-template-rows: auto !important;
        gap: 1.5rem !important;
        align-items: start !important;
        max-width: 1400px !important;
        margin: 0 auto !important;
        padding: 2rem 2rem 0 !important;
    }

    /* Column 1: The Grid */
    #calcudoku-grid {
        grid-column: 1 / 2;
        width: 100% !important;
        max-width: 80vh !important;
        /* Enforce square scaling */
        min-width: 600px !important;
        aspect-ratio: 1 / 1 !important;
        margin: 0 !important;
        /* Align left in its column */
    }

    #puzzle-grid {
        display: grid !important;
        width: 100% !important;
        height: 100% !important;
        max-width: none !important;
        /* Kill the 400px cap */
        min-width: 100% !important;
        aspect-ratio: 1 / 1 !important;
        grid-auto-rows: 1fr !important;
    }

    .calcudoku-cell {
        aspect-ratio: 1 / 1 !important;
        width: 100% !important;
        height: auto !important;
    }

    /* Column 2: The Controls */
    #controls-wrapper {
        grid-column: 2 / 3;
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
        max-width: 260px !important;
    }

    #number-pad {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: none !important;
    }

    .numpad-btn {
        width: 100% !important;
        height: 60px !important;
        /* Tightened height */
        font-size: 1.8rem !important;
        aspect-ratio: unset !important;
    }

    /* Vertical stack for action buttons on desktop */
    #controls-wrapper .hidden.sm\:flex {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100% !important;
    }

    .action-btn {
        width: 100% !important;
        height: 50px !important;
        font-size: 1.15rem !important;
    }

    .numpad-btn.clear-btn {
        grid-column: 1 / -1 !important;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
.calcudoku-cell:focus {
    outline: 3px solid var(--calcudoku-selected);
    outline-offset: -3px;
}

.numpad-btn:focus {
    outline: 2px solid var(--calcudoku-selected);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {

    .calcudoku-cell,
    .numpad-btn,
    #new-game,
    #check-btn,
    #hint-btn {
        transition: none;
    }

    .calcudoku-cell.incorrect {
        animation: none;
    }
}

.calcudoku-cell.incorrect {
    background-color: rgba(220, 38, 38, 0.1) !important;
}

.dark .calcudoku-cell.incorrect {
    background-color: rgba(248, 113, 113, 0.15) !important;
}

.calcudoku-cell.incorrect .cell-value {
    color: var(--calcudoku-incorrect) !important;
}

.calcudoku-cell.success {
    animation: none;
}

.calcudoku-toast {
    animation: none;
}
}

/* ============================================
   MONEY LAYOUT ENFORCEMENT (REFINED)
   ============================================ */
/* Desktop Layout Rules */
.page-container {
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping on mobile */
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    position: relative;
    align-items: flex-start;
    /* Ensure proper alignment */
}

/* Columns - Mobile Default */
.game-column,
.sidebar-column {
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Desktop Styles (> 1024px to match 'lg') */
/* Default / Mobile Styles (< 1024px) */
.main-layout-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin: 0 auto;
    padding-top: 20px;
}

.game-container {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.sticky-sidebar {
    display: none;
    /* Hide on mobile per request */
}

/* Desktop Styles (> 1024px to match 'lg') */
@media (min-width: 1024px) {
    .main-layout-wrapper {
        display: flex;
        flex-direction: row;
        gap: 40px;
        align-items: flex-start;
        max-width: 1536px;
        margin: 0 auto;
        padding-top: 0px !important;
    }

    .game-container {
        flex: 0 0 65%;
        max-width: 65%;
        min-width: 0;
    }

    .sticky-sidebar {
        flex: 0 0 300px;
        width: 300px;
        margin-top: 40px;
        display: block;
        position: sticky;
        top: 20px;
        height: auto;
        padding-left: 0;
    }

    /* Ensure gecko wrapper is sized correctly primarily on desktop */
    .gecko-wrapper {
        width: 180px !important;
        flex-shrink: 0;
    }

    /* Redundant grid overrides removed */
}

footer {
    clear: both;
}