:root {
  --bg: #0a0a0f;
  --bg-elev: #12121a;
  --bg-card: #16161f;
  --bg-hover: #1c1c28;
  --border: #252532;
  --text: #f0f0f5;
  --text-muted: #8b8b9a;
  --text-dim: #5c5c6e;
  --accent: #7c5cfc;
  --accent-soft: rgba(124, 92, 252, 0.15);
  --accent-hover: #9478ff;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --font: 'Inter', system-ui, sans-serif;
  --font-jp: 'Noto Sans JP', sans-serif;
  --header-h: 64px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="light"] {
  --bg: #f5f5f8;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f0f0f5;
  --border: #e4e4ec;
  --text: #12121a;
  --text-muted: #5c5c6e;
  --text-dim: #8b8b9a;
  --accent: #6b4ce6;
  --accent-soft: rgba(107, 76, 230, 0.12);
  --shadow: 0 8px 32px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(124,92,252,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124,92,252,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

/* HEADER */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

[data-theme="light"] .header {
  background: rgba(245,245,248,0.9);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 32px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.logo-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 18px;
}

.logo-text {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.logo-text span { color: var(--accent); }

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font: 500 0.9rem var(--font);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover { color: var(--text); background: var(--bg-hover); }
.nav-link.active { color: var(--text); background: var(--accent-soft); }

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
}

.search-box input {
  width: 220px;
  padding: 9px 12px 9px 38px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font: 400 0.875rem var(--font);
  outline: none;
  transition: border-color 0.2s, width 0.25s var(--ease);
}

.search-box input:focus {
  border-color: var(--accent);
  width: 280px;
}

.search-box input::placeholder { color: var(--text-dim); }

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  min-width: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 400px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

.search-results.open { display: block; }

.search-item {
  display: flex;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  font: inherit;
}

.search-item:hover { background: var(--bg-hover); }

.search-item img {
  width: 40px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-card);
}

.search-item-info { flex: 1; min-width: 0; }
.search-item-title { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item-meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  border-color: var(--border);
}

.menu-toggle { display: none; }

/* MOBILE NAV */
.mobile-nav {
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 85vw);
  height: 100%;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  z-index: 200;
  padding: 72px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transform: translateX(100%);
  transition: transform 0.3s var(--ease);
}

.mobile-nav.open { transform: translateX(0); }

.mobile-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.overlay.open { opacity: 1; pointer-events: auto; }

/* MAIN */
.main {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 64px;
  min-height: calc(100vh - var(--header-h) - 80px);
}

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.35s var(--ease); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* HERO */
.hero {
  position: relative;
  height: 420px;
  border-radius: 16px;
  overflow: hidden;
  margin: 24px 0 40px;
  background: var(--bg-card);
}

.hero-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center top;
  transition: opacity 0.5s;
}

.hero-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(10,10,15,0.95) 0%, rgba(10,10,15,0.7) 45%, transparent 75%),
              linear-gradient(0deg, rgba(10,10,15,0.9) 0%, transparent 40%);
}

[data-theme="light"] .hero-fade {
  background: linear-gradient(90deg, rgba(245,245,248,0.95) 0%, rgba(245,245,248,0.7) 45%, transparent 75%),
              linear-gradient(0deg, rgba(245,245,248,0.85) 0%, transparent 40%);
}

.hero-body {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 40px;
  max-width: 520px;
}

.hero-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
  width: fit-content;
}

.hero-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin-bottom: 8px;
}

.hero-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.hero-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 20px;
}

.hero-actions { display: flex; gap: 10px; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font: 600 0.875rem var(--font);
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 20px rgba(124,92,252,0.35);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover { background: var(--bg-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
}

.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: 500 0.85rem var(--font);
  cursor: pointer;
}

.link-btn:hover { text-decoration: underline; }

/* SECTIONS */
.section {
  margin-bottom: 40px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head h2 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.row {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

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

/* CARD */
.card {
  flex: 0 0 160px;
  scroll-snap-align: start;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: transform 0.2s var(--ease);
}

.card:hover { transform: translateY(-4px); }

.card-poster {
  position: relative;
  aspect-ratio: 2/3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
  margin-bottom: 10px;
}

.card-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease);
}

.card:hover .card-poster img { transform: scale(1.05); }

.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 3px 7px;
  border-radius: 6px;
}

.card-score {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 3px 6px;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* PAGE HEAD */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 32px 0 24px;
}

.page-head h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.filters {
  display: flex;
  gap: 10px;
}

.filters select {
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: 500 0.85rem var(--font);
  cursor: pointer;
  outline: none;
}

.filters select:focus { border-color: var(--accent); }

/* GRID */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}

.grid .card { flex: none; width: 100%; }

/* GENRES */
.genre-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 28px;
}

.genre-pill {
  padding: 8px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: 500 0.85rem var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.genre-pill:hover, .genre-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* DETAIL */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font: 500 0.9rem var(--font);
  cursor: pointer;
  padding: 24px 0 16px;
  transition: color 0.2s;
}

.back-btn:hover { color: var(--text); }

.detail {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 40px;
  padding-bottom: 40px;
}

.detail-poster {
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-card);
  aspect-ratio: 2/3;
}

.detail-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-info h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.detail-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.detail-genres {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.detail-genres span {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
}

.detail-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 28px;
  max-width: 640px;
}

.detail-actions { display: flex; gap: 10px; }

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.detail-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.detail-jp {
  color: var(--text-muted);
  font-family: var(--font-jp);
  margin-bottom: 12px;
}

.detail-seasons { margin-bottom: 26px; }

.detail-seasons h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
}

/* SEASON STRIP */
.season-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: thin;
}

.season-strip::-webkit-scrollbar { height: 4px; }
.season-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.season-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: 500 0.8rem var(--font);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.season-chip:hover,
.season-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.season-chip-num {
  font-weight: 800;
  font-size: 0.7rem;
  color: var(--accent);
}

.season-chip-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.season-chip-soon {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-hover);
  color: var(--text-dim);
  padding: 2px 6px;
  border-radius: 4px;
}

#playerSeasons { margin-bottom: 18px; }
#playerSeasons[hidden] { display: none; }

/* UPCOMING CARDS */
.card-upcoming .card-poster img {
  filter: grayscale(0.6) brightness(0.72);
}

.card-upcoming:hover .card-poster img {
  filter: grayscale(0.3) brightness(0.85);
}

.card-badge-soon {
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* PLAYER EPISODE NAV */
.ep-nav {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.ep-nav-btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}

.ep-chunks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.ep-chunks:empty { display: none; }

.ep-chunk {
  padding: 5px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font: 500 0.75rem var(--font);
  cursor: pointer;
  transition: all 0.15s;
}

.ep-chunk:hover,
.ep-chunk.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* PLAYER */
.player-wrap {
  padding-top: 16px;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.player-bar .back-btn { padding: 0; }

.player-title {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-stage {
  position: relative;
  aspect-ratio: 16/9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}

.player-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 0.95rem;
}

#playerFrame {
  width: 100%;
  height: 100%;
  border: none;
  display: none;
}

#playerFrame.active { display: block; }

.episode-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.ep-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.ep-head h3 {
  font-size: 1rem;
  font-weight: 700;
}

.server-tabs {
  display: flex;
  gap: 6px;
}

.server-tab {
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font: 500 0.8rem var(--font);
  cursor: pointer;
  transition: all 0.15s;
}

.server-tab:hover, .server-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.ep-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.ep-btn {
  padding: 10px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font: 600 0.85rem var(--font);
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.ep-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.ep-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* EMPTY */
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 64px 24px;
  font-size: 0.95rem;
}

/* FOOTER */
.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .nav { display: none; }
  .menu-toggle { display: grid; }
  .search-box input { width: 160px; }
  .search-box input:focus { width: 200px; }
  .detail { grid-template-columns: 1fr; }
  .detail-poster { max-width: 200px; }
  .hero { height: 360px; }
  .hero-body { padding: 28px; max-width: 100%; }
}

@media (max-width: 600px) {
  .header-inner { padding: 0 16px; gap: 12px; }
  .main { padding: 0 16px 48px; }
  .search-box { display: none; }
  .hero { height: 320px; margin: 16px 0 28px; }
  .hero-body { padding: 20px; }
  .card { flex: 0 0 130px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  .page-head { padding: 24px 0 16px; }
  .page-head h1 { font-size: 1.4rem; }
}
