@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* Any element with the `hidden` attribute must actually be hidden, even if
   a later class rule (e.g. .modal-scrim { display: flex }) targets it -
   author rules of equal specificity otherwise beat the UA's [hidden] rule. */
[hidden] { display: none !important; }

:root {
  --bg: #000000;
  --bg-elevated: #0c0c0d;
  --bg-card: #121214;
  --bg-muted: #181818;
  --accent: #e11d48;
  --accent-hover: #f43f5e;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: #312e81;
  --radius: 12px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 16px;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection { background: var(--accent); color: #fff; }

.icon { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.brand-icon { color: var(--accent); width: 24px; height: 24px; }
.brand b { font-weight: 800; }

.tabs { display: flex; gap: 4px; }

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  transition: background 200ms var(--ease), color 200ms var(--ease), border-color 200ms var(--ease);
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.tab.active { color: #fff; background: var(--accent); }
.tab .icon { width: 18px; height: 18px; }

.search-wrap {
  margin-left: auto;
  position: relative;
  width: 320px;
  max-width: 40vw;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
}
#search {
  width: 100%;
  padding: 10px 12px 10px 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 150ms var(--ease), background 150ms var(--ease);
}
#search:focus { border-color: var(--accent); background: #1c1c1e; }
#search::placeholder { color: var(--text-muted); }

.status-bar {
  padding: 6px 24px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.status-bar.error { color: #fca5a5; }
.status-bar.ok { color: #6ee7b7; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 84px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px 8px;
  overflow-y: auto;
  max-height: calc(100vh - 84px);
  position: sticky;
  top: 84px;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 8px 12px;
}
.sidebar-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.gear-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.gear-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.gear-btn .icon { width: 18px; height: 18px; }
.gear-btn:disabled { opacity: 0.5; cursor: default; }
#refreshBtn { margin-left: 8px; }
#refreshBtn.spinning .icon { animation: spin 900ms linear infinite; }
.sidebar-hint {
  padding: 12px;
  font-size: 12.5px;
  color: var(--text-muted);
}
.cat-search-wrap { padding: 0 4px 8px 12px; }
.cat-search-wrap input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  transition: border-color 150ms var(--ease), background 150ms var(--ease);
}
.cat-search-wrap input:focus { border-color: var(--accent); background: #1c1c1e; }
.cat-search-wrap input::placeholder { color: var(--text-muted); }
.cat-item-fav { font-weight: 600; }
.cat-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.cat-item:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.cat-item.active { background: var(--bg-card); color: #fff; border: 1px solid var(--border-strong); }

.content { padding: 20px 24px 48px; }

/* ---------- Grid & cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 18px;
}
.grid.live-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 200ms var(--ease), border-color 200ms var(--ease), box-shadow 200ms var(--ease);
  position: relative;
}
.card:hover, .card:focus-within {
  transform: translateY(-4px) scale(1.02);
  border-color: var(--border-strong);
  box-shadow: 0 12px 28px rgba(0,0,0,0.55);
}

.poster-wrap {
  position: relative;
  aspect-ratio: 2 / 3;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.live-grid .poster-wrap { aspect-ratio: 16 / 10; padding: 14px; }
.poster-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.live-grid .poster-wrap img { object-fit: contain; }
.poster-fallback { color: var(--text-muted); width: 40%; height: 40%; opacity: 0.5; }

.card-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 20px 10px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.92), rgba(0,0,0,0));
  pointer-events: none;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge-rating {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 3px;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(6px);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-rating .icon { width: 12px; height: 12px; color: #fbbf24; }

.fav-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 150ms var(--ease), transform 150ms var(--ease);
}
.fav-btn:hover { background: rgba(0,0,0,0.85); transform: scale(1.08); }
.fav-btn .icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.fav-btn.active .icon { fill: var(--accent); stroke: var(--accent); }

.play-hover {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 200ms var(--ease);
}
.card:hover .play-hover { opacity: 1; }
.play-hover .icon { width: 46px; height: 46px; color: #fff; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6)); }

.card-name-below {
  padding: 8px 10px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Loading state ---------- */
.loading-state {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  padding: 80px 0;
  color: var(--text-muted);
  font-size: 14px;
}
.loading-state::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-muted);
}
.empty-icon { width: 42px; height: 42px; }

/* ---------- Modal ---------- */
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 180ms var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  animation: modalIn 220ms var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.modal-close:hover { background: rgba(0,0,0,0.8); }

.modal-hero {
  width: 100%;
  aspect-ratio: 16 / 7;
  object-fit: cover;
  background: var(--bg-muted);
  display: block;
}
.modal-content { padding: 24px 28px 28px; }
.modal-title { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.modal-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.modal-meta .badge-rating { position: static; background: var(--bg-muted); }
.modal-plot { font-size: 14px; line-height: 1.65; color: var(--text); margin-bottom: 18px; }
.modal-plot.muted { color: var(--text-muted); }

.modal-actions { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 14px;
  font-weight: 600;
  transition: background 150ms var(--ease), transform 150ms var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn-play { background: var(--accent); color: #fff; }
.btn-play:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-muted); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #222226; }
.btn-secondary.active { color: var(--accent); border-color: var(--accent); }
.btn .icon { width: 17px; height: 17px; }

.resume-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-muted);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  cursor: pointer;
  color: var(--text);
}
.resume-chip:hover { border-color: var(--accent); }

.season-select {
  background: var(--bg-muted);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

.ep-list { display: flex; flex-direction: column; gap: 8px; }
.ep-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 150ms var(--ease);
}
.ep-row:hover { border-color: var(--border-strong); }
.ep-num {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.ep-title { flex: 1; font-size: 13.5px; }
.ep-play {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--bg-muted);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ep-play:hover { background: var(--accent); color: #fff; }
.ep-play .icon { width: 15px; height: 15px; }

/* ---------- Settings modal ---------- */
.settings-modal { padding: 24px 28px 28px; }
.settings-search { width: 100%; max-width: none; margin: 14px 0; }
.settings-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.settings-actions .btn { padding: 7px 14px; font-size: 12.5px; }
.settings-cat-list {
  max-height: 340px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 18px;
}
.settings-cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  cursor: pointer;
}
.settings-cat-row:hover { background: rgba(255,255,255,0.06); }
.settings-cat-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.settings-order-list {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 18px;
}
.order-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid transparent;
  font-size: 13px;
  cursor: grab;
}
.order-row:active { cursor: grabbing; }
.order-row.dragging { opacity: 0.5; border-color: var(--accent); }
.order-drag-handle { color: var(--text-muted); font-size: 12px; letter-spacing: 1px; user-select: none; }
.order-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.order-pos-input {
  width: 60px;
  padding: 4px 4px 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 12px;
  text-align: center;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a2e; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a40; }

/* ---------- Responsive ---------- */
html, body { overflow-x: hidden; max-width: 100vw; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    display: flex;
    overflow-x: auto;
    gap: 6px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-title { display: none; }
  .cat-item { white-space: nowrap; }
  .topbar { flex-wrap: wrap; row-gap: 10px; }
  .tabs {
    order: 2;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex-shrink: 0; }
  .search-wrap { width: 100%; max-width: none; order: 3; }
  .user-menu { order: 1; margin-left: auto; }
}

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

/* ---------- User menu / auth ---------- */
.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 12px;
}
.user-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}
.logout-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  transition: background 150ms var(--ease), color 150ms var(--ease);
}
.logout-btn:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* ---------- Video player ---------- */
.player-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.player-wrap {
  width: 100%;
  max-width: 1100px;
  max-height: 70vh;
  aspect-ratio: 16 / 9;
  position: relative;
}
.player-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  border-radius: 10px;
  display: block;
}
.player-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  margin-top: 12px;
  text-align: center;
}
.player-scrim .modal-close { top: -46px; right: 0; }
.player-scrim #playerMinimize { right: 46px; }

/* ---------- Docked / mini player ----------
   The scrim itself shrinks to a small corner box instead of covering the
   viewport, so the sidebar, category search, top-bar search, and grid are
   simply not underneath it anymore - no pointer-events juggling needed. The
   [hidden] attribute (governed by the global [hidden] rule) still controls
   whether the whole player is shown at all; .docked only ever changes LAYOUT
   of an already-visible player, so it never fights that rule. */
.player-scrim.docked {
  inset: auto;
  top: auto;
  left: auto;
  right: 20px;
  bottom: 20px;
  width: 320px;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
  z-index: 500;
  animation: none;
  justify-content: stretch;
}
.player-scrim.docked .player-wrap {
  width: 100%;
  max-width: none;
  max-height: none;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  box-shadow: 0 14px 34px rgba(0,0,0,0.6);
}
.player-scrim.docked .player-wrap video {
  border-radius: 0;
}
.player-scrim.docked .player-controls,
.player-scrim.docked .player-title,
.player-scrim.docked #playerClose,
.player-scrim.docked #playerMinimize {
  display: none;
}
.player-mini-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px 8px;
  background: rgba(0,0,0,0.88);
}
.mini-ctrl-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms var(--ease);
}
.mini-ctrl-btn:hover { background: rgba(255,255,255,0.2); }
.mini-ctrl-btn .icon { width: 16px; height: 16px; }

@media (max-width: 480px) {
  .player-scrim.docked { width: calc(100vw - 24px); right: 12px; bottom: 12px; }
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.player-controls .btn {
  padding: 8px 10px;
}
.player-controls .btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.player-controls .btn:disabled:hover { background: var(--bg-muted); }
.player-volume {
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-volume input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
}
#playerFavBtn .icon { fill: none; stroke: currentColor; stroke-width: 1.8; }
#playerFavBtn.active { color: var(--accent); border-color: var(--accent); }
#playerFavBtn.active .icon { fill: var(--accent); stroke: var(--accent); }

/* ---------- Users admin panel ---------- */
.users-panel { max-width: 760px; }
.users-panel .btn { margin-bottom: 16px; }
.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  background: var(--bg-card);
}
.user-row .u-name { font-weight: 600; flex: 1; }
.user-row .u-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
}
.user-row .u-badge.admin { background: var(--accent); color: #fff; }
.user-row .u-actions { display: flex; gap: 8px; }
.user-row .u-actions button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12.5px;
}
.user-row .u-actions button:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.user-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}
.user-form-grid input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 13.5px;
}
.perm-section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 16px 0 8px;
}
.perm-quick-select { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 8px; }
.perm-quick-select .btn { padding: 5px 10px; font-size: 11.5px; }
.perm-check-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 160px;
  overflow-y: auto;
  padding: 4px;
}
.perm-check-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}
.perm-check-list input { accent-color: var(--accent); }
