/* ===== Reset & Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  background: #0b0b0d;
  color: #f2f2f4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; background: none; border: 0; outline: 0; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }

:root {
  --bg: #0b0b0d;
  --card: #161618;
  --card-2: #202024;
  --line: #2c2c31;
  --text: #f2f2f4;
  --dim: #9a9aa2;
  --accent: #8c8c93;
  --accent-hi: #b4b4bb;
  --radius: 12px;
  --gap: 12px;
}

/* ===== Header ===== */
.top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 11, 13, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.logo {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--text);
  margin-bottom: 10px;
  text-align: center;
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  transition: border-color 0.2s;
}
.search-wrap:focus-within { border-color: var(--accent); }
.search-wrap svg { width: 18px; height: 18px; color: var(--dim); flex-shrink: 0; }
.search-wrap input { flex: 1; min-width: 0; font-size: 15px; }
.search-wrap input::placeholder { color: var(--dim); }
.search-wrap input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--card);
  color: var(--dim);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all 0.18s;
}
.tab.on {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ===== Grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 12px;
  padding: 4px 16px 32px;
}
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.card {
  display: block;
  text-align: start;
  background: transparent;
  transition: transform 0.15s;
}
.card:active { transform: scale(0.97); }
.card .poster {
  position: relative;
  width: 100%;
  aspect-ratio: 2/3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card-2);
  display: grid;
  place-items: center;
}
.card .poster .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 44px;
  font-weight: 800;
  color: rgba(255,255,255,0.15);
  letter-spacing: 2px;
}
.card .poster .badges {
  position: absolute;
  top: 8px;
  right: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  pointer-events: none;
}
.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 4px;
  color: #fff;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
}
.badge.kind-movie { background: rgba(140, 140, 147, 0.9); color: #0b0b0d; }
.badge.kind-series { background: rgba(60, 60, 66, 0.9); }
.badge.quality {
  position: absolute;
  bottom: 8px;
  left: 8px;
  top: auto;
  right: auto;
}
.card h3 {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3px;
  font-size: 12px;
  color: var(--dim);
}

/* ===== Detail ===== */
.detail {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}
.detail.on { display: block; }
.detail-veil {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}
.detail-body {
  position: absolute;
  inset: 0;
  background: var(--bg);
  overflow-y: auto;
  padding-bottom: 40px;
}
.close-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 10;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(22, 22, 24, 0.9);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
}

/* Work header */
.work-hero {
  position: relative;
  height: 320px;
  background: var(--card-2);
  overflow: hidden;
}
.work-hero .hero-bg {
  position: absolute;
  inset: 0;
  filter: blur(20px);
  opacity: 0.5;
}
.work-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, var(--bg) 100%);
}
.work-hero .hero-content {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 20px 16px;
}
.work-poster {
  width: 110px;
  aspect-ratio: 2/3;
  border-radius: 10px;
  background: var(--card-2);
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 800;
  color: rgba(255,255,255,0.15);
  flex-shrink: 0;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.work-head-info { min-width: 0; padding-bottom: 6px; }
.work-head-info h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.work-head-info .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--dim);
}
.chip {
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--card);
  color: var(--dim);
  font-size: 12px;
}

/* Story */
.story {
  padding: 16px;
  font-size: 14px;
  line-height: 1.8;
  color: #c9c9cf;
}

/* Sections */
.sec {
  padding: 0 16px;
  margin-top: 20px;
}
.sec h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}
.sec h2 small {
  font-size: 12px;
  font-weight: 400;
  color: var(--dim);
  margin-inline-start: 8px;
}
.opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.opt {
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
.opt.on {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Episodes */
.eps {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ep {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: start;
  font-size: 14px;
  transition: all 0.15s;
}
.ep:hover { border-color: var(--accent); }
.ep .n {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--card-2);
  display: grid;
  place-items: center;
  font-weight: 600;
  color: var(--accent);
}
.ep .t { flex: 1; min-width: 0; }

/* Watch button */
.watch-wrap {
  padding: 16px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(0deg, var(--bg) 60%, transparent);
  margin-top: 16px;
}
.watch-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--bg);
  font-size: 16px;
  font-weight: 700;
  transition: all 0.15s;
}
.watch-btn:active { background: var(--accent-hi); }
.watch-btn:disabled { opacity: 0.5; cursor: wait; }
.watch-btn svg { width: 20px; height: 20px; }

/* Loader */
.loader {
  display: grid;
  place-items: center;
  padding: 40px;
  color: var(--dim);
}
.loader::after {
  content: "";
  width: 32px;
  height: 32px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--dim);
}
.empty h3 { font-size: 17px; color: var(--text); margin-bottom: 6px; }

/* Sentinel for infinite scroll */
.sentinel { height: 40px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--card-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 200;
  text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }