:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #1f242d;
  --border: #2a303b;
  --text: #e6e9ef;
  --muted: #9aa4b2;
  --accent: #7aa2ff;
  --accent-ink: #0b1220;
  --live: #e5384a;
  --warn-bg: #2a2416;
  --warn-border: #5a4a1e;
  --radius: 12px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}
body:has(dialog[open]) { overflow: hidden; }

h1, h2, p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 1rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---- controls ---- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: 0 .95rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .92rem; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: #3a4250; background: #262c37; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: #93b3ff; border-color: #93b3ff; }
.btn-quiet { background: transparent; }
.btn-close { background: var(--surface-2); font-weight: 600; }

input[type="text"], input[type="password"], input[type="search"] {
  width: 100%; min-height: 44px; padding: 0 .85rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}
input::placeholder { color: #6f7988; }

/* ---- login ---- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login-card {
  width: min(100%, 380px); display: grid; gap: 1rem; padding: 1.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.field { display: grid; gap: .35rem; font-size: .9rem; color: var(--muted); }
.form-error {
  padding: .6rem .75rem; border-radius: 8px; font-size: .92rem;
  background: #2b171b; border: 1px solid #63262f; color: #ffb3bb;
}

/* ---- top bar ---- */
.brand { font-weight: 700; letter-spacing: .02em; font-size: 1.2rem; }
.brand-lg { font-size: 1.8rem; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .5rem 1.25rem; flex-wrap: wrap;
  padding: .6rem clamp(.75rem, 3vw, 1.5rem);
  background: rgba(14, 17, 22, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: .25rem; overflow-x: auto; }
.tab {
  padding: .45rem .85rem; border-radius: 999px; color: var(--muted);
  text-decoration: none; white-space: nowrap; font-weight: 500;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab[aria-current="page"] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--border); }
.user { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
@media (max-width: 560px) {
  .user .muted { display: none; }
  .tabs { order: 3; width: 100%; }
}

/* ---- content ---- */
.content { max-width: 1400px; margin: 0 auto; padding: 1rem clamp(.75rem, 3vw, 1.5rem) 3rem; }
.search { margin-bottom: 1rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; margin-bottom: 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip {
  appearance: none; display: inline-flex; align-items: center; gap: .4rem;
  min-height: 36px; padding: 0 .85rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font: inherit; font-size: .9rem;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip-count { font-size: .78rem; opacity: .8; }
.refresh { display: flex; align-items: center; gap: .6rem; margin-left: auto; }

.notices { display: grid; gap: .5rem; }
.notices:not(:empty) { margin-bottom: 1rem; }
.notice {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .45rem .5rem .45rem .85rem; border-radius: 8px; font-size: .9rem;
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: #f1dca6;
}
.notice-x {
  appearance: none; flex: none; width: 32px; height: 32px; border-radius: 8px; border: 0;
  background: transparent; color: inherit; font-size: 1.25rem; line-height: 1; cursor: pointer;
}
.notice-x:hover { background: rgba(255, 255, 255, .08); }

.empty { text-align: center; padding: 4rem 1rem; display: grid; gap: .5rem; justify-items: center; }
.empty-title { font-size: 1.15rem; font-weight: 600; }

/* ---- cards ---- */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.card {
  appearance: none; display: flex; flex-direction: column; padding: 0; text-align: left;
  background: var(--surface); color: inherit; font: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  transition: transform .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: #3d4656; }
.thumb {
  display: block; position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, #222a38, #161b24); overflow: hidden;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb-glyph {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  font-size: 2.5rem; font-weight: 700; color: #3c465a;
}
.thumb.noimg .thumb-glyph { display: flex; }
.thumb-badges { position: absolute; left: .5rem; top: .5rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.badge {
  display: inline-block; padding: .1rem .45rem; border-radius: 6px; font-size: .75rem; font-weight: 600;
  line-height: 1.5; white-space: nowrap;
}
.badge-live { background: var(--live); color: #fff; letter-spacing: .05em; }
.badge-dark { background: rgba(0, 0, 0, .75); color: #fff; }
.badge-dur { position: absolute; right: .5rem; bottom: .5rem; }
.badge-provider { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); font-weight: 500; }
.card-body { padding: .7rem .8rem .85rem; display: flex; flex-direction: column; gap: .2rem; }
.card-title {
  font-weight: 600; line-height: 1.3; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.card-channel { display: block; color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; margin-top: .3rem; }
.meta-text { color: var(--muted); font-size: .82rem; }

.skeleton { pointer-events: none; }
.skeleton .thumb { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---- player ---- */
.player {
  width: min(96vw, 1100px); max-height: 96vh; max-height: 96dvh; padding: 0; overflow: auto;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
}
.player::backdrop { background: rgba(0, 0, 0, .78); }
.player-shell { display: flex; flex-direction: column; gap: .6rem; padding: .75rem; }
.player-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.player-title { flex: 1 1 200px; min-width: 0; font-size: 1.05rem; line-height: 1.3; overflow-wrap: anywhere; }
.player-stage {
  /* Embedded players must stay >= 400x300: 16:9 at 534px wide is 300px tall.
     Narrower viewports get the full width and a 300px floor. */
  width: min(100%, max(534px, calc((100vh - 170px) * 16 / 9)));
  width: min(100%, max(534px, calc((100dvh - 170px) * 16 / 9)));
  min-height: 300px; margin-inline: auto; aspect-ratio: 16 / 9;
  background: #000; border-radius: 8px; overflow: hidden;
}
.player-stage:empty { background: var(--bg); }
.player-frame { display: block; width: 100%; height: 100%; border: 0; background: #000; }
.player-link { height: 100%; display: grid; place-content: center; justify-items: center; gap: 1rem; padding: 1rem; text-align: center; }
.player-status { min-height: 1.4em; }
.player-desc { max-height: 6em; overflow: auto; white-space: pre-line; overflow-wrap: anywhere; }
@media (max-width: 560px) {
  .player { width: 100vw; max-width: 100vw; border-radius: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .card:hover { transform: none; }
}

/* ---- footer ---- */
.site-footer {
  max-width: 1400px; margin: 0 auto; padding: 1rem clamp(.75rem, 3vw, 1.5rem) 2rem;
  border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem;
  display: flex; flex-wrap: wrap; gap: .3rem 1rem;
}
.site-footer a { color: var(--accent); }
