:root {
    --font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-weight: 600;
    --background-color: #F9F6E9;
    --tile-gap: 2%;          /* Gap between tiles */
    --board-padding: 2%;     /* Padding around the board */
    --total-padding: 4%;     /* Total vertical padding (top + bottom) */
    --total-gap: 6%;         /* Total vertical gaps (3 gaps between 4 rows) */
    --button-bg: #8C7B68;
    --button-hover-bg: #AA9681;
    --button-color: #F7F4F1;
    --button-padding: 0.7em 1.4em;
    --button-transition: background-color 0.3s ease, transform 0.3s ease;
    --button-transform: scale(1.05);
}


/* Apply box-sizing globally */
*, *::before, *::after {
    box-sizing: border-box;
}

/* General body styles */
body {
    font-family: var(--font-family);
    font-weight: 600;
    font-style: normal;
    display: flex;
    justify-content: center; /* Horizontally centers .game-container */
    align-items: center;     /* Vertically centers .game-container */
    height: 100vh;           /* Full viewport height */
    margin: 0;
    background-color: #F9F6E9;
    /* overflow: hidden; */
    touch-action: manipulation;
}

/* Header styles */
h1 {
    color: #776e65;
    margin: 0px 0px 5px 0px;
    font-size: clamp(20px, 8vw, 32px); /* Responsive font size */
}

h2 {
    font-family: var(--font-family);
    font-weight: 200;
    font-style: normal;
    margin-top: 0px;
    color: #000;
    opacity: 0.7;
    font-size: clamp(14px, 4vw, 24px);
}

/* Game container styles */
.game-container {
    position: relative;
    text-align: center;
    width: 90vw;
    max-width: 500px;
    max-height: auto; /* 90vh; */
    margin: auto;
    padding: 0px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* overflow: hidden; /* Prevent internal scrolling */
}

/* Board styles */
.board {
    width: 100%;
    max-width: 500px;
    max-height: auto;
    min-width: 350px;
    min-height: 350px;
    margin: 0 auto;
    background-color: #B9AEA1;
    border-radius: 10px;
    border: 3px solid #000;
    box-sizing: border-box;
    position: relative;
    /* padding-top: 100%; /* Maintains 1:1 aspect ratio */

    /* Modern browsers will use aspect-ratio */
    aspect-ratio: 1 / 1;

    

}

.board > * {
    position: absolute;
    top: 0; /* Changed from var(--board-padding) */
    left: 0;
    right: 0;
    bottom: 0;
    padding: var(--board-padding);
    background-color: inherit;
    border-radius: inherit;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
}

/* Tiles container styles */
#tiles {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr); /* Define rows explicitly */
    gap: var(--tile-gap); /* Use CSS variable for gap */
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

/* Tile styles */
.tile {
    width: 100%;
    height: 100%; /* Added */
    position: relative;
    background-color: #ECE0CA;
    color: #766E66;
    font-size: 3em; /* Increased font size */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    box-shadow: 0px 2px 7px rgba(0, 0, 0, 0.25);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.tile > span {
    /* Center the number using Flexbox */
    position: static; /* Removed absolute positioning */
    transform: none;
}

/* Empty tile styles */
.empty {
    background-color: #C9BCAD;
    box-shadow: none;
}

/* Disabled tile styles */
.disabled {
    background-color: #E4E4E4;
    color: #969696;
}

/* Overlay styles confined within the board */
.overlay {
    position: absolute; /* Changed from fixed to absolute */
    top: 0;
    left: 0;
    width: 100%; /* Cover the entire board */
    height: 100%; /* Cover the entire board */
    background: rgba(0, 0, 0, 0.8);
    color: #ffffff;
    display: none; /* Hidden by default */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* font-size: 1.5em;   Relative font size */
    z-index: 10;
    padding: 5%; /* 10px */
    gap: 10%;/* 44px; */
    box-sizing: border-box;
    text-align: center;
    border-radius: 2px; /* Match board's border radius */
    overflow: hidden; /* Prevent internal scrolling */
    /* overflow: auto;  Allow scrolling within overlay if content exceeds */
}

.overlay p {
    font-family: "Clear Sans", sans-serif;
    font-weight: normal;
    font-style: normal;
    /*font-size: 1.5em;  Responsive font size */
}

.overlay h2 {
    font-family: "Clear Sans", sans-serif;
    font-weight: 600;
    font-style: normal;
    /* font-size: 1.5em; */
    color: #F39C12;
    opacity: 1;
    margin-top: 0;
    margin-bottom: 10px;
}

/* Specific styles for Game Over Overlay */
#gameOverOverlay .overlay-content h2 {
    color: #99EA7B;
}

#gameOverOverlay .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2em; /* Space between shortcuts */
}

#scoreValue, #movesValue, #timeValue {
    font-weight: 200;
    font-style: normal;
}

.stats {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    padding: 0px;
    gap: 2em;
    color: #fff;
}

.stats div > div:first-child {
    font-size: 2em;
    text-align: center;
}

.stats div > div:last-child {
    text-align: center;
}

#shortcutOverlay .overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2em; /* Space between shortcuts */
    padding: 5%;
    width: 100%;
    color: #ffffff;
    opacity: 1;
    /* font-size: 0.7em; Relative to overlay's font-size */
    /* word-wrap: break-word;  Allow text to wrap */
    
}

#shortcutOverlay .overlay-content h2 {
    font-size: 2em; /* Responsive font size */
}

#shortcutOverlay .overlay-content .shortcutList {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
}

#shortcutOverlay .shortcut {
    font-style: normal;
    font-weight: normal;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
}

.key {
    color: #EACF7B;
    font-weight: bold;
    margin: 0em 0.5em;
}

#shortcutOverlay .close a {
    font-size: 1.2em; /* Relative font size */
    color: #f0d078;
    text-decoration: none;
    font-weight: bold;
}

/* Status Bar Styles */
.status-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px; /* Space below the status bar */
    font-size: 1em; /* Relative to .game-container */
    box-sizing: border-box;
}

.move-counter, .timer {
    font-size: 1em; /* Relative to .status-bar */
    font-weight: bold;
}

/* Buttons Container Styles */
.buttons {
    display: flex;
    justify-content: center; /* Center buttons horizontally */
    gap: var(--tile-gap); /* Maintain 2% gap */
    margin-bottom: 10px; /* Space below buttons */
    flex-wrap: wrap; /* Allow buttons to wrap if space is limited */
}


/* Footer styles */
.footer {
    margin-top: 10px;
    font-size: 0.9em; /* Relative to .game-container */
    flex-shrink: 0; /* Prevents footer from shrinking */
}

.footer p {
    font-family: "Clear Sans", sans-serif;
    font-weight: normal;
    color: #333;
    margin: 0 auto;
    line-height: 1.4;
    word-wrap: break-word; /* Prevent long words from overflowing */
}

.footer a {
    color: #2962ff;
    text-decoration: underline;
    font-weight: bold;
}

.footer a:hover {
    text-decoration: none;
}

/* Buttons */
button {
    font-size: 1em; /* Relative to .game-container */
    padding: var(--button-padding);
    border-radius: 5px;
    cursor: pointer;
    margin: 0.5em;
    background-color: var(--button-bg);
    color: var(--button-color);
    border: none;
    transition: var(--button-transition);
    /*transition: background 0.3s ease; */
}

.overlayButton {
    font-size: 0.75em;
    padding: 0.7em 1.4em;
    background-color: #4CAF50;
}

.overlayButton:hover {
    background-color: #4CAF50;
}

#shareMessage {
    display: none;
    font-size: 0.75em;
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 1000;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}


/* Hover Styles for Devices with Hover Capability and Sufficient Screen Width */
@media (min-width: 769px) and (hover: hover) and (pointer: fine) {
    button:hover {
        background-color: var(--button-hover-bg);
    }
    
    /* Hover and Active States */
    .tile:hover:not(.empty):not(.disabled),
    .tile:active:not(.empty):not(.disabled) {
        background-color: #EAB47F;
        color: #F9F6F3;
        cursor: pointer;
        transform: scale(1.05);
    }
}


/* Base styles for smaller screens (max-width: 768px) */
@media (max-width: 768px) {

    body {
        font-family: var(--font-family);
        font-weight: var(--font-weight);
        display: inline;
        /*height: 100vh;           /* Full viewport height */
        margin: 0;
        background-color: var(--background-color);
        overflow: hidden;        /* Prevent any scrolling */
    }

    .game-container {
        width: 95vw;
        max-height: 95vh; /* Slightly larger max-height for medium screens */
    }

    h1 {
        font-size: clamp(24px, 10vw, 36px);
    }

    h2 {
        font-size: clamp(16px, 5vw, 28px);
    }

    #shortcutOverlay.overlay-content,
    #shortcutOverlay .close a,
    .status-bar,
    button,
    .footer p {
        font-size: 1em;
    }

    #shortcutOverlay h2 {
        font-size: 2em;
    }

    .status-bar {
        font-size: 0.9em; /* Slightly reduce font size */
    }

    .buttons,
    #tiles {
        gap: var(--tile-gap); /* Maintain 2% gap */
    }

    .board {
        padding: var(--board-padding); /* Maintain 2% padding */
    }
}

/* Further adjustments for the smallest screens (max-width: 400px) */
@media (max-width: 400px) {

    #shortcutOverlay .overlay-content {
        font-size: 1.2em;
    }

    #shortcutOverlay h2 {
        font-size: 2.5em;
    }

    #shortcutOverlay .close a {
        font-size: 1.5em;
    }

    /* .buttons, #tiles, and .board already have necessary styles from larger media queries */
}

.board:focus-visible,
button:focus-visible {
    outline: 4px solid #2563eb;
    outline-offset: 4px;
}
