:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaef;
  --muted: #9aa1ad;
  --accent: #4f8cff;
  --accent-2: #3a73e0;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: #3b4252; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=search], select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
code { background: var(--panel-2); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); white-space: pre-line; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Login */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.advanced summary { cursor: pointer; color: var(--muted); }
.advanced[open] { display: flex; flex-direction: column; gap: 12px; }
.advanced[open] summary { margin-bottom: 2px; }

/* Top bar */
#app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 800; letter-spacing: .5px; color: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav button { background: transparent; border-color: transparent; }
.nav button.active { background: var(--panel-2); border-color: var(--line); color: #fff; font-weight: 600; }
.global-search { margin-left: auto; width: 260px; max-width: 100%; }

#main { flex: 1; min-height: 0; position: relative; }

/* Browse */
.browse { display: flex; height: 100%; }
.sidebar {
  width: 260px; flex-shrink: 0; border-right: 1px solid var(--line); display: flex;
  flex-direction: column; padding: 12px; gap: 10px; min-height: 0;
}
.cat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.cat-list li {
  padding: 7px 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between;
  gap: 8px; color: var(--muted);
}
.cat-list li:hover { background: var(--panel-2); color: var(--text); }
.cat-list li.active { background: var(--panel-2); color: #fff; font-weight: 600; }
.cat-list li .n { font-size: 12px; opacity: .7; }
.content { flex: 1; min-width: 0; overflow-y: auto; padding: 12px 16px 24px; }
.toolbar {
  display: flex; gap: 10px; align-items: center; position: sticky; top: -12px; z-index: 2;
  background: var(--bg); padding: 12px 0; margin-top: -12px;
}
.toolbar #search { flex: 1; }
.toolbar #sort { width: auto; }
.cat-select { display: none; }

/* Items */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.card { cursor: pointer; border-radius: var(--radius); overflow: hidden; background: var(--panel); border: 1px solid var(--line); }
.card:hover, .card:focus-visible { border-color: var(--accent); }
.card .poster { aspect-ratio: 2/3; background: var(--panel-2); position: relative; overflow: hidden; }
.card .poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .meta { padding: 8px; }
.card .name { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.placeholder {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; font-weight: 700;
  color: #4a5160; text-transform: uppercase; padding: 8px; text-align: center;
}
.list { display: flex; flex-direction: column; gap: 4px; }
.chan {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.chan:hover, .chan:focus-visible { background: var(--panel); border-color: var(--line); }
.chan .logo { width: 56px; height: 36px; flex-shrink: 0; position: relative; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.chan .logo img { width: 100%; height: 100%; object-fit: contain; }
.chan .logo .placeholder { font-size: 13px; }
.chan .num { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; flex-shrink: 0; }
.chan .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* Loading */
.loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; background: rgba(15,17,21,.85); z-index: 5; color: var(--muted);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.main-error { padding: 24px 16px; max-width: 700px; white-space: pre-line; }

/* Results */
.results, .info { height: 100%; overflow-y: auto; padding: 16px 16px 32px; }
.results h2, .info h2 { font-size: 16px; margin: 22px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.results h2:first-child, .info h2:first-child { margin-top: 0; }
.results h2 button { font-size: 12px; padding: 3px 8px; }

/* Info */
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.info-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.info-card h3 { margin: 0 0 10px; font-size: 14px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.ok { color: #5ad18a; }
.no { color: var(--danger); }

/* Overlays */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 20; display: flex;
  align-items: flex-start; justify-content: center; padding: 32px 16px; overflow-y: auto;
}
.close { background: transparent; border: none; font-size: 26px; line-height: 1; padding: 2px 8px; color: var(--muted); }
.close:hover { color: #fff; }
.detail-card {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 900px; overflow: hidden;
}
.detail-card > .close { position: absolute; top: 10px; right: 10px; z-index: 2; background: rgba(0,0,0,.5); border-radius: 8px; }
.detail-hero { position: relative; padding: 24px; display: flex; gap: 20px; background-size: cover; background-position: center; }
.detail-hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(23,26,33,.97) 35%, rgba(23,26,33,.8)); }
.detail-hero > * { position: relative; }
.detail-hero .cover { width: 170px; flex-shrink: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 2/3; background: var(--panel-2); position: relative; }
.detail-hero .cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-hero h2 { margin: 0 0 6px; font-size: 22px; padding-right: 40px; }
.detail-hero .facts { color: var(--muted); font-size: 13px; display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.detail-hero .plot { margin: 0 0 12px; }
.detail-hero .people { font-size: 13px; color: var(--muted); margin: 0 0 14px; }
.detail-body { padding: 0 24px 24px; }
.seasons { display: flex; gap: 6px; flex-wrap: wrap; margin: 16px 0 12px; }
.seasons button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.episode {
  display: flex; gap: 12px; padding: 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; align-items: flex-start;
}
.episode:hover, .episode:focus-visible { background: var(--panel-2); border-color: var(--line); }
.episode .thumb { width: 130px; aspect-ratio: 16/9; flex-shrink: 0; background: var(--panel-2); border-radius: 6px; overflow: hidden; position: relative; }
.episode .thumb img { width: 100%; height: 100%; object-fit: cover; }
.episode .thumb .placeholder { font-size: 16px; }
.episode .ep-title { font-weight: 600; }
.episode .ep-plot { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.progress-bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); }

/* Player */
.player-overlay { background: rgba(0,0,0,.9); padding: 16px; align-items: center; }
.player-card { width: 100%; max-width: 1200px; display: flex; flex-direction: column; gap: 8px; }
.player-head { display: flex; align-items: center; gap: 8px; }
.player-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.player-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.video-wrap { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; max-height: calc(100vh - 190px); }
.video-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.video-spinner { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.video-error {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; background: rgba(0,0,0,.85);
}
.video-error p { max-width: 640px; margin: 0; white-space: pre-line; }
.player-foot { display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.badge { font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; color: var(--muted); }
.epg { flex-basis: 100%; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.epg .now { color: var(--text); }
.epg .later { color: var(--muted); }
.epg time { font-variant-numeric: tabular-nums; margin-right: 8px; color: var(--accent); }
.epg .desc { color: var(--muted); font-size: 12px; margin-left: 2px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 50;
}

@media (max-width: 760px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .global-search { width: 100%; margin-left: 0; }
  .sidebar { display: none; }
  .cat-select { display: block; }
  .toolbar { flex-wrap: wrap; }
  .toolbar #search { flex-basis: 100%; order: -1; }
  .toolbar .cat-select, .toolbar #sort { flex: 1; width: auto; }
  .content { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
  .detail-hero { flex-direction: column; padding: 16px; }
  .detail-hero .cover { width: 120px; }
  .detail-body { padding: 0 16px 16px; }
  .episode .thumb { width: 96px; }
  .player-overlay { padding: 8px; }
}
