/* ═══════════════════════════════════════════════════════════════
   AV1 Stream Viewer — Stylesheet
   Design: Intentional Minimalism, TS6-adjacent dark aesthetic.
   ═══════════════════════════════════════════════════════════════ */

/* ── Tokens ──────────────────────────────────────────────────── */
:root {
    --bg:           #0e0e10;
    --surface:      #18181b;
    --surface-2:    #1f1f23;
    --border:       #2a2a2e;

    --text:         #efeff1;
    --text-dim:     #adadb8;
    --text-muted:   #636369;

    --accent:       #9147ff;
    --accent-glow:  rgba(145, 71, 255, 0.25);

    --live:         #eb0400;
    --live-glow:    rgba(235, 4, 0, 0.4);
    --success:      #00f593;
    --warning:      #fab908;
    --error:        #eb0400;

    --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:    'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;

    --radius:       8px;
    --radius-sm:    4px;
    --transition:   180ms ease;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Root Container ──────────────────────────────────────────── */
#viewer-root {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: var(--bg);
    cursor: none;
}

#viewer-root.controls-visible {
    cursor: default;
}

/* ── Video ───────────────────────────────────────────────────── */
#video-element {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--bg);
    z-index: 1;
}

/* ── Scanlines (aesthetic overlay) ───────────────────────────── */
.scanlines {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
    mix-blend-mode: multiply;
}

/* ── State Overlay ───────────────────────────────────────────── */
.state-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    transition: opacity 400ms ease, visibility 400ms ease;
}

.state-overlay[data-state="connected"] {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.state-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 360px;
    text-align: center;
}

/* State Icons */
.state-icon {
    width: 48px;
    height: 48px;
    color: var(--text-dim);
}

.state-icon svg {
    width: 100%;
    height: 100%;
    display: none;
}

/* Show the right icon per state */
[data-state="connecting"] .spinner,
[data-state="reconnecting"] .spinner    { display: block; }
[data-state="disconnected"] .signal-icon,
[data-state="waiting"] .signal-icon     { display: block; }
[data-state="error"] .error-icon        { display: block; }

/* Spinner animation */
.spinner {
    animation: spin 1.2s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Waiting state — signal icon pulse */
[data-state="waiting"] .signal-icon,
[data-state="disconnected"] .signal-icon {
    animation: pulse-signal 2s ease-in-out infinite;
}

@keyframes pulse-signal {
    0%, 100% { opacity: 0.5; }
    50%      { opacity: 1; }
}

/* Error state — red tint */
[data-state="error"] .state-icon {
    color: var(--error);
}

.state-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
    letter-spacing: -0.01em;
}

.state-sub {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    min-height: 16px;
}

.retry-btn {
    display: none;
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.retry-btn:hover {
    background: var(--surface-2);
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}

[data-state="error"] .retry-btn {
    display: inline-flex;
}

/* ── HUD ─────────────────────────────────────────────────────── */
.hud {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
    opacity: 0;
    transition: opacity 300ms ease;
}

#viewer-root.controls-visible .hud {
    opacity: 1;
}

.hud-top,
.hud-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    pointer-events: auto;
}

/* Gradient scrims for readability */
.hud-top {
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.6) 0%,
        rgba(0, 0, 0, 0) 100%
    );
    padding-bottom: 40px;
}

.hud-bottom {
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.7) 0%,
        rgba(0, 0, 0, 0) 100%
    );
    padding-top: 40px;
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ── LIVE Badge ──────────────────────────────────────────────── */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--live);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    user-select: none;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
    animation: live-pulse 1.5s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.6); }
    50%      { opacity: 0.6; box-shadow: 0 0 0 4px rgba(255, 255, 255, 0); }
}

/* ── Codec Badge ─────────────────────────────────────────────── */
.codec-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    background: rgba(145, 71, 255, 0.2);
    border: 1px solid rgba(145, 71, 255, 0.4);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.04em;
    user-select: none;
}

/* ── Stats Display ───────────────────────────────────────────── */
.stats-display {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-dim);
    user-select: none;
}

.stat-sep {
    color: var(--text-muted);
    font-size: 8px;
}

/* ── HUD Buttons ─────────────────────────────────────────────── */
.hud-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.hud-btn:active {
    transform: scale(0.95);
}

.hud-btn svg {
    width: 18px;
    height: 18px;
}

/* Mute button icon states */
.icon-unmuted { display: none; }
.icon-muted  { display: block; }

[data-muted="false"] .icon-unmuted { display: block; }
[data-muted="false"] .icon-muted  { display: none; }

/* ── Volume Slider ───────────────────────────────────────────── */
.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.15);
    outline: none;
    cursor: pointer;
    transition: width 200ms ease;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text);
    border: none;
    cursor: pointer;
    transition: transform var(--transition);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

.volume-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text);
    border: none;
    cursor: pointer;
}

/* ── Utility ─────────────────────────────────────────────────── */
[hidden] {
    display: none !important;
}

/* ── Fullscreen adjustments ──────────────────────────────────── */
:fullscreen #viewer-root,
:-webkit-full-screen #viewer-root {
    width: 100vw;
    height: 100vh;
}

/* ── Animation: Fade in video on first frame ─────────────────── */
#video-element {
    opacity: 0;
    transition: opacity 600ms ease;
}

#video-element.playing {
    opacity: 1;
}

/* ── Responsive: Embedded (small container) ──────────────────── */
@media (max-width: 480px) {
    .hud-top, .hud-bottom {
        padding: 10px 12px;
    }

    .stats-display {
        font-size: 9px;
    }

    .volume-slider {
        width: 50px;
    }
}
