body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; 
    min-height: 100vh; 
    padding-top: 100px; /* Room for the papel picado banner */
    padding-bottom: 50px;
    margin: 0;
    background-color: #EFE9D8; 
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.08'/%3E%3C/svg%3E");
    font-family: sans-serif;
    transition: background-color 0.3s ease, background-image 0.3s ease;
}

/* --- Papel picado banner (Día de los Muertos) --- */
#papelBanner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 82px;
    display: flex;
    justify-content: center;
    gap: 6px;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

/* The string the flags hang from */
#papelBanner::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 0;
    right: 0;
    height: 2px;
    background: #6b4a2b;
}

.papel-flag {
    flex: 0 0 60px;
    height: 68px;
    margin-top: 8px;
    transform-origin: 50% 0; /* Swings from the string */
    animation: papel-sway 3s ease-in-out infinite alternate;
    filter: drop-shadow(1px 2px 1px rgba(0, 0, 0, 0.15));
}

@keyframes papel-sway {
    from { transform: rotate(-3deg); }
    to { transform: rotate(3deg); }
}

/* No swaying for players who've asked their device for less motion */
@media (prefers-reduced-motion: reduce) {
    .papel-flag { animation: none; }
}

/* Mobile Warning Styles */
#mobileWarning {
    background-color: #2b2b2b;
    color: #F4F1EA;
    border: 3px solid #2b2b2b;
    padding: 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.4);
    max-width: 80%;
    margin: auto;
}

#mobileWarning h2 {
    font-size: 2rem;
    margin-top: 0;
    margin-bottom: 15px;
    color: #ff5252;
}

#mobileWarning p {
    font-size: 1.2rem;
    margin: 5px 0;
}

#mainWrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    width: 600px;
}

#topBar {
    width: 100%;
    display: flex;
    flex-wrap: wrap; /* Lets the power-up counters sit on their own row */
    justify-content: space-between;
    align-items: center;
}

/* Power-up counters: always the same size, faded until you have one */
#powerup-hud {
    flex-basis: 100%;
    gap: 22px;
    height: 26px;
    margin-top: 8px;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    color: #2b2b2b;
    white-space: nowrap;
}

.hud-item {
    font-variant-numeric: tabular-nums; /* Digits are all the same width */
    transition: opacity 0.2s ease;
}

.hud-item.hud-empty {
    opacity: 0.35;
}

#timerDisplay {
    color: #2b2b2b;
    margin: 0;
    font-size: 1.8rem;
}

#menuBtn {
    background-color: transparent;
    color: #2b2b2b;
    border: 2px solid #2b2b2b;
    padding: 8px 16px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

#menuBtn:hover {
    background-color: #2b2b2b;
    color: #F4F1EA;
}

#menuBtn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    border-color: #888888;
    color: #888888;
}

#gameContainer {
    position: relative;
    width: 600px;
    height: 600px;
}

#startScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column; 
    align-items: center;
    justify-content: center;
    gap: 20px; 
    background: radial-gradient(circle, rgba(239,233,216,0.95) 15%, rgba(239,233,216,0.95) 100%);
    z-index: 10;
}

#startBtn {
    background-color: #2b2b2b;
    color: #F4F1EA;
    border: 2px solid #2b2b2b;
    padding: 15px 30px;
    font-size: 1.5rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.15);
}

#startBtn:hover {
    background-color: transparent;
    color: #2b2b2b;
}

/* Custom In-Game Prompt Styles */
#dailyPromptOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    align-items: center;
    justify-content: center;
    z-index: 30;
}

.promptBox {
    background-color: #EFE9D8;
    padding: 30px 40px;
    border-radius: 8px;
    text-align: center;
    width: 70%;
    border: 3px solid #2b2b2b;
    box-shadow: 0px 8px 20px rgba(0, 0, 0, 0.6);
}

.promptBox p {
    color: #2b2b2b;
    font-size: 1.3rem;
    font-weight: bold;
    margin-top: 0;
    margin-bottom: 25px;
    line-height: 1.4;
}

.promptButtons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.promptButtons button {
    background-color: #2b2b2b;
    color: #F4F1EA;
    border: 2px solid #2b2b2b;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.promptButtons button:hover {
    background-color: transparent;
    color: #2b2b2b;
}

/* Share Button Styles */
#endButtonContainer {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 20;
}

#shareBtn {
    background-color: #ffffff;
    color: #000000;
    border: 2px solid #ffffff;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
}

#shareBtn:hover {
    background-color: #000000;
    color: #ffffff;
    border-color: #ffffff;
}

#bottomMenu {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

#bottomMenu h3 {
    color: #2b2b2b;
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.4rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

#practiceOptions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap; /* Wraps to a second row if there are too many modes to fit */
    gap: 25px;
}

.practiceBtn {
    background: transparent;
    border: none;
    outline: none;
    box-shadow: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.practiceBtn span {
    color: #2b2b2b;
    font-size: 0.9rem;
    font-weight: bold;
}

.sketch-path {
    fill: transparent;
    stroke: #2b2b2b;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: fill 0.2s ease, transform 0.1s ease;
}

.practiceBtn:hover .sketch-path {
    fill: #2b2b2b;
}

.practiceBtn:active .sketch-path {
    transform: scale(0.90);
}

/* Disabled state for practice buttons */
.practiceBtn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.practiceBtn:disabled .sketch-path {
    stroke: #888888;
}

.practiceBtn:disabled span {
    color: #888888;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.3); /* Lighter background so the map is visible */
    justify-content: center;
    align-items: flex-end; /* Moves the modal to the bottom */
    padding-bottom: 30px; /* Lifts it slightly off the bottom edge */
    z-index: 1000;
}

.modal-content {
    background: #EFE9D8;
    padding: 15px 25px; /* Reduced padding */
    border-radius: 8px;
    text-align: center;
    border: 3px solid #333;
    max-width: 300px; /* Thinner box */
    font-family: sans-serif;
    box-shadow: 0px 10px 20px rgba(0,0,0,0.5); /* Adds a nice drop shadow */
}

/* Optional: Shrink the paragraph text slightly */
.modal-content p {
    margin: 5px 0;
    font-size: 14px;
}

.modal-content input {
    padding: 10px;
    font-size: 16px;
    width: 80%;
    margin: 15px 0;
    border-radius: 4px;
    border: 1px solid #777;
    text-align: center;
}

.modal-buttons button {
    padding: 10px 20px;
    font-size: 16px;
    margin: 0 5px;
    cursor: pointer;
    border: none;
    border-radius: 4px;
    font-weight: bold;
}

#btn-submit-score { background-color: #4CAF50; color: white; }
#btn-skip-score { background-color: #ff5252; color: white; }

/* --- Leaderboards (daily box, expert boxes, and the book) --- */
.lb-card {
    width: 320px;
    max-width: 320px;
    padding: 20px 24px;
    text-align: left;
}

.lb-header {
    text-align: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 2px solid #2b2b2b;
}

.lb-eyebrow {
    display: block;
    font-size: 11px;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #8a7f66;
}

.lb-header h2 {
    margin: 2px 0;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 26px;
    color: #2b2b2b;
}

.lb-subtitle {
    display: block;
    font-size: 13px;
    color: #6b6352;
}

.lb-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 6px;
    border-radius: 6px;
    font-size: 16px;
    color: #2b2b2b;
}

.lb-row:nth-child(even) {
    background: rgba(43, 43, 43, 0.05);
}

/* Rank badge: gold, silver, bronze for the top 3, outlined for the rest */
.lb-rank {
    flex: 0 0 26px;
    height: 26px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #2b2b2b;
    border-radius: 50%;
    font-size: 13px;
    font-weight: bold;
}

.lb-rank-1 .lb-rank { background: #e9b949; border-color: #b8862b; color: #3d2a05; }
.lb-rank-2 .lb-rank { background: #cfd3d6; border-color: #8d9499; color: #2b2b2b; }
.lb-rank-3 .lb-rank { background: #d99a6c; border-color: #a5683c; color: #3a1f0a; }

.lb-name {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 17px;
    letter-spacing: 2px;
}

/* Dotted line connecting the name to the time */
.lb-dots {
    flex: 1;
    min-width: 10px;
    border-bottom: 2px dotted rgba(43, 43, 43, 0.3);
    transform: translateY(4px);
}

.lb-time {
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The player's own score */
.lb-row.lb-you {
    background: #fff4c2;
    box-shadow: inset 0 0 0 2px #e9b949;
}

/* "You placed #4 today!" */
.lb-you-banner {
    margin: 0 0 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: #2b2b2b;
    color: #F4F1EA;
    font-weight: bold;
    font-size: 15px;
    text-align: center;
}

.initials-error {
    margin: 2px 0 0;
    font-size: 12px;
    font-weight: bold;
    color: #c62828;
}

.lb-message {
    padding: 18px 0;
    text-align: center;
    font-style: italic;
    color: #6b6352;
}

.lb-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
}

.lb-btn {
    padding: 9px 18px;
    font-size: 15px;
    font-weight: bold;
    border: 2px solid #2b2b2b;
    border-radius: 6px;
    background: transparent;
    color: #2b2b2b;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lb-btn:hover { background: #2b2b2b; color: #F4F1EA; }
.lb-btn-primary { background: #2b2b2b; color: #F4F1EA; }
.lb-btn-primary:hover { background: transparent; color: #2b2b2b; }

/* Smaller rows to fit 10 scores inside the book */
.lb-compact .lb-row {
    gap: 6px;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 3px;
    color: #3b2410;
}

.lb-compact .lb-row:nth-child(even) { background: rgba(74, 46, 21, 0.08); }

.lb-compact .lb-rank {
    flex-basis: 16px;
    height: 16px;
    border-width: 1px;
    border-color: #4a2e15;
    font-size: 9px;
}

.lb-compact .lb-name {
    font-size: 12px;
    letter-spacing: 1px;
}

.lb-compact .lb-dots {
    border-bottom-width: 1px;
    border-bottom-color: rgba(74, 46, 21, 0.35);
    transform: translateY(3px);
}

.lb-compact .lb-message {
    padding: 10px 0;
    font-size: 12px;
    color: #6b4a2b;
}

.controls-hint {
    text-align: center;
    margin-top: 15px;
    font-family: Arial, sans-serif;
    color: #2b2b2b;
}

.controls-hint p {
    margin: 0 0 5px 0;
    font-weight: bold;
    font-size: 14px;
}

.arrow-keys {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.key-row {
    display: flex;
    gap: 3px;
}

.key {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    background-color: #EFE9D8; /* Matches your off-white game theme */
    border: 2px solid #2b2b2b;
    border-radius: 4px;
    font-size: 10px;
    color: #2b2b2b;
    font-weight: bold;
    box-shadow: 1px 1px 0px #2b2b2b;
}

#leaderboard-book {
    position: fixed;
    right: 40px; /* Moves it into the empty right-side space */
    top: 50%;
    transform: translateY(-50%);
    width: 180px;
    height: 260px;
    z-index: 20;
}

/* Always-open page with a leather spine down the left side */
.book-page {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #cfa57b 0%, #dcb38a 8%, #e3bf98 100%); /* Tan paper, darker near the spine */
    border-left: 10px solid #4a2e15;
    position: absolute;
    top: 0; left: 0;
    padding: 14px 12px;
    box-sizing: border-box;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.1), 4px 4px 10px rgba(0,0,0,0.25);
    border-radius: 0 5px 5px 0;
}

.book-page h3 {
    margin: 0 0 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(74, 46, 21, 0.4);
    text-align: center;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 15px;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #4a2e15;
}

/* --- Flying bats (Pumpkin and Tombstone modes) --- */
#batLayer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none; /* Purely decoration, never blocks clicks */
    z-index: 5; /* Above the maze, below the start screen and pop-ups */
}

.bat,
.witch {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0.75;
}

/* Warning: an attacking bat glows red while it winds up and dives */
.bat.bat-diving {
    opacity: 1;
    filter: drop-shadow(0 0 4px #ff2a2a) drop-shadow(0 0 2px #ff2a2a);
}

/* --- Ofrenda decoration (candle mode) --- */
.ofrenda-decor {
    position: absolute;
    line-height: 0;
    pointer-events: none;
}

.candle-glow {
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 190, 80, 0.45) 0%, rgba(255, 190, 80, 0.15) 40%, rgba(255, 190, 80, 0) 70%);
    animation: glow-pulse 2.2s ease-in-out infinite alternate;
}

.candle-wick {
    background: #3a2a1a;
    border-radius: 1px;
}

.candle-flame {
    transform-origin: 50% 100%; /* Flickers from the wick */
    animation: flame-flicker 0.22s ease-in-out infinite alternate;
    filter: drop-shadow(0 0 6px rgba(255, 170, 60, 0.8));
}

@keyframes glow-pulse {
    from { transform: scale(0.92); opacity: 0.8; }
    to { transform: scale(1.05); opacity: 1; }
}

@keyframes flame-flicker {
    0% { transform: scale(1, 1) skewX(0deg); }
    50% { transform: scale(0.95, 1.05) skewX(2deg); }
    100% { transform: scale(1.03, 0.96) skewX(-2deg); }
}

@media (prefers-reduced-motion: reduce) {
    .candle-glow, .candle-flame { animation: none; }
}

/* --- Pumpkin patch vines --- */
.vine-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

/* Dashed pencil ring on the square a vine is reaching for */
.vine-target {
    position: absolute;
    box-sizing: border-box;
    border: 3px dashed #3d3d3d;
    border-radius: 50%;
    pointer-events: none;
}

/* --- Witch spells --- */
/* Warning: the witch glows purple as she throws */
.witch.witch-casting {
    opacity: 1;
    filter: drop-shadow(0 0 5px #b44cff) drop-shadow(0 0 2px #b44cff);
}

/* Dashed ring on the square the spell is aimed at */
.spell-target {
    position: absolute;
    box-sizing: border-box;
    border: 3px dashed #9d4edd;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(157, 78, 221, 0.6);
    pointer-events: none;
}

/* The glowing spell orb */
.spell-orb {
    position: absolute;
    top: 0;
    left: 0;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px; /* Centers the orb on its path */
    border-radius: 50%;
    background: radial-gradient(circle, #ffffff 0 20%, #c77dff 45%, #7b2cbf 100%);
    box-shadow: 0 0 10px 4px rgba(170, 90, 255, 0.7);
    pointer-events: none;
}

/* Splash where the spell lands */
.spell-splash {
    position: absolute;
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border: 3px solid #9d4edd;
    border-radius: 50%;
    background: rgba(199, 125, 255, 0.25);
    pointer-events: none;
}

/* Burst ring when a bat hits the pumpkin */
.bat-hit {
    position: absolute;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px; /* Centers the ring on the pumpkin */
    border: 3px solid #ff7a00;
    border-radius: 50%;
    pointer-events: none;
}

/* --- Zombies rising out of the ground (Tombstone mode) --- */
.zombie {
    position: absolute;
    opacity: 0.85;
    transform-origin: 50% 100%; /* Sways from the ground up */
}

.zombie-dirt {
    position: absolute;
    bottom: -5px;
    height: 12px;
    background: #5b3f24;
    border-radius: 50% 50% 0 0;
    opacity: 0;
}

.zombie-dirt-clump {
    position: absolute;
    width: 5px;
    height: 5px;
    background: #5b3f24;
    border-radius: 40%;
}

.flyer-flip {
    width: 100%;
    height: 100%;
}

/* Witch gently rocks on her broom as she flies */
.witch svg {
    animation: witch-bob 1.2s ease-in-out infinite alternate;
}

@keyframes witch-bob {
    from { transform: rotate(-5deg) translateY(-2px); }
    to { transform: rotate(4deg) translateY(2px); }
}

.bat-wing {
    transform-box: fill-box;
    animation: bat-flap 0.22s ease-in-out infinite alternate;
}

.bat-wing-left { transform-origin: 100% 40%; }
.bat-wing-right { transform-origin: 0% 40%; animation-name: bat-flap-right; }

@keyframes bat-flap {
    from { transform: rotate(-28deg) scaleY(1); }
    to { transform: rotate(18deg) scaleY(0.6); }
}

@keyframes bat-flap-right {
    from { transform: rotate(28deg) scaleY(1); }
    to { transform: rotate(-18deg) scaleY(0.6); }
}

/* Sits in the strip below the mini map (map box ends at y=420 on the 600px canvas) */
#practice-over-modal,
#expert-over-modal {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999; /* Ensures it stays on top of the maze and other UI */
}

#practice-over-modal .modal-content,
#expert-over-modal .modal-content {
    padding: 10px 20px;
    white-space: nowrap;
}

#practice-over-modal h2,
#expert-over-modal h2 {
    margin: 0 0 4px;
    font-size: 22px;
}

#practice-over-modal button,
#expert-over-modal button {
    margin-top: 6px;
}

/* Expert finish box: initials and buttons on one row so it fits under the mini map */
.expert-submit-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.expert-submit-row input {
    width: 80px;
    margin: 6px 0 0;
    padding: 6px;
    font-size: 15px;
    text-transform: uppercase;
}

/* --- Expert maze picker --- */
#expertPicker {
    position: absolute;
    inset: 0;
    z-index: 50; /* Above the start screen, below the modals */
    background-color: #EFE9D8;
    flex-direction: column;
    align-items: center;
    padding: 12px 16px;
    box-sizing: border-box;
    overflow-y: auto;
    font-family: Arial, sans-serif;
    color: #2b2b2b;
}

#expertPicker h2 {
    margin: 0 0 4px;
}

#expertPicker p {
    margin: 0 0 12px;
    font-size: 13px;
    text-align: center;
}

#expertGrid {
    display: grid;
    grid-template-columns: repeat(5, auto);
    gap: 10px 14px;
}

.expertCard {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.expertPlayBtn {
    width: 100px;
    height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0;
    border: 2px solid #2b2b2b;
    border-radius: 6px;
    background-color: #F4F1EA;
    color: #2b2b2b;
    cursor: pointer;
    font-family: Arial, sans-serif;
    transition: transform 0.1s;
}

.expertPlayBtn:hover {
    transform: scale(1.06);
}

.expertCardNumber {
    font-size: 28px;
    font-weight: bold;
}

.expertCardTime {
    font-size: 12px;
    color: #5a5a5a;
}

.expertBoardBtn {
    margin-top: 4px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    color: #2b2b2b;
    padding: 2px;
}

#btnExpertBack {
    margin-top: 12px;
    padding: 8px 18px;
    background-color: #2b2b2b;
    color: #F4F1EA;
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
}
