/* CSS Variables for Themes */
:root {
    --bg-color: linear-gradient(to bottom right, #1e3c72, #2a5298, #43cea2);
    --ball-color: #ff0000;
    --wall-color: #ffd700;
    --wall-building-color: #ffe866;
    --filled-color: rgba(0, 0, 0, 0.4);
    --text-color: #ffffff;
    --header-bg: rgba(0, 0, 0, 0.85);
    --btn-bg: #4caf50;
    --btn-hover: #45a049;
    --canvas-border: #ffffff;
}

body.theme-bw {
    --bg-color: #ffffff;
    --ball-color: #000000;
    --wall-color: #888888;
    --wall-building-color: #aaaaaa;
    --filled-color: rgba(200, 200, 200, 1);
    --text-color: #333333;
    --header-bg: #e0e0e0;
    --btn-bg: #555555;
    --btn-hover: #333333;
    --canvas-border: #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    font-weight: bold;
}

body, html {
    width: 100vw;
    height: 100dvh; 
    overflow: hidden; 
    position: fixed; 
    overscroll-behavior: none; 
    background: var(--bg-color);
    background-size: cover;
    color: var(--text-color);
    transition: background 0.3s ease;
    font-size: 16px;
    touch-action: none; 
}

#game-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: var(--header-bg);
    color: var(--text-color);
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    z-index: 10;
}

#stats {
    display: flex;
    gap: 30px;
    align-items: center;
}

.stat-box {
    font-size: 1.3em;
    font-weight: 700;
    white-space: nowrap;
}

.highlight-stat {
    font-size: 1.4em;
    font-weight: 900;
    color: #ffeb3b;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

body.theme-bw .highlight-stat {
    color: #000000;
    text-shadow: none;
}

button {
    cursor: pointer;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    background: var(--btn-bg);
    color: #fff;
    font-size: 1.1em;
    font-weight: 800;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    white-space: nowrap;
}

button:hover { background: var(--btn-hover); }
button:active { transform: translateY(2px); box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

#btn-return { background: #d32f2f; font-size: 1em; }
#btn-return:hover { background: #b71c1c; }

#main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 10px;
    min-height: 0; 
    overflow: hidden;
}

#canvas-container {
    flex: 1;
    width: 100%;
    height: 100%; 
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0; 
    min-width: 0;
    padding: 4px; /* Padding ensures the border doesn't clip against the screen edge */
}

canvas {
    background-color: transparent;
    border: 4px solid var(--canvas-border);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 8 / 5; /* This ensures the element shrinks wrapping the 800x500 content exactly */
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

body.theme-bw canvas {
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

#controls-footer {
    appearance: none;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: rgba(0,0,0,0.4);
    padding: 10px 25px;
    border-radius: 50px;
    flex-shrink: 0; 
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    color: white;
}

#controls-footer:hover { background: rgba(0,0,0,0.6); }
#controls-footer:active { transform: translateY(2px); box-shadow: 0 2px 5px rgba(0,0,0,0.3); }

#btn-toggle-dir-text {
    background: #007bff;
    font-size: 1.2em;
    padding: 12px 24px;
    border-radius: 6px;
    font-weight: 800;
    transition: background 0.2s;
}

#controls-footer:hover #btn-toggle-dir-text {
    background: #0056b3;
}

#direction-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
    height: 50px;
}

#dir-arrow {
    width: 100%;
    height: 100%;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    filter: drop-shadow(0px 4px 4px rgba(0,0,0,0.4));
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    color: #fff;
}

.overlay.hidden { display: none !important; }

.overlay-content {
    background: #333;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.overlay-content h1 { font-size: 2.2em; margin-bottom: 15px; color: #fff; }
.overlay-content h2 { font-size: 1.8em; margin-bottom: 15px; color: #fff; }
.overlay-content p { margin-bottom: 15px; font-size: 1.2em; }

.form-group { margin-bottom: 15px; text-align: left; }
.form-group label { display: block; margin-bottom: 6px; font-size: 1.1em; font-weight: 800; }
.form-group select { width: 100%; padding: 10px; border-radius: 4px; border: 1px solid #555; background: #222; color: #fff; font-size: 1em; font-weight: bold; }

.primary-btn { width: 100%; padding: 14px; font-size: 1.3em; margin-top: 10px; }


/* -------------------------------------- */
/* RESPONSIVE LAYOUT RULES FOR NO-SCROLL  */
/* -------------------------------------- */

@media screen and (orientation: portrait) and (max-width: 768px) {
    header {
        display: flex;
        flex-wrap: wrap; 
        padding: 10px;
        gap: 10px;
    }
    #btn-return { order: 1; font-size: 0.9em; padding: 8px 12px; }
    #btn-pause { order: 2; font-size: 0.9em; padding: 8px 12px; }
    #stats {
        order: 3;
        width: 100%; 
        justify-content: space-around;
        gap: 5px;
    }
    .stat-box { font-size: 1em; }
    .highlight-stat { font-size: 1.1em; }
    
    #controls-footer {
        padding: 8px 20px;
        margin-top: 5px;
        margin-bottom: 5px;
    }
}

@media screen and (orientation: landscape) and (max-height: 600px) {
    header { padding: 5px 15px; }
    .stat-box { font-size: 1em; }
    .highlight-stat { font-size: 1.1em; }
    
    #main-content {
        flex-direction: row; 
        padding: 5px;
        height: 100%;
    }
    
    #controls-footer {
        flex-direction: column; 
        margin-top: 0;
        margin-left: 10px;
        padding: 10px;
        border-radius: 20px;
        height: auto;
    }
    
    #btn-toggle-dir-text {
        font-size: 1em;
        padding: 8px 12px;
        white-space: normal;
        text-align: center;
    }
}
