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

:root {
    --accent: #f2a65a;
    --accent-dark: #12141c;
    --bg-main: #0a0c10;
    --bg-app: #0f1117;
    --bg-bar: #1e1f2c;
    --bg-sidebar: #12141c;
    --bg-card: #1a1e2a;
    --bg-input: #2a2c3a;
    --bg-item: #1a1c26;
    --border: #2d2f3e;
    --border-2: #252836;
    --text: #eef2ff;
    --text-muted: #8e96af;
    --text-dim: #9aa4bf;
    --red: #c44536;
    --green: #2e7d64;
}

html {
    font-size: 16px;
}

body {
    background: var(--bg-main);
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-app);
}

/* ─── TOP BAR ─────────────────────────────────────────── */
.top-bar {
    background: var(--bg-bar);
    padding: 0.6rem 1rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 10;
    flex-shrink: 0;
}

.m3u-control {
    display: flex;
    flex: 2;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    min-width: 0;
}

.m3u-control input {
    flex: 1;
    min-width: 120px;
    background: var(--bg-input);
    border: 1px solid #3d4050;
    padding: 0.5rem 0.8rem;
    border-radius: 2rem;
    color: white;
    font-size: 0.8rem;
    outline: none;
    transition: 0.2s;
}

.m3u-control input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(242,166,90,0.3);
}

/* ─── BUTTONS ─────────────────────────────────────────── */
button, .auth-btn, .load-btn {
    background: #2d2f3e;
    border: none;
    color: white;
    padding: 0.45rem 1rem;
    border-radius: 2rem;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    outline: none;
    white-space: nowrap;
}

button:focus-visible, .load-btn:focus-visible, .channel-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:hover { background: #3f4256; transform: scale(1.02); }

.sign-out-btn { background: var(--red); }
.sign-out-btn:hover { background: #a33c2f; }

.user-badge {
    background: #1f2a3e;
    padding: 0.35rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.75rem;
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    background: transparent;
    font-size: 1.2rem;
    padding: 0.4rem;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-btn:hover { background: #3f4256; transform: scale(1.05); }

.lang-buttons {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}

.lang-btn {
    background: #2d2f3e;
    padding: 0.35rem 0.8rem;
    font-size: 0.72rem;
    border-radius: 2rem;
}

.lang-btn.active {
    background: var(--accent);
    color: var(--accent-dark);
}

/* ─── MODALS ──────────────────────────────────────────── */
.settings-modal, .account-modal {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(5px);
    z-index: 1001;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.settings-modal.active, .account-modal.active { display: flex; }

.settings-card, .account-card {
    background: var(--bg-card);
    border-radius: 1.5rem;
    width: 100%;
    max-width: 440px;
    padding: 1.5rem;
    border: 1px solid #2f3548;
    box-shadow: 0 20px 35px rgba(0,0,0,0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.settings-card h3, .account-card h3 {
    margin-bottom: 1.2rem;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-card input {
    width: 100%;
    padding: 0.7rem;
    background: #2c2f3c;
    border: 1px solid #40455e;
    border-radius: 1rem;
    color: white;
    margin: 0.5rem 0 1rem;
    font-size: 0.9rem;
}

.settings-actions, .account-actions {
    display: flex;
    gap: 0.8rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.settings-actions button, .account-actions button {
    background: #2d2f3e;
    padding: 0.5rem 1rem;
}

.settings-actions button.primary, .account-actions button.primary,
.subscribe-btn.primary {
    background: var(--accent);
    color: var(--accent-dark);
}

.account-info {
    background: #2c2f3e;
    padding: 0.8rem 1rem;
    border-radius: 1rem;
    margin: 0.8rem 0;
    text-align: left;
    word-break: break-all;
}

.account-info p {
    margin: 0.4rem 0;
    font-size: 0.88rem;
    line-height: 1.5;
}

.subscribe-btn {
    background: var(--green);
    width: 100%;
    justify-content: center;
    margin-top: 0.5rem;
    padding: 0.7rem;
    font-size: 0.9rem;
}

.subscribe-btn:hover { background: #3a9b7c; }

/* ─── MAIN LAYOUT ─────────────────────────────────────── */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.sidebar {
    width: 300px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    transition: width 0.2s;
}

.sidebar-header {
    padding: 0.8rem;
    border-bottom: 1px solid var(--border-2);
    flex-shrink: 0;
}

.tabs {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 0.8rem;
}

.tab-btn {
    background: transparent;
    padding: 0.35rem 0.8rem;
    border-radius: 2rem;
    font-weight: 600;
    color: #b9c3db;
    font-size: 0.78rem;
}

.tab-btn.active {
    background: var(--accent);
    color: var(--accent-dark);
}

.search-box {
    width: 100%;
    background: #1e202b;
    border: 1px solid var(--border);
    padding: 0.6rem 0.8rem;
    border-radius: 2rem;
    color: white;
    font-size: 0.82rem;
}

.channels-container {
    flex: 1;
    overflow-y: auto;
    padding: 0.4rem 0.2rem 1rem 0;
    min-height: 0;
}

/* ─── CHANNEL ITEMS ───────────────────────────────────── */
.channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 0.8rem;
    margin: 0.25rem 0.5rem;
    background: var(--bg-item);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.1s ease;
    gap: 0.6rem;
    border: 1px solid transparent;
}

.channel-item.active-channel {
    background: #2a4b6e;
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.channel-item:hover, .channel-item:focus-visible {
    background: #282d3c;
    border-color: var(--accent);
    transform: scale(1.01);
}

.channel-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}

.channel-logo {
    width: 30px;
    height: 30px;
    object-fit: contain;
    background: #0f1117;
    border-radius: 6px;
    flex-shrink: 0;
}

.channel-name {
    font-weight: 500;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.star-btn {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: #a0a5bf;
    transition: 0.1s;
    padding: 0 4px;
    flex-shrink: 0;
}

.star-btn.active {
    color: #f5b342;
    text-shadow: 0 0 2px gold;
}

.loading-spinner {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* ─── PLAYER AREA ─────────────────────────────────────── */
.player-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #090b10;
    padding: 0.8rem;
    gap: 0.8rem;
    overflow-y: auto;
    position: relative;
    min-width: 0;
}

.video-wrapper {
    background: #000;
    border-radius: 1.2rem;
    overflow: hidden;
    aspect-ratio: 16 / 9;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.6);
    width: 100%;
}

video {
    width: 100%;
    height: 100%;
    display: block;
}

.now-playing {
    background: #1e202b;
    padding: 0.6rem 1rem;
    border-radius: 0.8rem;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    flex-shrink: 0;
}

.channel-title {
    font-weight: bold;
    color: var(--accent);
}

.helper-text {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* ─── AUTH ────────────────────────────────────────────── */
.auth-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: radial-gradient(circle at center, #1b1f2b, #050608);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    padding: 1rem;
}

.auth-card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 2rem;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 40px rgba(0,0,0,0.5);
    border: 1px solid #2f3548;
}

.auth-card h2 {
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1.4rem;
}

.auth-card input {
    width: 100%;
    padding: 0.75rem;
    margin: 0.4rem 0;
    background: #2c2f3c;
    border: 1px solid #40455e;
    border-radius: 1rem;
    color: white;
    font-size: 0.95rem;
}

.auth-buttons {
    display: flex;
    gap: 0.8rem;
    margin-top: 1rem;
}

.auth-buttons button {
    flex: 1;
    justify-content: center;
    padding: 0.6rem;
    font-size: 0.85rem;
}

.error-msg {
    color: #ff8a7a;
    font-size: 0.8rem;
    margin-top: 0.5rem;
    text-align: center;
}

.hidden { display: none; }

/* ─── SUBSCRIPTION OVERLAY ────────────────────────────── */
.channels-container.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.subscription-disabled-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: 1.2rem;
    padding: 1rem;
}

.subscription-message {
    background: var(--red);
    color: white;
    padding: 1.5rem;
    border-radius: 1.5rem;
    text-align: center;
    max-width: 90%;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    font-size: 0.9rem;
    line-height: 1.5;
}

.subscription-message i {
    font-size: 2rem;
    display: block;
    margin-bottom: 0.8rem;
}

/* ─── SCROLLBAR ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg-item); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 8px; }

/* ─── FOCUS ───────────────────────────────────────────── */
button:focus-visible, .channel-item:focus-visible, input:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (max 900px)
════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .sidebar { width: 260px; }
    .user-badge { max-width: 100px; font-size: 0.7rem; }
    .lang-btn { padding: 0.3rem 0.6rem; font-size: 0.68rem; }
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (max 650px)
════════════════════════════════════════════════════════ */
@media (max-width: 650px) {
    html { font-size: 14px; }

    body { overflow: auto; height: auto; min-height: 100vh; }

    .app-container { height: auto; min-height: 100vh; }

    .top-bar {
        padding: 0.5rem 0.6rem;
        gap: 0.4rem;
    }

    .m3u-control { order: 2; width: 100%; }
    .m3u-control input { font-size: 0.78rem; padding: 0.45rem 0.7rem; }

    .lang-buttons {
        order: 3;
        width: 100%;
        justify-content: center;
        gap: 0.3rem;
    }

    .lang-btn { padding: 0.28rem 0.55rem; font-size: 0.66rem; }

    .top-bar > div:last-child {
        order: 1;
        width: 100%;
        justify-content: flex-end;
    }

    .user-badge { flex: 1; max-width: none; font-size: 0.72rem; }

    .main-layout {
        flex-direction: column;
        overflow: visible;
        height: auto;
    }

    .sidebar {
        width: 100%;
        height: 45vh;
        border-right: none;
        border-bottom: 1px solid var(--border-2);
        flex-shrink: 0;
    }

    .player-area {
        height: auto;
        min-height: 55vw;
        overflow: visible;
        padding: 0.6rem;
    }

    .video-wrapper { border-radius: 0.8rem; }

    .now-playing {
        font-size: 0.78rem;
        padding: 0.5rem 0.7rem;
    }

    .channel-item {
        padding: 0.55rem 0.7rem;
        margin: 0.2rem 0.4rem;
        border-radius: 0.8rem;
    }

    .channel-name { font-size: 0.78rem; }
    .channel-logo { width: 26px; height: 26px; }
    .star-btn { font-size: 1.1rem; }

    .auth-card { padding: 1.5rem; border-radius: 1.5rem; }
    .auth-card h2 { font-size: 1.2rem; }

    .settings-card, .account-card { padding: 1.2rem; border-radius: 1.2rem; }
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE (max 400px)
════════════════════════════════════════════════════════ */
@media (max-width: 400px) {
    html { font-size: 13px; }
    .lang-btn { padding: 0.25rem 0.45rem; font-size: 0.62rem; }
    .sidebar { height: 42vh; }
    .channel-item { padding: 0.5rem 0.6rem; }
}

/* ════════════════════════════════════════════════════════
   TV / LARGE SCREENS (min 1400px)
════════════════════════════════════════════════════════ */
@media (min-width: 1400px) {
    html { font-size: 18px; }
    .sidebar { width: 360px; }
    .channel-logo { width: 38px; height: 38px; }
    .channel-item { padding: 0.9rem 1.2rem; border-radius: 1.4rem; }
    .icon-btn { width: 44px; height: 44px; font-size: 1.4rem; }
}

/* ════════════════════════════════════════════════════════
   4K / VERY LARGE SCREENS (min 1920px)
════════════════════════════════════════════════════════ */
@media (min-width: 1920px) {
    html { font-size: 22px; }
    .sidebar { width: 420px; }
    .channel-logo { width: 44px; height: 44px; }
    .channel-item { padding: 1rem 1.4rem; }
    .top-bar { padding: 0.8rem 2rem; }
}
