/* ===== CSS Variables & Design Tokens - New Year Celebration Theme ===== */
:root {
    /* Colors - Midnight Blue New Year's Eve Theme */
    --bg-primary: #0c1445;
    --bg-secondary: #111c52;
    --bg-tertiary: #1a2568;
    --bg-card: rgba(20, 30, 90, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --bg-glass-hover: rgba(255, 255, 255, 0.1);

    /* Accent Colors - Festive Gold & Red */
    --accent-primary: #ffd700;
    --accent-secondary: #ff4757;
    --accent-tertiary: #ff6b81;
    --accent-highlight: #00d4ff;
    --accent-gold: linear-gradient(135deg, #ffd700, #ffaa00, #ffd700);

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-tertiary: #a0a0a0;
    --text-muted: #666680;

    /* Border Colors */
    --border-primary: rgba(255, 215, 0, 0.2);
    --border-secondary: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(255, 215, 0, 0.4);

    /* Shadows - Glowing */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(255, 215, 0, 0.3);
    --shadow-glow-red: 0 0 20px rgba(255, 71, 87, 0.3);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;

    /* Z-index */
    --z-toolbar: 100;
    --z-overlay: 200;
    --z-modal: 300;
    --z-toast: 400;
    --z-fireworks: 50;

    /* Layout */
    --toolbar-height: 64px;
    --grid-gap: 4px;
}

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

html {
    font-size: 16px;
}

body {
    position: relative;
    z-index: 0;
    font-family: var(--font-family);
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at top, rgba(255, 215, 0, 0.07) 0%, transparent 50%),
        radial-gradient(ellipse at bottom, rgba(255, 71, 87, 0.06) 0%, transparent 50%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ===== Starfield & Sparkle Ambience (CSS only) ===== */
body::before,
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-repeat: no-repeat;
}

/* Layer 1: faint white stars scattered across the night sky */
body::before {
    background-image:
        radial-gradient(1.5px 1.5px at 8% 15%, #fff 50%, transparent 100%),
        radial-gradient(1px 1px at 18% 42%, rgba(255, 255, 255, 0.85) 50%, transparent 100%),
        radial-gradient(1px 1px at 32% 8%, rgba(255, 255, 255, 0.7) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 45% 65%, #fff 50%, transparent 100%),
        radial-gradient(1px 1px at 58% 25%, rgba(255, 255, 255, 0.75) 50%, transparent 100%),
        radial-gradient(1px 1px at 68% 78%, rgba(255, 255, 255, 0.8) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 78% 38%, #fff 50%, transparent 100%),
        radial-gradient(1px 1px at 85% 62%, rgba(255, 255, 255, 0.7) 50%, transparent 100%),
        radial-gradient(1px 1px at 92% 12%, rgba(255, 255, 255, 0.85) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 12% 82%, #fff 50%, transparent 100%),
        radial-gradient(1px 1px at 25% 92%, rgba(255, 255, 255, 0.7) 50%, transparent 100%),
        radial-gradient(1px 1px at 96% 88%, rgba(255, 255, 255, 0.75) 50%, transparent 100%);
    animation: starTwinkle 4s ease-in-out infinite alternate;
}

/* Layer 2: warm gold sparkle glints, a little slower & offset for depth */
body::after {
    background-image:
        radial-gradient(2px 2px at 15% 30%, rgba(255, 215, 0, 0.9) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 40% 12%, rgba(255, 215, 0, 0.7) 50%, transparent 100%),
        radial-gradient(2px 2px at 62% 55%, rgba(255, 215, 0, 0.8) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 82% 22%, rgba(255, 215, 0, 0.7) 50%, transparent 100%),
        radial-gradient(2px 2px at 90% 70%, rgba(255, 215, 0, 0.75) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 30% 75%, rgba(255, 215, 0, 0.65) 50%, transparent 100%);
    animation: starTwinkle 5.5s ease-in-out infinite alternate;
    animation-delay: 1.2s;
}

@keyframes starTwinkle {
    0% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.85;
    }

    100% {
        opacity: 0.4;
    }
}

/* ===== Toolbar ===== */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    background: rgba(10, 10, 26, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    z-index: var(--z-toolbar);
    transition: transform var(--transition-normal);
    box-shadow: var(--shadow-md), 0 1px 0 rgba(255, 215, 0, 0.1);
}

.toolbar.hidden {
    transform: translateY(-100%);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.toolbar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.5));
}

.logo-text {
    font-size: var(--font-size-lg);
    font-weight: 600;
    background: var(--accent-gold);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

/* ===== Status Indicator ===== */
.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-glass);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-primary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-secondary);
    box-shadow: 0 0 10px var(--accent-secondary);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

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

    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

.status-text {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* ===== Countdown Display ===== */
.countdown-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-md);
    background: var(--bg-glass);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-primary);
}

.countdown-label {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
}

.countdown-time {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    background: var(--accent-gold);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-variant-numeric: tabular-nums;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.55));
}

.countdown-display.celebration .countdown-time {
    animation: celebrationPulse 0.5s ease infinite;
}

@keyframes celebrationPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* ===== Toolbar Buttons ===== */
.toolbar-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-glass);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.toolbar-btn:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-primary);
    color: var(--text-primary);
}

.toolbar-btn.primary {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 170, 0, 0.2));
    border-color: var(--border-accent);
    color: var(--accent-primary);
}

.toolbar-btn.primary:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 170, 0, 0.3));
    box-shadow: var(--shadow-glow);
}

.toolbar-btn.muted svg {
    opacity: 0.5;
}

/* ===== Video Grid Container ===== */
.video-grid-container {
    padding-top: var(--toolbar-height);
    min-height: 100vh;
    padding-bottom: var(--spacing-xl);
}

/* ===== Video Grid ===== */
.video-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--grid-gap);
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
    padding: var(--spacing-md);
}

/* Each video cell has fixed aspect ratio */
.video-grid .video-cell {
    aspect-ratio: 16 / 9;
}

/* ===== Video Cell ===== */
.video-cell {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: all var(--transition-normal);
}

.video-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    pointer-events: none;
    z-index: 1;
    transition: all var(--transition-fast);
}

.video-cell:hover::before {
    border-color: var(--accent-primary);
    box-shadow: inset 0 0 20px rgba(255, 215, 0, 0.1);
}

.video-cell iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ===== Video Number Badge ===== */
.video-number {
    position: absolute;
    top: var(--spacing-xs);
    left: var(--spacing-xs);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent-primary), #ffaa00);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 700;
    color: #000;
    z-index: 2;
    opacity: 0;
    transition: opacity var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.video-cell:hover .video-number {
    opacity: 1;
}

/* ===== Video Name Label ===== */
.video-name {
    position: absolute;
    bottom: var(--spacing-xs);
    left: var(--spacing-xs);
    right: var(--spacing-xs);
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: #fff;
    z-index: 2;
    opacity: 0;
    transition: opacity var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.video-cell:hover .video-name {
    opacity: 1;
}

/* ===== Expand Button ===== */
.expand-btn {
    position: absolute;
    top: var(--spacing-xs);
    right: var(--spacing-xs);
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    z-index: 2;
    opacity: 0;
    transition: all var(--transition-fast);
}

.expand-btn svg {
    width: 14px;
    height: 14px;
}

.video-cell:hover .expand-btn {
    opacity: 1;
}

.expand-btn:hover {
    background: var(--accent-primary);
    color: #000;
    border-color: var(--accent-primary);
}

/* ===== Expanded Overlay ===== */
.expanded-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.expanded-overlay.active {
    opacity: 1;
    visibility: visible;
}

.expanded-close {
    position: absolute;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: var(--text-primary);
    cursor: pointer;
    z-index: 1;
    transition: all var(--transition-fast);
}

.expanded-close svg {
    width: 24px;
    height: 24px;
}

.expanded-close:hover {
    background: var(--accent-primary);
    color: #000;
    border-color: var(--accent-primary);
}

.expanded-video {
    width: 100%;
    max-width: 1280px;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-glow);
}

.expanded-video iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    bottom: var(--spacing-lg);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-sm);
    animation: slideUp 0.3s ease;
}

.toast.success {
    border-color: var(--accent-primary);
}

.toast.success::before {
    content: '✓';
    color: var(--accent-primary);
    font-weight: bold;
}

.toast.error {
    border-color: var(--accent-secondary);
}

.toast.error::before {
    content: '✕';
    color: var(--accent-secondary);
    font-weight: bold;
}

.toast.info {
    border-color: var(--accent-highlight);
}

.toast.info::before {
    content: 'ℹ';
    color: var(--accent-highlight);
    font-weight: bold;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Fireworks Container ===== */
.fireworks-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: var(--z-fireworks);
    overflow: hidden;
}

.firework {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    animation: fireworkExplode 1.5s ease-out forwards;
}

@keyframes fireworkExplode {
    0% {
        transform: scale(0);
        opacity: 1;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: scale(1) translateY(100px);
        opacity: 0;
    }
}

/* ===== Responsive Design ===== */

/* Large Desktop - 4 columns */
@media (min-width: 1201px) {
    .video-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-sm);
    }
}

/* Desktop - 4 columns */
@media (max-width: 1200px) {
    .video-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-sm);
    }
}

/* Medium screens - hide center toolbar */
@media (max-width: 1024px) {
    .toolbar-center {
        display: none;
    }

    .btn-text {
        display: none;
    }

    .countdown-display {
        flex-direction: row;
        gap: var(--spacing-sm);
    }

    .countdown-time {
        font-size: 1.35rem;
    }

    .video-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Landscape mobile - 3 columns */
@media (max-width: 900px) and (orientation: landscape) {
    :root {
        --toolbar-height: 48px;
        --grid-gap: 2px;
    }

    .logo-text {
        display: none;
    }

    .countdown-display {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .countdown-label {
        display: none;
    }

    .countdown-time {
        font-size: 1.1rem;
    }

    .video-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Tablet Portrait - 3 columns */
@media (max-width: 768px) {
    :root {
        --toolbar-height: 56px;
        --grid-gap: 4px;
    }

    .logo-text {
        display: none;
    }

    .toolbar-btn {
        padding: var(--spacing-sm);
    }

    .btn-text {
        display: none;
    }

    .video-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: var(--spacing-sm);
    }

    .expanded-overlay {
        padding: var(--spacing-md);
    }
}

/* Mobile Portrait - 2 columns */
@media (max-width: 480px) {
    :root {
        --toolbar-height: 52px;
        --grid-gap: 4px;
    }

    .toolbar {
        padding: 0 var(--spacing-sm);
    }

    .countdown-display {
        display: none;
    }

    .video-grid {
        grid-template-columns: repeat(2, 1fr);
        padding: var(--spacing-xs);
    }
}

/* Extra small mobile - 1 column */
@media (max-width: 360px) {
    .video-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Fullscreen Mode ===== */
body.fullscreen-mode .toolbar {
    transform: translateY(-100%);
}

body.fullscreen-mode .video-grid-container {
    padding-top: 0;
}

body.fullscreen-mode .video-grid {
    height: 100vh;
}

body.fullscreen-mode:hover .toolbar {
    transform: translateY(0);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* ===== Focus States ===== */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ===== Loading State ===== */
.video-cell.loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-cell.loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-secondary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
