:root {
  --bg: #0a0b10;
  --bg-soft: #12141d;
  --surface: #181b27;
  --surface-2: #1f2333;
  --border: #262a3a;
  --text: #e7e9f0;
  --muted: #9aa0b4;
  --accent: #6c5ce7;
  --accent-2: #00d2ff;
  --danger: #ff5c7c;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  font-size: 16px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 92, 231, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(0, 210, 255, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
button { font-family: inherit; cursor: pointer; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: rgba(10, 11, 16, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; user-select: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px;
  box-shadow: 0 6px 18px rgba(108, 92, 231, 0.45);
}
.brand-name { font-weight: 800; letter-spacing: 0.3px; font-size: 1.15rem; }
.brand-name span { color: var(--accent-2); }

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  max-width: 620px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25); }
.search-icon { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 0.95rem;
}
.search input::placeholder { color: var(--muted); }
.clear-search {
  background: none; border: none; color: var(--muted);
  font-size: 1.3rem; line-height: 1; padding: 0 4px;
}

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 0.2s, transform 0.1s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn svg { width: 20px; height: 20px; }

/* Tabs */
.tabs {
  display: flex; gap: 8px;
  padding: 16px 22px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(108, 92, 231, 0.35);
}

/* Hero */
.hero {
  margin: 14px 22px 6px;
  border-radius: 18px;
  overflow: hidden;
  position: relative;
  min-height: 360px;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--border);
}
.hero-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(10,11,16,0.1) 0%, rgba(10,11,16,0.55) 55%, var(--bg) 100%);
}
.hero-content { position: relative; z-index: 2; padding: 28px; max-width: 640px; }
.hero-tag {
  display: inline-block; font-size: 0.72rem; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--accent-2); font-weight: 700; margin-bottom: 8px;
}
.hero-title { font-size: 2.1rem; margin: 0 0 10px; line-height: 1.15; }
.hero-overview { color: var(--muted); margin: 0 0 18px; font-size: 0.95rem; }
.hero .play-btn { font-size: 1rem; }

/* Main */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 22px 22px 12px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 1.35rem; }
.filters { display: flex; gap: 10px; }
.filters select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font-size: 0.85rem; outline: none;
}
.filters select:focus { border-color: var(--accent); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 0 22px 30px;
}

.card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
  animation: fade 0.35s ease both;
}
.card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow);
  border-color: var(--accent);
}
.card-poster {
  aspect-ratio: 2 / 3;
  width: 100%;
  object-fit: cover;
  background: var(--surface-2);
}
.card-fallback {
  aspect-ratio: 2 / 3;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--surface-2), var(--bg-soft));
  color: var(--muted); font-size: 2.4rem; font-weight: 800; text-align: center;
  padding: 10px;
}
.card-body { padding: 10px 12px 12px; }
.card-title {
  font-size: 0.86rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-sub { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.card-year { color: var(--muted); font-size: 0.78rem; }
.badge {
  font-size: 0.7rem; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: rgba(255,255,255,0.08); color: var(--text);
}
.badge.tv { color: var(--accent-2); }
.badge.movie { color: var(--accent); }
.rating {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(6px);
  padding: 3px 8px; border-radius: 8px; font-size: 0.72rem; font-weight: 700;
  display: flex; align-items: center; gap: 4px;
}
.rating svg { width: 11px; height: 11px; color: #ffce3a; }

/* Loader / empty / button */
.loader { display: grid; place-items: center; padding: 30px; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.load-more {
  display: block; margin: 0 auto 40px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 11px 28px; font-weight: 600; transition: all 0.2s;
}
.load-more:hover { border-color: var(--accent); background: var(--surface-2); }

/* Overlays / detail */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 6, 10, 0.82);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade 0.25s ease;
  overflow-y: auto;
}
.detail {
  position: relative;
  width: min(860px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.detail-bg { position: absolute; inset: 0; height: 280px; object-fit: cover; opacity: 0.35; }
.detail-bg::after { content: ""; }
.detail::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 280px;
  background: linear-gradient(180deg, transparent, var(--surface));
}
.detail-body { position: relative; z-index: 2; display: flex; gap: 22px; padding: 24px; }
.detail-poster { width: 180px; border-radius: 12px; flex: none; box-shadow: var(--shadow); }
.detail-info { flex: 1; }
.detail-info h1 { margin: 0 0 8px; font-size: 1.7rem; }
.meta { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; }
.meta .dot { color: var(--accent-2); }
.overview { color: #c8cce0; line-height: 1.55; font-size: 0.92rem; }
.seasons { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.season-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px; font-size: 0.8rem; cursor: pointer;
}
.season-chip.active { border-color: var(--accent); color: var(--accent-2); }
.actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

.play-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 12px;
  padding: 12px 26px; font-weight: 700; font-size: 0.95rem;
  box-shadow: 0 8px 22px rgba(108, 92, 231, 0.4);
  transition: transform 0.12s, box-shadow 0.2s;
}
.play-btn:hover { transform: translateY(-2px); box-shadow: 0 12px 28px rgba(108, 92, 231, 0.55); }
.play-btn:active { transform: translateY(0); }
.ghost-btn {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 22px; font-weight: 600; transition: all 0.2s;
}
.ghost-btn:hover { border-color: var(--accent); }

.close-btn {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(0,0,0,0.5); border: 1px solid var(--border);
  color: #fff; font-size: 1.4rem; line-height: 1;
}
.close-btn:hover { background: var(--danger); }

/* Player */
.player-view {
  position: fixed; inset: 0; z-index: 80;
  background: #000;
  display: flex; flex-direction: column;
  animation: fade 0.25s ease;
}
.player-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.player-title { font-weight: 700; flex: 1; min-width: 160px; }
.servers { display: flex; gap: 8px; flex-wrap: wrap; }
.server-btn {
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 14px; font-size: 0.82rem; font-weight: 600; transition: all 0.18s;
}
.server-btn:hover { color: var(--text); }
.server-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }
.player-frame-wrap { flex: 1; position: relative; background: #000; }
#playerFrame { width: 100%; height: 100%; border: none; }
.player-fallback {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); background: var(--bg); text-align: center; padding: 20px;
}

/* Auth + user menu */
.login-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; border-radius: 10px;
  padding: 9px 16px; font-weight: 700; font-size: 0.85rem; transition: transform 0.12s;
}
.login-btn:hover { transform: translateY(-1px); }
.user-area { position: relative; }
.user-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border: none; font-weight: 800; cursor: pointer;
}
.user-dropdown {
  position: absolute; right: 0; top: 46px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px; min-width: 150px; box-shadow: var(--shadow);
}
.dropdown-item {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 9px 12px; border-radius: 8px; font-size: 0.88rem;
}
.dropdown-item:hover { background: var(--surface-2); }

.auth-card {
  position: relative; width: min(380px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px; box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0 0 18px; text-align: center; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form input {
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-size: 0.95rem; outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-toggle { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 14px 0 0; }
.auth-toggle a { color: var(--accent-2); cursor: pointer; font-weight: 700; }
.auth-error { color: var(--danger); text-align: center; font-size: 0.85rem; min-height: 1em; margin: 10px 0 0; }

.player-progress {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.player-progress .prog-label { font-size: 0.82rem; color: var(--muted); white-space: nowrap; }
.player-progress .prog-label b { color: var(--accent-2); }
.player-progress input[type="range"] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.player-progress .prog-saved { color: var(--accent-2); font-size: 0.8rem; }

/* History cards */
.history-card {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
}
.history-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--accent); }
.history-poster { aspect-ratio: 2/3; width: 100%; object-fit: cover; background: var(--surface-2); }
.history-body { padding: 10px 12px 12px; }
.history-title { font-size: 0.84rem; font-weight: 600; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.history-meta { font-size: 0.74rem; color: var(--muted); margin-top: 4px; }
.history-bar { height: 6px; border-radius: 4px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.history-bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.history-actions { display: flex; gap: 8px; margin-top: 10px; }
.history-actions button { flex: 1; padding: 8px 0; font-size: 0.8rem; }
.history-remove {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(0,0,0,0.6); border: 1px solid var(--border);
  color: #fff; font-size: 1.1rem; line-height: 1;
}
.history-remove:hover { background: var(--danger); }
.history-empty { text-align: center; color: var(--muted); padding: 50px 20px; }

/* Settings */
.settings-card {
  position: relative;
  width: min(520px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.settings-card h2 { margin: 0 0 18px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-weight: 600; margin-bottom: 7px; font-size: 0.9rem; }
.field input[type="text"], .field select {
  width: 100%; background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; font-size: 0.9rem; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field small { display: block; color: var(--muted); margin-top: 6px; font-size: 0.78rem; }
.field code { background: var(--bg-soft); padding: 1px 5px; border-radius: 5px; color: var(--accent-2); }
.server-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.server-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 0.85rem;
}
.server-row .sname { font-weight: 600; flex: 1; }
.server-row .sdefault { color: var(--accent-2); font-size: 0.72rem; }
.server-row button { background: none; border: none; color: var(--danger); font-size: 1.1rem; }
.add-server { display: flex; gap: 8px; flex-wrap: wrap; }
.add-server input { flex: 1; min-width: 120px; background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; outline: none; }
.add-server input:focus { border-color: var(--accent); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 12px 20px; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 100; font-size: 0.9rem;
  animation: fade 0.2s ease;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Responsive */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .search { order: 3; max-width: 100%; flex-basis: 100%; }
  .brand-name { font-size: 1.05rem; }
  .hero { min-height: 300px; margin: 12px 16px; }
  .hero-title { font-size: 1.5rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; padding: 0 16px 24px; }
  .detail-body { flex-direction: column; }
  .detail-poster { width: 140px; align-self: center; }
  .section-head { padding: 18px 16px 10px; }
}
