/* Basic Reset & Body Style */
html, body {
    height: 100%;
    overscroll-behavior-y: contain;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Press Start 2P', cursive;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    touch-action: manipulation;
    /* Background/text color set by Bootstrap classes */
}

/* Game Area Container */
.game-area {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Game Canvas Styling */
canvas#tetris {
    border: 2px solid #555;
    background-color: #000;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* UI Panel Customization */
.ui-box {
    background-color: #333;
    /* Using Bootstrap p-2 for padding */
}

.ui-label {
    font-size: 0.6em;
    margin-bottom: 0.1rem !important; /* Reduce default Bootstrap margin */
    color: #aaa;
    line-height: 1;
    display: block; /* Ensure label takes its own line if needed */
}

.ui-value {
    font-size: 1em;
    line-height: 1.1;
}

#next-piece {
    background-color: #000;
    border: 1px solid #555;
    display: block;
    margin: 0 auto;
    max-width: 100%;
    width: 100px !important; /* Force size via CSS */
    height: 100px !important;
}

.controls-text {
    font-size: 0.65em;
    line-height: 1.3;
    color: #bbb;
}

/* === ADDED: Audio Control Styling === */
#music-toggle, #sfx-toggle {
    font-size: 0.6em !important; /* Smaller font for these buttons */
    padding: 0.25rem 0.5rem !important; /* Adjust padding for small buttons */
    line-height: 1.2; /* Adjust line height if text wraps */
    /* Bootstrap btn-sm is already applied in HTML */
}

/* Styling for the volume slider range input */
#volume-slider {
    height: 0.5rem;     /* Make slider track thinner */
    cursor: pointer;    /* Indicate it's interactive */
    padding: 0 !important; /* Remove default padding if necessary */
    margin-top: 0.25rem; /* Add small space above slider */
    vertical-align: middle; /* Align better with label if needed */
}
/* Optional: More specific styling for track/thumb (browser-specific) */
/* Example for Webkit (Chrome/Safari) */
#volume-slider::-webkit-slider-runnable-track {
  background: #555; /* Darker track */
  height: 0.4rem;
  border-radius: 0.2rem;
}
#volume-slider::-webkit-slider-thumb {
  background: #bbb; /* Lighter thumb */
  height: 0.8rem; /* Make thumb slightly larger */
  width: 0.8rem;
  margin-top: -0.2rem; /* Center thumb vertically */
  border-radius: 50%;
}
/* Example for Firefox */
#volume-slider::-moz-range-track {
  background: #555;
  height: 0.4rem;
  border-radius: 0.2rem;
}
#volume-slider::-moz-range-thumb {
   background: #bbb;
   height: 0.8rem;
   width: 0.8rem;
   border-radius: 50%;
   border: none; /* Remove default border */
}
/* ================================== */

/* Touch Controls Specific Layout & Size */
.touch-grid {
    display: grid;
    grid-template-areas:
        ". rotate ."
        "left down right"
        ". drop .";
    gap: 8px;
    justify-content: center;
    max-width: 300px;
    margin: 0 auto;
}

#touch-left { grid-area: left; }
#touch-rotate { grid-area: rotate; }
#touch-right { grid-area: right; }
#touch-down { grid-area: down; }
#touch-drop { grid-area: drop; }

.btn-touch {
    padding: 0.6rem 0.4rem !important;
    font-size: 1.3em !important;
    min-width: 60px !important;
    max-width: 75px;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}


/* Message Overlay Styling */
#message-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85); color: #fff;
    display: none; flex-direction: column; justify-content: center;
    align-items: center; text-align: center;
    z-index: 1050; cursor: default; padding: 1rem;
}
#message-overlay.game-over { cursor: pointer; }
#message-overlay h1 { font-size: 1.8em; margin-bottom: 1rem; color: #ff4141; }
#message-overlay p { font-size: 1em; }
#message-overlay.paused h1 { color: #ffff41; }


/* === Media Queries for Mobile Layout === */

@media (max-width: 767.98px) { /* Below Bootstrap 'md' */
    .game-area { padding-top: 5px; align-items: flex-start; }
    #canvas-controls-container { display: flex; flex-direction: column; align-items: center; width: 100%; }
    canvas#tetris { max-width: 95vw; }
    #ui-column { margin-top: 10px; max-width: 320px; margin-left: auto; margin-right: auto; }
    #ui-column .vstack { gap: 8px !important; }
    .ui-label { font-size: 0.55em; }
    .ui-value { font-size: 0.9em; }
    #next-piece { width: 80px !important; height: 80px !important; }
    #message-overlay h1 { font-size: 1.4em; }
    #message-overlay p { font-size: 0.9em; }

    /* Adjust audio control font size on mobile */
    #music-toggle, #sfx-toggle {
        font-size: 0.55em !important;
    }
}

@media (max-width: 400px) { /* Very small screens */
    .btn-touch { font-size: 1.1em !important; min-width: 50px !important; padding: 0.5rem 0.3rem !important; }
    .touch-grid { gap: 5px; }
    #next-piece { width: 60px !important; height: 60px !important; }
    #message-overlay h1 { font-size: 1.2em; }

     /* Further adjust audio control font size */
    #music-toggle, #sfx-toggle {
        font-size: 0.5em !important;
    }
}

/* Optional: Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .game-area { align-items: center; }
    #next-piece { display: none; }
    .ui-label { font-size: 0.5em; }
    .ui-value { font-size: 0.8em; }
    .btn-touch { font-size: 1.0em !important; min-width: 45px !important; }
    .touch-grid { gap: 4px; }

    /* Hide audio controls entirely in cramped landscape? Optional. */
    /* #ui-column .ui-box:nth-child(3) { display: none; } */
    /* OR just make buttons smaller */
    #music-toggle, #sfx-toggle {
         font-size: 0.45em !important;
         padding: 0.2rem 0.3rem !important;
    }
     #volume-slider { height: 0.4rem; }
     #volume-slider::-webkit-slider-thumb { height: 0.7rem; width: 0.7rem; margin-top: -0.15rem;}
     #volume-slider::-moz-range-thumb { height: 0.7rem; width: 0.7rem;}
}

