/* === Reset & Base === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-card: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.15);
  --accent: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --header-h: 64px;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", PingFang SC,
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

/* === Header === */
.header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 24px;
}

.search-form {
  flex: 1;
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin-left: auto;
}

.search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-wrap input {
  flex: 1;
  height: 40px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  min-width: 0;
}

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

.search-wrap input::-webkit-search-cancel-button {
  display: none;
}

.clear-btn {
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  border-radius: 50%;
  flex-shrink: 0;
}

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

.clear-btn.show {
  display: flex;
}

.submit-btn {
  padding: 0 20px;
  height: 42px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  border-radius: var(--radius);
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.submit-btn:hover {
  background: var(--primary-hover);
}

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

/* === Main === */
.main {
  flex: 1;
  padding: 24px 16px 48px;
}

/* === Watch History === */
.history-section {
  margin-bottom: 8px;
}

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

.history-heading {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.history-rail {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.history-rail::-webkit-scrollbar {
  display: none;
}

.history-card {
  flex: 0 0 148px;
  width: 148px;
  text-align: left;
  padding: 0;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
  transition: border-color 0.15s, transform 0.15s;
}

.history-card:active {
  transform: scale(0.98);
}

.history-card:hover {
  border-color: var(--primary);
}

.history-poster {
  aspect-ratio: 2 / 3;
  background: var(--bg-elevated);
  overflow: hidden;
}

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

.history-poster-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  opacity: 0.5;
}

.history-body {
  padding: 10px 10px 12px;
}

.history-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 4px;
}

.history-meta,
.history-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-progress {
  height: 3px;
  margin-top: 8px;
  border-radius: 99px;
  background: rgba(148, 163, 184, 0.25);
  overflow: hidden;
}

.history-progress span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
}

@media (min-width: 640px) {
  .history-card {
    flex: 0 0 168px;
    width: 168px;
  }

  .history-title {
    font-size: 14px;
  }
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 48px 16px;
}

.empty-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.7;
}

.empty-state h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.hot-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hot-label {
  color: var(--text-muted);
  font-size: 13px;
}

.tag {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  transition: all 0.2s;
}

.tag:hover {
  color: var(--primary-hover);
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* === Status === */
.status {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.status.error {
  color: var(--danger);
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

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

/* === Results Grid === */
.results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

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

@media (min-width: 900px) {
  .results {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
  }
}

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

/* === Card === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.card-poster {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--bg);
}

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

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

.card-poster-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: var(--text-dim);
  background: var(--bg-elevated);
}

.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 11px;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}

.card-remarks {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 3px 8px;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
}

.card-body {
  padding: 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (min-width: 900px) {
  .card-title {
    font-size: 15px;
  }
}

/* === Footer === */
.footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg);
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 900px) {
  .modal-content {
    width: min(1100px, 95vw);
    height: min(90vh, 800px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(360px, 1fr);
    grid-template-rows: 100%;
    overflow: hidden;
  }

  .player-area {
    align-self: start;
    width: 100%;
  }

  .detail-area {
    height: 100%;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  transition: background 0.2s;
  line-height: 1;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* === Player === */
.player-area {
  background: #000;
  position: relative;
  display: flex;
  flex-direction: column; /* 关键：视频在上 + toolbar 在下，避免宽屏被 row 推到右侧 */
  align-items: stretch;
  justify-content: flex-start;
}

.player-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

#player {
  width: 100%;
  height: 100%;
  background: #000;
  display: block;
}

.player-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 14px;
  text-align: center;
  padding: 16px;
  pointer-events: none;
}

.player-status.hidden {
  display: none;
}

/* === Artplayer 容器 === */
/* 让 #player div 占满 .player-wrap；artplayer 自己处理内部布局 */
#player {
  width: 100%;
  height: 100%;
}
/* 自定义 prev/next 控件按钮（注入到 artplayer controls left 位置） */
.art-control-prev svg,
.art-control-next svg {
  width: 18px;
  height: 18px;
  display: block;
}
.art-control-prev,
.art-control-next {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s, transform 0.1s;
}
.art-control-prev:hover,
.art-control-next:hover {
  opacity: 1;
}
.art-control-prev:active,
.art-control-next:active {
  transform: translateY(1px);
}
/* 禁用态（首集 / 末集） */
.art-control-prev.is-disabled,
.art-control-next.is-disabled {
  opacity: 0.3 !important;
  cursor: not-allowed;
  pointer-events: none;
}

/* === Detail === */
.detail-area {
  padding: 16px;
  overflow-y: auto;
}

@media (min-width: 900px) {
  .detail-area {
    padding: 24px;
  }
}

.detail-head {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-pic {
  width: 80px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

@media (min-width: 900px) {
  .detail-pic {
    width: 100px;
  }
}

.detail-info {
  flex: 1;
  min-width: 0;
}

.detail-info h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.3;
}

@media (min-width: 900px) {
  .detail-info h2 {
    font-size: 22px;
  }
}

.detail-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.detail-meta span + span::before {
  content: "·";
  margin-right: 8px;
  color: var(--text-dim);
}

.detail-remarks {
  display: inline-block;
  padding: 2px 8px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  font-size: 12px;
  border-radius: 4px;
  margin-top: 4px;
}

.detail-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

@media (min-width: 900px) {
  .detail-desc {
    -webkit-line-clamp: 6;
    line-clamp: 6;
  }
}

/* === Episodes === */
.episodes-section {
  margin-top: 8px;
}

.episodes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.episodes-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.episode-count {
  font-size: 12px;
  color: var(--text-muted);
}

.episodes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

@media (min-width: 900px) {
  .episodes {
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  }
}

.episode {
  padding: 10px 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: center;
  transition: all 0.2s;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.episode:hover {
  border-color: var(--primary);
  color: var(--text);
  background: var(--primary-soft);
}

.episode.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}

/* === Mobile-specific tweaks === */
@media (max-width: 639px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 0;
    gap: 12px;
  }

  .logo {
    font-size: 16px;
  }

  .logo-text {
    display: none;
  }

  .search-form {
    width: 100%;
    margin-left: 0;
  }

  .submit-btn {
    padding: 0 16px;
  }

  .empty-state {
    padding: 32px 16px;
  }

  .empty-icon {
    font-size: 48px;
  }

  .empty-state h2 {
    font-size: 18px;
  }
}

/* prevent body scroll when modal open */
body.modal-open {
  overflow: hidden;
}
