/* === Custom Media Player === */
.mp-wrapper {
    position: relative;
    width: 100%;
}

.mp-wrapper.mp-video {
    background: var(--player-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
    line-height: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.mp-wrapper.mp-video.mp-pending-metadata {
    aspect-ratio: 16 / 9;
}

/* Wrapper inside .player-container already has its own border-radius */
.player-container .mp-wrapper.mp-video {
    border-radius: 0;
    height: 100%;
}

body:not(.theater-mode) .player-container .mp-wrapper.mp-video video {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
    position: absolute;
    inset: 0;
}

body.theater-mode .player-layout .player-container .mp-wrapper.mp-video {
    height: auto;
}

/* Keep the actual video/audio element full width */
.mp-wrapper video,
.mp-wrapper audio {
    width: 100%;
    display: block;
}

.mp-wrapper.mp-video video {
    max-height: 80vh;
    -webkit-tap-highlight-color: transparent;
}

.mp-wrapper.mp-video.mp-pending-metadata video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}

/* Fullscreen: video fills the entire screen */
.mp-wrapper.mp-video:fullscreen,
.mp-wrapper.mp-video:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.mp-wrapper.mp-video:fullscreen video,
.mp-wrapper.mp-video:-webkit-full-screen video {
    flex: 1;
    width: 100%;
    height: 0; /* flex sizes it to fill remaining space */
    max-height: none;
    object-fit: contain;
}

/* --- Overlay (video only): big play icon when paused --- */
.mp-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mp-overlay-icon {
    width: 64px;
    height: 64px;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.mp-video.mp-paused .mp-overlay-icon {
    opacity: 1;
}

.mp-overlay-icon svg {
    width: 30px;
    height: 30px;
    color: #fff;
    margin-left: 3px; /* optical centering for play triangle */
}

/* --- Loading spinner (video only) --- */
.mp-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 5;
    animation: mp-spin 0.8s linear infinite;
    transition: opacity 0.2s ease;
}

.mp-spinner.mp-spinner-visible {
    opacity: 1;
}

/* Hide spinner when paused — overlay play icon takes precedence */
.mp-video.mp-paused .mp-spinner {
    opacity: 0;
}

@keyframes mp-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* --- Controls bar --- */
.mp-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    line-height: 1;
}

/* Video: absolute overlay at bottom, fades in on hover/pause */
.mp-video .mp-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    background: transparent;
    padding: 0.85rem 0.9rem 0.8rem;
    opacity: 0;
    transform: translateY(8px);
    transition:
        opacity 0.24s ease,
        transform 0.24s ease;
    will-change: opacity, transform;
    pointer-events: none;
}

.mp-status-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: stretch;
    padding: 0.85rem 0.9rem 0.6rem;
    opacity: 0;
    transform: translateY(-8px);
    transition:
        opacity 0.24s ease,
        transform 0.24s ease;
    will-change: opacity, transform;
    pointer-events: none;
}

.mp-status-top::before {
    content: "";
    position: absolute;
    inset: 0 0 -78px;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.7) 0%,
        rgba(0, 0, 0, 0.5) 34%,
        rgba(0, 0, 0, 0.24) 66%,
        rgba(0, 0, 0, 0.06) 90%,
        rgba(0, 0, 0, 0) 100%
    );
    pointer-events: none;
    z-index: 0;
    opacity: 1;
}

.mp-status-top > * {
    position: relative;
    z-index: 1;
}

.mp-video .mp-controls::before {
    content: "";
    position: absolute;
    inset: -78px 0 0;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.7) 0%,
        rgba(0, 0, 0, 0.5) 34%,
        rgba(0, 0, 0, 0.24) 66%,
        rgba(0, 0, 0, 0.06) 90%,
        rgba(0, 0, 0, 0) 100%
    );
    pointer-events: none;
    z-index: 0;
    opacity: 1;
}

.mp-video .mp-controls > * {
    position: relative;
    z-index: 1;
}

.mp-skip-hints {
    display: none;
}

.mp-controls-top {
    display: flex;
    align-items: center;
    width: 100%;
}

.mp-controls-bottom {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.mp-control-bubble {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.22rem;
    min-height: 2.35rem;
    padding: 0.2rem 0.28rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mp-audio .mp-control-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.mp-control-bubble-play {
    padding-inline: 0.24rem;
}

.mp-control-bubble-transport {
    gap: 0.08rem;
    padding-inline: 0.24rem;
}

.mp-control-bubble-volume {
    padding-inline: 0.24rem 0.45rem;
    overflow: visible;
}

.mp-control-bubble-theater {
    margin-left: auto;
    padding-inline: 0.24rem;
}

.mp-control-bubble-actions {
    padding-inline: 0.24rem;
}

.mp-tag-status {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    width: 100%;
}

.mp-status-top .mp-tag-status-item {
    background: rgba(0, 0, 0, 0.55);
    border-color: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mp-tag-status-item {
    position: relative;
    display: grid;
    align-content: center;
    gap: 0.28rem;
    min-width: 0;
    min-height: 3.05rem;
    padding: 0.56rem 0.65rem;
    border-radius: 0.7rem;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.52);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

.mp-tag-status-button {
    appearance: none;
    text-align: left;
    color: inherit;
    cursor: pointer;
    transition:
        background var(--transition),
        border-color var(--transition),
        transform var(--transition);
}

.mp-tag-status-button:hover,
.mp-tag-status-button:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.mp-tag-status-button:disabled {
    cursor: default;
}

.mp-tag-status-button:disabled:hover,
.mp-tag-status-button:disabled:focus-visible {
    background: rgba(0, 0, 0, 0.52);
    border-color: rgba(255, 255, 255, 0.08);
    transform: none;
}

.mp-tag-status-label {
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.62);
    line-height: 1;
}

.mp-tag-status-value {
    min-width: 0;
    font-size: 0.77rem;
    font-weight: 600;
    line-height: 1.28;
    color: rgba(255, 255, 255, 0.96);
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: anywhere;
}

.mp-control-bubble-actions .mp-btn,
.mp-control-bubble-theater .theater-overlay-toggle {
    min-height: 2.1rem;
}

.mp-video:not(.mp-paused, .mp-controls-visible),
.mp-video:not(.mp-paused, .mp-controls-visible) * {
    cursor: none;
}

.mp-video.mp-paused .mp-status-top,
.mp-video.mp-controls-visible .mp-status-top,
.mp-video.mp-paused .mp-controls,
.mp-video.mp-controls-visible .mp-controls {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Audio: static bar with glassmorphism */
.mp-audio .mp-controls {
    background: var(--bg-tertiary);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow);
    margin-top: 6px;
}

/* --- Buttons --- */
.mp-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background var(--transition);
    flex-shrink: 0;
    line-height: 0;
}

.mp-control-bubble .mp-btn {
    border-radius: 999px;
}
