:root {
  --bg: #0f1115;
  --surface: #14171d;
  --card: #181b21;
  --text: #e6e6e6;
  --muted: #9aa0a6;
  --accent: #ff4d6d;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
}

header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(20, 23, 29, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #222;
  padding: 14px 20px;

  display: flex;
  align-items: center;
  gap: 12px;
}


header h1 {
  font-size: 20px;
  color: var(--accent);
}

main {
  padding: 20px;
  min-height: calc(100vh - 60px);
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 360px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.card {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  min-width: 0;
  transition: transform .2s ease, box-shadow .2s ease;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
}

.cover {
  aspect-ratio: 2 / 3;
  position: relative;
}

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

.badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0,0,0,.65);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 999px;
}

.info {
  padding: 13px;
}

.title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

@media (min-width: 640px) {
  .title {
    font-size: 13px;
  }
}

.meta {
  font-size: 12px;
  color: var(--muted);
}

.content-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15,17,21,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #333;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.detail-info {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 20px;
  max-width: 820px;
}

.detail-poster {
  width: 100%;
  border-radius: 10px;
}

.episode-list button {
  width: 100%;
  background: #181b21;
  color: #fff;
  border: none;
  padding: 8px;
  margin-bottom: 6px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
}

.episode-list button.active {
  background: #ff4d6d;
  color: #fff;
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
  color: #9aa0a6;
  cursor: pointer;
  display: none;
  z-index: 20;
  outline: none;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
}

.search-clear:hover {
  color: #ffffff;
}

.search-clear:active {
  transform: translateY(-50%) scale(0.9);
}

.search-clear:focus {
  outline: none;
}

#searchInput {
  padding-right: 40px;
}

.video-wrapper {
  position: relative;
  background: #000;
  border-radius: 12px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

.video-wrapper video {
  width: 100%;
  height: 100%;
}

.video-play-btn {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-play-btn:focus {
  outline: none;
}

.video-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: rgba(255,255,255,.25);
  cursor: pointer;
  touch-action: none;
}

.video-progress div {
  height: 100%;
  width: 0%;
  background: #ff4d6d;
}

.video-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: 14px;
}

.video-ui-hidden .video-play-btn,
.video-ui-hidden .video-progress,
.video-ui-hidden .video-fullscreen-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

.video-play-btn,
.video-progress,
.video-fullscreen-btn {
  transition: opacity .3s ease;
}

.video-play-btn,
.video-progress {
  transition: opacity .3s ease;
}

.video-fullscreen-btn {
  position: absolute;
  right: 10px;
  bottom: 14px;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: none;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-fullscreen-btn::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  box-sizing: border-box;
}

.video-fullscreen-btn.exit::before {
  width: 10px;
  height: 10px;
}

.section {
  margin-bottom: 24px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.section.hidden {
  display: none;
}

.horizontal-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.horizontal-scroll::-webkit-scrollbar {
  display: none;
}

.horizontal-scroll .card {
  flex: 0 0 140px;
  scroll-snap-align: start;
}

@media (min-width: 1024px) {
  .horizontal-scroll .card {
    flex-basis: 160px;
  }
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

input {
  font: inherit;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

#searchInput.search-input,
#searchInput {
  width: 100%;
  padding: 10px 36px 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.06);
  outline: none;
  background: #181b21;
  color: #fff;
  transition: border-color .2s ease, box-shadow .2s ease, transform .1s ease;
}

#searchInput::placeholder {
  color: rgba(255,255,255,.45);
}

#searchInput:focus {
  border-color: rgba(255,77,109,.45);
  box-shadow: 0 0 0 4px rgba(255,77,109,.12);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 6px 2px;
  cursor: pointer;
}

.link-btn:active {
  transform: translateY(1px);
}

.back-btn {
  margin-bottom: 16px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: .65;
  cursor: not-allowed;
  transform: none;
}

.btn--primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 22px rgba(255,77,109,.18);
}

.btn--primary:hover {
  box-shadow: 0 14px 30px rgba(255,77,109,.22);
}

.btn--ghost {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.10);
}

.modal {
  position: fixed;
  inset: 0;
  padding: 18px;
  background: rgba(0,0,0,.62);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s ease, visibility .18s ease;
}

.modal.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.modal__dialog {
  width: min(420px, 100%);
  background: #181b21;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 14px;
  padding: 16px 16px 14px;
  box-shadow: 0 18px 44px rgba(0,0,0,.55);
  transform: translateY(10px) scale(.98);
  transition: transform .18s ease;
}

.modal.is-open .modal__dialog {
  transform: translateY(0) scale(1);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.modal__title {
  margin: 0;
  color: var(--accent);
  font-size: 18px;
}

.modal__hint {
  margin: 0 0 12px;
  color: rgba(255,255,255,.62);
  font-size: 13px;
  line-height: 1.35;
}

.form-input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(0,0,0,.18);
  color: #fff;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.form-input:focus {
  border-color: rgba(255,77,109,.45);
  box-shadow: 0 0 0 4px rgba(255,77,109,.12);
}

.form-error {
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent);
}

.modal__actions {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

#detailView {
  max-width: 1100px;
  margin: 0 auto;
}

#episodeList {
  margin-top: 8px;
  max-height: 220px;
  overflow: auto;
}

.detail-info p {
  color: rgba(255,255,255,.72);
  line-height: 1.45;
  margin-top: 8px;
}

@media (hover: none) {
  .card:hover {
    transform: none;
    box-shadow: none;
  }
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1f2937;
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  box-shadow: 0 10px 25px rgba(0,0,0,.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 1000;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
