@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg: #0e1013;
    --bg-alt: #14161a;
    --bg-raised: #1b1e23;
    --bg-input: #101215;
    --border: #262a31;
    --border-soft: #1e2127;
    --text: #eaecef;
    --text-dim: #9aa0aa;
    --text-faint: #6b7078;
    --accent: #4f8cff;
    --accent-dim: #3868c7;
    --accent-soft: rgba(79, 140, 255, 0.12);
    --danger: #ff6b5e;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    height: 100%;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ===== Topbar ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 20px;
    height: 58px;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 30;
}

.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
}
.menu-toggle:hover { color: var(--text); border-color: var(--text-faint); background: var(--bg-raised); }
.menu-toggle svg { width: 18px; height: 18px; }

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
}
.brand .brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.brand .brand-mark svg { width: 15px; height: 15px; color: #05070a; }
.brand .brand-tag {
    color: var(--text-faint);
    font-weight: 500;
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    border: 1px solid var(--border);
    padding: 1px 7px;
    border-radius: 20px;
    margin-left: 2px;
}

.source-info {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.source-info span {
    font-size: 0.8rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.btn-reset {
    color: var(--text-dim);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    transition: border-color .15s, color .15s;
}
.btn-reset:hover { color: var(--text); border-color: var(--text-faint); }

/* ===== Layout ===== */
.app {
    display: grid;
    grid-template-columns: 320px 1fr;
    min-height: calc(100vh - 58px);
}

.sidebar-backdrop {
    display: none;
}

/* ===== Sidebar ===== */
.sidebar {
    background: var(--bg-alt);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 58px);
}

.load-box {
    padding: 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.load-box label {
    display: block;
    font-size: 0.74rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.input-row { display: flex; gap: 8px; }

input[type="text"], input[type="file"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.84rem;
    width: 100%;
}
input[type="text"]::placeholder { color: var(--text-faint); }
input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="file"] {
    padding: 8px;
    font-size: 0.78rem;
    color: var(--text-dim);
}

button {
    background: var(--accent);
    color: #ffffff;
    border: none;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.84rem;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
button:hover { background: var(--accent-dim); }
button:active { transform: translateY(1px); }

.alert {
    margin: 0 18px 16px;
    padding: 10px 12px;
    background: rgba(255, 107, 94, 0.1);
    border: 1px solid rgba(255, 107, 94, 0.35);
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    line-height: 1.4;
}

.advanced-box {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
}
.advanced-box summary {
    cursor: pointer;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 500;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.advanced-box summary::-webkit-details-marker { display: none; }
.advanced-box summary::before {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--text-faint);
    border-bottom: 1.5px solid var(--text-faint);
    transform: rotate(-45deg);
    transition: transform .15s;
    flex-shrink: 0;
}
.advanced-box[open] summary::before { transform: rotate(45deg); }
.advanced-box summary:hover { color: var(--text); }
.advanced-hint {
    color: var(--text-faint);
    font-size: 0.76rem;
    line-height: 1.5;
    margin: 10px 0;
}
.advanced-box label {
    display: block;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-dim);
    margin: 10px 0 5px;
}
.advanced-box input[type="text"] {
    margin-bottom: 2px;
}

.channel-search {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.channel-search::before {
    content: '';
    position: absolute;
    left: 30px;
    top: 50%;
    width: 13px;
    height: 13px;
    margin-top: -7px;
    border: 1.6px solid var(--text-faint);
    border-radius: 50%;
    pointer-events: none;
}
.channel-search::after {
    content: '';
    position: absolute;
    left: 40px;
    top: 50%;
    width: 6px;
    height: 1.6px;
    margin-top: 5px;
    background: var(--text-faint);
    transform: rotate(45deg);
    pointer-events: none;
}
.channel-search input {
    padding-left: 32px;
}

.channel-list {
    overflow-y: auto;
    flex: 1;
    padding: 8px 0 20px;
}

.empty-note {
    padding: 24px 18px;
    color: var(--text-faint);
    font-size: 0.85rem;
    line-height: 1.6;
}

.group-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-faint);
    padding: 14px 18px 6px;
}

.channel-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 18px;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background .1s;
}
.channel-item:hover { background: var(--bg-raised); }
.channel-item.active {
    background: var(--accent-soft);
    border-left-color: var(--accent);
}
.channel-item img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    background: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    flex-shrink: 0;
    padding: 3px;
}
.channel-item span {
    font-size: 0.85rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.channel-item.active span { color: var(--text); font-weight: 500; }

/* ===== Player area ===== */
.player-area {
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 14px;
}

.video-wrapper {
    position: relative;
    background: #000;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    aspect-ratio: 16 / 9;
    width: 100%;
    overflow: hidden;
    box-shadow: var(--shadow);
}

#videoPlayer {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
}

.player-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-faint);
    font-size: 0.88rem;
    padding: 24px;
    background: #000;
}

.now-playing {
    font-weight: 600;
    font-size: 1.02rem;
    color: var(--text);
}

.player-meta {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.74rem;
    color: var(--text-faint);
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== Responsive: tablet / mobile ===== */
@media (max-width: 900px) {
    .menu-toggle { display: flex; }

    .app {
        grid-template-columns: 1fr;
        min-height: calc(100vh - 58px);
    }

    .sidebar {
        position: fixed;
        top: 58px;
        left: 0;
        bottom: 0;
        width: min(84vw, 340px);
        max-height: none;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 12px 0 32px rgba(0,0,0,0.4);
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 58px 0 0 0;
        background: rgba(0,0,0,0.5);
        z-index: 35;
    }
    .sidebar-backdrop.open { display: block; }

    .source-info span { max-width: 130px; }

    .player-area { padding: 16px; }
}

@media (max-width: 480px) {
    .topbar { padding: 0 14px; gap: 10px; }
    .brand .brand-tag { display: none; }
    .btn-reset { padding: 5px 9px; }
    .player-area { padding: 12px; gap: 10px; }
    .load-box { padding: 14px; }
    .now-playing { font-size: 0.94rem; }
}
