/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-color: #ffb7b2;
    --text-color: #c70039;
    --btn-yes-bg: #98ff98;
    --btn-yes-text: #005f00;
    --btn-no-bg: #ff6961;
    --btn-no-text: #5f0000;
}

body {
    background-color: var(--bg-color);
    font-family: 'Press Start 2P', cursive;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Critical for keeping buttons inside */
    position: relative;
    user-select: none;
    
    /* Animation: Dark to Light */
    animation: fadeInPage 2.5s ease-out forwards;
}

@keyframes fadeInPage {
    0% { opacity: 0; filter: brightness(0); background-color: #000; }
    100% { opacity: 1; filter: brightness(1); background-color: var(--bg-color); }
}

.container {
    text-align: center;
    position: relative;
    z-index: 10; /* Above hearts */
    width: 100%;
    max-width: 800px;
    padding: 20px;
}

h1.question {
    color: var(--text-color);
    font-size: 1.5rem; /* Better for mobile/desktop split */
    line-height: 1.6;
    margin-bottom: 60px;
    text-shadow: 4px 4px 0px #ffdac1;
}

@media (min-width: 768px) {
    h1.question { font-size: 2.5rem; }
}

/* 8-bit Button Styling */
.pixel-btn {
    font-family: 'Press Start 2P', cursive;
    border: 4px solid #000;
    cursor: pointer;
    box-shadow: 6px 6px 0px rgba(0,0,0,0.5);
    transition: transform 0.1s, background-color 0.2s;
    outline: none;
}

.pixel-btn:active {
    transform: translate(4px, 4px) !important;
    box-shadow: 2px 2px 0px rgba(0,0,0,0.5) !important;
}

#yes-btn {
    background-color: var(--btn-yes-bg);
    color: var(--btn-yes-text);
    font-size: 0.8rem;
    padding: 10px 15px;
    margin-right: 20px;
    pointer-events: none;
    opacity: 0.6;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#yes-btn.active {
    pointer-events: auto;
    opacity: 1;
    cursor: pointer;
    box-shadow: 0 0 15px #98ff98;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(var(--current-scale, 1)); }
    to { transform: scale(calc(var(--current-scale, 1) * 1.05)); }
}

#no-btn {
    background-color: var(--btn-no-bg);
    color: var(--btn-no-text);
    font-size: 1.5rem;
    padding: 15px 30px;
    position: absolute; /* Allows movement */
    /* Initial position relative to container is tricky, 
       we'll set it static initially in flow, then absolute on move */
    position: static; 
    z-index: 20;
    transition: top 0.3s ease-out, left 0.3s ease-out; /* Smooth glide */
}

/* --- Password Screen Styles --- */
.hidden {
    display: none !important;
}

#password-container h2 {
    font-size: 2.5rem;
    color: var(--text-color);
    margin-bottom: 30px;
    text-shadow: 4px 4px 0px #ffdac1;
}

.password-wrapper {
    position: relative;
    margin: 20px auto;
    width: fit-content;
}

#password-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0; /* Invisible but clickable */
    cursor: text;
    z-index: 2;
}

.password-display {
    display: flex;
    gap: 10px;
}

.password-display span {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 50px;
    background-color: #fff;
    border: 4px solid #000;
    font-size: 1.5rem;
    color: var(--text-color);
    box-shadow: 4px 4px 0px rgba(0,0,0,0.2);
}

.hint {
    margin-top: 30px;
    font-size: 0.8rem;
    color: #555;
    background: rgba(255, 255, 255, 0.5);
    padding: 10px;
    border-radius: 5px;
    display: inline-block;
}

#message {
    height: 30px;
    margin-top: 20px;
    font-weight: bold;
    font-size: 1rem;
}

/* --- Snake Game Styles --- */
.game-wrapper {
    position: relative;
    width: fit-content;
    margin: 20px auto;
}

#game-canvas {
    background-color: #2e050c; /* Dark retro color */
    border: 4px solid #000;
    box-shadow: 6px 6px 0px rgba(0,0,0,0.3);
    display: block;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0,0,0,0.85);
    color: #fff;
    font-size: 3rem;
    z-index: 50;
    flex-direction: column;
}

.overlay.hidden-overlay {
    display: none;
}

#score-board {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--text-color);
}

.error-shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
    color: var(--btn-no-text);
}

/* --- Memory Game Styles --- */
#memory-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr); /* 6 columns */
    gap: 10px;
    margin: 20px auto;
    max-width: 600px;
    perspective: 1000px;
}

.memory-card {
    background-color: #fff;
    border: 3px solid #000;
    aspect-ratio: 1; /* Square cards */
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    border-radius: 5px;
    box-shadow: 3px 3px 0px rgba(0,0,0,0.2);
}

.memory-card.flip {
    transform: rotateY(180deg);
}

.front-face, .back-face {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    object-fit: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    pointer-events: none; /* Let clicks pass to card */
}

.front-face {
    transform: rotateY(180deg); /* Start hidden */
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.front-face img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.front-face span {
    font-size: 2rem;
    font-weight: bold;
    color: #333;
}

/* Matched Card State */
.memory-card.matched .front-face {
    border: 4px solid #98ff98; /* Green border for matched */
    box-sizing: border-box;
}

.back-face {
    background-color: #ffb7b2;
    color: #c70039;
    font-size: 1.5rem;
    font-family: 'Press Start 2P', cursive;
}

/* --- Responsive Grid --- */
@media (max-width: 600px) {
    #memory-grid {
        grid-template-columns: repeat(5, 1fr); /* 5 cols for mobile */
        gap: 5px;
        width: 100%;
    }
    
    #rainbow-text {
        font-size: 1.5rem !important; /* Smaller text for mobile */
    }
}

/* --- Counter Styles --- */
.large-counter {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}

.mini-counter {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px; /* Tighter gap */
}

.time-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 4px solid #000;
    box-shadow: 4px 4px 0px rgba(0,0,0,0.3);
    border-radius: 5px;
}

/* Base styles for large units */
.time-unit.large {
    padding: 15px;
    min-width: 90px;
}

.time-unit.large span {
    font-size: 2rem; /* Bigger */
    color: #c70039;
    font-weight: bold;
}

.time-unit.large label {
    font-size: 0.6rem;
    margin-top: 5px;
    color: #555;
    font-family: sans-serif;
    font-weight: bold;
    text-transform: uppercase;
}

/* Mini version */
.time-unit.mini {
    padding: 5px;
    min-width: 50px;
    border-width: 2px;
    box-shadow: 2px 2px 0px rgba(0,0,0,0.3);
}

.time-unit.mini span {
    font-size: 1rem;
    color: #000;
}

.time-unit.mini label {
    font-size: 0.4rem;
    margin-top: 2px;
    color: #555;
    font-family: sans-serif;
    font-weight: bold;
}

.break {
    flex-basis: 100%;
    height: 0;
}


.success-text {
    color: var(--btn-yes-text);
    animation: bounce 1s infinite;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-8px, 0, 0); }
    40%, 60% { transform: translate3d(8px, 0, 0); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* --- Decorations --- */
#hearts-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

/* --- Transition Layer --- */
#transition-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

#transition-layer img {
    width: 300px; /* Start size */
    height: auto;
    transform: scale(0); /* Start invisible/tiny */
    /* Optimized for performance and speed */
    will-change: transform; 
    transition: transform 2.5s cubic-bezier(0.7, 0, 0.9, 0.5); /* Linger start, accelerate finish */
}

#transition-layer.active img {
    transform: scale(25); /* Zoom way in to cover screen completely */
}

.heart {
    position: absolute;
    color: #ff6961;
    text-shadow: 2px 2px 0px #000;
    opacity: 0.7;
    animation: floatUp linear forwards;
}

@keyframes floatUp {
    0% { transform: translateY(110vh) rotate(0deg); opacity: 0; }
    20% { opacity: 0.8; }
    100% { transform: translateY(-10vh) rotate(20deg); opacity: 0; }
}

.corner-decoration {
    position: absolute;
    font-size: 3rem;
    color: #c70039;
    text-shadow: 4px 4px 0px #000;
    z-index: 5;
    animation: cornerBeat 1.5s infinite ease-in-out;
}

.top-left { top: 20px; left: 20px; transform: rotate(-15deg); }
.bottom-right { bottom: 20px; right: 20px; transform: rotate(15deg); }

@keyframes cornerBeat {
    0%, 100% { transform: scale(1) rotate(var(--r, 0deg)); }
    50% { transform: scale(1.1) rotate(var(--r, 0deg)); }
}
.top-left { --r: -15deg; }
.bottom-right { --r: 15deg; }