@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&display=swap');

:root {
    --bg-color: #f0f2f5;
    --text-color: #1c1e21;
    --primary-color: #4361ee;
    --primary-hover: #3a56d4;
    --danger-color: #ef233c;
    --success-color: #06d6a0;
    --surface-color: #ffffff;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden; /* Prevent scrolling */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 100%;
    max-height: 1000px;
    background-color: var(--surface-color);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* Main Menu */
#main-menu {
    padding: 2rem;
    align-items: center;
    background: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
}

.title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 2rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 15px;
    width: 100%;
    overflow-y: auto;
    padding: 10px;
    padding-bottom: 40px;
}

.level-btn {
    aspect-ratio: 1;
    border: none;
    border-radius: 12px;
    background-color: var(--surface-color);
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.level-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(67, 97, 238, 0.2);
}

.level-btn.locked {
    background-color: #e4e6eb;
    color: #bcc0c8;
    cursor: not-allowed;
    box-shadow: none;
}

.level-btn.locked:hover {
    transform: none;
}

/* Game Screen */
#game-screen {
    background-color: var(--bg-color);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 10;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: #f0f2f5;
}

.level-title {
    font-size: 1.2rem;
    font-weight: 600;
}

.hearts {
    display: flex;
    gap: 5px;
    font-size: 1.2rem;
}

.heart {
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.heart.lost {
    filter: grayscale(100%);
    opacity: 0.3;
    transform: scale(0.8);
}

.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

canvas {
    /* No visible borders or grid background */
    touch-action: none; /* Prevent browser handling of gestures */
}

/* Shake Animation for Canvas */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* Overlays */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal {
    background: var(--surface-color);
    padding: 2.5rem;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    text-align: center;
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.overlay.hidden .modal {
    transform: scale(0.9);
}

.modal h2 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal button {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background-color: var(--primary-color);
    color: white;
}

.modal button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

.modal button.secondary {
    background-color: transparent;
    color: var(--text-color);
    border: 2px solid #e4e6eb;
}

.modal button.secondary:hover {
    background-color: #f0f2f5;
    border-color: #d0d2d6;
}

/* Red Flash Overlay for errors */
#game-screen::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--danger-color);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 50;
}

#game-screen.flash-red::after {
    opacity: 0.3;
}
