:root {
    --bg-color-1: #0A58CA;
    --bg-color-2: #41D5E2;
    --board-bg: #FFFFFF;
    --grid-line-thick: #1e3c72;
    --grid-line-thin: #a0c4ff;
    --cell-selected: #FFC107;
    --cell-highlight: #FFF3E0;
    --cell-error: #FFCDD2;
    --text-main: #1e3c72;
    --text-fixed: #000000;
    --text-error: #D32F2F;
    --btn-bg: #FFFFFF;
    --btn-hover: #e3f2fd;
    --btn-active: #FFC107;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    /* Hard-lock scrolling */
    position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, var(--bg-color-1), var(--bg-color-2));
    color: white;
    touch-action: none; 
}

.game-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.screen {
    width: 100%;
    height: 100%;
    max-width: 900px;
    padding: 5px 10px; /* Reduced outer padding */
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-in-out;
}

#menu-screen {
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none !important;
}

header {
    text-align: center;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    flex-shrink: 0;
}

/* Normal Header (Menu) */
header h1 {
    font-family: 'Nunito', sans-serif;
    font-weight: 900;
    font-size: 2.2rem;
    letter-spacing: 2px;
    color: #FFF;
    -webkit-text-stroke: 1.5px #1e3c72;
    line-height: 1.2;
}

header .subtitle {
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* Menu Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 250px;
    margin-top: 20px;
}

.menu-btn {
    background: var(--btn-bg);
    color: var(--text-main);
    border: none;
    padding: 12px 30px;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 30px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: transform 0.2s, background 0.2s;
    font-family: inherit;
}

.menu-btn:hover { background: var(--btn-hover); }
.menu-btn:active { background: var(--btn-active); transform: scale(0.95); }

/* Game Header Styles - Ultra Compact for Mobile */
.game-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 5px;
}

.header-titles { text-align: left; }
.game-header h1 { font-size: 1.6rem; line-height: 1; -webkit-text-stroke: 1px #1e3c72; }
.game-header .subtitle { font-size: 0.75rem; margin-top: 2px; }

.small-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Board Styles - Guaranteed Square */
.board-container {
    /* Hard calculation: Viewport width OR (Viewport Height - 250px space for controls) */
    width: min(95vw, calc(100vh - 250px));
    height: min(95vw, calc(100vh - 250px));
    max-width: 450px;
    max-height: 450px;
    flex-shrink: 0; /* Prevents flex from squishing it */
    background: var(--board-bg);
    padding: 3px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    border: 3px solid var(--grid-line-thick);
}

#sudoku-board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    background: var(--grid-line-thick);
    gap: 1px;
}

.cell {
    background: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(1rem, 5vmin, 1.8rem);
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    position: relative;
}

.cell.fixed { color: var(--text-fixed); cursor: default; }

.cell.error {
    background-color: var(--cell-error) !important;
    color: var(--text-error) !important;
}

.cell.selected { background-color: var(--cell-selected); color: #000; }
.cell.highlighted { background-color: var(--cell-highlight); }

.cell:nth-child(3n) { margin-right: 2px; }
.cell:nth-child(9n) { margin-right: 0; }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { margin-bottom: 2px; }

/* Candidates */
.candidates {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    font-size: clamp(0.5rem, 1.5vmin, 0.7rem);
    color: #666;
    font-weight: 600;
}

.candidate-num {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Controls Styles - Ultra Compact */
.controls-container {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px; /* Tighter gap */
    width: 100%;
    max-width: 450px;
    padding-bottom: 5px;
}

.mode-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 30px;
    padding: 3px;
}

.mode-toggle button {
    flex: 1;
    border: none;
    padding: 6px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    background: transparent;
    color: white;
}

.mode-toggle button.active {
    background: var(--btn-bg);
    color: var(--text-main);
}

.numpad {
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* 2 rows on mobile */
    gap: 5px;
}

.num-btn {
    background: var(--btn-bg);
    border: none;
    border-radius: 8px;
    height: 45px; /* Hardcap height to save vertical space */
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.num-btn:active { background: var(--btn-active); transform: scale(0.95); }

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
}

.action-btn {
    background: var(--btn-bg);
    border: none;
    border-radius: 8px;
    padding: 8px 0;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.action-btn:active { transform: scale(0.95); }

/* Desktop adjustments */
@media (min-width: 800px) {
    .main-content {
        flex-direction: row;
        align-items: flex-start;
        padding-top: 20px;
        gap: 40px;
    }
    .board-container {
        width: 450px;
        height: 450px;
    }
    .controls-container {
        width: 250px;
        gap: 15px;
        padding-top: 0;
    }
    .numpad {
        grid-template-columns: repeat(3, 1fr); /* 3 rows on desktop */
        gap: 10px;
    }
    .num-btn {
        height: 60px;
        font-size: 1.5rem;
    }
    .action-buttons {
        gap: 10px;
    }
    .action-btn {
        padding: 15px 0;
        font-size: 1rem;
    }
    .game-header h1 {
        font-size: 2.5rem;
    }
    .game-header .subtitle {
        font-size: 1rem;
    }
}
