/* Basic Reset & Body Styling */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
}

html, body {
    height: 100%;
    width: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #1a1a1a; /* Dark background */
    color: #e0e0e0; /* Light text */
    overflow: hidden; /* Prevent scrolling */
}

/* Define consistent CSS variables */
:root {
    --button-min-height: 70px; /* Standard button height */
    --slider-track-width: 14px; /* Thickness of the fader track */
    --slider-thumb-size: 26px; /* Width/Height of the square thumb */
    --source-button-size: 160px; /* Width and Height for square source buttons */
}


/* Main container */
.panel-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 25px;
    background-color: #111;
    border-bottom: 1px solid #333;
    height: 85px;
    flex-shrink: 0;
}
.time {
    font-size: 1.6em;
    font-weight: bold;
    white-space: nowrap;
}
.spacer {
    flex-grow: 1;
}

/* Bottom Bar */
.bottom-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 15px;
    background-color: #111;
    border-top: 1px solid #333;
    height: 90px;
    flex-shrink: 0;
}
.control-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    text-align: center;
}
.volume-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 100px;
}
.vol-label {
    font-size: 0.8em;
    color: #aaa;
}
.vol-db {
    font-size: 1.3em;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
}

/* Icon Button Styling (Base for most buttons) */
.icon-button {
    background: linear-gradient(to bottom, #444, #222);
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.4em;
    transition: background-color 0.2s ease, transform 0.1s ease;
    min-width: var(--button-min-height); /* Use variable */
    min-height: var(--button-min-height); /* Use variable */
    display: inline-flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    overflow: hidden;
    text-align: center;
}
.icon-button:hover {
    background: linear-gradient(to bottom, #555, #333);
}
.icon-button:active {
    background: linear-gradient(to bottom, #333, #111);
    transform: scale(0.95);
}

/* Specific button adjustments */
.power-btn {
    color: #ff4d4d;
    border-color: #777;
    font-size: 1.8em;
}
.power-btn:hover { color: #ff6666; }
.mute-btn.active {
    background: linear-gradient(to bottom, #ff6666, #cc0000);
    color: #fff;
    border-color: #ff8888;
}
.nav-button.active {
    background: linear-gradient(to bottom, #66aaff, #3377cc);
    border-color: #88ccff;
}

/* Main Content Area */
.content-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
}
.page {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: flex-start; /* Align content to top */
    align-items: center;
    flex-direction: column;
    padding-top: 20px;
}
.page.active {
    display: flex;
}

/* Home Page Source Selector (Square Buttons) */
.source-selector {
    display: flex;
    gap: clamp(25px, 4vw, 40px); /* Adjusted gap */
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-wrap: wrap;
    margin-top: 5vh;
}

.source-button {
    background: linear-gradient(to bottom, #5a5a5a, #3a3a3a);
    border: 1px solid #666;
    color: #f0f0f0;
    padding: 15px; /* Internal padding */
    border-radius: 15px;
    cursor: pointer;
    font-size: 1.1em; /* Adjusted font size */
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center content vertically and horizontally */
    width: var(--source-button-size); /* Use variable */
    height: var(--source-button-size); /* Use variable */
    gap: 8px; /* Space between icon and text */
    text-align: center;
}

.source-button i {
    font-size: 3.5em; /* Adjust icon size as needed */
    margin-bottom: 8px;
    flex-shrink: 0; /* Prevent icon shrinking */
}

.source-button span {
    white-space: normal; /* Allow text wrapping */
    line-height: 1.2;
    flex-shrink: 0; /* Prevent text shrinking */
    max-width: 90%; /* Prevent text overflow */
}

.source-button:hover {
    background: linear-gradient(to bottom, #6a6a6a, #4a4a4a);
}

.source-button:active {
    transform: scale(0.96);
    background: linear-gradient(to bottom, #4a4a4a, #2a2a2a);
}


/* Controls Section within Pages */
.controls-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(20px, 3vh, 30px);
    width: 100%;
    max-width: 800px;
    padding: 10px;
    margin-top: 0;
}
.page h2 {
    margin-bottom: 25px;
    color: #fff;
    text-align: center;
    width: 100%;
    font-size: 1.5em;
}
.page p {
    color: #ccc;
    margin-bottom: 20px;
    text-align: center;
}
.control-group-separator {
    width: 70%;
    height: 1px;
    background-color: #444;
    margin: 15px 0;
}

/* D-Pad & Transport Controls */
.dpad-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    width: calc(var(--button-min-height) * 3 + 16px);
    height: calc(var(--button-min-height) * 3 + 16px);
}
.dpad-container .icon-button {
    min-width: auto;
    min-height: auto;
    width: 100%;
    height: 100%;
    font-size: 1.6em;
    padding: 5px;
}
.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-select { grid-column: 2; grid-row: 2; font-size: 1.1em !important; background: linear-gradient(to bottom, #66aaff, #3377cc); border-color: #88ccff; }
.dpad-select:hover { background: linear-gradient(to bottom, #77bbff, #4488dd); }
.dpad-select:active { background: linear-gradient(to bottom, #5599dd, #2266bb); }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }
.transport-controls, .menu-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(10px, 2vw, 15px);
    flex-wrap: wrap;
    width: 100%;
}

/* Back Button */
.back-button {
    background: #555;
    color: white;
    padding: 10px 25px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    margin-top: 10px;
    min-height: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.back-button:hover { background: #666; }
.back-button:active { background: #444; transform: scale(0.97); }

/* --- Popup Styling --- */
.popup {
    display: none;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 15px;
}
.popup.show {
    display: flex;
    animation: fadeInPopup 0.3s ease-out;
}
@keyframes fadeInPopup { from { opacity: 0; } to { opacity: 1; } }
.popup-content {
    background-color: #2c2c2c;
    padding: 25px 30px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid #444;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    width: auto;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}
.popup-content h2 {
    margin-top: 10px;
    margin-bottom: 20px;
    color: #fff;
    font-size: 1.4em;
    flex-shrink: 0;
}
.popup-content p {
    margin-bottom: 25px;
    color: #ddd;
    font-size: 1.1em;
}
.popup-close-button {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #aaa;
    font-size: 1.6em;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    z-index: 1010;
}
.popup-close-button:hover { color: #fff; }
.popup-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: auto;
    padding-top: 20px;
    flex-shrink: 0;
}
.popup-button {
    padding: 10px 25px;
    border: none;
    border-radius: 5px;
    font-size: 1.1em;
    cursor: pointer;
    min-width: 100px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    min-height: var(--button-min-height);
    display: inline-flex;
    justify-content: center;
    align-items: center;
}
.popup-button:active { transform: scale(0.95); }
.popup-button.yes { background-color: #d9534f; color: white; }
.popup-button.yes:hover { background-color: #c9302c; }
.popup-button.no { background-color: #5cb85c; color: white; }
.popup-button.no:hover { background-color: #4cae4c; }


/* --- Lighting Popup Specific Styles --- */
.lighting-popup-content {
    max-width: 700px; /* Wider popup */
}
.lighting-popup-body {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    gap: 40px;
    overflow-y: auto;
    padding: 10px 0;
}
.lighting-sliders-container {
    display: flex;
    gap: 30px;
    height: 350px; /* Taller sliders */
    flex-shrink: 0;
    padding: 15px 0;
}
.slider-group.vertical {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: auto;
    height: 100%;
}
.slider-group.vertical label {
    font-size: 0.8em;
    color: #ccc;
    margin-bottom: 8px;
    white-space: nowrap;
}
.slider-group.vertical .slider-wrapper {
    flex-grow: 1;
    width: var(--slider-thumb-size);
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 5px 0;
}

/* Vertical Slider Styling (Fader Style) */
.level-slider.vertical {
    appearance: none; -webkit-appearance: none;
    width: calc(100% - 20px); /* Length */
    height: var(--slider-track-width); /* Thickness */
    background: transparent;
    cursor: pointer;
    transform-origin: center center;
    transform: rotate(-90deg);
    margin: 0;
    position: relative;
    border: 1px solid #888;
    border-radius: 4px;
    background-image: linear-gradient(to right, #ffc107, #ffc107 var(--value-percent, 0%), #3a3a3a var(--value-percent, 0%), #3a3a3a 100%);
}
/* Square Thumb Styling */
.level-slider.vertical::-webkit-slider-thumb {
    appearance: none; -webkit-appearance: none;
    width: var(--slider-thumb-size);
    height: var(--slider-thumb-size);
    background: #ddd;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #aaa;
    margin-top: calc((var(--slider-thumb-size) - var(--slider-track-width)) / -2);
    box-shadow: 0 0 3px rgba(0,0,0,0.3);
}
.level-slider.vertical::-moz-range-thumb {
    width: var(--slider-thumb-size);
    height: var(--slider-thumb-size);
    background: #ddd;
    border-radius: 3px;
    cursor: pointer;
    border: 1px solid #aaa;
    box-shadow: 0 0 3px rgba(0,0,0,0.3);
}

.slider-group.vertical .slider-percentage {
    font-size: 0.9em;
    font-weight: bold;
    color: #fff;
    margin-top: 8px;
}

/* Wider Preset Buttons */
.lighting-presets-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: stretch;
    flex-shrink: 0;
    min-width: 140px;
}
.preset-button {
    background: linear-gradient(to bottom, #484848, #282828);
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 10px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease, transform 0.1s ease;
    min-height: var(--button-min-height);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    text-align: center;
}
.preset-button:hover { background: linear-gradient(to bottom, #585858, #383838); }
.preset-button:active, .preset-button.active { background: linear-gradient(to bottom, #66aaff, #3377cc); color: #fff; border-color: #88ccff; }
.preset-button:active { transform: scale(0.96); }


/* --- Masking Popup Specific Styles --- */
.masking-popup-content {
    max-width: 500px;
}
.masking-options {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    padding: 20px 0;
}
.masking-button {
    background: linear-gradient(to bottom, #444, #222);
    border: 1px solid #555;
    color: #e0e0e0;
    padding: 15px;
    border-radius: 12px;
    width: 180px;
    min-height: var(--button-min-height);
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, border-color 0.2s ease;
}
.masking-button:hover { background: linear-gradient(to bottom, #555, #333); }
.masking-button:active, .masking-button.active { background: linear-gradient(to bottom, #66aaff, #3377cc); color: #fff; border-color: #88ccff; }
.masking-button:active { transform: scale(0.96); }
.masking-button svg { width: 80%; height: auto; max-height: 60px; display: block; }
.masking-button .screen-bg { fill: #ccc; stroke: #eee; stroke-width: 1px; transition: fill 0.2s ease; }
.masking-button .mask { fill: #222; stroke: #444; stroke-width: 0.5px; transition: fill 0.2s ease, stroke 0.2s ease; }
.masking-button.active .screen-bg { fill: #fff; }
.masking-button.active .mask { fill: #333; stroke: #555; }
.masking-button span { font-size: 0.9em; font-weight: bold; text-align: center; margin-top: 5px; }