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

:root {
    --color-bg-start: #0a0a1a;
    --color-bg-mid: #1a1a3e;
    --color-bg-end: #0f0f2d;
    --color-primary: #667eea;
    --color-primary-light: #7c94f5;
    --color-secondary: #764ba2;
    --color-success: #48bb78;
    --color-error: #f56565;
    --color-warning: #ecc94b;
    --color-info: #4299e1;
    --color-text: #ffffff;
    --color-text-muted: rgba(255, 255, 255, 0.7);
    --color-text-dimmed: rgba(255, 255, 255, 0.45);
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-light: rgba(255, 255, 255, 0.15);
    --color-surface: rgba(15, 15, 30, 0.95);
    --color-surface-hover: rgba(255, 255, 255, 0.08);
    --color-input-bg: rgba(0, 0, 0, 0.5);
    --color-code-bg: rgba(0, 0, 0, 0.6);
    --color-console-bg: rgba(10, 10, 20, 0.95);
    --radius-lg: 16px;
    --radius-md: 10px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-lg: 0 25px 60px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 8px 25px rgba(102, 126, 234, 0.3);
    --transition-base: 0.25s ease;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--color-bg-start) 0%, var(--color-bg-mid) 50%, var(--color-bg-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
    color: var(--color-text);
}

.app-container {
    width: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Header */
.header {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
}

.header-top {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.header-top h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--color-text-dimmed);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.url-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.url-input {
    flex: 1;
    padding: 13px 18px;
    border: 2px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-input-bg);
    color: var(--color-text);
    font-size: 14px;
    outline: none;
    transition: all var(--transition-base);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.url-input::placeholder {
    color: var(--color-text-dimmed);
}

.url-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.15);
}

/* Buttons */
.btn {
    padding: 13px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 12px;
    border-radius: var(--radius-xs);
}

.btn-xs {
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 4px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: var(--color-text);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text);
    border: 1px solid var(--color-border-light);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--color-primary);
}

.btn-test {
    padding: 7px 14px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-text-muted);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-weight: 500;
}

.btn-test:hover {
    background: rgba(102, 126, 234, 0.2);
    border-color: var(--color-primary);
    color: var(--color-text);
}

.btn-icon {
    padding: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-text);
}

.btn:active {
    transform: translateY(0);
}

.test-streams {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.test-streams-label {
    color: var(--color-text-dimmed);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    white-space: nowrap;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    min-height: 400px;
}

.player-section {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.video-wrapper {
    position: relative;
    width: 100%;
    background: black;
    min-height: 250px;
    flex: 1;
}

.video-wrapper video {
    width: 100%;
    display: block;
    outline: none;
    height: 100%;
}

.video-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--color-text-dimmed);
    pointer-events: none;
}

.video-placeholder p {
    font-size: 14px;
    text-align: center;
}

.video-wrapper.playing .video-placeholder {
    display: none;
}

.status-bar {
    padding: 12px 18px;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--color-border);
    font-size: 13px;
    gap: 10px;
    flex-wrap: wrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.status-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #4a5568;
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.status-dot.active {
    background: var(--color-success);
    box-shadow: 0 0 10px rgba(72, 187, 120, 0.6);
    animation: pulse 2s infinite;
}

.status-dot.error {
    background: var(--color-error);
    box-shadow: 0 0 10px rgba(245, 101, 101, 0.6);
}

.status-dot.warning {
    background: var(--color-warning);
    box-shadow: 0 0 10px rgba(236, 201, 75, 0.6);
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.6); }
    70% { box-shadow: 0 0 0 7px rgba(72, 187, 120, 0); }
    100% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0); }
}

/* Quality Selector */
.quality-selector {
    padding: 7px 30px 7px 12px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-xs);
    font-size: 12px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    cursor: pointer;
    outline: none;
    transition: all var(--transition-base);
    max-width: 180px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
}

.quality-selector:hover {
    background-color: rgba(255, 255, 255, 0.12);
    border-color: var(--color-primary);
    color: var(--color-text);
}

.quality-selector:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.2);
}

.quality-selector option {
    background: #1a1a3e;
    color: var(--color-text);
    padding: 8px;
}

/* Inspector Panel */
.inspector-panel {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 500px;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.panel-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--color-text-dimmed);
    font-size: 14px;
}

/* Inspector Content Styles */
.inspector-section {
    margin-bottom: 20px;
}

.inspector-section:last-child {
    margin-bottom: 0;
}

.inspector-section h3 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--color-primary-light);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--color-border);
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 13px;
}

.info-item {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-xs);
}

.info-label {
    color: var(--color-text-dimmed);
    font-size: 11px;
    margin-bottom: 2px;
}

.info-value {
    color: var(--color-text-muted);
    word-break: break-all;
}

.info-value.valid {
    color: var(--color-success);
}

.info-value.invalid {
    color: var(--color-error);
}

.info-value.warning {
    color: var(--color-warning);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    padding: 4px 10px;
    background: rgba(102, 126, 234, 0.15);
    border-radius: 20px;
    font-size: 11px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--color-primary-light);
    white-space: nowrap;
}

/* Raw Playlist */
.raw-playlist {
    background: var(--color-code-bg);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.7;
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    word-break: break-all;
    overflow-wrap: break-word;
    tab-size: 2;
}

/* ==================== CONSOLE PANEL ==================== */
.console-panel {
    background: var(--color-console-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all var(--transition-base);
}

.console-panel.collapsed .console-content {
    display: none;
}

.console-panel.collapsed #toggleIcon {
    transform: rotate(-90deg);
}

.console-header {
    padding: 12px 18px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
    cursor: pointer;
    user-select: none;
}

.console-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.console-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.console-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.console-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.console-dot-error {
    background: var(--color-error);
    box-shadow: 0 0 6px rgba(245, 101, 101, 0.4);
}

.console-dot-warn {
    background: var(--color-warning);
    box-shadow: 0 0 6px rgba(236, 201, 75, 0.4);
}

.console-dot-info {
    background: var(--color-info);
    box-shadow: 0 0 6px rgba(66, 153, 225, 0.4);
}

.console-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
}

.console-counter {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-dimmed);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.console-counter.has-errors {
    background: rgba(245, 101, 101, 0.2);
    color: var(--color-error);
}

#toggleIcon {
    transition: transform var(--transition-base);
}

.console-content {
    max-height: 250px;
    overflow-y: auto;
    padding: 12px 18px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.6;
    background: rgba(0, 0, 0, 0.4);
}

.console-placeholder {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.console-line {
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    word-break: break-all;
    overflow-wrap: break-word;
}

.console-line:last-child {
    border-bottom: none;
}

.console-line-dimmed {
    color: var(--color-text-dimmed);
    font-style: italic;
}

.console-line-info {
    color: var(--color-info);
}

.console-line-warn {
    color: var(--color-warning);
}

.console-line-error {
    color: var(--color-error);
}

.console-line-success {
    color: var(--color-success);
}

.console-timestamp {
    color: var(--color-text-dimmed);
    margin-right: 8px;
    opacity: 0.6;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 1000;
}

.loading-overlay.visible {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
    color: var(--color-text-muted);
    font-size: 14px;
}

/* Copy Notification */
.copy-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--color-success);
    color: var(--color-text);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    transform: translateX(120%);
    transition: transform var(--transition-base);
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.copy-notification.visible {
    transform: translateX(0);
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .url-input-group {
        flex-wrap: wrap;
    }

    .btn {
        padding: 12px 16px;
        font-size: 13px;
    }

    .header {
        padding: 16px;
    }

    .header-top h1 {
        font-size: 22px;
    }

    .test-streams {
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    .status-bar {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .console-content {
        max-height: 200px;
    }
}

@media (max-width: 500px) {
    body {
        padding: 8px;
    }

    .url-input-group {
        flex-direction: column;
    }

    .btn {
        justify-content: center;
        width: 100%;
    }

    .header {
        padding: 12px;
    }

    .header-top h1 {
        font-size: 20px;
    }

    .test-streams {
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .test-streams-label {
        flex-shrink: 0;
    }

    .btn-test {
        flex-shrink: 0;
        padding: 6px 10px;
        font-size: 11px;
    }

    .status-bar {
        flex-direction: column;
        gap: 8px;
    }

    .status-actions {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .quality-selector {
        max-width: 140px;
        font-size: 11px;
    }

    #streamInfo {
        font-size: 11px;
    }

    .inspector-panel {
        max-height: 400px;
    }

    .panel-content {
        padding: 12px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .raw-playlist {
        font-size: 10px;
        padding: 10px;
        max-height: 200px;
    }

    .console-header {
        padding: 10px 14px;
    }

    .console-header h2 {
        font-size: 12px;
    }

    .console-content {
        max-height: 150px;
        padding: 10px 14px;
        font-size: 10px;
    }

    .console-line {
        font-size: 10px;
    }
}