:root {
    --bg: #0b1220;
    --panel: rgba(11, 18, 32, 0.78);
    --panel-strong: rgba(9, 14, 26, 0.9);
    --text: #f7f8fc;
    --text-dim: #b7bfd7;
    --accent: #f97316;
    --accent-soft: #fb923c;
    --timeline-accent: #4c1d95;
    --timeline-unplayed: rgba(148, 163, 184, 0.46);
    --border: rgba(247, 248, 252, 0.16);
    --ok: #22c55e;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    color: var(--text);
    background: #000;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

.app-shell {
    padding: 1rem;
    min-height: 100vh;
    position: relative;
    isolation: isolate;
}

.app-shell::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 22%, rgba(59, 130, 246, 0.46), rgba(30, 64, 175, 0.22) 38%, transparent 68%),
        radial-gradient(circle at 50% 78%, rgba(37, 99, 235, 0.34), rgba(15, 23, 42, 0.08) 44%, transparent 72%);
    filter: blur(68px) saturate(118%);
    pointer-events: none;
    z-index: 0;
}

.layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
    max-width: 1500px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.viewer-panel {
    min-width: 0;
}

@media (min-width: 761px) {
    .layout {
        flex-direction: row;
        align-items: flex-start;
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .layout > .viewer-panel {
        flex: 1 1 0;
    }

    .layout > .viewer-panel .video-shell {
        width: 100%;
        margin: 0;
    }

    .layout > .playlist-panel {
        flex: 0 0 clamp(24rem, 33vw, 36rem);
        max-width: 36rem;
        min-height: calc(100vh - 2rem);
        min-height: calc(100dvh - 2rem);
        height: calc(100vh - 2rem);
        height: calc(100dvh - 2rem);
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - 2rem);
    }

    .layout.theater-mode {
        flex-direction: column;
        align-items: stretch;
    }

    .layout.theater-mode > .viewer-panel .video-shell {
        width: 80%;
        margin: 0 auto;
    }

    .layout.theater-mode > .playlist-panel {
        flex: 1 1 auto;
        width: 100vw;
        max-width: none;
        margin-left: calc(50% - 50vw);
        margin-right: 0;
        min-height: 320px;
        height: auto;
        max-height: none;
        border-radius: 0;
    }
}

.video-shell {
    position: relative;
    width: 50%;
    max-width: 100%;
    margin: 0 auto;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 20px;
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow:
        0 22px 45px rgba(0, 0, 0, 0.42),
        0 0 52px rgba(37, 99, 235, 0.4),
        0 0 120px rgba(30, 64, 175, 0.24);
}

.video-shell.no-ambient-light {
    box-shadow: 0 22px 45px rgba(0, 0, 0, 0.42);
}

.video-shell.theater {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16 / 9;
}

.video-shell:fullscreen,
.video-shell:-webkit-full-screen {
    width: 100vw;
    max-width: none;
    height: 100vh;
    border-radius: 0;
}

.video-shell:fullscreen video,
.video-shell:-webkit-full-screen video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
}

.top-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.44rem 0.62rem 0.78rem;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.76), rgba(0, 0, 0, 0));
}

.top-overlay h1 {
    margin: 0;
    font-size: clamp(0.82rem, 1.35vw, 1rem);
    font-weight: 650;
    letter-spacing: 0.01em;
    line-height: 1.25;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
}

.top-overlay p {
    margin: 0.14rem 0 0;
    color: var(--text-dim);
    font-size: 0.72rem;
    line-height: 1.25;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.center-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 0;
    width: 5.1rem;
    height: 5.1rem;
    border-radius: 999px;
    background: rgba(7, 12, 22, 0.72);
    backdrop-filter: blur(4px);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, opacity 0.16s ease;
}

.center-play:hover {
    transform: translate(-50%, -50%) scale(1.03);
    background: rgba(9, 16, 28, 0.92);
}

.center-play.hidden {
    display: none;
}

.status-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    padding: 0.7rem 0.9rem;
    border-radius: 0.55rem;
    background: rgba(11, 18, 32, 0.84);
    border: 1px solid var(--border);
    font-size: 0.92rem;
    text-align: center;
}

.status-message.error {
    border-color: rgba(248, 113, 113, 0.48);
    color: #fecaca;
}

.status-message.hidden {
    display: none;
}

.nerd-info {
    position: absolute;
    top: 0.56rem;
    left: 0.56rem;
    margin: 0;
    padding: 0.4rem 0.5rem;
    border-radius: 0.46rem;
    border: 1px solid rgba(247, 248, 252, 0.2);
    background: rgba(8, 12, 22, 0.8);
    color: #f7f8fc;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.66rem;
    line-height: 1.35;
    white-space: pre-wrap;
    z-index: 3;
    max-width: min(92%, 36rem);
    pointer-events: none;
}

.interaction-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    color: #fff;
    background: rgba(7, 12, 22, 0.58);
    backdrop-filter: blur(3px);
    z-index: 4;
}

.interaction-indicator::before {
    content: "";
}

.interaction-indicator.is-play::before {
    content: "▶";
    font-size: 2rem;
    margin-left: 0.18rem;
}

@media (min-width: 761px) {
    .interaction-indicator.is-play::before {
        position: relative;
        top: -3px;
    }
}

.interaction-indicator.is-pause::before {
    content: "❚❚";
    font-size: 1.7rem;
    letter-spacing: 0.02rem;
}

.interaction-indicator.is-visible {
    animation: interaction-fade 1s ease;
}

@keyframes interaction-fade {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.84);
    }
    15% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    75% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.08);
    }
}

.resume-toast {
    margin-top: 0.28rem;
    padding: 0.16rem 0.44rem;
    font-size: 0.68rem;
    border-radius: 0.38rem;
    background: rgba(11, 18, 32, 0.9);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #d6ffe5;
    display: inline-block;
}

.controls {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.38rem 0.46rem 0.46rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.84), rgba(0, 0, 0, 0.16));
    border-top: 1px solid rgba(247, 248, 252, 0.1);
}

.top-overlay,
.controls,
.status-message {
    transition: opacity 0.16s ease;
}

.seek-wrap {
    margin-bottom: 0.3rem;
}

.seek-bar {
    --seek-progress: 0%;
    --seek-played: var(--timeline-accent);
    --seek-unplayed: var(--timeline-unplayed);
    width: 100%;
    margin: 0;
    accent-color: var(--timeline-accent);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    height: 1rem;
    background: transparent;
}

.seek-bar::-webkit-slider-runnable-track {
    height: 0.34rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: linear-gradient(
        to right,
        var(--seek-played) 0 var(--seek-progress),
        var(--seek-unplayed) var(--seek-progress) 100%
    );
}

.seek-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -0.34rem;
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    border: 2px solid #fff;
    background: #a78bfa;
    box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.3);
}

.seek-bar::-moz-range-track {
    height: 0.34rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: linear-gradient(
        to right,
        var(--seek-played) 0 var(--seek-progress),
        var(--seek-unplayed) var(--seek-progress) 100%
    );
}

.seek-bar::-moz-range-thumb {
    width: 1rem;
    height: 1rem;
    border-radius: 999px;
    border: 2px solid #fff;
    background: #a78bfa;
    box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.3);
}

@media (hover: hover) and (pointer: fine) {
    .video-shell.ui-idle .top-overlay,
    .video-shell.ui-idle .controls,
    .video-shell.ui-idle .center-play,
    .video-shell.ui-idle .status-message,
    .video-shell:not(:hover) .top-overlay,
    .video-shell:not(:hover) .controls,
    .video-shell:not(:hover) .center-play,
    .video-shell:not(:hover) .status-message {
        opacity: 0;
        pointer-events: none;
    }
}

@media (hover: none), (pointer: coarse) {
    .video-shell.touch-ui-hidden .top-overlay,
    .video-shell.touch-ui-hidden .controls,
    .video-shell.touch-ui-hidden .center-play,
    .video-shell.touch-ui-hidden .status-message,
    .video-shell.touch-ui-hidden .nerd-info {
        opacity: 0;
        pointer-events: none;
    }
}

.time-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.12rem;
    font-size: 0.66rem;
    color: var(--text-dim);
}

.button-wrap {
    display: flex;
    gap: 0.36rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.left-controls,
.right-controls {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.reset-time-btn {
    white-space: nowrap;
    font-size: 0.64rem;
    height: 1.56rem;
    padding: 0 0.5rem;
}

.settings-wrap {
    position: relative;
}

.settings-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.34rem);
    width: min(86vw, 17.5rem);
    padding: 0.44rem;
    border-radius: 0.64rem;
    border: 1px solid var(--border);
    background: rgba(8, 12, 22, 0.96);
    box-shadow: 0 18px 34px rgba(0, 0, 0, 0.44);
    display: grid;
    gap: 0.34rem;
    z-index: 9;
}

.settings-menu[hidden] {
    display: none;
}

.settings-row {
    display: grid;
    gap: 0.26rem;
}

.settings-row span {
    color: var(--text-dim);
    font-size: 0.67rem;
}

.settings-row select {
    width: 100%;
    height: 1.62rem;
    font-size: 0.74rem;
    padding: 0 0.44rem;
}

.settings-menu .settings-action {
    height: 1.62rem;
    padding: 0 0.52rem;
    width: 100%;
    text-align: left;
    font-size: 0.74rem;
}

button,
select,
input[type="search"] {
    color: var(--text);
    border: 1px solid var(--border);
    background: rgba(15, 23, 40, 0.92);
    border-radius: 0.52rem;
}

button {
    cursor: pointer;
    height: 1.56rem;
    padding: 0 0.44rem;
    font-size: 0.69rem;
    line-height: 1;
    transition: border-color 0.14s ease, transform 0.14s ease;
}

button:hover {
    transform: translateY(-1px);
    border-color: rgba(251, 146, 60, 0.66);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

button.is-on {
    border-color: rgba(34, 197, 94, 0.84);
    color: #dcfce7;
}

.icon-btn {
    min-width: 1.56rem;
    padding: 0;
    font-size: 0;
}

.icon-btn::before {
    content: "";
    display: block;
    width: 0.94rem;
    height: 0.94rem;
    margin: 0 auto;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.icon-repeat::before {
    background-image: url("./icons_white/09_repeat.png");
}

.icon-shuffle::before {
    background-image: url("./icons_white/10_shuffle.png");
}

.icon-prev::before {
    background-image: url("./icons_white/03_rewind.png");
}

.icon-next::before {
    background-image: url("./icons_white/05_forward.png");
}

.icon-play::before {
    background-image: url("./icons_white/04_play.png");
    background-size: contain;
}

#playPauseBtn.is-playing::before {
    background-image: url("./icons_white/17_pause.png");
    background-size: contain;
}

.icon-volume::before {
    background-image: url("./icons_white/16_volume_high.png");
}

#muteBtn.is-on::before {
    background-image: url("./icons_white/13_mute.png");
}

.icon-settings::before {
    background-image: url("./icons_white/28_settings.png");
}

.icon-pip::before {
    content: "P";
    background-image: none;
    width: auto;
    height: auto;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

.icon-theater::before {
    content: "T";
    background-image: none;
    width: auto;
    height: auto;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

.icon-fullscreen::before {
    content: "F";
    background-image: none;
    width: auto;
    height: auto;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

select {
    height: 1.56rem;
    padding: 0 0.34rem;
    font-size: 0.66rem;
}

#volumeBar {
    width: 4.2rem;
    accent-color: var(--timeline-accent);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    height: 1rem;
    background: transparent;
}

#volumeBar::-webkit-slider-runnable-track {
    height: 0.26rem;
    border-radius: 999px;
    background: var(--timeline-accent);
}

#volumeBar::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -0.35rem;
    width: 0.96rem;
    height: 0.96rem;
    border-radius: 999px;
    border: 2px solid #fff;
    background: #a78bfa;
    box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.3);
}

#volumeBar::-moz-range-track {
    height: 0.26rem;
    border-radius: 999px;
    background: var(--timeline-accent);
}

#volumeBar::-moz-range-thumb {
    width: 0.96rem;
    height: 0.96rem;
    border-radius: 999px;
    border: 2px solid #fff;
    background: #a78bfa;
    box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.3);
}

.toggle-wrap {
    margin-top: 0.34rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.26rem 0.58rem;
    color: var(--text-dim);
    font-size: 0.64rem;
}

.toggle-wrap label {
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    user-select: none;
}

.toggle-wrap input[type="checkbox"] {
    accent-color: var(--ok);
}

.playlist-panel {
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--panel);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    min-height: 260px;
    max-height: 42vh;
    overflow: hidden;
    box-shadow:
        0 18px 34px rgba(0, 0, 0, 0.32),
        0 0 42px rgba(37, 99, 235, 0.28),
        0 0 98px rgba(30, 64, 175, 0.2);
}

.playlist-head {
    display: none;
    padding: 0.88rem 0.9rem 0.6rem;
    border-bottom: 1px solid var(--border);
    background: var(--panel-strong);
}

.playlist-head h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
}

.playlist-head span {
    display: inline-block;
    margin-top: 0.28rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}

#playlistSearch {
    margin: 0.72rem 0.9rem;
    padding: 0.5rem 0.6rem;
    font-size: 0.86rem;
    outline: none;
}

.folder-filter {
    margin: 0.72rem 0.9rem 0;
    display: grid;
    gap: 0.34rem;
}

.folder-filter label {
    font-size: 0.74rem;
    color: var(--text-dim);
}

.folder-filter select {
    width: 100%;
    height: 1.9rem;
    padding: 0 0.5rem;
    font-size: 0.82rem;
}

.folder-filter:not([hidden]) + #playlistSearch {
    margin-top: 0.5rem;
}

#playlistSearch:focus {
    border-color: rgba(251, 146, 60, 0.78);
}

#playlist {
    list-style: none;
    margin: 0;
    padding: 0 0.5rem 0.65rem;
    overflow: auto;
}

.playlist-item {
    margin: 0;
}

.playlist-item button {
    width: 100%;
    height: auto;
    text-align: left;
    padding: 0.55rem 0.62rem;
    margin: 0.18rem 0;
    border-radius: 0.58rem;
}

.playlist-item.is-active button {
    border-color: rgba(251, 146, 60, 0.96);
    background: rgba(249, 115, 22, 0.2);
}

.playlist-title {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-subtitle {
    margin-top: 0.2rem;
    display: block;
    color: var(--text-dim);
    font-size: 0.74rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-progress {
    margin-top: 0.2rem;
    display: block;
    color: #c4b5fd;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.playlist-empty {
    margin: 0.65rem;
    padding: 0.7rem;
    border-radius: 0.56rem;
    font-size: 0.82rem;
    color: var(--text-dim);
    border: 1px dashed var(--border);
}

@media (max-width: 760px) {
    .app-shell::before {
        display: none;
    }

    .app-shell {
        padding: 0.62rem;
    }

    .video-shell {
        width: 100%;
        max-width: 100%;
        border-radius: 14px;
        box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
    }

    .center-play,
    .interaction-indicator {
        backdrop-filter: none;
    }

    .top-overlay {
        display: none;
    }

    .status-message {
        top: 0.56rem;
        left: 0.56rem;
        right: auto;
        transform: none;
        margin: 0;
        padding: 0.3rem 0.5rem;
        max-width: min(84%, 14rem);
        font-size: 0.76rem;
        text-align: left;
        z-index: 7;
    }

    #videoTitle,
    #videoMeta {
        display: none;
    }

    .controls {
        top: 0;
        bottom: 0;
        padding: 0;
        border-top: 0;
        background: none;
        display: grid;
        pointer-events: none;
    }

    .button-wrap {
        position: static;
        justify-self: center;
        align-self: center;
        margin: 0;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        flex-wrap: nowrap;
        gap: 0.34rem;
        overflow: visible;
        white-space: normal;
        -webkit-overflow-scrolling: touch;
        pointer-events: auto;
        scrollbar-width: none;
        z-index: 5;
    }

    .button-wrap::-webkit-scrollbar {
        display: none;
    }

    .left-controls,
    .right-controls {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.3rem;
        flex-wrap: nowrap;
        flex: 0 0 auto;
    }

    .controls .icon-btn {
        display: none;
    }

    .reset-time-btn {
        display: none;
    }

    #prevBtn,
    #playPauseBtn,
    #nextBtn,
    #fullscreenBtn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #fullscreenBtn {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(calc(-50% - 2px), calc(-50% - 2.9rem - 20px));
        z-index: 6;
    }

    #fullscreenBtn::before {
        position: relative;
        top: 2px;
    }

    #playPauseBtn {
        min-width: 3.22rem;
        width: 3.22rem;
        height: 3.22rem;
        border-radius: 999px;
    }

    #prevBtn {
        margin-right: 30px;
    }

    #nextBtn {
        margin-left: 30px;
    }

    #prevBtn::before,
    #nextBtn::before {
        width: 1.18rem;
        height: 1.18rem;
    }

    #playPauseBtn::before {
        width: 1.22rem;
        height: 2.28rem;
        background-size: contain;
    }

    #playPauseBtn:not(.is-playing)::before {
        background-position: calc(50% + 2px) center;
    }

    #volumeBar {
        display: none;
    }

    .seek-wrap {
        position: absolute;
        left: 0.34rem;
        right: 0.34rem;
        bottom: 0.34rem;
        margin-top: 0;
        margin-bottom: 0;
        pointer-events: auto;
    }

    #seekBar {
        -webkit-appearance: none;
        appearance: none;
        height: 1.5rem;
        background: transparent;
    }

    #seekBar::-webkit-slider-runnable-track {
        height: 0.5rem;
        border-radius: 999px;
        background: linear-gradient(
            to right,
            var(--seek-played) 0 var(--seek-progress),
            var(--seek-unplayed) var(--seek-progress) 100%
        );
        border: 1px solid rgba(255, 255, 255, 0.24);
    }

    #seekBar::-webkit-slider-thumb {
        -webkit-appearance: none;
        appearance: none;
        margin-top: -0.37rem;
        width: 1.18rem;
        height: 1.18rem;
        border-radius: 999px;
        border: 2px solid #fff;
        background: #a78bfa;
        box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.38);
    }

    #seekBar::-moz-range-track {
        height: 0.5rem;
        border-radius: 999px;
        background: linear-gradient(
            to right,
            var(--seek-played) 0 var(--seek-progress),
            var(--seek-unplayed) var(--seek-progress) 100%
        );
        border: 1px solid rgba(255, 255, 255, 0.24);
    }

    #seekBar::-moz-range-thumb {
        width: 1.18rem;
        height: 1.18rem;
        border-radius: 999px;
        border: 2px solid #fff;
        background: #a78bfa;
        box-shadow: 0 0 0 2px rgba(76, 29, 149, 0.38);
    }

    button,
    select {
        height: 1.46rem;
    }

    .icon-btn {
        min-width: 1.61rem;
        height: 1.61rem;
    }

    .icon-btn::before {
        width: 1.03rem;
        height: 1.03rem;
    }

    .icon-pip::before,
    .icon-theater::before,
    .icon-fullscreen::before {
        font-size: 0.79rem;
    }

    .settings-menu {
        width: min(92vw, 15.8rem);
    }
}
