/* Google Fonts import - Jersey 20 for most text, Handjet for level indicator */ 
@import url('https://fonts.googleapis.com/css2?family=Handjet&family=Jersey+20&display=swap');

/* ................................... */
/* ========== Global Styles ========== */
/* ................................... */

/* ========== CSS Variables ========== */

:root {
    --primary-color: #91D4F2; /* Light blue for text content against dark backgrounds */
    --secondary-color: #0d0c11; /* Dark background backup, modal backgrounds and text on light backgrounds */
    --primary-highlight-color: #507F92; /* Air force blue for modal borders and highlights */
    --primary-background-color: #1A303B; /* Gunmetal */
    --secondary-background-color: #2a3c48; /* Less saturated slate/charcoal for background */
    --primary-font: 'Jersey 20', sans-serif; /* Jersey 20 font for most text */
    --secondary-font: 'Handjet', sans-serif; /* Handjet font for level indicator/settings */
}

/* global body styles */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* JavaScript to set responsive height with setBodyHeight() */
    margin: 0; /* background behind game container */
    background-color: var(--secondary-color);  /* Fallback colour if image fails */
    background-image: url('../images/cavewalls-background.png');
    filter: brightness(1.3); /* Increase brightness (1 is normal, 1.2 is slightly brighter. this could be modal settings feature - user controlled?) */
    background-position: top;
    background-size: cover;
    overflow: hidden; /* Prevents horizontal scrollbar */
    -webkit-text-size-adjust: 100%; /* Prevents font scaling on iOS */
}

/* Home page layout */
.home-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    text-align: center;
    position: relative; /* Ensures children with absolute positioning are positioned relative to this container */
}

/* Home page header */
header {
    position: relative;
    width: 100%;
}

/* Home page heading */
h1 {
    font-family: var(--primary-font); /* Jersey 20 font */
    color: var(--primary-color); /* Light blue for text content */
    text-align: center;
    margin: 0; /* Remove default margin */
    font-size: 5rem; /* Adjust size as needed */
    text-transform: uppercase; /* Uppercase text */
    position: relative;
}

/* Intro text below the home page heading */
p.intro-text {
    font-family: var(--primary-font); /* Jersey 20 font */
    color: var(--primary-color); /* Light blue for text content */
    font-size: 2rem; /* Adjust font size */
    width: 60%; /* Set a responsive width */
    margin: 1rem auto; /* Center horizontally and add spacing */
    text-align: center; /* Center the text content */
    line-height: 1.5; /* Improve readability */
}

/* Fade-in effect for the intro heading and text */
/* credit: https://blog.hubspot.com/website/css-fade-in by: Jamie Juviler */
.fade-in-text {
    opacity: 0; /* Start invisible */
    animation: fadeIn 3s forwards; /* Fade in animation */
}
@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* Game container fades in first */
.fade-in-game-container {
    opacity: 0;
    animation: fadeIn 1s forwards;
    animation-delay: 0.5s;
}
.fade-in-ui {
    opacity: 0;
    animation: fadeIn 1s forwards;
    animation-delay: 0.5s;
}

/* home page non animated image of bat sprite */
.home-brucey {
    position: absolute;
    top: 0px; /* Adjust to position above the heading */
    left: 13em; /* Adjust to position to the left of the heading */
    width: 112px; /* Width of one frame */
    height: 112px; /* Height of one frame */
    background-image: url('../images/bat-sprite.png'); /* Sprite sheet */
    background-size: 224px 112px; /* Total width of the sprite sheet */
    background-position: 0 0; /* Show only the first frame */
    z-index: 2; /* On top of everything */
    transform: scale(1.6); /* Scale up Brucey */
}

/* play now button on home page */
button {
    font-family: var(--primary-font); /* Jersey 20 font */
    color: var(--primary-color); /* Light blue for text content */
    background-color: var(--secondary-background-color); /* Dark background for contrast */
    border: 2px solid var(--primary-background-color); /* Gunmetal border */
    padding: 10px 20px;
    font-size: 1.5rem; 
    cursor: pointer;
}

/* Home page decorative crystals */
.crystal-row {
    display: flex; /* Arrange crystals in a row */
    justify-content: center; /* Center the row horizontally */
    align-items: center; /* Align crystals vertically */
    gap: 50px; /* Add spacing between crystals */
    margin: 2rem 0; /* Add spacing above and below the row */
}

/* Individual crystals on home page */
.crystal {
    width: 50px; /* Set a consistent size for the crystals */
    height: auto; /* Maintain aspect ratio */
    pointer-events: none; /* Decorative, so no interaction */
}

/*--------------------------------------------------------------*/
/*------------------Audio user event overlay--------------------*/
/*--------------------------------------------------------------*/

/* overlay for audio permission listener event. must be hidden by default */
.audio-user-event-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0); /* Semi-transparent overlay */
    color: var(--primary-color); /* Light blue for text content */
    font-family: var(--primary-font); /* Jersey 20 font */
    font-size: 1.5rem; /* Adjust font size */
    text-align: center;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    z-index: 10000; /* Ensure it's on top of everything */
}
.audio-user-event-overlay p {
    margin: 0; /* Remove default margin */
    padding: 0 20px; /* Add padding for better readability */
    line-height: 1.5; /* Improve readability */
}
.hidden-on-audio-overlay {
    display: none;
}


/* ----------------------------------*/
/* --- Wrapper for game container -- */
/* ----------------------------------*/

.game-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: min(95vw, 95vh, 700px); /* Slightly larger square to crystal-grid (bat positioned in this area relative to crystal-grid container */
    height: min(95vw, 95vh, 700px);
    margin: 0 auto; /* Center horizontally */
    box-sizing: border-box; /* Include padding and border in width/height */
}


/* ----------------------------------*/
/* -- Crystal cave game container -- */
/* ----------------------------------*/

.crystal-grid {
    position: relative; /* Allows absolute positioning of children (each crystal container) */
    display: flex;
    flex-direction: column;
    justify-content: center; /* Even spacing between rows */
    gap: 1%; /* Adjust gap between rows */
    width: min(85vw, 85vh, 400px);
    height: min(85vw, 85vh, 400px); /* position: relative; */
    background-image: url('../images/cave-in-container.png');
    background-size: contain; /* Make sure the border fits inside */
    background-position: center;
    background-repeat: no-repeat;
    padding: 3%;
}

/* crystal row container */
.row {
    display: flex;
    justify-content: space-evenly;
    width: 100%;
}

/* Individual crystal container */
.crystal-container {
    width: 30%; /* Adjust crystal size */
    aspect-ratio: 1 / 1; /* Square container */
    position: relative; /* Allows absolute positioning of children (crystal images) */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer; /* Change cursor on hover */
}

/* Smaller size for top row crystals to create a sense of depth */
.row:first-child .crystal-container {
    width: 25%;
    margin-top: 33%; /* Slightly move top row down */
}

.row:last-child {
    margin-bottom: 10%; /* adjust slightly nudge bottom row to align within cave walls */
}

/* All crystal images positioned inside the crystal container (game container)*/
.crystal-container img {
    position: absolute; /* Allows for stacking of images */
    width: 100%; /* Fill the container */
    height: 100%; /* Fill the container */
    object-fit: contain; /* Maintain aspect ratio */
    transition: opacity 0.3s ease-in-out; /* Smooth transition for hover effect */
}

/* Glow effect (behind the crystal) */
/* adapted from https://stackoverflow.com/questions/8693733/how-to-give-outer-glow-to-an-object-in-a-transparent-png-using-css3 */
/* & https://jsfiddle.net/nkq1uxfb/3/ */
.glow {
    filter: brightness(2) blur(30px); /* Increase brightness and add blur - increase if needed for visual cue accessability */
    opacity: 0;
    z-index: 0; /* Behind everything */
}

/* Main crystal (default state) */
.main-crystal {
    z-index: 2;
}

/* Lighter crystal (hidden until hover) */
.light-crystal {
    opacity: 0;
    z-index: 3; /* On top of the main crystal */
}

/* Active state for the glow and light-crystal when clicked */
.glow.active,
.light-crystal.active {
    opacity: 1;
}

.crystal-container.disabled {
    pointer-events: none; /* Prevents clicks */
}

/* Celebration-specific glow effect */
.glow.celebration-active,
.light-crystal.celebration-active {
    transition: opacity 0.8s ease-in-out; /* Slightly longer transition for celebration */
}

/* ----------------------------------------------------------------------*/

/* ----------------------------------*/
/* ----- Bat sprite animation ------ */
/* ----------------------------------*/

.bat {
    position: absolute; /* Position relative to the crystal container */
    left: -10%; /* Adjust to be just outside the crystal container */
    top: 50%;
    width: 112px; /* Width of the bat sprite */
    height: 112px; /* Height of the bat sprite */
    background-image: url('../images/bat-sprite.png'); /* Sprite sheet */
    background-size: 224px 112px; /* Width of the sprite sheet */
    transform: translateY(-50%) scale(1.6); /* Scale up the bat */
    animation: flap 0.3s steps(2) infinite alternate; /* Quick flap effect adapted from https://blog.teamtreehouse.com/css-sprite-sheet-animations-steps */
    z-index: 100;
    opacity: 1;; 
}

/* Flap animation */
/* adapted from https://www.joshwcomeau.com/animation/keyframe-animations/ */
@keyframes flap {
    /* First frame */
    from {
        background-position: 0 0;
    }
    /* Second frame */
    to {
        background-position: -210px 0;
    }
}

/* --------------------------------------------------------------*/

/* ----------------------------------*/
/* ----------------------------------*/
/* -- Level Number indicator ------- */
/* ----------------------------------*/
/* ----------------------------------*/


.level-indicator {
    position: absolute; /* Position relative to the crystal container */
    top: 90%; /* Adjust to position below the crystal container */
    right: 30px;
    transform: translateX(-50%);
    background-color: var(--secondary-color); /* Dark background for contrast */
    color: var(--primary-color); /* Light blue for text content */
    border: 2px solid var(--primary-background-color); /* Gunmetal border */
    font-size: 2rem;
    font-family: "Handjet", sans-serif; /*  Handjet font */
    text-align: center;
    padding: 8px 20px;
    width: fit-content;
    z-index: 1000; /* On top of everything */
    display: none; /* Hide by default */
    opacity: 0; /* Start invisible */
    animation: fadeInText 0.5s ease-in-out forwards; /* Fade-in animation */
}

@keyframes fadeInText {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}


/* --------------------------------------------------------------*/

/* ----------------------------------*/
/* ----------------------------------*/
/* ------- UI Buttons----------------*/
/* ----------------------------------*/
/* ----------------------------------*/

.buttons-container {
    position: fixed;
    top: 10px;
    right: 20px;
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 buttons per row */
    grid-template-rows: repeat(5, auto); /* Automatically size rows */
    gap: 10px; /* Add space between buttons */
    padding: 10px;
    border-radius: 10px;
    justify-content: right;
    z-index: 5000; /* buttons on top of overlay */
}

.game-button {
    position: relative;
    background-color: transparent;
    background-image: url('../images/button-sprite-sheet-700x140.png'); /* Sprite sheet for buttons */
    background-size: 700px 140px; 
    background-repeat: no-repeat;
    width: 70px; /* button size */
    height: 70px; /* button size */ 
    border: none;
    padding: 0;
    cursor: pointer;
    image-rendering: pixelated; /* Keeps pixel art sharp - keeps the button icons clear */
    transition: transform 0.1s ease, filter 0.1s ease; /* smooths transition between 'pressed' active button images */
}
/* Tooltip adapted from w3schools https://www.w3schools.com/css/css_tooltip.asp */
.tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: var(--secondary-color);
    background-image: none; /* Ensure to remove inherited background images */
    color: #fff;
    font-family: var(--secondary-font);
    text-align: center;
    border: solid 2px #ffffff; 
    border-radius: 5px;
    padding: 5px 3px;
    position: absolute;
    z-index: 1;
    top: -5px;
    right: 110%;  
    opacity: 0; /* Start invisible */
    transition: opacity 0.3s; /* Smooth fade-in effect */
}

/* Show tooltip on hover */
.game-button:hover .tooltiptext {
    visibility: visible;
    opacity: 1; /* Fade in */
}
/* Tooltip container for delete data button within settings modal */
.delete-data-button {
    position: relative;
    display: inline-block;
    cursor: pointer;
}
/* Show tooltip on hover */
.delete-data-button:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
    background-color: var(--secondary-color);
    font-size: 1.3rem; /* Adjust font size */
    width: 200px; /* Adjust width */
    top: -80px;
    right: 12%; 
}

/* replace button images when clicked to pressed versions using sprite sheet positioning */
.game-button.how-to-play {
    background-position: 0 0; /* Default state */
}
.game-button.how-to-play:active {
    background-position: 0 -70px; /* Pressed state (first button, second row) */
}
.game-button.restart {
    background-position: -70px 0; /* Default state (second button, first row) */
}
.game-button.restart:active {
    background-position: -70px -70px; /* Pressed state (second button, second row) */
}
.game-button.sound {
    background-position: -140px 0; /* Default state (third button, first row) */
}
.game-button.sound:active {
    background-position: -140px -70px; /* Pressed state (third button, second row) */
}
.game-button.sound.muted {
    background-position: -210px 0; /* Default state (fourth button, first row) */
}
.game-button.sound.muted:active {
    background-position: -210px -70px; /* Pressed state (fourth button, second row) */
}
.game-button.settings {
    background-position: -280px 0; /* Default state (skip to fifth button, first row) */
}
.game-button.settings:active {
    background-position: -280px -70px; /* Pressed state (skip to fifth button, second row) */
}
.game-button.home {
    background-position: -350px 0; /* Default state (sixth button, first row) */
}
.game-button.home:active {
    background-position: -350px -70px; /* Pressed state (sixth button, second row) */
}
.game-button.freestyle {
    background-position: -420px 0; /* Default state (seventh button, first row) */
}
.game-button.freestyle:active {
    background-position: -420px -70px; /* Pressed state (seventh button, second row) */
}
.game-button.freestyle.mode {
    background-position: -630px 0; /* button ten on sprite sheet - yellow star freestyle mode */          
}
.game-button.freestyle.mode:active {
    background-position: -630px -70px; /* button ten in pressed state */
}
.game-button.full-screen {
    background-position: -490px 0; /* Default state (eighth button, first row) */
}
.game-button.full-screen:active {
    background-position: -490px -70px; /* Pressed state (eighth button, second row) */
}
.game-button.exit-full-screen {
    background-position: -560px 0; /* Default state (exit fullscreen icon) */
}
.game-button.exit-full-screen:active {
    background-position: -560px -70px; /* Pressed state (exit fullscreen icon) */
}

/* ----------------------------------------------------------------------*/

/*------------------------------------------------*/
/* --------------Speech Bubble Modal------------- */
/*------------------------------------------------*/
.speech-bubble {
    position: absolute;
    top: 6%;
    left: 9%;
    width: 350px;
    aspect-ratio: 3 / 2; /* Maintain aspect ratio */
    background: url('../images/speech-bubble-blank.png') no-repeat center;
    background-size: contain;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 20px;
    text-align: center;
    z-index: 2000;
    cursor: default;
    font-family: var(--primary-font); /* Jersey 20 font */
    color: black; /* Black text */
    font-size: 1.8rem; /* Adjust font size as needed */
    margin: 0; /* Remove default margin */
    line-height: 1; /* Improve readability */
}
/* Add padding to the text container */
.speech-bubble .text-container {
    padding-top: 5px; /* Add space above the text */
    padding-bottom: 5px; /* Add space below the text */
    width: 95%; /* Ensure it spans the width of the bubble */
    height: auto;
    text-align: center;;
}
/* Style for the instructions (e.g., "Tap anywhere to continue") */
.speech-bubble .instructions {
    font-size: 1rem; /* Slightly smaller font size */
    font-style: italic; /* Make the text italic */
    color: var(--primary-background-color); 
}
/* Add fade-in animation for the text container */
.text-container {
    opacity: 0; /* Start invisible */
    animation: fadeInText 0.5s ease-in-out forwards; /* Fade-in animation */
}

@keyframes fadeInText {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

/* --------------------------------------------------- */
/* ----------------- Game Modal Content -------------- */
/* --------------------------------------------------- */

/* Modal container */
.modal-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); 
    width: 50%;
    max-width: 70vw; /* Limit width to 70% of viewport width */
    max-height: 70vh; /* Limit height to 70% of viewport height */
    overflow-y: auto; /* Enable scrolling if content exceeds max height */
    background-color: var(--primary-highlight-color); /* Light blue */
    color: var(--secondary-color); /* Dark charcoal for text */
    border: 2px solid var(--primary-background-color); /* Gunmetal border */
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    text-align: center;
    pointer-events: auto; /* Enable clicks */
}

/* Modal title */
.modal-title {
    font-family: var(--primary-font);
    font-size: 2rem;
    margin-bottom: 1rem;
}

/* Modal text */
.modal-text {
    font-family: var(--primary-font);
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
}

/* Modal buttons */
.modal-buttons {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    width: 100%;
}

.modal-button {
    font-family: var(--primary-font);
    font-size: 1rem;
    padding: 10px 20px;
    background-color: var(--secondary-background-color); /* Dark background */
    color: var(--primary-color); /* Light blue text */
    border: 2px solid var(--primary-background-color); /* Gunmetal border */
    border-radius: 5px;
    cursor: pointer;
    pointer-events: auto; /* Enable clicks */
    transition: background-color 0.3s ease;
}

.modal-button:hover {
    background-color: var(--primary-background-color); /* Gunmetal on hover */
}
/* Close button */
.close-modal-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
    z-index: 6000; /* Ensure it's above the modal content */
    pointer-events: auto; /* Ensure the button is clickable */
}
/* How to play modal AWSED keys image */
.awsed-keys-image {
    width: 130px;
}

/* overflow modal scrollbar */
.modal-container::-webkit-scrollbar {
    width: 8px; /* Width of the scrollbar */
}

.modal-container::-webkit-scrollbar-thumb {
    background-color: var(--primary-background-color); /* Gunmetal */
}

/*  Settings modal styles*/
.settings-section {
    margin-bottom: 20px;
}

.setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.setting label {
    flex: 1; /* Take up equal space for alignment */
    font-size: 1.2rem; /* Adjust font size */
    margin-right: 10px;
}

.section-divider {
    border: none;
    border-top: 1px solid #ccc;
    margin: 20px 0;
}

.mute-toggle {
    background-color: var(--secondary-background-color);
    color: white;
    border: 2px solid var(--primary-background-color); /* Gunmetal border */
    padding: 5px 10px;
    cursor: pointer;
    font-size: 14px;
}
.mute-toggle.muted {
    background-color: #924411; /* Background colour when muted */
    color: white; 
}

button.delete-data-button {
    background-color: #924411;
    font-family: var(--primary-font);
    font-size: 1rem;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    pointer-events: auto; /* Enable clicks */
    transition: background-color 0.3s ease;
}

button.delete-data-button:hover {
    background-color: #7a3b0d; /* Darker shade on hover */
}

.volume-slider,
.brightness-slider {
    width: 150px;
    height: 10px;
    background: #ccc;
    border: 1px solid var(--primary-background-color);
    appearance: none;
}

.volume-slider::-webkit-slider-thumb,
.brightness-slider::-webkit-slider-thumb {
    width: 15px;
    height: 15px;
    background: var(--secondary-background-color);
    border: 1px solid var(--primary-background-color);
    cursor: pointer;
    appearance: none;
}

/* -----------------------------------------------------------------------------------------*/
/* ---------------------- Invisible overlay for toggling click events ----------------------*/
/* -----------------------------------------------------------------------------------------*/

/* This overlay is used to disable clicks on the game container when the modal is open */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0); /* Fully transparent */
    z-index: 3000; /* Ensure it sits above the crystals and other elements */
    pointer-events: none; /* Disable clicks by default */
}

.overlay.active {
    pointer-events: all; /* Enable clicks when active */
    background: rgba(0, 0, 0, 0); /* transparent overlay */
}

/* Hide modals and level indicators by default */
.hidden {
    display: none; 
}

.overlay.with-game-modal {
    pointer-events: none; /* Disable overlay clicks when game modal is active */
}

/*----------------------------------------*/
/*----------------------------------------*/
/* ------------ 404 Page -----------------*/
/*----------------------------------------*/
/*----------------------------------------*/

/* 404 page container */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    text-align: center;
    padding: 2rem;
}
.error-title {
    font-size: 4rem; 
    margin: 1rem 0 4rem 0;
    letter-spacing: 1px;
}
.error-message {
    font-size: 2rem;
    font-family: var(--primary-font); /* Jersey 20 font */
    margin-bottom: 2rem;
    line-height: 1.5; /* Improve readability */
    color: var(--primary-color); /* Light blue for text content */
}
/* Flickering crystal styles */
.crystal-flicker-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.2rem;
    margin-bottom: 2rem;
}
/* Flicker effect css implementation (drop shadow and opacity keyframes) 
inspired by this flickering neon sign https://codepen.io/patrickhill/pen/eYNbdQ by Patrick Hill 
and this flickering light effect https://codepen.io/prathameshkoshti/pen/PVVRMG by Prathamesh Koshti */
.crystal.flicker {
    width: 64px;
    height: auto;
    animation: flicker 3s infinite ease-in-out;
}

/* Custom glow colours */
.flicker-blue {
    filter: brightness(0.7) drop-shadow(0 0 12px #5655fd88);
}
.flicker-pink {
    filter: brightness(0.7) drop-shadow(0 0 12px #fd71e588);
}
.flicker-green {
    filter: brightness(0.7) drop-shadow(0 0 12px #2fff6d88);
}
.flicker-yellow {
    filter: brightness(0.7) drop-shadow(0 0 12px #ffff4d88);
}
.flicker-orange {
    filter: brightness(0.7) drop-shadow(0 0 12px #ff454988);
}

/* Flicker animation. Adjust opacity and add more keyframe percentages to make it more random/less static flickering *if needed*  */
@keyframes flicker {
    0%   { opacity: 0.6; }
    5%   { opacity: 0.85; }
    10%  { opacity: 0.5; }
    20%  { opacity: 0.8; }
    30%  { opacity: 0.95; }
    40%  { opacity: 0.5; }
    50%  { opacity: 0.8; }
    60%  { opacity: 1; }
    70%  { opacity: 0.7; }
    80%  { opacity: 0.8; }
    90%  { opacity: 0.5; }
    95%  { opacity: 0.3; }
    100% { opacity: 0.8; }
}
/* -------------------------------------------------------------------------*/

/* ---------------------------------------*/
/*----------------------------------------*/
/* -- Media queries for responsiveness -- */
/*----------------------------------------*/
/* ---------------------------------------*/

/* -- large tablets and desktop devices --*/
@media (min-width: 600px) {
    /* Player name input modal */
    .modal-container.player-name-modal {
        max-width: 500px; /* Adjust width for larger screens */ 
    }
}

/* -- tablet devices --*/
@media (max-width: 900px) {
    /* home page heading */
    h1 {
        font-size: 4rem; /* Reduce heading size */
    }
    /* home page text */
    p.intro-text {
        font-size: 1.8rem; /* Slightly smaller intro text */
        width: 80%; /* Increase width for better readability */
    }
    /* home page decorative crystals */
    .crystal-row {
        gap: 30px; /* Reduce spacing between crystals */
    }
    .crystal {
        width: 40px; /* Reduce crystal size */
    }
    /* home page button */
    button {
        font-size: 1.2rem; /* Reduce button font size */
        padding: 8px 16px; /* Adjust padding */
    }
    /* home page bat sprite */
    .home-brucey {
        top: 0.2em; /* Adjust to position above the heading */
        left: 8em; /* Adjust to position to the left of the heading */
        transform: scale(1.4); /* Scale down Brucey */
    }
    /* game page bat sprite */
    /* -- bat moves below the crystal container on smaller devices --*/
    .bat {
        top: 82%;
        left: 30%;
        transform: translateX(-50%) scale(1.3);
    }
    /* speech bubble modal */
    .speech-bubble {
        width: 350px; /* Adjust width for smaller screens */
        top: 43%;
        left: 25%;
        font-size: 1.7rem; /* Adjust font size for smaller screens */
        padding: 15px; /* Adjust padding for smaller screens */
    }
    .speech-bubble .text-container {
        padding-top: 3px; /* Reduce top padding */
    }
    
    .speech-bubble .instructions {
        font-size: 0.9rem; /* Slightly smaller instructions */
        margin-top: 0.5rem; /* Less space above instructions */
    }

    .buttons-container {
        display: grid;
        grid-template-columns: repeat(6, 0fr); /* 4 buttons per row */
        grid-template-rows: auto; /* Automatically adjust rows */
        gap: 5px; /* Space between buttons */
        position: absolute;
        top: 8px; /* Position above the game container */
        left: 50%;
        transform: translateX(-50%);
        width: max-content; /* Ensure the container spans most of the screen width */
    }

    .buttons-container .game-button {
        width: 60px; /* Button width */
        height: 60px; /* Button height */
        background-size: 600px 120px; /* Scale sprite sheet proportionally */
    }

    /* Adjust background positions for each button to the new proportions - (multiples of 60) */
    .game-button.how-to-play {
        background-position: 0 0; 
    }
    .game-button.how-to-play:active {
        background-position: 0 -60px; 
    }
    .game-button.restart {
        background-position: -60px 0; 
    }
    .game-button.restart:active {
        background-position: -60px -60px; 
    }
    .game-button.sound {
        background-position: -120px 0; 
    }
    .game-button.sound:active {
        background-position: -120px -60px; 
    }
    .game-button.sound.muted {
        background-position: -180px 0 ; 
    }
    .game-button.sound.muted:active {
        background-position: -180px -60px; 
    }
    .game-button.settings {
        background-position: -240px 0; 
    }
    .game-button.settings:active {
        background-position: -240px -60px; 
    }
    .game-button.home {
        background-position: -300px 0; 
    }
    .game-button.home:active {
        background-position: -300px -60px; 
    }
    .game-button.freestyle {
        background-position: -360px 0; 
    }
    .game-button.freestyle:active {
        background-position: -360px -60px; 
    }
    .game-button.freestyle.mode {
        background-position: -540px 0; 
    }
    .game-button.freestyle.mode:active {
        background-position: -540px -60px; 
    }
    .game-button.full-screen {
        background-position: -420px 0; 
    }
    .game-button.full-screen:active {
        background-position: -420px -60px; 
    }
    .game-button.exit-full-screen {
        background-position: -480px 0; 
    }
    .game-button.exit-full-screen:active {
        background-position: -480px -60px; 
    }
}

/* -- tablet/phone breakpoint --*/
@media (max-width: 768px) {
    /* remove full screen button on touchscreen mobile devices */
    .game-button.full-screen {
        display: none;
    }
    .modal-container {
        width: 95%; /* Adjust width for smaller screens */
        max-height: 70%; /* Reduce height for smaller screens */
        padding: 15px; /* Adjust padding */
    }
}

/* --  small tablet devices --*/
@media (max-width: 700px) {
    /* home page heading */
    h1 {
        font-size: 3.5rem; /* Reduce heading size */
    }
    /* home page text */
    p.intro-text {
        font-size: 1.5rem; /* Slightly smaller intro text */
        width: 90%; /* Increase width for better readability */
    }
    /* home page decorative crystals */
    .crystal-row {
        gap: 20px; /* Reduce spacing between crystals */
    }
    .crystal {
        width: 35px; /* Reduce crystal size */
    }
    /* home page button */
    button {
        font-size: 1.2rem; /* Reduce button font size */
        padding: 8px 16px; /* Adjust padding */
    }
    /* home page bat sprite */
    .home-brucey {
        top: 0.2em; /* Adjust to position above the heading */
        left: 4em; /* Adjust to position to the left of the heading */
        transform: scale(1.2); /* Scale down Brucey */
    }
    /* game page bat sprite */
    .bat {
        top: 85%;
        left: 25%;
        transform: translateX(-50%) scale(1);
    }
    /* game page level indicator */
    .level-indicator {
        transform: scale(0.8) translateX(-50%); /* Scale down the level indicator */
        /*font-size: 1.2rem; /* Adjust font size for smaller screens */
        top: 90%;
        right: 25px;
    }
    /* game page buttons */
    .buttons-container {
        display: grid;
        grid-template-columns: repeat(6, 0fr); /* 4 buttons per row */
        grid-template-rows: auto; /* Automatically adjust rows */
        gap: 5px; /* Space between buttons */
        position: absolute;
        top: 8px; /* Position above the game container */
        left: 50%;
        transform: translateX(-50%);
        width: max-content; /* Ensure the container spans most of the screen width */
    }
   
}

@media (max-width: 590px) {
    /* game page bat sprite */
    .bat {
        top: 95%;
        left: 20%;
        transform: translateX(-50%) scale(1);
    }
    /* game page level indicator */
    .level-indicator {
        transform: scale(0.8) translateX(-50%); /* Scale down the level indicator */
        top: 100%;
        right: -10px;
    }
    /* game page speech bubble modal */
    .speech-bubble {
        width: 320px; /* Adjust width for smaller screens */
        font-size: 1.5rem; /* Adjust font size for smaller screens */
        padding: 10px; /* Adjust padding for smaller screens */
        top: 50%;
    }
    
}



/* -- mobile devices --*/
@media (max-width: 500px) {
    /* home page heading */
    h1 {
        font-size: 3rem; /* Reduce heading size */
    }
    /* home page text */
    p.intro-text {
        font-size: 1.2rem; /* Slightly smaller intro text */
        width: 100%; /* Increase width for better readability */
    }
    /* home page decorative crystals */
    .crystal-row {
        gap: 10px; /* Reduce spacing between crystals */
    }
    .crystal {
        width: 30px; /* Reduce crystal size */
    }
    /* home page button */
    button {
        font-size: 1rem; /* Reduce button font size */
        padding: 6px 12px; /* Adjust padding */
    }
    /* home page bat sprite */
    .home-brucey {
        top: 0.2em; /* Adjust to position above the heading */
        left: 2em; /* Adjust to position to the left of the heading */
        transform: scale(0.8); /* Scale down Brucey */
    }
    .game-container {
        width: 90vw; /* Adjust width for smaller screens */
        height: 90vw; /* Maintain square aspect ratio */
        margin: 0 auto; /* Center horizontally */
    }
    /* Game page level indicator */
    .level-indicator {
        transform: scale(0.8) translateX(-50%); /* Scale down the level indicator */
        top: 100%;
        right: -30px;
    }
    /* Game page buttons */
    .buttons-container {
        display: grid;
        grid-template-columns: repeat(3, 0fr); 
        grid-template-rows: auto; /* Automatically adjust rows */
        gap: 5px; /* Space between buttons */
        position: absolute;
        top: 10%; /* Position above the game container */
        left: 50%;
        transform: translateX(-50%);
        width: max-content; /* Ensure the container spans most of the screen width */
    }

    /* game page speech bubble modal */
    .speech-bubble {
       left: 20%;
       top: 30%;
        width: 290px; /* Adjust width for smaller screens */
        font-size: 1.2rem; /* Adjust font size for smaller screens */
        padding: 15px; /* Adjust padding for smaller screens */
    }
    .speech-bubble .text-container {
        padding-top: 15px; /* Add more space above the text */
        padding-bottom: 10px;;
    }

    .speech-bubble .instructions {
        font-size: 0.9rem; /* Slightly smaller instructions */
        margin-top: 0.5rem; /* Add spacing above instructions */
    }
    .modal-container {
        max-height: 60%; /* Further reduce height */
        padding: 10px; /* Adjust padding */
    }
    /* 404 page: small device adjustments */
    .error-container {
        padding: 1rem;
        min-height: 90vh;
      }
      .error-title {
        font-size: 2.2rem;
        margin: 1rem 0 1.5rem 0;
      }
      .error-message {
        font-size: 1.1rem;
        margin-bottom: 1.2rem;
      }
      .crystal-flicker-container {
        margin-bottom: 1rem;
      }
      .crystal.flicker {
        width: 38px;
      }
      .return-message {
        font-size: 1rem;
        margin: 1.2rem 0 0.7rem 0;
      }
      .home-btn {
        font-size: 1rem;
        padding: 0.5em 1.2em;
        border-radius: 6px;
      }
}

/* -- mobile devices with smaller height --*/
@media (max-height: 750px) {
    .buttons-container {
        top: 2%;;
}
}

/* -- mobile devices medium to small sizes --*/
@media (max-width: 400px) {
    /* home page heading */
    h1 {
        font-size: 2.5rem; /* Reduce heading size */
    }
    /* home page text */
    p.intro-text {
        font-size: 1rem; /* Slightly smaller intro text */
        width: 100%; /* Increase width for better readability */
    }
    /* home page decorative crystals */
    .crystal-row {
        gap: 5px; /* Reduce spacing between crystals */
    }
    .crystal {
        width: 25px; /* Reduce crystal size */
    }
    /* home page button */
    button {
        font-size: 0.8rem; /* Reduce button font size */
        padding: 4px 8px; /* Adjust padding */
    }
    /* home page bat sprite */
    .home-brucey {
        top: 0.2em; /* Adjust to position above the heading */
        left: 0em; /* Adjust to position to the left of the heading */
        transform: scale(0.8); /* Scale down Brucey */
    }
    /* Game page level indicator */
    .level-indicator {
        transform: scale(0.8) translateX(-50%); /* Scale down the level indicator */
        top: 100%;
        right: -40px;
    }
    /* Game page buttons */
    .buttons-container {
        display: grid;
        grid-template-columns: repeat(3, 0fr); /* 4 buttons per row */
        grid-template-rows: auto; /* Automatically adjust rows */
        gap: 3px; /* Space between buttons */
        position: absolute;
        top: 20px; /* Position above the game container */
        left: 50%;
        transform: translateX(-50%);
        width: max-content; /* Ensure the container spans most of the screen width */
    }
    /* game page speech bubble modal */
    .speech-bubble {
        width: 270px; /* Adjust width for smaller screens */
        top: 20%;
        left: 5%;
    }
    .speech-bubble .text-container {
        padding-top: 10px; /* Add more space above the text */
        width: 85%; /* Reduce width further */
        padding-bottom: 5px; /* Add space below the text */
    }

    .speech-bubble .instructions {
        font-size: 0.8rem; /* Smaller instructions */
        margin-top: 0.1rem; /* Adjust spacing above instructions */
    }

    /* settings modal content*/ 
    .settings-section .setting {
        /* Set up a 2-column grid */
        display: grid;
        grid-template-columns: auto 1fr;
        grid-gap: 0.5rem; /* Spacing between grid cells */
    }
    
    /* Label spans the entire first row */
    .settings-section .setting label {
        grid-column: 1 / 3; /* Spans both columns */
        font-size: 1.2rem; /* Adjust font size */
        text-align: left;
    }
    
    /* Mute toggle in the second row, first column */
    .settings-section .setting .mute-toggle {
        grid-column: 1;
    }
    
    /* Slider in the second row, second column */
    .settings-section .setting .volume-slider {
        grid-column: 2;
        width: 100%; /* Let the slider fill its grid cell */
    }
    /* Let brightness slider fill the full width */
    .settings-section .setting .brightness-slider {
        grid-column: 1 / 3;
        width: 100%;
    }
}
       
/*------------------------------------------------------------------*/
/* -- media query for rotated view (landscape) on smaller devices --*/
/*------------------------------------------------------------------*/
@media (max-height: 420px) and (orientation: landscape) {
    /* home page heading */
    h1 {
        font-size: 2.5rem; /* Reduce heading size */
    }
    /* home page text */
    p.intro-text {
        font-size: 1rem; /* Slightly smaller intro text */
        width: 100%; /* Increase width for better readability */
    }
    /* home page decorative crystals */
    .crystal-row {
        gap: 5px; /* Reduce spacing between crystals */
    }
    .crystal {
        width: 25px; /* Reduce crystal size */
    }
    /* home page button */
    button {
        font-size: 0.8rem; /* Reduce button font size */
        padding: 4px 8px; /* Adjust padding */
    }
    /* home page bat sprite */
    .home-brucey {
        top: 0.2em; /* Adjust to position above the heading */
        left: 5em; /* Adjust to position to the left of the heading */
        transform: scale(0.8); /* Scale down Brucey */
    }

    /* game page bat sprite */
    .bat {
        top: 40px; /* Reset top position */
        left: -15%;
        transform: translateX(-50%) scale(1.2);
    }
    /* game page level indicator */
    .level-indicator {
        transform: scale(0.8) translateX(-50%); /* Scale down the level indicator */
        top: 70%; /* Reset top position */
        left: -25%; /* align to the left side of the screen */
        right: auto; /* Reset right position */
    }
    /* Shrink game container to fit within landscape mobile view */
    .crystal-grid {
        max-width: 75vw; /* Scale down a bit */
        max-height: 75vh; /* Reduce height to avoid address bar */
        width: min(75vw, 75vh, 375px); /* Adjust width and height to maintain proportionality */
        height: min(75vw, 75vh, 375px); /* Same ratio, adjusted size */
        padding: 2%; /* Slightly reduce padding to accommodate the smaller size */
    }
    /* game page buttons */
    .buttons-container {
        position: fixed; /* Ensures it's placed relative to the viewport */
        top: auto; /* Reset top position */
        left: auto; /* Reset left position */
        right: -5%; /* Position to the right side of the screen */
        display: grid;
        grid-template-columns: repeat(2, 1fr); /* 2 buttons per row */
        grid-template-rows: repeat(5, auto); /* Automatically size rows */
        gap: 5px; /* Space between buttons */
        padding: 10px;
        width: max-content; /* make sure buttons only take up necessary space */
    }
    .game-button.full-screen {
        display: none;
    }
    /* speech bubble modal */
    .speech-bubble {
        width: 290px; /* Adjust width for smaller screens */
        top: 20%;
        left: 5%;
        
        padding: 10px; /* Adjust padding for smaller screens */
        transform: scaleY(-1); /* This flips the entire bubble including content */ 
    }
    /* Counter-flip the text container to keep text readable */
    .speech-bubble .text-container {
        transform: scaleY(-1); /* This flips the text back to normal */
        position: absolute;
        top: 30px;
        font-size: 1.4rem; /* Adjust font size for smaller screens */
        width: 85%; /* Reduce width further */
    }
    /* 404 page: mobile landscape adjustments */
    .error-container {
        padding: 0.5rem;
      
      }
      .error-title {
        font-size: 2rem;
        margin: 0.5rem 0 1.5rem 0;
      }
      .error-message {
        font-size: 1.5rem;
        margin-bottom: 1.2rem;
      }
      .crystal-flicker-container {
        margin-bottom: 0.5rem;
      }
      .crystal.flicker {
        width: 3rem;
      }
      .home-btn {
        font-size: 1.3rem;
        padding: 0.3em 0.7em;
        border-radius: 5px;
      }
}


/* Only applies to touchscreen devices without hover (tablets and mobiles) */
/* Credit: https://natenorthway.com/css-sass/hover-and-pointer-media-queries/ */
/* This hides the tooltip on touch devices to avoid cluttering the screen */
/* and to prevent the tooltip from showing when the user taps on the button. */
@media (hover: none) and (pointer: coarse) {
  .tooltiptext {
    display: none;
  }
}