:root {
    --bg-color: #eef2f5;
    --text-color: #2c3e50;
    --primary-color: #2ecc71;
    --primary-hover: #27ae60;
    --secondary-color: #95a5a6;
    --board-bg: #ffffff;
    --border-color: #2c3e50;

    /* Region Colors - stronger contrast */
    --region-0: #ffffff;
    --region-1: #e3f2fd;
    /* Light Blue */
    --region-2: #fff3e0;
    /* Light Orange */
    --region-3: #e8f5e9;
    /* Light Green */
    --region-4: #fce4ec;
    /* Light Pink */
    --region-5: #f3e5f5;
    /* Light Purple */
    --region-6: #fffde7;
    /* Light Yellow */
    --region-7: #eceff1;
    /* Light Grey */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.app-container {
    max-width: 600px;
    width: 100%;
    text-align: center;
    background: white;
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

header h1 {
    font-weight: 700;
    color: #27ae60;
    /* Darker Green */
    margin-bottom: 0.5rem;
}

header p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
}

header a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

#daily-info {
    display: flex;
    justify-content: space-between;
    /* Date left, Timer right */
    align-items: center;
    width: 100%;
    max-width: 400px;
    /* Constrain width matches board roughly */
    margin: 0 auto 1.5rem;
    font-weight: 600;
    font-size: 1.1rem;
    color: #34495e;
    background: #f8f9fa;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    border: 1px solid #eee;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 1rem;
}

.primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px rgba(46, 204, 113, 0.2);
}

.primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(46, 204, 113, 0.3);
}

.secondary {
    background-color: #ecf0f1;
    color: #7f8c8d;
}

.secondary:hover {
    background-color: #bdc3c7;
    color: #2c3e50;
}

select {
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid #ddd;
    font-family: inherit;
}

.game-status {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    min-height: 1.5rem;
    font-weight: 600;
}

.game-status.error {
    color: #c0392b;
}

.game-status.success {
    color: #27ae60;
}

.board-container {
    display: grid;
    gap: 0;
    /* Remove gap, handle borders on cells */
    background-color: var(--border-color);
    margin: 0 auto 2rem;
    user-select: none;
    width: fit-content;
    border: 3px solid var(--border-color);
    /* Outer border */
}

.cell {
    width: 45px;
    height: 45px;
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    cursor: pointer;
    transition: background-color 0.1s;
    /* Borders */
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    position: relative;
    box-sizing: border-box;
    /* Ensure borders don't break layout */
}

/* Thicker borders for Region boundaries */
.cell.border-right-thick {
    border-right: 3px solid #2c3e50 !important;
}

.cell.border-bottom-thick {
    border-bottom: 3px solid #2c3e50 !important;
}

.cell:hover {
    filter: brightness(0.95);
}

.cell.disabled {
    cursor: default;
    pointer-events: none;
}

/* Region styling - High Contrast Mode */
.region-0 {
    background-color: #ffffff;
}

.region-1 {
    background-color: #bbdefb;
}

/* Blue 100 */
.region-2 {
    background-color: #ffe0b2;
}

/* Orange 100 */
.region-3 {
    background-color: #c8e6c9;
}

/* Green 100 */
.region-4 {
    background-color: #f8bbd0;
}

/* Pink 100 */
.region-5 {
    background-color: #e1bee7;
}

/* Purple 100 */
.region-6 {
    background-color: #f0f4c3;
}

/* Lime 100 */
.region-7 {
    background-color: #cfd8dc;
}

/* Blue Grey 100 */

/* Icons */
.cell.tree::after {
    content: "🌳";
    animation: pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cell.cross::after {
    content: "❌";
    font-size: 1rem;
    opacity: 0.6;
    animation: fadein 0.2s;
}

.cell.error {
    box-shadow: inset 0 0 0 3px #c0392b;
    /* Inner red border */
    animation: shake 0.3s;
}

.rules-hint {
    font-size: 0.85rem;
    color: #7f8c8d;
    background: #f9f9f9;
    padding: 1rem;
    border-radius: 8px;
    margin-top: 1rem;
}

footer {
    margin-top: 2rem;
    font-size: 0.75rem;
    color: #aaa;
    border-top: 1px solid #eee;
    padding-top: 1rem;
}

@keyframes shake {
    0% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-4px);
    }

    75% {
        transform: translateX(4px);
    }

    100% {
        transform: translateX(0);
    }
}

@keyframes pop {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(1);
    }
}

/* Size Selector */
.size-btn {
    min-width: 60px;
    font-size: 0.9rem;
    padding: 0.4rem 0.6rem;
}

.size-btn.active {
    background-color: var(--primary-color);
    color: white;
    border: 2px solid var(--primary-hover);
}

.size-btn.completed {
    background-color: #f1c40f;
    /* Gold for completed */
    color: #fff;
}

/* Ensure mobile responsiveness */
@media (max-width: 500px) {
    .cell {
        width: 38px;
        height: 38px;
        font-size: 1.3rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .app-container {
        padding: 1rem;
    }

    #daily-info {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* Modal Archivio */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(44, 62, 80, 0.6);
    backdrop-filter: blur(3px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: #fff;
    padding: 2.5rem 2rem;
    border-radius: 16px;
    text-align: center;
    max-width: 90%;
    width: 380px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.large-input {
    font-family: inherit;
    font-size: 1.3rem;
    padding: 0.6rem;
    margin: 1rem 0 1.5rem;
    width: 100%;
    border: 2px solid #ddd;
    border-radius: 8px;
    color: #2c3e50;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.large-input:focus {
    border-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-actions .btn {
    flex: 1;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Auth Container */
.auth-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.auth-user-name {
    font-weight: 600;
    color: #27ae60;
    font-size: 0.9rem;
}

.auth-local-mode {
    font-size: 0.8rem;
    color: #95a5a6;
    font-style: italic;
}

.btn-small {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}

/* Auth Tabs */
.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #eee;
}

.auth-tab {
    flex: 1;
    padding: 0.7rem;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: #95a5a6;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.auth-tab.active {
    color: #27ae60;
    border-bottom-color: #27ae60;
}

.auth-tab:hover {
    color: #2c3e50;
}

.auth-error {
    color: #c0392b;
    font-size: 0.85rem;
    min-height: 1.2rem;
    margin-bottom: 0.5rem;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 0.8rem 0.5rem;
    border: 1px solid #eee;
}

.stat-number {
    font-size: 1.8rem;
    font-weight: 700;
    color: #27ae60;
}

.stat-label {
    font-size: 0.75rem;
    color: #7f8c8d;
    margin-top: 0.2rem;
}

.best-times {
    text-align: left;
    max-width: 250px;
    margin: 0 auto;
}

.best-time-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid #eee;
    font-size: 0.95rem;
}

.best-time-row:last-child {
    border-bottom: none;
}

@media (max-width: 500px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    .stat-number {
        font-size: 1.4rem;
    }
}

/* Login Overlay (obbligatorio) */
.login-overlay {
    display: flex;
    position: fixed;
    z-index: 900;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(44, 62, 80, 0.85);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}

.login-overlay-content {
    background: white;
    padding: 3rem 2.5rem;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.login-overlay-content h1 {
    font-size: 2rem;
    color: #27ae60;
    margin-bottom: 0.5rem;
}

.login-overlay-content p {
    color: #666;
    font-size: 0.95rem;
}

/* Leaderboard */
.leaderboard-tabs {
    display: flex;
    gap: 0.3rem;
    justify-content: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.leaderboard-tab.active {
    background-color: #f39c12;
    color: white;
}

.leaderboard-list {
    text-align: left;
    max-height: 350px;
    overflow-y: auto;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.5rem;
    border-bottom: 1px solid #eee;
    gap: 0.5rem;
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-me {
    background-color: #e8f5e9;
    border-radius: 6px;
    font-weight: 600;
}

.leaderboard-rank {
    min-width: 2rem;
    text-align: center;
    font-size: 1.1rem;
}

.leaderboard-name {
    flex: 1;
    font-size: 0.95rem;
}

.leaderboard-time {
    font-weight: 700;
    color: #2c3e50;
    font-size: 0.95rem;
}