:root {
  --bg: #0b0f17;
  --bg2: #111724;
  --panel: #161d2c;
  --panel2: #1c2436;
  --line: #262f44;
  --text: #e8ecf4;
  --muted: #8a94a9;
  --accent: #ffb547;
  --accent-ink: #1b1305;
  --live: #ff5d5d;
  --fav: #ff5d8f;
  --radius: 10px;
  --row: 60px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--live); min-height: 1.2em; font-size: 13px; }

/* ---------- login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(1200px 600px at 30% 0%, #1d2740, var(--bg)); }
.login-card { width: min(340px, 90vw); display: grid; gap: 12px; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }

/* ---------- controls */
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #3a4560; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--live); }
.btn.small { padding: 5px 10px; font-size: 13px; }
input[type=text], input[type=password], input[type=url], input[type=search], select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: -1px; }
.search { flex: 1; }

/* ---------- layout */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 18px; padding: 0 16px; height: 56px; background: var(--bg2); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.brand.big { font-size: 26px; justify-content: center; margin-bottom: 6px; }
.brand-mark { width: 22px; height: 16px; border-radius: 4px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 8px; top: 4px; border-left: 7px solid var(--bg); border-top: 4px solid transparent; border-bottom: 4px solid transparent; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.tabs a { color: var(--muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; white-space: nowrap; }
.tabs a:hover { color: var(--text); background: var(--panel); }
.tabs a.active { color: var(--text); background: var(--panel2); box-shadow: inset 0 -2px 0 var(--accent); }
.source-select { max-width: 200px; }
main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: flex; }
.scroll-view { overflow-y: auto; }
.page { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#view-guide, #view-movies, #view-series { flex-direction: column; }

/* ---------- live view */
.sidebar { width: 340px; flex-shrink: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg2); min-height: 0; }
.side-tools { display: grid; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.side-status { padding: 6px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); min-height: 28px; }
.vlist { flex: 1; overflow-y: auto; position: relative; contain: strict; }
.vinner { position: relative; width: 100%; }
.row { position: absolute; left: 0; right: 0; height: var(--row); display: flex; align-items: center; gap: 10px; padding: 0 8px 0 12px; cursor: pointer; border-bottom: 1px solid #ffffff08; }
.row:hover { background: var(--panel); }
.row.active { background: var(--panel2); box-shadow: inset 3px 0 0 var(--accent); }
.row-num { width: 30px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.logo { width: 44px; height: 32px; flex-shrink: 0; border-radius: 6px; background: #ffffff0d; display: grid; place-items: center; overflow: hidden; font-size: 11px; font-weight: 700; color: var(--muted); }
.logo img { width: 100%; height: 100%; object-fit: contain; }
.row-text { flex: 1; min-width: 0; }
.row-title, .row-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-title { font-weight: 500; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.fav-btn { background: none; border: 0; padding: 6px; cursor: pointer; color: #ffffff30; display: grid; place-items: center; flex-shrink: 0; }
.fav-btn svg { width: 18px; height: 18px; fill: currentColor; }
.fav-btn:hover { color: #ffffff70; }
.fav-btn.on { color: var(--fav); }

.stage { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.player-slot { background: #000; aspect-ratio: 16 / 9; max-height: calc(100vh - 56px - 150px); width: 100%; position: relative; flex-shrink: 0; }
.empty-player { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 8px; line-height: 1.8; }
.player { position: absolute; inset: 0; background: #000; }
.player video { width: 100%; height: 100%; background: #000; display: block; }
.player-msg { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #000000b0; padding: 10px 16px; border-radius: 8px; pointer-events: none; text-align: center; max-width: 80%; }
.player-msg.loading::before { content: ""; display: block; margin: 0 auto 8px; width: 26px; height: 26px; border: 3px solid #ffffff30; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.nownext { padding: 16px 20px; display: grid; gap: 14px; }
.nn-head { display: flex; align-items: center; gap: 12px; }
.nn-head .logo { width: 64px; height: 44px; }
.nn-head h2 { margin: 0; font-size: 20px; }
.nn-prog { display: grid; gap: 4px; }
.nn-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.nn-label.live { color: var(--live); }
.nn-title { font-weight: 600; font-size: 16px; }
.nn-desc { color: var(--muted); line-height: 1.5; }
.progress { height: 4px; background: #ffffff15; border-radius: 2px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }

/* ---------- guide */
.guide { flex: 1; overflow: auto; position: relative; --ch: 210px; --gh: 36px; --gr: 58px; }
.g-head { position: sticky; top: 0; z-index: 3; height: var(--gh); display: flex; background: var(--bg2); border-bottom: 1px solid var(--line); }
.g-corner { position: sticky; left: 0; z-index: 4; width: var(--ch); flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--line); }
.g-times { position: relative; flex: 1; }
.g-time { position: absolute; top: 0; height: 100%; display: flex; align-items: center; padding-left: 8px; font-size: 12px; color: var(--muted); border-left: 1px solid var(--line); }
.g-body { position: relative; }
.g-row { position: absolute; left: 0; height: var(--gr); border-bottom: 1px solid var(--line); }
.g-ch { position: sticky; left: 0; z-index: 2; width: var(--ch); height: 100%; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--bg2); border-right: 1px solid var(--line); cursor: pointer; }
.g-ch:hover { background: var(--panel); }
.g-ch .row-title { font-size: 13px; }
.g-prog { position: absolute; top: 3px; bottom: 3px; background: var(--panel); border-radius: 6px; padding: 6px 8px; overflow: hidden; cursor: pointer; border: 1px solid transparent; }
.g-prog:hover { border-color: var(--accent); }
.g-prog.now { background: #2a2416; }
.g-prog .t { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-prog .s { font-size: 11px; color: var(--muted); white-space: nowrap; }
.g-empty { position: absolute; top: 3px; bottom: 3px; padding: 6px 8px; color: #ffffff30; font-size: 12px; }
.g-nowline { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--live); z-index: 1; pointer-events: none; }

/* ---------- poster grids */
.vgrid { flex: 1; overflow-y: auto; position: relative; padding: 0; }
.card { position: absolute; padding: 8px; cursor: pointer; }
.card-inner { height: 100%; display: flex; flex-direction: column; gap: 6px; }
.poster { flex: 1; min-height: 0; border-radius: 8px; background: var(--panel); overflow: hidden; position: relative; display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 22px; transition: transform .15s; }
.card:hover .poster { transform: scale(1.03); box-shadow: 0 0 0 2px var(--accent); }
.poster img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.poster .fav-btn { position: absolute; top: 4px; right: 4px; background: #000000a0; border-radius: 50%; color: #ffffffa0; }
.poster .fav-btn.on { color: var(--fav); }
.poster .badge { position: absolute; left: 6px; bottom: 6px; background: #000000b0; padding: 2px 6px; border-radius: 4px; font-size: 11px; color: var(--accent); }
.poster .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: #ffffff20; }
.poster .bar > div { height: 100%; background: var(--accent); }
.card-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.static-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.static-grid .card { position: relative; height: 270px; }
.chan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.chan-card { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--panel); border-radius: var(--radius); cursor: pointer; }
.chan-card:hover { background: var(--panel2); }

/* ---------- favorites / settings pages */
.page h1 { font-size: 22px; margin: 0 0 18px; }
.page h2 { font-size: 16px; margin: 28px 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.empty { color: var(--muted); padding: 30px; text-align: center; background: var(--panel); border-radius: var(--radius); line-height: 1.6; }
.src-card { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; flex-wrap: wrap; }
.src-card.current { border-color: var(--accent); }
.src-card .grow { flex: 1; min-width: 200px; }
.src-card .row-sub { white-space: normal; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: var(--panel2); color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.form { display: grid; gap: 12px; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.seg button { background: none; border: 0; padding: 6px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }
.ok { color: #6fdc8c; }
details summary { cursor: pointer; color: var(--muted); }

/* ---------- modal */
.modal { position: fixed; inset: 0; background: #000000c0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-card { position: relative; width: min(1100px, 100%); max-height: calc(100vh - 40px); overflow-y: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; }
.modal-close { position: absolute; top: 10px; right: 10px; z-index: 5; width: 34px; height: 34px; border-radius: 50%; background: #000000a0; border: 0; cursor: pointer; font-size: 16px; }
.detail { display: grid; grid-template-columns: 220px 1fr; gap: 24px; padding: 24px; }
.detail .poster { aspect-ratio: 2 / 3; flex: none; }
.detail h1 { margin: 0 0 6px; font-size: 24px; padding-right: 40px; }
.meta { color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; font-size: 13px; }
.plot { line-height: 1.6; color: #c9d0de; }
.detail .actions { display: flex; gap: 8px; margin: 18px 0; }
.seasons { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 24px; }
.episodes { padding: 12px 24px 24px; display: grid; gap: 6px; }
.ep { display: flex; gap: 12px; padding: 10px; background: var(--panel); border-radius: 8px; cursor: pointer; align-items: center; }
.ep:hover { background: var(--panel2); }
.ep-thumb { width: 120px; aspect-ratio: 16/9; border-radius: 6px; background: #000; flex-shrink: 0; overflow: hidden; position: relative; }
.ep-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ep-text { min-width: 0; flex: 1; }
.ep-text .row-sub { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.vod-wrap .player-slot { max-height: calc(100vh - 140px); border-radius: 14px 14px 0 0; overflow: hidden; }
.vod-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.vod-bar .grow { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.error { border-color: var(--live); }

/* ---------- small screens */
@media (max-width: 820px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .brand { font-size: 0; gap: 0; }
  .source-select { max-width: 110px; }
  #view-live.active { flex-direction: column-reverse; }
  .sidebar { width: 100%; flex: 1; border-right: 0; }
  .stage { flex: none; overflow: visible; }
  .nownext { display: none; }
  .player-slot { max-height: 40vh; }
  .guide { --ch: 120px; }
  .g-ch .logo { display: none; }
  .detail { grid-template-columns: 1fr; }
  .detail .poster { width: 160px; }
  .form .two { grid-template-columns: 1fr; }
}
