html, body {
    width: 100%;
    overflow-x: hidden; 
    position: relative; 
    overscroll-behavior-x: none;
    
}

/* Layout General */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: center; 
    align-items: center;
    box-sizing: border-box;
    padding: max(20px, env(safe-area-inset-top)) 10px 20px;
}

/* Calendar View */
#calendar-view {
    width: 550px;
    height: 550px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}


.calendar-header {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--surface); padding: 15px; border-radius: 20px 20px 0 0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); backdrop-filter: blur(5px); 
}
.calendar-header h3 { margin: 0; color: var(--primary-blue); font-size: 1.6rem; }

.nav-btn {
    width: 32px; height: 32px; border-radius: 50%; border: none;
    background: rgba(0,0,0,0.05); color: var(--text-main); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

.calendar-week-header {
    display: grid; grid-template-columns: repeat(7, 1fr);
    background: var(--primary-blue); color: white; padding: 10px 0;
    text-align: center; font-weight: bold; font-size: 1.2rem;
}

.calendar-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    background: var(--surface); padding: 10px; gap: 8px;
    border-radius: 0 0 20px 20px; backdrop-filter: blur(5px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.05);
    padding: 16px;
    gap: clamp(4px, 1.5vw, 10px);
}

.calendar-day {
    aspect-ratio: 1; 
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center;
    border-radius: 10px; 
    font-weight: 700; 
    cursor: pointer;
    border: 2px solid transparent; 
    color: var(--text-main);
    background: rgba(0,0,0,0.02); 
    font-size: clamp(1rem, 4vw, 1.4rem); 
    min-width: 0; 
    overflow: hidden;
}

.calendar-day:hover:not(.empty) { background: var(--highlight-bg); border-color: var(--primary-blue); }
.calendar-day.today { border-color: var(--primary-blue); color: var(--primary-blue); }
.calendar-day.completed { background-color: #22c55e; color: white; border-color: #22c55e; }
.star-icon { font-size: 0.6rem; margin-top: 2px; display: none; }
.calendar-day.completed .star-icon { display: block; }

.calendar-footer-text {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 16px;
    text-align: center;
    font-size: 1.2rem;
}

.theme-day .calendar-footer-text,
.theme-night .calendar-footer-text {
    color: #ffffff;
}

.calendar-day.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}


/* ================= HEADER & STATS ================= */
.top-bar {
    display: flex;
    flex-direction: column;   
    align-items: center; 
    width: 100%;
    max-width: 500px;
    margin: 0 auto;   
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: 10px;
    padding-left: 15px; 
    padding-right: 15px;
    gap: 15px; 
}

.back-btn {
    align-self: flex-start;  
    text-decoration: none;
    display: flex;
    align-items: center;
    width: 120px;
    height: 40px;
    gap: 8px;
}

#game-date-display {
    text-align: center;
    font-size: clamp(1.8rem, 5vw, 2.0rem);
    font-weight: 600;
    
    
    
    margin-top: 35px; 
    margin-bottom: 0;
    line-height: 1.2;
}

.stats-bar {
    width: 100%;
    display: flex;
    justify-content: center; 
    gap: 5px;
    margin-bottom: 5px;
}

.stat-card {
    background: var(--surface);
    padding: 6px 14px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    font-weight: 700;
    color: var(--text-main);
    font-size: 1.2rem;
    backdrop-filter: blur(4px);

    min-width: 90px; 
    font-variant-numeric: tabular-nums; 
    white-space: nowrap;
}
.stat-card i { color: var(--primary-blue); }
.stat-card.has-errors i, #errors-count { color: #d32f2f; }
.theme-night #errors-count { color: #ff6b6b; }

/* ================= BOARD ================= */
.game-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px; 
    width: 100%;
    flex-grow: 0; 
}

.board-area {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 5px 0;
}

#sudoku-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    width: 96vw;
    max-width: 520px;
    aspect-ratio: 1 / 1;
    border: 3px solid var(--board-border);
    gap: 1px;
    border-radius: 8px;
    overflow: hidden;
    background: transparent; 
}


.cell {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    font-size: 38px;
    font-weight: bold;
    background: var(--cell-bg); 
    color: var(--cell-text);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.cell .value { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; line-height: 1; }
.cell.error .value { color: #d32f2f !important; }
.theme-night .cell.error .value { color: #ff6b6b !important; }

.cell:not(.fixed) .value {
    color: var(--color-cell); 
}

/* Stări celulă */
.cell.selected { background: var(--selected-bg) !important; color: var(--text-main); z-index: 2; }
.cell.highlighted { background: var(--highlight-bg); }
.cell.match { background: var(--match-bg); }

/* Grid 3x3 */
.cell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--board-border); }
.cell:nth-child(n+19):nth-child(-n+27),
.cell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--board-border); }

/* Note */
.notes {
    position: absolute;
    inset: 0;             
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    pointer-events: none;
    padding: 2px;
    z-index: 1;
}
.notes-digit { font-size: clamp(0.5rem, 1.8vw, 0.7rem); color: var(--cell-text); display: flex; justify-content: center; align-items: center; font-weight: bold; }


/* Controls */
.controls-area {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 10px; 
    margin-bottom: 0; 
}

/* Zona Butoane Numere (1-9) */
.number-controls {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 4px; 
    width: 100%;
    
}

.digit-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;         
    border: 1px solid var(--primary-blue); 
    border-radius: 8px;
    color: var(--primary-blue);
    cursor: pointer;
    padding: 5px 0;
    transition: transform 0.1s;
    backdrop-filter: blur(5px);       
    aspect-ratio: 0.8;
}

.digit-btn:active { 
    transform: scale(0.9); 
    background: var(--highlight-bg); 
}

.digit-span { font-size: clamp(1.4rem, 4vw, 1.8rem); font-weight: 700; line-height: 1; }
.count-span { font-size: 0.65rem; color: var(--text-secondary); margin-top: 1px; }
.digit-btn:disabled { opacity: 0.4; filter: grayscale(1); border-color: transparent; background: rgba(0,0,0,0.05); }

/* Zona Acțiuni */
.action-buttons-column {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;          
    border: 1px solid var(--primary-blue);
    border-radius: 8px;
    padding: 5px 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    backdrop-filter: blur(5px);    
}

.action-btn i { font-size: 1.1rem; color: var(--primary-blue); }

.action-btn:active {
    transform: scale(0.9);
    background: var(--highlight-bg);
}

.action-btn.active { 
    background-color: var(--primary-blue) !important; 
    color: #fff !important; 
    border-color: var(--primary-blue); 
    
}

.action-btn.active i { color: #fff; }



/* Modal - stil general */
.custom-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.custom-modal {
    background: var(--surface);
    padding: 30px;
    border-radius: 24px;
    text-align: center;
    width: 85%;
    max-width: 350px;
    border: 1px solid rgba(255,255,255,0.2);
    box-shadow: 0 20px 50px rgba(0,0,0,0.4);
    font-size: 1.8rem;
    line-height: 1.6;
}

.modal-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: bold;
    font-size: 1.4rem;
    margin-top: 15px;
}

.custom-modal .modal-icon {
    font-size: 3em;      
    display: block;       
    text-align: center;   
    margin-bottom: 0.5em; 
}


/* Stilul unit-complete si modal */
.cell.unit-complete {
    position: relative; 
    z-index: 10; 
    background-color: var(--selected-bg) !important;
    box-shadow: 0 0 12px 3px var(--primary-blue);
    animation: unitFlashCompleteNeonShake 0.8s ease-out forwards;
}


@keyframes unitFlashCompleteNeonShake {
    0% {
        transform: scale(0.95);
        opacity: 0.6;
        box-shadow: 0 0 0 2px var(--primary-blue);
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
        box-shadow: 0 0 20px 5px var(--primary-blue);
    }
    100% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 12px 2px var(--primary-blue);
    }
}

/* ===================== MEDIA QUERIES ===================== */

/* LARGE SCREENS - Desktop / Laptop (>900px) */
@media (min-width: 900px) {
    .app-container { 
        display: flex;
        flex-direction: column;
        justify-content: center; 
        align-items: center;
        min-height: 100dvh; 
        padding: 0; 
        margin: 0 auto;
    }

    .top-bar, .stats-bar {
        width: 100%;
        max-width: 900px;
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
    }

    .game-layout {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 40px;
        margin-top: 0;
    }

    .board-area { width: auto; flex: 0 0 auto; }
    #sudoku-board { width: 550px; height: 550px; }

    
    .digit-btn { aspect-ratio: 1; padding: 10px; }
    .digit-span { font-size: 34px; }
    .count-span { font-size: 1.2rem; margin-top: 4px; }
    .controls-area { 
        flex-direction: column;
        width: fit-content; 
        align-items: center;
    }
    
    .number-controls {
        display: grid;
        grid-template-columns: repeat(3, 1fr); 
        gap: 10px;
        width: 100%; 
    }

    .controls-area .action-buttons-column {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%; 
    }
    
    .action-btn { flex-direction: row; justify-content: center; gap: 10px; padding: 15px; font-size: 1rem; }
    
}

/* ===================== MOBILE / TABLET SMALL (<900px) ===================== */
@media (max-width: 899px) {

     #calendar-view {
        width: 100% !important;
        max-width: 100vw;
        height: auto;
        margin: 0;
        padding: 0;
    }

    .calendar-grid {
        padding: 5px;
        gap: 2px;     
    }

    .calendar-day {
        font-size: 1.0rem; 
    }

    .calendar-header h3 {
        font-size: 1.6rem; 
    }

    .top-bar {
        display: flex;
        flex-direction: column;   
        align-items: center; 
        gap: 15px;               
        padding: 10px 15px;
    }

    .back-btn {
        margin-bottom: 5px;     
        font-size: 0.9rem;      
        padding: 8px 12px;
    }
    
    .game-layout { 
        flex-direction: column; 
        gap: 12px; 
        align-items: center; 
    }

    .board-area, .controls-area { 
        width: 100%; 
        max-width: 500px; 
    }

    #sudoku-board { 
        width: 96vw; 
        max-width: 520px; 
        aspect-ratio: 1; 
    }

    .digit-btn { 
        aspect-ratio: auto; 
        padding: 5px 2px; 
        border-radius: 8px; 
        min-height: fit-content; 
    }

    .digit-span { font-size: 30px; }
    .count-span { font-size: 1.0rem; }

    
    .action-buttons-column {
        display: grid;
        grid-template-columns: repeat(4, 1fr); 
        gap: 5px;
        width: 100%;
    }

    .action-btn {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        padding: 10px 0;
        font-size: 0.8rem;
    }

    .action-btn i { font-size: 1.0rem;
    }

    .cell {
    font-size: 30px;   
    
    }

    .custom-modal { 
        padding: 20px; 
        width: 95%; 
        max-width: 280px; 
        font-size: 1.3rem; 
    }

    .modal-btn { 
        width: auto; 
        padding: 18px; 
        font-size: 1.0rem; 
    }

    .stat-card {
        font-size: 1.0rem;
    }

}

/* MOBILE VERY SMALL (<360px) */
@media (max-width: 360px) {

    .stats-bar {
        width: 100%;
        justify-content: center;
        gap: 8px;
    }

    .custom-modal { 
        padding: 20px; 
        width: 95%; 
        max-width: 280px; 
        font-size: 1.3rem; 
    }

    .modal-btn { 
        padding: 18px; 
        font-size: 1.3rem; 
    }
}