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

/* Custom Font */
@font-face {
    font-family: 'Berkeley Mono';
    src: url('../fonts/BerkeleyMono-Regular.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

/* CSS Variables */
:root {
    --bg-primary: #0A0A0A;
    --bg-surface: #141414;
    --border-subtle: #1F1F1F;
    --controls-bg: rgba(0, 0, 0, 0.9);
    --text-primary: #FFFFFF;
    --text-hover: rgba(255, 255, 255, 0.8);
    --text-inactive: rgba(255, 255, 255, 0.4);
    --stream-live: #10B981;
    --no-stream: #6B7280;
    --error-state: #EF4444;
    --loading: #3B82F6;
    --twitch-red: #E91916;
    --duration-gray: #909090;
    --control-height: 48px;
    --margin-base: 16px;
    --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0.0, 0.2, 1);
}

/* Base styles */
html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Berkeley Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh;  /* iOS Safari - use small viewport height */
}

/* Container */
.container {
    width: 100vw;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Player wrapper */
.player-wrapper {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    width: 100vw;
    height: calc(100vh - 40px);
    height: calc(100svh - 40px);  /* iOS Safari - use small viewport height */
    background: var(--bg-surface);
    border-radius: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Video element */
#video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
    display: none;
}

#video.active {
    display: block;
}

/* Big center play button */
.center-play {
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 200ms var(--ease-out);
    backdrop-filter: blur(10px);
}

.center-play:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.center-play:active {
    transform: scale(0.95);
}

.center-play svg {
    width: 48px;
    height: 48px;
    fill: white;
    margin-left: 8px; /* Visual centering for play icon */
}

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

/* Starting message */
.starting-message {
    position: absolute;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 500;
    display: none;
}

.starting-message.visible {
    display: block;
}

/* Controls container */
.controls {
    position: absolute;
    bottom: 0;
    bottom: env(safe-area-inset-bottom, 0px);  /* iOS - position above home indicator */
    left: 0;
    right: 0;
    height: var(--control-height);
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.7) 50%, transparent 100%);
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transition: opacity 250ms var(--ease-out);
    z-index: 10;
}

.controls.visible {
    opacity: 1;
}

/* Control buttons */
.control-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background 150ms var(--ease-out);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Safari fixes */
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.control-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--text-primary);
    /* Safari fixes */
    pointer-events: none;
    flex-shrink: 0;
}

/* Status bar */
.status-bar {
    position: relative;
    width: 100%;
    height: 40px;
    background: #000;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    z-index: 10;
    opacity: 0.8;
}

.status-bar-left {
    flex: 1;
}

.status-bar-right {
    margin-left: 12px;
}

/* Stream status indicator */
.stream-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    text-transform: uppercase;
}

/* Viewer stats container */
.viewer-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

/* Viewer count (heart + number) */
.viewer-count {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--twitch-red);
}

.watching-icon {
    display: inline-flex;
    align-items: center;
    line-height: 1;
}

.viewer-count.pulse {
    animation: pulse-count 500ms ease-out;
}

@keyframes pulse-count {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

/* Stream duration timer */
.stream-duration {
    color: var(--duration-gray);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--no-stream);
    animation: none;
}

.status-dot.live {
    background: var(--stream-live);
    animation: pulse-live 20s infinite;
}

.status-dot.connecting {
    background: var(--loading);
    animation: pulse 1s infinite;
}

@keyframes pulse-live {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.67;
    }
}

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

/* Streamer info - inline with status */
.streamer-info {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.streamer-avatar {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bg-surface);
    object-fit: cover;
    display: inline-block;
    vertical-align: middle;
}

.streamer-name {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    display: inline;
}

/* Volume/unmute button for autoplay */
.unmute-prompt {
    position: absolute;
    bottom: 60px;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));  /* iOS - adjust for home indicator */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 13px;
    display: none;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 150ms var(--ease-out);
}

.unmute-prompt.visible {
    display: flex;
}

.unmute-prompt:hover {
    background: rgba(0, 0, 0, 0.95);
}

/* Hidden class utility */
.hidden {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .center-play {
        width: 100px;
        height: 100px;
    }

    .center-play svg {
        width: 40px;
        height: 40px;
    }

    .starting-message {
        font-size: 16px;
    }
}
