:root {
  --bg: #000;
  --surface: #141414;
  --text: #f5f5f5;
  --muted: #8b949e;
  --red: #e50914;
  --card: #1a1a1a;
  --radius: 10px;
  --nav-h: 64px;
  --top-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  padding-top: calc(var(--top-h) + var(--safe-top));
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.muted { color: var(--muted); }
.center { text-align: center; }

.topbar {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: 40;
  height: calc(var(--top-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 16px;
  background: linear-gradient(180deg, #000 60%, transparent);
}
.topbar__brand {
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--red);
  font-size: 1.15rem;
}
.topbar__title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.95rem;
  color: var(--text);
  max-width: 42vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#app { min-height: 60vh; padding-inline: 0; }

.bottom-nav {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(8px + var(--safe-bottom));
  z-index: 50;
  height: var(--nav-h);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 28px;
  background: rgba(28, 28, 28, 0.92);
  border: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 18px;
  color: #808080;
  font-size: 0.7rem;
}
.nav-item svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.nav-item.is-active {
  color: #fff;
  background: rgba(255,255,255,0.08);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.14);
  background: #222;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.btn--primary { background: var(--red); border-color: var(--red); }

.spinner {
  width: 36px; height: 36px;
  margin: 48px auto;
  border: 3px solid #333;
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  margin: 40px 20px;
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.hero {
  position: relative;
  height: min(72vh, 520px);
  overflow: hidden;
  margin-bottom: 12px;
}
.hero__bg {
  width: 100%; height: 100%;
  object-fit: cover;
  filter: brightness(0.55);
}
.hero__content {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  padding: 28px 18px 36px;
  background: linear-gradient(transparent, #000 85%);
}
.hero__title {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  line-height: 1.15;
}
.hero__meta { margin: 0 0 14px; color: #ddd; }

.row { margin: 18px 0 8px; }
.row__title {
  margin: 0 16px 10px;
  font-size: 1.15rem;
}
.row__scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 0 16px 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.row__scroller::-webkit-scrollbar { display: none; }

.poster-card {
  flex: 0 0 118px;
  width: 118px;
  scroll-snap-align: start;
  position: relative;
}
.poster-card__img {
  width: 118px;
  height: 177px;
  object-fit: cover;
  border-radius: 8px;
  background: #1a1a1a;
}
.poster-card__title {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  line-height: 1.25;
  max-height: 2.5em;
  overflow: hidden;
}
.poster-card__rating {
  position: absolute;
  top: 6px;
  inset-inline-end: 6px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

.person-card {
  flex: 0 0 96px;
  width: 96px;
  text-align: center;
}
.person-card__img {
  width: 84px;
  height: 84px;
  margin-inline: auto;
  border-radius: 50%;
  object-fit: cover;
  background: #222;
  border: 2px solid #333;
}
.person-card__name {
  display: block;
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 700;
}
.person-card__role {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  padding: 8px 16px 20px;
}
.grid .poster-card { width: auto; flex: none; }
.grid .poster-card__img { width: 100%; height: auto; aspect-ratio: 2/3; }

.page-head { padding: 8px 16px 0; }
.page-head h1 { margin: 0 0 4px; font-size: 1.5rem; }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px;
}
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: #1f1f1f;
  border: 1px solid #333;
  font-size: 0.85rem;
}
.chip.is-active { background: var(--red); border-color: var(--red); }

.pager {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px 24px;
}

.search-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}
.search-input {
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid #333;
  background: #141414;
  color: #fff;
  padding: 0 14px;
  font-size: 1rem;
}

.detail-hero { position: relative; margin-bottom: 8px; }
.detail-hero__bg {
  width: 100%;
  height: 240px;
  object-fit: cover;
  filter: brightness(0.4);
}
.detail-hero__body {
  display: flex;
  gap: 14px;
  padding: 0 16px;
  margin-top: -72px;
  position: relative;
}
.detail-hero__poster {
  width: 120px;
  height: 180px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  background: #222;
}
.detail-hero__info { flex: 1; padding-top: 78px; }
.detail-hero__info h1 { margin: 0 0 8px; font-size: 1.35rem; line-height: 1.25; }
.genres { color: #ccc; font-size: 0.85rem; }

.block { padding: 12px 16px 4px; }
.block h2 { margin: 0 0 8px; font-size: 1.1rem; }
.overview { margin: 0; line-height: 1.7; color: #ddd; white-space: pre-wrap; }

.play-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  padding: 12px 16px 4px;
}
.play-actions .btn { width: 100%; font-size: 0.88rem; padding: 0 10px; }
.play-actions__play { font-size: 0.95rem; }
.btn--sm {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
  border-radius: 999px;
}

.season-list { display: grid; gap: 8px; }
.season-item {
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
}
.season-item--expandable { padding: 0; }
.season-item__head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  text-align: start;
  font: inherit;
}
.season-item.is-open { outline: 1px solid rgba(229, 9, 20, 0.35); }
.episode-list {
  display: grid;
  gap: 8px;
  padding: 0 10px 12px;
}
.episode-list.is-collapsed { display: none; }
.episode-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 10px;
  border-radius: 10px;
  background: #111;
  border: 1px solid #222;
}
.episode-row__meta { display: flex; justify-content: space-between; gap: 8px; }
.episode-row__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: min(560px, 100%);
  max-height: min(72vh, 560px);
  overflow: auto;
  background: #161616;
  border-radius: 18px 18px 0 0;
  padding: 10px 14px 18px;
  border: 1px solid #2a2a2a;
}
.sheet__handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: #444;
  margin: 4px auto 12px;
}
.sheet__title { margin: 0 4px 6px; font-size: 1.05rem; }
.sheet__sub { margin: 0 4px 10px; font-size: 0.82rem; }
.sheet__list { display: grid; gap: 6px; }
.sheet__item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: start;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid #2a2a2a;
  background: #1c1c1c;
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.sheet__item:active { background: #262626; }
.sheet__hint { font-size: 0.75rem; color: var(--muted); }
.sheet__cancel { width: 100%; margin-top: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 24px);
  transform: translateX(-50%) translateY(20px);
  z-index: 90;
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20,20,20,0.95);
  border: 1px solid #333;
  color: #fff;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  flex-direction: column;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + var(--safe-top));
  background: #0a0a0a;
}
.player-bar__title {
  flex: 1;
  text-align: center;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-bar__btn {
  border: 0;
  background: #222;
  color: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
.player-video {
  width: 100%;
  flex: 1;
  min-height: 0;
  background: #000;
  object-fit: contain;
}
.player-status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #ddd;
  pointer-events: none;
  text-align: center;
  padding: 0 16px;
}
body.player-open { overflow: hidden; }
body.player-open .bottom-nav,
body.player-open .topbar { visibility: hidden; }

.person-hero {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: center;
}
.person-hero__photo {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #333;
  background: #222;
}
.person-hero__info h1 { margin: 0 0 8px; }

@media (min-width: 900px) {
  .hero { height: 560px; }
  .poster-card, .poster-card { flex-basis: 140px; width: 140px; }
  .poster-card__img { width: 140px; height: 210px; }
  #app { max-width: 1100px; margin-inline: auto; }
}
