/* Kino Web — dark, mobile-first UI */
:root {
  --bg: #0b0d12;
  --bg-2: #12151c;
  --surface: #181c25;
  --surface-2: #202533;
  --line: #2a3040;
  --text: #eef0f5;
  --muted: #9aa3b5;
  --accent: #e8b04b;
  --accent-ink: #1a1408;
  --danger: #ff6b6b;
  --radius: 12px;
  --poster-w: 148px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  grid-template-areas: "brand search tabs repo settings";
  align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 20px 10px;
  background: rgba(11, 13, 18, .86);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, .05);
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 10px; top: 7px; border: 6px solid transparent; border-left: 9px solid var(--bg); border-right: 0; }
.brand-name span { color: var(--accent); }
.repo-picker { grid-area: repo; }
.repo-picker select, .field input, .search input {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 16px; /* prevents iOS zoom */
}
.repo-picker select { padding: 8px 30px 8px 10px; max-width: 220px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.search { grid-area: search; display: flex; align-items: center; gap: 8px; min-width: 0; }
.search input { width: 100%; padding: 9px 12px; }
.search input:focus, .field input:focus, .repo-picker select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.search-scope { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; white-space: nowrap; cursor: pointer; }
.tabs { grid-area: tabs; display: flex; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.tabs a.active { background: var(--surface-2); color: var(--text); }
.icon-btn {
  grid-area: settings;
  display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border-radius: 50%; border: 0; background: var(--surface); color: var(--text); cursor: pointer; font-size: 16px;
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "brand repo settings" "search search search" "tabs tabs tabs";
    gap: 10px; padding-left: 14px; padding-right: 14px;
  }
  .repo-picker { justify-self: end; }
  .repo-picker select { max-width: 46vw; }
  .tabs a { flex: 1; text-align: center; }
}

/* ── Main views ──────────────────────────────────────── */
main { padding: 18px 20px calc(40px + var(--safe-bottom)); outline: none; }
@media (max-width: 760px) { main { padding: 14px 14px calc(32px + var(--safe-bottom)); } :root { --poster-w: 118px; } }

.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 4px; }
.section-title h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.section-title button, .linkish {
  background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; padding: 4px 0;
}

.row {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--poster-w); gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity;
  padding-bottom: 6px; margin: 0 -20px; padding-left: 20px; padding-right: 20px; scrollbar-width: thin;
}
@media (max-width: 760px) { .row { margin: 0 -14px; padding-left: 14px; padding-right: 14px; gap: 10px; } }
.row > * { scroll-snap-align: start; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--poster-w), 1fr)); gap: 16px 12px; }

.card { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 7px; min-width: 0; -webkit-tap-highlight-color: transparent; }
.card:focus-visible .poster { outline: 2px solid var(--accent); outline-offset: 2px; }
.poster {
  position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  transition: transform .18s ease;
}
.card:hover .poster { transform: translateY(-3px); }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.poster .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; color: var(--muted); font-weight: 700; font-size: 14px; }
.poster .badge { position: absolute; top: 7px; left: 7px; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; background: rgba(0,0,0,.7); color: var(--text); text-transform: uppercase; letter-spacing: .03em; }
.card .t { font-size: 13.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .s { font-size: 12px; color: var(--muted); margin-top: -4px; }
.card.wide .poster { aspect-ratio: 16 / 9; }
.grid.channels { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.channels .poster img { object-fit: contain; padding: 14%; background: #0e1117; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 13px; font: inherit; font-size: 13.5px; cursor: pointer; text-decoration: none;
}
.chip.active, .chip:hover { border-color: var(--accent); color: var(--accent); }

.empty, .error-box {
  margin: 40px auto; max-width: 520px; text-align: center; color: var(--muted);
  padding: 26px 20px; border: 1px dashed var(--line); border-radius: var(--radius);
}
.error-box { border-style: solid; border-color: rgba(255, 107, 107, .35); }
.error-box strong { color: var(--text); display: block; margin-bottom: 6px; }
.error-box .btn { margin-top: 14px; }

.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.load-more { display: flex; justify-content: center; margin: 22px 0 0; }
.group-label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 26px 0 10px; }

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 15px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #3a4256; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── Dialogs ────────────────────────────────────────── */
dialog { color: var(--text); border: 0; padding: 0; background: var(--bg-2); }
dialog::backdrop { background: rgba(3, 4, 8, .72); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.modal { width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border-radius: 16px; }
.modal form { padding: 18px 20px 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.field { display: block; border: 0; margin: 14px 0 0; padding: 0; min-width: 0; }
.field > span, .field legend { display: block; margin-bottom: 6px; font-weight: 600; font-size: 13.5px; color: var(--muted); padding: 0; }
.field input { width: 100%; padding: 10px 12px; }
.with-btn { display: flex; gap: 8px; }
.with-btn input { flex: 1; min-width: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.hint.ok { color: #7ddc9b; } .hint.bad { color: var(--danger); }
.repo-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; }
.repo-list li { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.repo-list li.muted { color: var(--muted); font-size: 13.5px; }
.repo-meta { flex: 1; min-width: 0; display: grid; }
.repo-meta strong { font-size: 14px; }
.repo-meta code { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-src { flex: none; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 7px; border-radius: 6px; }
.badge-src.server { background: rgba(125, 220, 155, .12); color: #7ddc9b; }
.badge-src.browser { background: rgba(232, 176, 75, .12); color: var(--accent); }
.btn.small { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.icon-x { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; width: 30px; height: 30px; border-radius: 8px; flex: none; }
.icon-x:hover { color: var(--danger); background: var(--surface-2); }
.legend-note { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
@media (max-width: 760px) {
  .repo-list li { flex-wrap: wrap; }
  .repo-list li .btn.small { order: 5; width: 100%; }
}

/* Detail sheet */
.sheet { width: min(860px, 100vw); max-height: min(92dvh, 900px); border-radius: 18px; overflow: auto; overscroll-behavior: contain; }
.sheet-hero { position: relative; height: 230px; background: var(--surface) center / cover no-repeat; }
.sheet-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(18,21,28,.1), var(--bg-2)); }
.sheet-hero .close { position: absolute; top: 12px; right: 12px; z-index: 1; background: rgba(0,0,0,.55); }
.sheet-body { padding: 0 22px 26px; margin-top: -90px; position: relative; }
.detail-head { display: flex; gap: 18px; align-items: flex-end; }
.detail-poster { width: 120px; aspect-ratio: 2/3; object-fit: cover; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); flex: none; }
.detail-head h2 { margin: 0 0 4px; font-size: 26px; line-height: 1.15; letter-spacing: -.02em; }
.meta { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.overview { color: #c9cfdb; margin: 16px 0 6px; max-width: 70ch; }
.season-tabs { margin: 20px 0 12px; }
.episodes { display: grid; gap: 8px; }
.episode {
  all: unset; cursor: pointer; display: grid; grid-template-columns: 132px 1fr; gap: 12px; align-items: center;
  padding: 8px; border-radius: 12px; background: var(--surface); border: 1px solid transparent;
}
.episode:hover, .episode:focus-visible { border-color: var(--line); background: var(--surface-2); }
.episode .still { aspect-ratio: 16/9; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.episode .still img { width: 100%; height: 100%; object-fit: cover; }
.episode .et { font-weight: 600; font-size: 14px; }
.episode .eo { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
@media (max-width: 760px) {
  .sheet { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto auto 0; border-radius: 18px 18px 0 0; }
  .sheet-hero { height: 170px; }
  .sheet-body { padding: 0 16px calc(24px + var(--safe-bottom)); margin-top: -70px; }
  .detail-poster { width: 92px; }
  .detail-head h2 { font-size: 21px; }
  .episode { grid-template-columns: 112px 1fr; }
}

/* Player */
.player { width: min(1100px, 100vw); max-width: 100vw; max-height: 100dvh; border-radius: 16px; overflow: auto; background: #07080b; }
.player-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; }
.player-bar h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.video-wrap { position: relative; background: #000; aspect-ratio: 16 / 9; }
.video-wrap video { width: 100%; height: 100%; display: block; background: #000; }
.video-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--text); background: rgba(0,0,0,.78); font-size: 15px; }
.video-msg small { display: block; color: var(--muted); margin-top: 6px; }
.player-panel { padding: 14px 14px calc(18px + var(--safe-bottom)); display: grid; gap: 12px; }
.ext-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.notice { background: rgba(232, 176, 75, .1); border: 1px solid rgba(232, 176, 75, .35); color: #f2d9a6; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.stream-url { display: block; color: var(--muted); font-size: 12px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.chips:empty { display: none; }
.chips .label { color: var(--muted); font-size: 13px; align-self: center; margin-right: 2px; }
@media (max-width: 760px) {
  .player { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; padding-top: var(--safe-top); }
  .ext-buttons .btn { flex: 1 1 calc(50% - 8px); }
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + var(--safe-bottom)); transform: translateX(-50%); z-index: 100;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { border-color: rgba(255, 107, 107, .5); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
