:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-tertiary: #1a1a25;
    --bg-card: #161620;
    --bg-hover: #1e1e2e;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

/* Background Animations */
.bg-mesh {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; opacity: 0.4;
    background: radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
                radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.1) 0%, transparent 50%),
                radial-gradient(ellipse at 50% 80%, rgba(59, 130, 246, 0.1) 0%, transparent 50%);
}
.bg-grid {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1; opacity: 0.03;
    background-image: linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px);
    background-size: 50px 50px;
}

/* Layout */
.app-container { max-width: 1200px; margin: 0 auto; padding: 24px; min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.header { text-align: center; padding: 40px 0 32px; animation: fadeInDown 0.6s ease-out; }
.logo { display: inline-flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.logo-icon { width: 48px; height: 48px; background: linear-gradient(135deg, var(--accent), #8b5cf6); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 24px; box-shadow: var(--shadow-glow); }
.logo-text { font-size: 28px; font-weight: 700; background: linear-gradient(135deg, var(--text-primary), var(--accent-hover)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.header-subtitle { color: var(--text-secondary); font-size: 16px; max-width: 500px; margin: 0 auto; }

/* Inputs */
.input-section { max-width: 800px; margin: 0 auto 32px; width: 100%; animation: fadeInUp 0.6s ease-out 0.1s both; }
.input-wrapper { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: 6px; display: flex; gap: 8px; transition: all 0.3s ease; box-shadow: var(--shadow-md); }
.input-wrapper:focus-within { border-color: var(--accent); box-shadow: var(--shadow-glow), var(--shadow-md); }
.url-input { flex: 1; background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 15px; padding: 14px 18px; }
.url-input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn-primary { background: linear-gradient(135deg, var(--accent), #8b5cf6); color: white; border: none; padding: 14px 32px; border-radius: var(--radius-lg); font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.3s; white-space: nowrap; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow), var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border); padding: 10px 20px; border-radius: var(--radius-md); font-size: 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; transition: all 0.2s; text-decoration: none; }
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--accent); }

/* States */
.loading-container { display: none; text-align: center; padding: 60px 20px; animation: fadeIn 0.3s ease; }
.loading-container.active { display: block; }
.spinner { width: 56px; height: 56px; border: 3px solid var(--bg-tertiary); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 24px; position: relative; }
.spinner::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid transparent; border-top-color: rgba(99, 102, 241, 0.3); animation: spin 1.2s linear infinite reverse; }
.loading-text { color: var(--text-secondary); font-size: 16px; }
.loading-subtext { color: var(--text-muted); font-size: 13px; margin-top: 8px; }
.error-container { display: none; background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2); border-radius: var(--radius-md); padding: 20px 24px; margin: 20px auto; max-width: 800px; animation: shake 0.5s ease; }
.error-container.active { display: flex; align-items: center; gap: 12px; }
.error-icon { font-size: 24px; flex-shrink: 0; color: var(--error); }
.error-title { font-weight: 600; color: var(--error); margin-bottom: 4px; }
.error-message { color: var(--text-secondary); font-size: 14px; }

/* Video Player */
.video-card { display: none; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-xl); overflow: hidden; margin-top: 24px; animation: fadeInUp 0.5s ease-out; box-shadow: var(--shadow-lg); }
.video-card.active { display: block; }
.player-wrapper { position: relative; background: #000; aspect-ratio: 16/9; overflow: hidden; }
video { width: 100%; height: 100%; display: block; }
.big-play-btn { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80px; height: 80px; background: rgba(99, 102, 241, 0.9); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-size: 32px; cursor: pointer; opacity: 0; transition: all 0.3s ease; backdrop-filter: blur(10px); z-index: 10; }
.player-wrapper.paused .big-play-btn { opacity: 1; }
.big-play-btn:hover { transform: translate(-50%, -50%) scale(1.1); background: var(--accent); box-shadow: 0 0 30px var(--accent-glow); }

/* Close Player Button */
.close-player-btn {
    position: absolute; top: 16px; right: 16px; background: rgba(0, 0, 0, 0.5); border: 1px solid rgba(255, 255, 255, 0.1); color: white; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 20; font-size: 18px; transition: all 0.2s ease; backdrop-filter: blur(4px); opacity: 0; pointer-events: none;
}
.player-wrapper:hover .close-player-btn, .player-wrapper.paused .close-player-btn { opacity: 1; pointer-events: all; }
.close-player-btn:hover { background: rgba(239, 68, 68, 0.9); border-color: rgba(239, 68, 68, 1); transform: scale(1.1); box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4); }

/* Controls Overlay */
.player-overlay { position: absolute; bottom: 0; left: 0; right: 0; padding: 40px 16px 12px; background: linear-gradient(transparent, rgba(0,0,0,0.85)); opacity: 0; transition: opacity 0.3s ease; pointer-events: none; z-index: 5; }
.player-wrapper:hover .player-overlay, .player-wrapper.paused .player-overlay, .player-overlay.active { opacity: 1; pointer-events: all; }
.progress-container { position: relative; width: 100%; height: 20px; margin-bottom: 8px; cursor: pointer; display: flex; align-items: center; }
.progress-bar { width: 100%; height: 4px; background: rgba(255,255,255,0.2); border-radius: 2px; position: relative; transition: height 0.2s ease; }
.progress-container:hover .progress-bar { height: 6px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6); border-radius: 2px; width: 0%; position: relative; }
.progress-handle { position: absolute; right: -8px; top: 50%; transform: translateY(-50%) scale(0); width: 16px; height: 16px; background: white; border-radius: 50%; box-shadow: 0 0 10px rgba(0,0,0,0.5); transition: transform 0.2s ease; }
.progress-container:hover .progress-handle, .progress-container.dragging .progress-handle { transform: translateY(-50%) scale(1); }
.progress-buffered { position: absolute; top: 0; left: 0; height: 100%; background: rgba(255,255,255,0.15); border-radius: 2px; width: 0%; pointer-events: none; }
.progress-tooltip { position: absolute; top: -40px; transform: translateX(-50%); background: var(--bg-secondary); padding: 6px 12px; border-radius: var(--radius-sm); font-size: 12px; opacity: 0; border: 1px solid var(--border); pointer-events: none; }
.progress-container:hover .progress-tooltip, .progress-container.dragging .progress-tooltip { opacity: 1; }

.controls-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.controls-left, .controls-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.control-btn { background: none; border: none; color: white; font-size: 16px; cursor: pointer; padding: 8px; border-radius: 8px; transition: all 0.2s; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; position: relative; }
.control-btn:hover { background: rgba(255,255,255,0.15); transform: scale(1.1); }
.control-btn.skip-btn { font-size: 14px; }
.control-btn.skip-btn span { position: absolute; font-size: 9px; font-weight: 700; bottom: 4px; }
.control-btn.skip-btn.skip-back span { left: 6px; }
.control-btn.skip-btn.skip-forward span { right: 6px; }
.control-btn.play-btn { font-size: 18px; width: 40px; height: 40px; }
.time-display { color: rgba(255,255,255,0.9); font-size: 13px; font-family: 'Inter', monospace; margin-left: 8px; }
.volume-container { display: flex; align-items: center; position: relative; }
.volume-slider-wrapper { width: 0; overflow: hidden; transition: width 0.3s ease; }
.volume-container:hover .volume-slider-wrapper { width: 80px; }
.volume-slider { width: 80px; height: 4px; -webkit-appearance: none; appearance: none; background: rgba(255,255,255,0.3); border-radius: 2px; cursor: pointer; }
.volume-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: white; border-radius: 50%; }
.player-quality-badge, .speed-indicator { color: rgba(255,255,255,0.9); font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 4px; cursor: pointer; transition: all 0.2s; }
.player-quality-badge { background: rgba(99, 102, 241, 0.8); }
.player-quality-badge:hover, .speed-indicator:hover { background: var(--accent); }

/* Video Info */
.video-info { padding: 24px; }
.info-header { display: flex; gap: 20px; margin-bottom: 20px; }
.poster-thumb { width: 160px; aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: var(--radius-md); flex-shrink: 0; }
.info-text { flex: 1; min-width: 0; }
.video-title { font-size: 20px; font-weight: 600; margin-bottom: 8px; line-height: 1.3; word-break: break-word; }
.video-meta { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.meta-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 14px; }
.meta-badge.quality { padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; background: rgba(99, 102, 241, 0.15); border: 1px solid var(--accent); color: var(--accent-hover); }

/* Qualities */
.quality-section { margin-top: 20px; }
.section-label { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; margin-bottom: 12px; }
.quality-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.quality-option { position: relative; background: var(--bg-tertiary); border: 2px solid transparent; border-radius: var(--radius-md); padding: 14px 10px; cursor: pointer; transition: all 0.2s ease; text-align: center; }
.quality-option:hover { background: var(--bg-hover); border-color: var(--border); }
.quality-option.active { border-color: var(--accent); background: rgba(99, 102, 241, 0.1); }
.quality-option .q-label { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.quality-option .q-source { font-size: 11px; color: var(--text-muted); }
.quality-option .q-badge { position: absolute; top: -1px; right: 8px; background: var(--accent); color: white; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 0 0 6px 6px; }
.action-bar { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 20px; }

/* History & Community Typography Fixes */
.history-section { animation: fadeInUp 0.6s ease-out 0.2s both; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); }

/* Pixel-perfect heading alignment */
.section-title { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 8px; line-height: 1; }
.section-title i { color: var(--accent); }

/* Pixel-perfect Clear button alignment */
.btn-clear { background: rgba(239, 68, 68, 0.1); color: var(--error); border: 1px solid rgba(239, 68, 68, 0.2); padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1; align-self: center; transition: all 0.2s ease; }
.btn-clear:hover { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.4); transform: translateY(-1px); }
.btn-clear i { display: flex; align-items: center; font-size: 11px; }

.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.community-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.history-item, .community-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; transition: all 0.2s ease; cursor: pointer; }
.history-item { display: flex; gap: 12px; align-items: center; padding: 12px; }
.community-card { display: flex; flex-direction: column; }
.history-item:hover, .community-card:hover { border-color: var(--accent); transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.history-thumb { width: 90px; aspect-ratio: 16/9; object-fit: contain; background: #000; border-radius: var(--radius-sm); }
.history-info { flex: 1; min-width: 0; }
.history-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.history-delete { color: var(--text-muted); padding: 4px; opacity: 0; transition: 0.2s; }
.history-item:hover .history-delete { opacity: 1; }
.history-delete:hover { color: var(--error); }

.community-thumb-wrapper { position: relative; width: 100%; aspect-ratio: 16/9; background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.community-thumb { width: 100%; height: 100%; object-fit: contain; }
.community-play-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; }
.community-card:hover .community-play-overlay { opacity: 1; }
.community-play-overlay i { font-size: 40px; color: white; text-shadow: 0 4px 8px rgba(0,0,0,0.5); }
.community-info { padding: 14px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.community-title { font-size: 14px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.community-stats { display: flex; justify-content: space-between; color: var(--text-muted); font-size: 12px; margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.05); }
.like-btn { background: var(--bg-tertiary); border: none; color: var(--text-muted); padding: 6px 10px; border-radius: 20px; font-size: 12px; cursor: pointer; transition: 0.2s; display: flex; gap: 6px; }
.like-btn:hover, .like-btn.liked { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

/* Modals & Toasts */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 9999; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-xl); max-width: 500px; width: 100%; max-height: 80vh; display: flex; flex-direction: column; animation: scaleIn 0.2s ease; }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }
.modal-body { padding: 20px; overflow-y: auto; }
.shortcut-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border); }
.key { background: var(--bg-tertiary); border: 1px solid var(--border); padding: 4px 10px; border-radius: 6px; font-size: 13px; font-family: monospace; }
.toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-secondary); border: 1px solid var(--border); padding: 14px 24px; border-radius: var(--radius-lg); font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease; backdrop-filter: blur(10px); }
.toast.success { border-color: var(--success); } .toast.error { border-color: var(--error); } .toast.warning { border-color: var(--warning); }
.footer { text-align: center; padding: 40px 20px 20px; color: var(--text-muted); font-size: 13px; margin-top: auto; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) translateX(-50%); } to { opacity: 1; transform: translateY(0) translateX(-50%); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }

/* Responsive adjustments */
@media (max-width: 1024px) {
    .controls-row { flex-wrap: wrap; justify-content: center; }
    .volume-container .volume-slider-wrapper { width: 80px; }
}

@media (max-width: 768px) {
    .app-container { padding: 16px; }
    .input-wrapper { flex-direction: column; padding: 12px; }
    .btn-primary { width: 100%; justify-content: center; }
    
    /* Responsive layout fix for Mobile Thumbnail */
    .info-header { flex-direction: row; align-items: flex-start; gap: 12px; }
    .poster-thumb { width: 100px; height: auto; }
    .video-title { font-size: 16px; }

    .quality-grid { grid-template-columns: repeat(2, 1fr); }
    .action-bar { justify-content: center; }
    .history-grid { grid-template-columns: 1fr; }
    .community-grid { grid-template-columns: repeat(2, 1fr); }
    .time-display { font-size: 11px; }
    .control-btn.skip-btn span { display: none; }
    
    /* Touch target sizing */
    .control-btn { width: 44px; height: 44px; font-size: 18px; }
}

@media (max-width: 480px) {
    .community-grid { grid-template-columns: 1fr; }
    .time-display { display: none; }
}
