:root {
    --bg: #0d0a17;
    --bg-soft: #141024;
    --surface: #1b1530;
    --surface-2: #241c3d;
    --line: rgba(255, 255, 255, .08);
    --line-strong: rgba(255, 255, 255, .18);
    --fg: #f4f0ff;
    --fg-muted: #a79dc2;
    --fg-faint: #6e6488;
    --accent: #b48cff;
    --live: #5ee6b0;
    --radius: 14px;
    --header-h: 96px;
    --shadow: 0 18px 40px -20px rgba(0, 0, 0, .9);
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--bg);
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: "DM Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: #2c2347;
    border-radius: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(1200px 600px at 15% -10%, rgba(180, 140, 255, .12), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, rgba(255, 122, 162, .08), transparent 55%),
        var(--bg);
}

/* ---------- top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(13, 10, 23, .88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.topbar-inner {
    height: 56px;
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-shrink: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(145deg, var(--accent), #7a5bd6);
    color: #150f26;
    font-size: 15px;
    box-shadow: 0 6px 16px -8px var(--accent);
}

.brand-name {
    font-weight: 800;
    letter-spacing: -.02em;
    font-size: 1.05rem;
    white-space: nowrap;
}

.search {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 520px;
}

.search input {
    width: 100%;
    height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--fg);
    outline: none;
    transition: border-color .15s, background .15s;
}

.search input::placeholder {
    color: var(--fg-faint);
}

.search input:focus {
    border-color: var(--accent);
    background: var(--surface-2);
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.chip {
    height: 38px;
    min-width: 38px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--fg-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: .9rem;
    font-weight: 600;
    transition: background .15s, color .15s, border-color .15s;
}

.chip:hover {
    background: var(--surface-2);
    color: var(--fg);
}

.chip.is-on {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    color: var(--fg);
}

.cats {
    height: 40px;
    max-width: 1680px;
    margin: 0 auto;
    padding: 0 14px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
}

.cats::-webkit-scrollbar {
    display: none;
}

.cat {
    flex-shrink: 0;
    height: 30px;
    padding: 0 13px;
    border-radius: 999px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--fg-muted);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s;
}

.cat:hover {
    background: var(--surface);
    color: var(--fg);
}

.cat.is-on {
    background: var(--accent);
    color: #150f26;
}

/* ---------- stage / player ---------- */

.main {
    flex: 1;
    width: 100%;
}

.stage {
    padding: 14px 14px 10px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.player {
    position: relative;
    width: min(100%, calc((100dvh - var(--header-h) - 150px) * 16 / 9));
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

.player iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

.now {
    max-width: 1680px;
    margin: 10px auto 0;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.now-main {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    flex: 1 1 260px;
}

.now-main strong {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.now-epg {
    color: var(--fg-muted);
    font-size: .85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.now-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    height: 34px;
    padding: 0 12px;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--fg-muted);
    font-size: .82rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, color .15s, border-color .15s;
}

.btn:hover {
    background: var(--surface-2);
    color: var(--fg);
    border-color: var(--line-strong);
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--live);
    box-shadow: 0 0 0 0 rgba(94, 230, 176, .6);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(94, 230, 176, .55); }
    70% { box-shadow: 0 0 0 7px rgba(94, 230, 176, 0); }
    100% { box-shadow: 0 0 0 0 rgba(94, 230, 176, 0); }
}

.badge {
    flex-shrink: 0;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--fg-muted);
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .04em;
}

.hero {
    max-width: 720px;
    margin: 0 auto;
    padding: 34px 8px 26px;
    text-align: center;
}

.hero h1 {
    margin: 0 0 8px;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    letter-spacing: -.03em;
}

.hero p {
    margin: 0;
    color: var(--fg-muted);
}

/* ---------- channel grid ---------- */

.section {
    max-width: 1680px;
    margin: 0 auto;
    padding: 16px 14px 8px;
}

.section-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 0 10px;
    font-size: .95rem;
    font-weight: 700;
    letter-spacing: .01em;
}

.count {
    color: var(--fg-faint);
    font-size: .78rem;
    font-weight: 600;
}

.grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.ch-wrap {
    position: relative;
    min-width: 0;
}

.ch-card {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 11px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .15s;
}

.ch-card:hover {
    background: var(--surface-2);
    border-color: var(--line-strong);
    transform: translateY(-1px);
}

.ch-card.is-active {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
    box-shadow: inset 0 0 0 1px var(--accent);
}

.ch-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: hsl(var(--h, 260) 55% 26%);
    color: hsl(var(--h, 260) 80% 88%);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.ch-name {
    font-size: .88rem;
    font-weight: 700;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.2em;
}

.ch-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--fg-faint);
    font-size: .72rem;
    font-weight: 600;
    min-width: 0;
}

.ch-meta .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--live);
    flex-shrink: 0;
}

.ch-epg {
    color: var(--fg-muted);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.ch-fav {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--fg-faint);
    font-size: .95rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, color .15s, background .15s;
}

.ch-wrap:hover .ch-fav,
.ch-fav:focus-visible,
.ch-fav.is-on {
    opacity: 1;
}

.ch-fav:hover {
    background: rgba(0, 0, 0, .35);
    color: var(--fg);
}

.ch-fav.is-on {
    color: #ffd166;
}

.empty {
    color: var(--fg-muted);
    padding: 26px 4px;
    text-align: center;
}

/* ---------- matchora live matches ---------- */

.matches {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.match {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface);
    transition: border-color .15s, background .15s;
}

.match.is-active {
    border-color: var(--accent);
    background: var(--surface-2);
}

.match-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: .72rem;
    color: var(--fg-faint);
}

.match-league {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    letter-spacing: .02em;
}

.match-live {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    color: var(--live);
    font-weight: 800;
    letter-spacing: .04em;
}

.match-status {
    flex-shrink: 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.match-teams {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    font-size: .9rem;
    font-weight: 700;
}

.match-teams .team {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.match-teams .team.is-away {
    text-align: right;
}

.match-score {
    padding: 2px 8px;
    border-radius: 7px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
    font-size: .82rem;
    color: var(--fg);
}

.match-channels {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.mch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    height: 30px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--fg-muted);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.mch:hover {
    background: var(--surface-2);
    color: var(--fg);
    border-color: var(--line-strong);
}

.mch.is-on {
    background: var(--accent);
    border-color: var(--accent);
    color: #150f26;
}

.mch-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- native HLS player ---------- */

.player .video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    object-fit: contain;
}

.player-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px;
    text-align: center;
    color: var(--fg-muted);
    font-size: .88rem;
    background: rgba(6, 4, 12, .72);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.player-overlay.is-error {
    color: #ffb4c4;
}

.spinner {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, .16);
    border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- states ---------- */

.state {
    max-width: 520px;
    margin: 60px auto;
    padding: 26px;
    text-align: center;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
}

.state h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

.state p {
    margin: 0 0 16px;
    color: var(--fg-muted);
    font-size: .9rem;
    word-break: break-word;
}

.skeleton-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    padding: 16px 14px;
    max-width: 1680px;
    margin: 0 auto;
}

.skeleton {
    height: 96px;
    border-radius: 12px;
    background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
    background-size: 220% 100%;
    animation: shimmer 1.4s infinite linear;
}

@keyframes shimmer {
    from { background-position: 120% 0; }
    to { background-position: -120% 0; }
}

/* ---------- responsive ---------- */

@media (min-width: 640px) {
    .grid,
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    }

    .topbar-inner,
    .cats,
    .section,
    .skeleton-grid {
        padding-left: 20px;
        padding-right: 20px;
    }

    .stage {
        padding: 18px 20px 12px;
    }
}

@media (min-width: 900px) {
    .stage {
        position: sticky;
        top: var(--header-h);
        z-index: 30;
        box-shadow: 0 14px 24px -22px #000;
    }

    .grid,
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(184px, 1fr));
    }
}

@media (min-width: 1500px) {
    .grid,
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}

@media (max-width: 520px) {
    .brand-name {
        display: none;
    }

    .now-actions .btn span {
        display: none;
    }

    .ch-fav {
        opacity: 1;
    }
}

/* ---------- smart TV mode ---------- */

.tv-mode {
    --header-h: 108px;
    font-size: 17px;
}

.tv-mode .topbar-inner {
    height: 64px;
}

.tv-mode .cats {
    height: 44px;
}

.tv-mode .brand-name {
    font-size: 1.2rem;
}

.tv-mode .grid,
.tv-mode .skeleton-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.tv-mode .ch-card {
    padding: 14px;
    border-radius: 14px;
}

.tv-mode .ch-name {
    font-size: 1rem;
}

.tv-mode .avatar {
    width: 40px;
    height: 40px;
    font-size: .9rem;
}

.tv-mode :focus {
    outline: 4px solid var(--accent);
    outline-offset: 3px;
}

.tv-mode .ch-card:focus {
    background: var(--surface-2);
    border-color: var(--accent);
}

.tv-mode .ch-fav {
    opacity: 1;
    width: 34px;
    height: 34px;
}

.tv-mode .matches {
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
}

.tv-mode .match {
    padding: 16px;
}

.tv-mode .match-teams {
    font-size: 1rem;
}

.tv-mode .mch {
    height: 36px;
    font-size: .86rem;
}

.tv-mode .mch:focus {
    background: var(--surface-2);
    border-color: var(--accent);
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: .001ms !important;
        transition-duration: .001ms !important;
    }
}
