/* Base Styles & Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-color: #0d0d0d;
    --text-color: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-color: #6fb3e0;
    /* brighter pastel blue */
    --accent-hover: #5fa8d3;
    /* slightly darker for hover state */
    --media-border-color: #ffffff;

    --overlay-exif-size: 14px;
    --overlay-exif-visible: block;
    --overlay-gps-size: 16px;
    --overlay-gps-visible: block;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    /* Prevent scrolling in gallery view */
    width: 100vw;
    height: 100vh;
}

/* =========================================
   Gallerie (index.html) Styles
   ========================================= */

/* Overlay - Used for starting Audio Policy */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.5s ease;
}

.overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    padding: 3rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

/* Retro Countdown Styles */
.countdown-number {
    font-size: 15rem;
    font-weight: 800;
    color: #ffffff;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.8), 2px 2px 0px rgba(0, 0, 0, 1);
    opacity: 0;
    transform: scale(0.5);
    transition: none;
}

.countdown-number.animate {
    animation: countdownTick 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes countdownTick {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    20% {
        opacity: 1;
        transform: scale(1.1);
    }

    30% {
        transform: scale(1);
    }

    80% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

.overlay-content h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
    background: linear-gradient(to right, var(--accent-color), var(--accent-hover));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.overlay-content p {
    color: #aaaaaa;
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

/* Main Gallery Grid */
.gallery {
    width: 100%;
    height: 100%;
    padding: 2rem;
    display: grid;
    gap: 1.5rem;
}

/* Different Layout Configurations using CSS Grid */
.gallery.layout-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.gallery.layout-2 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: 1fr;
}

.gallery.layout-4 {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.gallery.layout-6 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

/* Individual Media Items */
.media-item {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 0;
    min-height: 0;
    opacity: 0;
    /* GSAP will handle fade-in */
}

.media-wrapper {
    position: relative;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--media-border-radius, 12px);
    background-color: transparent;
    border: var(--media-border-width, 0px) solid var(--media-border-color, transparent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    box-sizing: content-box;
    /* The JS calculates the exact inner bounds now, so the border grows outwards */
    transform: translateZ(0);
}


.media-item-content {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: inherit;
    overflow: hidden;
}


/* =========================================
   OVERLAYS (EXIF, GPS)
   ========================================= */
.overlay-gps {
    position: absolute;
    top: 15px;
    left: 20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: var(--overlay-gps-size);
    display: var(--overlay-gps-visible);
    text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.8), 0px 0px 10px rgba(0, 0, 0, 0.5);
    z-index: 10;
    font-weight: 600;
    pointer-events: none;
    line-height: 1.2;
}

.overlay-gps .country {
    font-size: 0.75em;
    /* 1 / 0.75 = 1.333 -> Stadt ist 33% größer als das Land */
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
}

.overlay-exif {
    position: absolute;
    bottom: 15px;
    left: 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: var(--overlay-exif-size);
    display: var(--overlay-exif-visible);
    text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.8);
    z-index: 10;
    font-weight: 300;
    pointer-events: none;
}

.overlay-year {
    position: absolute;
    bottom: 15px;
    right: 30px;
    color: #ffffff;
    opacity: 0.6;
    font-size: var(--year-size, 8rem);
    display: var(--year-display, none);
    text-shadow:
        0px 0px 10px rgba(0, 0, 0, 0.9),
        -1px -1px 0 rgba(0, 0, 0, 0.9),
        1px -1px 0 rgba(0, 0, 0, 0.9),
        -1px 1px 0 rgba(0, 0, 0, 0.9),
        1px 1px 0 rgba(0, 0, 0, 0.9);
    z-index: 5;
    font-weight: 800;
    pointer-events: none;
    line-height: 1;
}

.overlay-stars {
    position: absolute;
    top: 15px;
    right: 20px;
    color: rgba(255, 255, 255, 0.4);
    font-size: var(--overlay-stars-size, 20px);
    display: var(--overlay-stars-visible, none);
    z-index: 20;
    pointer-events: auto; /* Klickbar! */
    gap: 5px;
    text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.8), 0px 0px 10px rgba(0, 0, 0, 0.5);
}

.overlay-stars .star {
    cursor: pointer;
    transition: transform 0.2s ease, color 0.1s ease;
}

.overlay-stars .star:hover {
    transform: scale(1.3);
}

.overlay-stars .star.hover,
.overlay-stars .star.active {
    color: #ffd700;
    text-shadow: 0px 0px 8px rgba(255, 215, 0, 0.8);
}

/* =========================================
   Remote Rating Stars (Mobile Friendly)
   ========================================= */
.remote-stars {
    display: inline-flex;
    justify-content: center;
    gap: 12px;
}

.remote-star {
    font-size: 2.5rem; /* Large enough for thumbs */
    color: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: transform 0.15s ease, color 0.15s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.remote-star.active {
    color: #ffd700;
    text-shadow: 0px 0px 10px rgba(255, 215, 0, 0.6);
}

.remote-star:active {
    transform: scale(0.85);
}

/* =========================================
   QR Code Overlay
   ========================================= */
.qr-container {
    position: fixed;
    z-index: 5002;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.qr-container.hidden {
    display: none !important;
}

.qr-container.small {
    top: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    border-radius: 12px;
}

.qr-container.small img {
    width: 44px;
    height: 44px;
    border-radius: 6px;
}

.qr-container.large {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: fit-content;
    height: fit-content;
    max-width: 95vw;
    max-height: 95vh;
    border-radius: 20px;
    box-shadow: 0 20px 80px rgba(0, 0, 0, 0.9);
    padding: 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.qr-container.large img {
    /* Set width/height constraints ensuring it stays square */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(95vh - 120px);
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    margin-top: 0;
    margin-bottom: 20px;
    background: white;
    /* Ensures contract for QR scanner */
    padding: 10px;
    box-sizing: border-box;
    object-fit: contain;
    /* Keep width and height equal so the padding forms a perfect square */
    display: block;
}

#qr-instruction {
    color: white;
    font-size: 1.1rem;
    font-weight: 600;
    transition: opacity 0.3s ease;
    text-align: center;
    max-width: 100%;
}

#qr-url {
    color: #ffeb3b;
    /* Vibrant Yellow */
    font-size: 1.2rem;
    font-weight: 400;
    margin-top: 5px;
    transition: opacity 0.3s ease;
    word-break: normal;
    overflow-wrap: normal;
    white-space: nowrap;
    text-align: center;
    max-width: 100%;
}

.qr-container.small #qr-instruction,
.qr-container.small #qr-url {
    opacity: 0;
    position: absolute;
    pointer-events: none;
}

.qr-container.large #qr-instruction,
.qr-container.large #qr-url {
    opacity: 1;
}

/* Remote-specific URL constraints to prevent wrapping and utilize zoom */
body.remote-body #qr-url {
    /* Use clamp for dynamic scaling: minimum 0.5rem (so it fits on small phones), preferred ~4vw, maximum 1.2rem */
    font-size: clamp(0.5rem, 4vw, 1.2rem);
}

/* Gallery-specific larger QR sizes (+ 1/3) */
body:not(.remote-body) .qr-container.small {
    width: 80px;
    height: 80px;
    border-radius: 16px;
}

body:not(.remote-body) .qr-container.small img {
    width: 60px;
    height: 60px;
    border-radius: 8px;
}

body:not(.remote-body) .qr-container.large {
    width: fit-content;
    height: fit-content;
    max-width: 50vw;
    max-height: 50vh;
    border-radius: 5px;
    z-index: 9999;
}

/* Toast Notifications */
.toast-notification {
    position: fixed;
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 30px;
    border-radius: 30px;
    font-size: 1.5rem;
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.toast-notification.show {
    opacity: 1;
}

body:not(.remote-body) .qr-container.large img {
    max-width: 100%;
    max-height: calc(50vh - 120px);
    width: auto;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 13px;
    margin-top: 0;
    margin-bottom: 26px;
    padding: 13px;
    box-sizing: border-box;
}

body:not(.remote-body) #qr-instruction {
    font-size: 1.4rem;
}

body:not(.remote-body) #qr-url {
    font-size: clamp(1rem, 2.5vw, 1.8rem);
    margin-top: 8px;
}

/* =========================================
   Remote Control (remote.html) Styles
   ========================================= */
body.remote-body {
    overflow-y: auto;
    /* Allow scrolling on remote */
    padding: 1.5rem;
}

.remote-container {
    max-width: 600px;
    margin: 0 auto;
}

.remote-title {
    text-align: center;
    margin-bottom: 2rem;
    font-weight: 300;
    letter-spacing: 2px;
}

.control-group {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1rem 1.2rem;
    margin-bottom: 1rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.control-group h2 {
    font-size: 1rem;
    margin-bottom: 0.8rem;
    color: #cccccc;
    font-weight: 400;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.3rem;
}

/* Buttons */
.glass-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    backdrop-filter: blur(10px);
}

.glass-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.glass-btn:active {
    transform: translateY(1px);
}

.dropdown-styled {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s ease;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1.2em;
    padding-right: 2.2rem;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.dropdown-styled:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.dropdown-styled:focus {
    outline: none;
    border-color: var(--accent-color);
}

.dropdown-styled option {
    background-color: #1e1e1e;
    color: #ffffff;
    font-weight: 400;
    padding: 10px;
}

.glass-btn.primary {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
    font-weight: 600;
}

.glass-btn.primary:hover {
    background: linear-gradient(135deg, var(--accent-hover), var(--accent-color));
}

.glass-btn.active {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.btn-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
}

/* Sliders */
.slider-group {
    margin-top: 1rem;
}

.slider-group label {
    display: block;
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
    color: #bbbbbb;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--text-color);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* Switch Toggles (Remote) */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* Custom Tree Dropdown for Folders */
.folder-tree-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    color: white;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s ease;
}

.folder-tree-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.folder-tree-item.selected {
    background: rgba(79, 172, 254, 0.2);
    border-left: 3px solid var(--accent-color);
}

.folder-tree-label {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95rem;
}

.folder-tree-toggle {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
    font-size: 0.7rem;
    color: #bbb;
}

.folder-tree-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.folder-tree-children {
    display: none;
    background: rgba(0, 0, 0, 0.2);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    margin-left: 15px;
}

.folder-tree-children.open {
    display: block;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
}

.slider.round {
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.switch input:checked+.slider {
    background-color: var(--accent-color) !important;
}

.switch input:checked+.slider:before {
    transform: translateX(24px);
}

/* =========================================
   REMOTE TABS & NAVIGATION
   ========================================= */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

.remote-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: rgba(20, 20, 20, 0.95);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-tab {
    background: transparent;
    border: none;
    color: #888;
    font-size: 1rem;
    font-weight: 600;
    padding: 10px 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 10px;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.nav-tab.active {
    color: var(--accent-color);
    background: rgba(79, 172, 254, 0.1);
}

/* Add padding to the remote container so the fixed bottom bar doesn't overlap the last item */
.remote-body .remote-container {
    padding-bottom: 120px;
}

/* =========================================
   REMOTE D-PAD
   ========================================= */
.dpad-grid {
    display: grid;
    grid-template-columns: 65px 90px 65px;
    grid-template-rows: 65px 90px 65px;
    gap: 12px;
    margin: 15px 0;
    align-items: center;
    justify-items: center;
    grid-template-areas:
        "top-left up top-right"
        "left center right"
        "bot-left down bot-right";
}

.dpad-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.35rem;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3), inset 0 2px 5px rgba(255, 255, 255, 0.1);
    transition: all 0.15s ease;
}

.dpad-btn.up {
    width: 90px;
    height: 65px;
    border-radius: 35px 35px 20px 20px;
    font-size: 1.15rem;
}

.dpad-btn.down {
    width: 90px;
    height: 65px;
    border-radius: 20px 20px 35px 35px;
    font-size: 1.15rem;
}

.dpad-btn.left {
    width: 65px;
    height: 90px;
    border-radius: 35px 20px 20px 35px;
    font-size: 1.6rem;
}

.dpad-btn.right {
    width: 65px;
    height: 90px;
    border-radius: 20px 35px 35px 20px;
    font-size: 1.6rem;
}

.dpad-btn.skip-left,
.dpad-btn.skip-right {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1rem;
}

.dpad-center-split {
    display: flex;
    flex-direction: row;
    width: 90px;
    height: 65px;
    border-radius: 32px;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

.dpad-btn.center-split {
    flex: 1;
    height: 100%;
    border-radius: 0;
    margin: 0;
    font-size: 1.35rem;
}

.dpad-btn.center-split:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

.dpad-btn.center-split:active {
    background: rgba(255, 255, 255, 0.25);
}

.dpad-btn.center-split.active {
    background: rgba(79, 172, 254, 0.3);
}

.dpad-btn.center-split.left-half {
    border-radius: 32px 0 0 32px;
    border-right: 1px solid rgba(0, 0, 0, 0.3);
}

.dpad-btn.center-split.right-half {
    border-radius: 0 32px 32px 0;
}

.dpad-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(0.92);
}

/* =========================================
   VIDEO PROGRESS BAR (Phase 7)
   ========================================= */
.video-progress-container {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9999;
    display: none;
    /* hidden by default */
}

.video-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-color);
    transition: width 0.1s linear;
}

/* =========================================
   IN-APP REMOTE OVERLAY
   ========================================= */
.btn-inapp-remote {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.btn-inapp-remote:hover {
    background: rgba(0, 0, 0, 0.7);
    color: rgba(255, 255, 255, 1);
    transform: scale(1.1);
    border-color: rgba(79, 172, 254, 0.5);
}

.inapp-remote-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.inapp-remote-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.inapp-remote-container {
    position: relative;
    width: 95%;
    max-width: 450px;
    height: 85vh;
    background: var(--bg-primary);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}

.inapp-remote-container iframe {
    width: 100%;
    flex: 1;
    border: none;
    border-radius: 0 0 20px 20px;
}

.btn-close-remote {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: none;
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s, transform 0.2s;
}

.btn-close-remote:hover {
    background: rgba(255, 50, 50, 0.8);
    transform: scale(1.1);
}

/* =========================================
   MOUSE OSD MENU (Phase 8)
   ========================================= */
.osd-menu {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translate(-50%, calc(100% - 12px));
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 12px 25px;
    display: flex;
    gap: 20px;
    z-index: 3000;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.osd-menu.visible {
    transform: translate(-50%, -20px);
}

/* Touch hint: subtle pill at the bottom, only shown on touch devices */
.osd-touch-hint {
    position: fixed;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    z-index: 2999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

@media (hover: none) and (pointer: coarse) {

    /* Touch/tablet: show the hint pill */
    .osd-touch-hint {
        opacity: 1;
    }
}

.osd-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    font-size: 1.6rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.osd-btn:hover {
    background: rgba(79, 172, 254, 0.5);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

.osd-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
}

/* =========================================
   ADVANCED OSD (Grid Layout)
   ========================================= */
.osd-advanced-container {
    display: grid;
    grid-template-columns: 250px auto;
    /* Left (Sliders), Center (D-Pad) */
    gap: 30px;
    align-items: center;
    justify-content: center;
}

.osd-col {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* OSD Sliders */
.osd-slider-group {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin-bottom: 15px;
}

.osd-slider-icon {
    font-size: 1.2rem;
    color: white;
    width: 25px;
    text-align: center;
}

.osd-slider-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.osd-slider-wrapper label {
    font-size: 0.75rem;
    color: #bbb;
    margin-bottom: 4px;
}

/* Mini D-Pad inside OSD */
.dpad-grid.mini {
    grid-template-areas:
        "top-left up top-right"
        "left center right"
        "bot-left down bot-right";
    grid-template-columns: 50px 60px 50px;
    grid-template-rows: 50px 60px 50px;
    gap: 8px;
    margin: 0;
}

.dpad-grid.mini .dpad-btn {
    width: 44px;
    height: 44px;
    font-size: 1rem;
}

.dpad-grid.mini .dpad-btn.up {
    width: 60px;
    height: 50px;
    border-radius: 25px 25px 12px 12px;
}

.dpad-grid.mini .dpad-btn.down {
    width: 60px;
    height: 50px;
    border-radius: 12px 12px 25px 25px;
}

.dpad-grid.mini .dpad-btn.left {
    width: 50px;
    height: 60px;
    border-radius: 25px 12px 12px 25px;
    font-size: 1.2rem;
}

.dpad-grid.mini .dpad-btn.right {
    width: 50px;
    height: 60px;
    border-radius: 12px 25px 25px 12px;
    font-size: 1.2rem;
}

.dpad-grid.mini .dpad-center-split {
    width: 70px;
    height: 50px;
    border-radius: 25px;
}

.dpad-grid.mini .dpad-btn.center-split {
    width: 100%;
    height: 100%;
    font-size: 1rem;
    border-radius: 0;
}

.dpad-grid.mini .dpad-btn.center-split.left-half {
    border-radius: 25px 0 0 25px;
}

.dpad-grid.mini .dpad-btn.center-split.right-half {
    border-radius: 0 25px 25px 0;
}

/* Interval Row under D-Pad */
.osd-interval-row {
    margin-top: 15px;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
}

.osd-interval-row span {
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
}

/* OSD QR Canvas embed */
#osd-qr-canvas {
    border-radius: 8px;
    background: white;
    padding: 5px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

/* Active Mode toggles inside OSD (Play, Sound, etc.) */
.osd-menu .dpad-btn.active,
.osd-menu .osd-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-hover);
    color: #fff;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
.modal-overlay.hidden {
    display: none;
}
.modal-content {
    background: #1e1e1e;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 20px;
    width: 90%;
    max-width: 400px;
    color: white;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* TV Overlay Title Banner */
.overlay-title {
    position: absolute;
    display: var(--overlay-title-display, block);
    /* Floating Card Layout */
    bottom: var(--overlay-title-bottom-gap, 0px);
    left: var(--overlay-title-horizontal-gap, 0px);
    right: var(--overlay-title-horizontal-gap, 0px);
    width: auto; /* Allow gaps to work */
    
    background-color: var(--overlay-title-bg, rgba(0, 0, 0, 0.5));
    backdrop-filter: blur(var(--overlay-title-blur, 0px));
    -webkit-backdrop-filter: blur(var(--overlay-title-blur, 0px));
    color: white;
    padding: 0.8rem 2rem;
    box-sizing: border-box;
    z-index: 20;
    font-family: inherit;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    border-radius: var(--overlay-title-border-radius, 0px);
    transition: background-color 0.3s ease, bottom 0.3s ease, left 0.3s ease, right 0.3s ease, border-radius 0.3s ease, backdrop-filter 0.3s ease;
}
.overlay-title h1 {
    font-size: var(--overlay-title-size, 2rem);
    margin: 0; 
    font-weight: 300;
    padding-right: 150px; /* Leave enough space for action icons (Title, Desc, Links, Edit) */
}
.overlay-title p {
    display: var(--overlay-desc-display, block);
    font-size: calc(var(--overlay-title-size, 2rem) * 0.6);
    margin: 0.5rem 0 0 0;
    color: #ddd;
    line-height: 1.4;
    padding-right: 150px;
}

/* Ensure text respects global settings even in grid mode, but keep compact padding for action icons */
.gallery:not(.layout-1) .overlay-title h1 {
    padding-right: 40px; /* Only leave space for the edit icon */
}

.gallery:not(.layout-1) .overlay-title p {
    padding-right: 40px;
}

/* Quick TV Actions Container inside Title Banner */
.overlay-actions-top-right {
    position: absolute;
    top: 0.5rem;
    right: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
    justify-content: flex-end;
}

.overlay-title:hover .overlay-actions-top-right,
.overlay-title.active .overlay-actions-top-right {
    opacity: 1;
    pointer-events: auto;
}

/* Elegant Hover Menu Groups */
.action-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.action-icon {
    width: 32px;
    height: 32px;
    border-radius: 50% !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--overlay-title-size, 2rem) * 0.35) !important;
    background: rgba(255,255,255,0.1) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    pointer-events: auto !important;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.action-icon:hover {
    background: rgba(255,255,255,0.25) !important;
    transform: scale(1.05);
}

.action-tooltip {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: rgba(20,20,20,0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    color: #eee;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 100;
}

/* JS-controlled visibility class (replaces unreliable CSS :hover) */
.action-tooltip.tooltip-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.action-tooltip.tooltip-upwards {
    top: auto;
    bottom: calc(100% + 6px);
    transform: translateY(8px);
}

.action-tooltip.tooltip-upwards.tooltip-visible {
    transform: translateY(0);
}

.action-tooltip-link {
    display: flex;
    flex-direction: column;
    gap: 8px;
    white-space: normal;
}

.tooltip-link-label {
    font-weight: 500;
    margin-bottom: 2px;
    word-break: break-all;
}

.tooltip-copy-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    align-self: flex-start;
    font-size: 13px;
    transition: background 0.2s;
}

.tooltip-copy-btn:hover {
    background: rgba(255,255,255,0.2);
}