body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    color: white;
    background-color: #000;
    font-family: 'Courier New', Courier, monospace;
}

/* --- NEW: LAYER MANAGEMENT --- */

#menu-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100; /* Stays on top of the game initially */
}

#game-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10; /* Sits behind the menu */
    /* Starts invisible so it doesn't flicker behind the menu */
    display: none; 
}

/* --- GAME UI ELEMENTS (Relocated from #ui-layer to avoid conflict) --- */

#game-ui {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 20;
    pointer-events: none;
    width: 80%;
}

#question {
    color: #fff;
    /* Min: 1.1rem (mobile), Preferred: 4vw, Max: 1.8rem (desktop) */
    font-size: clamp(1rem, 4vw, 1.8rem);
    margin-bottom: 20px;
    min-height: 3em;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);

    /* --- ADD THESE FOR SHARPNESS --- */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transform: translateZ(0); /* Forces GPU rendering */
    backface-visibility: hidden;
    perspective: 1000;
}

.buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: auto; /* Re-enables clicking on buttons */
}

.buttons.visible {
    opacity: 1;
}

/* --- SHARED COMPONENTS --- */

button {
    background: transparent;
    border: 1px solid #fff;
    color: #fff;
    padding: 10px 30px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    /* Changed 'all' to 'opacity, transform' to prevent background-color sticking */
    transition: opacity 0.3s, transform 0.1s, box-shadow 0.3s;
    outline: none; /* Removes the focus ring */
}

/* THE FIX: Only apply the white background highlight on devices with a mouse */
@media (hover: hover) {
    button:hover {
        background: #fff;
        color: #000;
        box-shadow: 0 0 15px #fff;
    }
}

/* MOBILE FEEDBACK: Button shrinks slightly when tapped without sticking white */
button:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2); /* Subtle flash of white while finger is down */
}

/* Ensure that when the button is disabled, it stays transparent/gray */
button:disabled {
    background: transparent !important;
    color: rgba(255, 255, 255, 0.5) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    box-shadow: none !important;
    cursor: default;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- RESET BUTTON --- */

#reset-button {
    position: fixed;
    top: 45px;
    right: 50%;
    transform: translateX(50%);
    background: #3347ff;
    border: 1px solid #fff;
    color: #fff;
    padding: 15px 30px;
    cursor: pointer;
    font-family: inherit;
    font-size: 1.2rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 200; /* Topmost element in game */
}

#reset-button.visible {
    opacity: 1;
    pointer-events: auto;
}

/* --- HUD LAYER --- */

#hud-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 15;
    pointer-events: none;
    color: #fff;
    font-size: 1rem;
}

.hud-item {
    position: absolute;
    padding: 15px;
}

.top-right { top: 0; right: 0; text-align: right; }
.bottom-center {
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    /* Min: 1.1rem (mobile), Preferred: 4vw, Max: 1.8rem (desktop) */
    font-size: clamp(0.6rem, 4vw, 1.2rem);
    font-weight: bold;
}

/* --- MENU SYSTEM STYLING --- */

.viewport {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.world {
    display: flex;
    width: 300vw;
    height: 100vh;
    transition: transform 1.5s cubic-bezier(0.45, 0, 0.55, 1);
    margin: 0;
    position: relative;
}

.screen {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    position: relative;
}

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

.title {
    position: absolute;
    bottom: calc(50% + 80px); 
    font-size: 3rem;
    margin: 0;
}

#credits-btn {
    position: absolute;
    top: calc(50% + 80px);
    width: 150px;
}

#start-btn {
    position: absolute;
    align-self: center;
    width: 150px
}

.line-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 300vw;
    height: 100vh;
    pointer-events: none;
}

#anim-path {
    filter: drop-shadow(0 0 5px white);
}

.credits-text {
    /* Min: 1.1rem (mobile), Preferred: 4vw, Max: 1.8rem (desktop) */
    font-size: clamp(0.8rem, 1.8vw, 1.4rem);
    position: absolute;
    top: 15%;
    left: 10%;
    padding-right: min(100px, 10vw);
    text-align: left;
    opacity: 0;
    transition: opacity 0.5s ease 1.0s;
}

.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* 1. Define the animation */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* 2. Apply it to your element */
.fade-in-element {
  animation: fadeIn 1s ease-in-out;
}

.back {
    position: absolute;
    bottom: 30px; 
    left: 50%;
    /* Keep this as the base state */
    transform: translateX(-50%);
    z-index: 20; 
}

/* THE FIX: Combine centering AND scaling for the active state */
.back:active {
    transform: translateX(-50%) scale(0.95) !important;
}

/* Also ensure the hover state (if applicable) doesn't break centering */
@media (hover: hover) {
    .back:hover {
        transform: translateX(-50%);
        background: #fff;
        color: #000;
    }
}

.title {
    min-height: 1.2em; /* Prevents the layout from jumping when the first letter appears */
}

.title::after {
    content: "_"; /* A terminal-style underscore cursor */
    margin-left: 8px;
    color: white;
    animation: blink 0.8s step-end infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Hide the credits screen by default */
#credits-screen {
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none; /* Prevents clicking the button while it's invisible */
}

/* Only show it when it has the 'active' class */
#credits-screen.active {
    opacity: 1;
    pointer-events: auto;
}

.subtitle {
    position: absolute;
    bottom: calc(50% + 65px); 
    font-size: 14px; /* Much smaller than title */
    margin-top: 10px;
    opacity: 0.9;    /* Slightly faded */
    letter-spacing: 2px;
    font-weight: 100;
    min-height: 1.2em; /* Prevents jumping */
}