:root {
  --bg: #131110;
  --panel: #1c1815;
  --panel-raised: #241f1a;
  --surface-sunken: #0d0b0a;
  --surface-hover: #2c2620;
  --border: #332c24;
  --text: #f3ede2;
  --text-muted: #a89d8d;
  --gold: #e8b84b;
  --gold-dim: #8a6a24;
  --teal: #4fb8a6;
  --teal-glow: rgba(79, 184, 166, 0.35);
  --crimson: #c8483f;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-color: 8, 5, 2;
}

* { box-sizing: border-box; }

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

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
}

body { overflow-x: hidden; }

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1, h2, h3 { font-family: 'Fraunces', serif; margin: 0; }

::-webkit-scrollbar { height: 8px; width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

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

/* ---------- nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1.75rem;
  padding: 1rem 2.5rem;
  background: linear-gradient(180deg, rgba(19, 17, 16, 0.95), rgba(19, 17, 16, 0.7));
  backdrop-filter: blur(10px);
}
.nav__brand {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.nav__brand-mark {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
}
.nav__links { display: flex; gap: 1.4rem; flex: 1; }
.nav__links a {
  font-size: 0.86rem;
  color: var(--text-muted);
  padding: 0.4rem 0;
  border-bottom: 2px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.nav__links a:hover, .nav__links a.active { color: var(--text); border-color: var(--gold); }
.nav__search {
  position: relative;
  width: 240px;
}
.nav__search input {
  width: 100%;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.nav__search input:focus-visible { outline: none; border-color: var(--gold-dim); background: var(--surface-hover); }
.nav__search-results {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 44px -16px rgba(var(--shadow-color), 0.7);
  max-height: 360px;
  overflow-y: auto;
  z-index: 60;
}
.nav__search-results.open { display: block; }
.nav__search-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.82rem;
}
.nav__search-item:hover { background: var(--surface-hover); }
.nav__search-item img { width: 32px; height: 44px; object-fit: cover; border-radius: 3px; background: var(--surface-sunken); flex-shrink: 0; }
.nav__search-empty { padding: 0.9rem; font-size: 0.8rem; color: var(--text-muted); text-align: center; }
.nav__user {
  display: flex; align-items: center; gap: 0.8rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-shrink: 0;
}
.nav__user button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.nav__user button:hover { border-color: var(--gold-dim); color: var(--text); }

/* ---------- hero ---------- */
.hero {
  position: relative;
  height: min(72vh, 640px);
  min-height: 360px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  margin-bottom: 2.5rem;
}
.hero__bg {
  position: absolute; inset: 0;
  background-size: cover;
  background-position: center 20%;
  animation: hero-drift 22s ease-in-out infinite alternate;
}
@keyframes hero-drift {
  from { transform: scale(1.02) translate(0, 0); }
  to { transform: scale(1.1) translate(-1%, -1.5%); }
}
.hero__scrim {
  position: absolute; inset: 0;
  background:
    linear-gradient(0deg, var(--bg) 4%, rgba(19, 17, 16, 0.55) 42%, rgba(19, 17, 16, 0.15) 75%),
    linear-gradient(90deg, rgba(19, 17, 16, 0.75) 0%, rgba(19, 17, 16, 0.1) 55%);
}
.hero__content {
  position: relative;
  z-index: 1;
  padding: 0 2.5rem 3rem;
  max-width: 640px;
}
.hero__eyebrow { font-size: 0.78rem; color: var(--gold); margin-bottom: 0.6rem; }
.hero__title {
  font-size: clamp(2.2rem, 4.5vw, 3.4rem);
  font-weight: 600;
  line-height: 1.05;
  margin-bottom: 0.9rem;
}
.hero__meta { display: flex; gap: 0.9rem; align-items: center; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.hero__overview {
  font-size: 0.92rem;
  color: var(--text-muted);
  max-width: 52ch;
  margin-bottom: 1.4rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hero__actions { display: flex; gap: 0.8rem; }

.btn {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.7rem 1.3rem;
  border-radius: 999px;
  font-family: inherit; font-size: 0.86rem; font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.15s ease, filter 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--gold); color: #1c1204; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: rgba(243, 237, 226, 0.08); color: var(--text); border-color: rgba(243, 237, 226, 0.18); backdrop-filter: blur(6px); }
.btn--ghost:hover { border-color: var(--text-muted); }

/* ---------- content rows ---------- */
.rows { padding: 0 0 3rem; display: flex; flex-direction: column; gap: 2.2rem; }
.row { padding-left: 2.5rem; }
.row__title { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.9rem; padding-right: 2.5rem; }
.row__track {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  padding-right: 2.5rem;
  scroll-behavior: smooth;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* old Edge */
}
.row__track::-webkit-scrollbar { display: none; } /* Chrome/Safari — dragging to scroll doesn't need a visible track */

/* ---------- poster cards ---------- */
.card {
  flex: 0 0 auto;
  width: 168px;
  position: relative;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.card:hover, .card:focus-within { transform: translateY(-6px); z-index: 2; }
.card__poster {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--panel-raised);
  box-shadow: 0 1px 2px rgba(var(--shadow-color), 0.4);
  transition: box-shadow 0.25s ease;
}
.card:hover .card__poster, .card:focus-within .card__poster {
  box-shadow: 0 22px 40px -16px rgba(var(--shadow-color), 0.85), 0 0 0 2px var(--gold-dim);
}
.card__poster img { width: 100%; height: 100%; object-fit: cover; }
.card__poster-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-family: 'Fraunces', serif;
  font-size: 0.85rem;
  text-align: center;
  padding: 0.6rem;
}
.card__progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(0, 0, 0, 0.5); }
.card__progress-fill { height: 100%; background: var(--gold); }
.card__play {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(19, 17, 16, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.card:hover .card__play, .card:focus-within .card__play { opacity: 1; }
.card__play svg { width: 34px; height: 34px; color: var(--text); filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.6)); }
/* transform: translateZ(0) forces these onto their own compositing layer —
   works around a Windows/Chrome bug where small text next to text-overflow:
   ellipsis can rasterize as garbled dots at certain display-scaling percentages. */
.card__title { margin-top: 0.55rem; font-size: 0.82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transform: translateZ(0); }
.card__subtitle { font-size: 0.74rem; color: var(--text-muted); transform: translateZ(0); }
.card--round .card__poster { aspect-ratio: 1 / 1; border-radius: 50%; }
.card--square .card__poster { aspect-ratio: 1 / 1; }
.card--wide .card__poster { aspect-ratio: 16 / 9; }

/* ---------- library grid page ---------- */
.page-header { padding: 2.5rem 2.5rem 1.5rem; }
.page-header h1 { font-size: 1.8rem; font-weight: 600; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 1.5rem 1rem;
  padding: 0 2.5rem 3rem;
}

/* ---------- item detail ---------- */
.detail-hero { position: relative; padding: 3rem 2.5rem; overflow: hidden; }
.detail-hero__bg { position: absolute; inset: 0; background-size: cover; background-position: center; opacity: 0.28; filter: blur(2px); }
.detail-hero__scrim { position: absolute; inset: 0; background: linear-gradient(0deg, var(--bg) 10%, transparent 90%); }
.detail-hero__content { position: relative; z-index: 1; display: flex; gap: 2rem; align-items: flex-end; flex-wrap: wrap; }
.detail-hero__poster { width: 200px; flex-shrink: 0; border-radius: var(--radius-sm); overflow: hidden; box-shadow: 0 24px 50px -18px rgba(var(--shadow-color), 0.8); }
.detail-hero__poster img { width: 100%; aspect-ratio: 2/3; object-fit: cover; }
.detail-hero__info { flex: 1; min-width: 280px; }
.detail-hero__info h1 { font-size: clamp(1.6rem, 3.5vw, 2.4rem); margin-bottom: 0.6rem; }
.detail-hero__meta { display: flex; gap: 0.9rem; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1rem; }
.detail-hero__overview { max-width: 68ch; color: var(--text-muted); font-size: 0.92rem; margin-bottom: 1.3rem; }
.tag { font-size: 0.72rem; padding: 0.25rem 0.6rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-muted); }

.section { padding: 0 2.5rem 3rem; }
.section h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.season-tabs { display: flex; gap: 0.4rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.season-tab {
  padding: 0.4rem 0.9rem; border-radius: 999px; font-size: 0.8rem;
  border: 1px solid var(--border); color: var(--text-muted); cursor: pointer; background: transparent;
  font-family: inherit;
}
.season-tab:hover { color: var(--text); border-color: var(--gold-dim); }
.season-tab.active { color: #1c1204; background: var(--gold); border-color: var(--gold); }

.episode-row {
  display: flex; gap: 1rem; align-items: center;
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  transition: background 0.2s ease;
}
.episode-row:hover { background: var(--surface-hover); }
.episode-row__thumb { width: 140px; aspect-ratio: 16/9; border-radius: 5px; overflow: hidden; background: var(--panel-raised); flex-shrink: 0; position: relative; }
.episode-row__thumb img { width: 100%; height: 100%; object-fit: cover; }
.episode-row__num { position: absolute; top: 0.3rem; left: 0.4rem; font-size: 0.7rem; background: rgba(0,0,0,0.6); padding: 0.1rem 0.4rem; border-radius: 3px; }
.episode-row__body { flex: 1; min-width: 0; }
.episode-row__title { font-size: 0.9rem; font-weight: 500; margin-bottom: 0.25rem; }
.episode-row__overview { font-size: 0.8rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.track-row {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}
.track-row:hover { background: var(--surface-hover); }
.track-row__num { width: 1.6rem; color: var(--text-muted); font-size: 0.8rem; text-align: right; flex-shrink: 0; }
.track-row__title { flex: 1; font-size: 0.88rem; }
.track-row__duration { color: var(--text-muted); font-size: 0.8rem; }
.track-row.playing .track-row__num { color: var(--teal); }
.track-row.playing .track-row__title { color: var(--teal); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.photo-grid img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 5px; cursor: pointer; transition: transform 0.15s ease; }
.photo-grid img:hover { transform: scale(1.03); }

/* ---------- lightbox ---------- */
.lightbox { display: none; position: fixed; inset: 0; z-index: 200; background: rgba(8, 6, 5, 0.92); align-items: center; justify-content: center; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 90vw; max-height: 88vh; object-fit: contain; border-radius: 4px; }
.lightbox__close { position: absolute; top: 1.5rem; right: 2rem; background: transparent; border: none; color: var(--text); font-size: 1.8rem; cursor: pointer; }
.lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,0.08); border: none; color: var(--text); width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; }
.lightbox__nav--prev { left: 1.5rem; }
.lightbox__nav--next { right: 1.5rem; }

/* ---------- watch page ---------- */
.watch { position: fixed; inset: 0; background: #000; z-index: 100; display: flex; flex-direction: column; cursor: default; }
.watch.hide-cursor { cursor: none; }
.watch video { flex: 1; width: 100%; height: 100%; object-fit: contain; background: #000; }
.watch__bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 1rem;
  padding: 1.2rem 1.6rem;
  background: linear-gradient(0deg, transparent, rgba(0,0,0,0.7));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 2;
}
.watch__bar.show { opacity: 1; pointer-events: auto; }
.watch__back { background: rgba(255,255,255,0.1); border: none; color: var(--text); width: 38px; height: 38px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.watch__title { font-family: 'Fraunces', serif; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- custom player chrome ---------- */
.watch__spinner {
  display: none;
  position: absolute; top: 50%; left: 50%; margin: -18px 0 0 -18px;
  width: 36px; height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: watch-spin 0.8s linear infinite;
  z-index: 1;
}
.watch__spinner.show { display: block; }
@keyframes watch-spin { to { transform: rotate(360deg); } }

.watch__big-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.85);
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1;
}
.watch__big-play.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.watch__big-play svg { width: 30px; height: 30px; margin-left: 3px; }

.watch__controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 2.5rem 1.6rem 1.2rem;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.8), transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 2;
}
.watch__controls.show { opacity: 1; pointer-events: auto; }

.watch__progress {
  position: relative;
  height: 16px;
  margin-bottom: 0.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  touch-action: none;
}
.watch__progress-track { position: relative; width: 100%; height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.22); overflow: hidden; transition: height 0.15s ease; }
.watch__progress-buffered { position: absolute; inset: 0; width: 0%; background: rgba(255, 255, 255, 0.3); }
.watch__progress-fill { position: absolute; inset: 0; width: 0%; background: var(--gold); }
.watch__progress-thumb {
  position: absolute; left: 0%; top: 50%;
  width: 13px; height: 13px; margin-left: -6.5px;
  border-radius: 50%; background: var(--gold);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: translateY(-50%) scale(0.001);
  transition: transform 0.15s ease;
  pointer-events: none;
}
.watch__progress:hover .watch__progress-thumb, .watch__progress:focus-visible .watch__progress-thumb { transform: translateY(-50%) scale(1); }
.watch__progress:hover .watch__progress-track { height: 6px; }

.watch__controls-row { display: flex; align-items: center; gap: 0.6rem; }
.watch__controls-row button {
  background: transparent; border: none; color: var(--text);
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background 0.15s ease;
}
.watch__controls-row button:hover { background: rgba(255, 255, 255, 0.12); }
.watch__controls-row button svg { width: 18px; height: 18px; }
#watch-play-btn svg { width: 20px; height: 20px; }
.watch__time { font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.watch__spacer { flex: 1; }
.watch__volume { display: flex; align-items: center; gap: 0.4rem; }
.watch__volume input[type="range"] {
  width: 0;
  opacity: 0;
  accent-color: var(--gold);
  transition: width 0.2s ease, opacity 0.2s ease;
}
.watch__volume:hover input[type="range"], .watch__volume:focus-within input[type="range"] { width: 70px; opacity: 1; }

@media (max-width: 760px) {
  .watch__controls { padding: 2rem 1rem 1rem; }
  .watch__volume input[type="range"] { width: 50px; opacity: 1; }
}

/* ---------- mini audio player ---------- */
.player-bar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  align-items: center; gap: 1rem;
  padding: 0.7rem 1.5rem;
  background: rgba(28, 24, 21, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.player-bar.open { display: flex; }
.player-bar__art { width: 42px; height: 42px; border-radius: 5px; object-fit: cover; background: var(--panel-raised); flex-shrink: 0; }
.player-bar__info { min-width: 0; width: 180px; flex-shrink: 0; }
.player-bar__title { font-size: 0.82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar__artist { font-size: 0.74rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-bar__controls { display: flex; align-items: center; gap: 0.7rem; }
.player-bar__controls button { background: transparent; border: none; color: var(--text); cursor: pointer; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }
.player-bar__controls button.play { background: var(--text); color: #1c1204; border-radius: 50%; }
.player-bar__seek { flex: 1; display: flex; align-items: center; gap: 0.6rem; font-size: 0.72rem; color: var(--text-muted); }
.player-bar__seek input[type="range"] { flex: 1; accent-color: var(--gold); }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; position: relative; overflow: hidden; }
.auth-wrap::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 900px 600px at 50% 0%, rgba(232, 184, 75, 0.12), transparent 60%);
}
.auth-card { position: relative; width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.2rem; box-shadow: 0 30px 70px -24px rgba(var(--shadow-color), 0.8); }
.auth-card h1 { font-size: 1.5rem; text-align: center; margin-bottom: 1.6rem; }
.auth-card label { font-size: 0.8rem; color: var(--text-muted); display: block; margin-bottom: 0.4rem; margin-top: 1rem; }
.auth-card input { width: 100%; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.65rem 0.8rem; color: var(--text); font-family: inherit; font-size: 0.9rem; }
.auth-card input:focus-visible { outline: none; border-color: var(--gold-dim); }
.auth-card button { width: 100%; justify-content: center; margin-top: 1.6rem; }
.auth-error { color: var(--crimson); font-size: 0.8rem; text-align: center; margin-top: 1rem; }

/* ---------- empty state ---------- */
.empty-state { padding: 4rem 2.5rem; text-align: center; color: var(--text-muted); }
.empty-state h2 { color: var(--text); margin-bottom: 0.5rem; }

@media (max-width: 760px) {
  .nav { padding: 0.9rem 1.2rem; gap: 0.9rem; }
  .nav__links { display: none; }
  .nav__search { width: 140px; }
  .hero__content, .row, .page-header, .grid, .section, .detail-hero { padding-left: 1.2rem; padding-right: 1.2rem; }
  .row__track { padding-right: 1.2rem; }
  .detail-hero__poster { width: 140px; }
}
