:root {
  --bg: #0c0e12;
  --panel: #15181f;
  --panel-2: #1d212b;
  --border: #2a2f3a;
  --text: #e8ebf0;
  --muted: #9aa3b2;
  --accent: #e5484d;
  --accent-2: #ff6b6f;
  --radius: 12px;
  --focus-ring: 0 0 0 3px rgba(229, 72, 77, 0.55);
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    sans-serif;
}
[hidden] {
  display: none !important;
}
a {
  color: inherit;
  text-decoration: none;
}
img {
  display: block;
  max-width: 100%;
}
button {
  font: inherit;
  color: inherit;
}
:focus {
  outline: none;
}
:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

/* header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 12px 20px;
  background: rgba(12, 14, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #22262f;
}
.brand {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-2);
  white-space: nowrap;
}
.brand-sub {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  border: 1px solid #333a47;
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}
#search-form {
  display: flex;
  flex: 1 1 240px;
  max-width: 460px;
  gap: 8px;
}
#search-input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 15px;
}
#search-form button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
}
#search-form button:hover {
  background: var(--accent-2);
}
.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}
.tabs a,
.ghost-btn {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 15px;
  white-space: nowrap;
}
.tabs a:hover,
.ghost-btn:hover,
.tabs a.active {
  color: var(--text);
  background: var(--panel-2);
}
.tabs a.active {
  color: var(--accent-2);
}
.content-type-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  max-width: 1400px;
  margin: 14px auto 0;
  padding: 0 20px;
}
.content-type-tabs button {
  min-width: 104px;
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}
.content-type-tabs button[aria-pressed="true"] {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

main#view {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  min-height: 62vh;
}
.section-title {
  font-size: 18px;
  margin: 6px 0 14px;
}
.state {
  padding: 64px 20px;
  text-align: center;
  color: var(--muted);
}
.spinner {
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}
.error-box .error-title {
  color: var(--accent-2);
  font-size: 18px;
  margin: 0 0 8px;
}
.error-msg {
  white-space: pre-wrap;
  margin: 0 0 16px;
}
.row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.card {
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}
.card:hover,
.card:focus-visible {
  transform: scale(1.04);
  box-shadow: var(--focus-ring);
  z-index: 1;
}
.card-cover {
  aspect-ratio: 3 / 4;
  background: var(--panel-2);
  overflow: hidden;
}
.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.card-body {
  padding: 8px 10px 10px;
}
.card-title {
  font-size: 14px;
  min-height: 2.4em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-badge {
  margin-top: 4px;
  font-size: 12px;
  color: var(--accent-2);
}

/* buttons / pager */
.btn {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover {
  border-color: var(--accent);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:hover {
  background: var(--accent-2);
}
.btn.ghost {
  background: transparent;
}
.btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}
.btn.danger:hover {
  border-color: var(--accent-2);
  color: var(--accent-2);
}
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin: 26px 0 12px;
}
.page-num {
  color: var(--muted);
  font-size: 14px;
}

/* detail */
.hero {
  display: flex;
  gap: 22px;
  margin-bottom: 22px;
}
.hero-cover {
  width: 200px;
  flex: none;
  border-radius: var(--radius);
}
.hero-info h2 {
  margin: 4px 0 10px;
  font-size: 26px;
}
.hero-info .meta {
  color: var(--accent-2);
  font-size: 13px;
  margin: 0 0 10px;
}
.hero-info .desc {
  color: var(--muted);
  line-height: 1.75;
  max-width: 760px;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hero-info .row {
  justify-content: flex-start;
  margin-top: 16px;
}
.group-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.group-tab {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.group-tab.active {
  color: var(--text);
  border-color: var(--accent);
}
.episodes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
}
.ep {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 0;
  text-align: center;
  cursor: pointer;
  font-size: 14px;
}
.ep:hover {
  border-color: var(--accent);
}
.ep.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* history */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history-item {
  display: flex;
  gap: 14px;
  align-items: center;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px;
}
.history-cover {
  width: 64px;
  height: 84px;
  flex: none;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-2);
  font-size: 11px;
  padding: 4px;
}
.history-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.history-info {
  flex: 1;
  min-width: 0;
}
.history-title {
  font-size: 15px;
  margin-bottom: 4px;
}
.history-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.history-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.foot {
  padding: 22px 20px 30px;
  text-align: center;
  color: #66707f;
  font-size: 12px;
  border-top: 1px solid #1b1f27;
  line-height: 1.8;
}
.foot a {
  color: var(--muted);
  text-decoration: underline;
}

/* player */
body.player-open {
  overflow: hidden;
}
body.player-open .topbar,
body.player-open .foot {
  display: none;
}
.player-shell {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 40;
}
.player-shell video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.player-shell:not(.controls-on) {
  cursor: none;
}
.player-controls {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.player-shell.controls-on .player-controls {
  opacity: 1;
  pointer-events: auto;
}
.player-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: linear-gradient(rgba(0, 0, 0, 0.7), transparent);
}
.player-title {
  font-size: 15px;
  text-shadow: 0 1px 3px #000;
}
.player-bottom {
  padding: 12px 18px 16px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
}
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.pbtn {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  color: #fff;
}
.pbtn:hover {
  background: rgba(255, 255, 255, 0.25);
}
.seek {
  width: 100%;
  margin: 0 0 10px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}
.time {
  color: #ddd;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.flex-spacer {
  flex: 1;
}
.speed {
  background: rgba(255, 255, 255, 0.12);
}
.player-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  background: rgba(0, 0, 0, 0.35);
  font-size: 15px;
  pointer-events: none;
}
.player-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  text-align: center;
  padding: 20px;
}
.player-error .error-title {
  color: var(--accent-2);
  font-size: 20px;
  margin: 0;
}
.player-error .error-msg {
  color: var(--muted);
  margin: 0 0 14px;
  white-space: pre-wrap;
}
.episode-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: rgba(12, 14, 18, 0.96);
  border-left: 1px solid #262b35;
  overflow-y: auto;
  padding: 16px;
  z-index: 5;
}
.drawer-head {
  font-size: 15px;
  margin-bottom: 12px;
}
.drawer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

/* modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
}
.dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.dialog h2 {
  margin-top: 0;
  font-size: 18px;
}
.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.dialog-heading h2 {
  margin: 0 0 16px;
}
.dialog-close {
  flex: none;
  width: 40px;
  height: 40px;
  margin: -8px -8px 8px 0;
  border: 0;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--muted);
}
.field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
}
.dialog .row {
  justify-content: flex-start;
}
.dialog hr {
  border: none;
  border-top: 1px solid #262b35;
  margin: 16px 0;
}
.about {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.8;
}
.about a {
  color: var(--accent-2);
}

@media (max-width: 640px) {
  .topbar {
    gap: 10px;
    padding: 10px 12px;
  }
  .brand {
    font-size: 18px;
  }
  main#view {
    padding: 14px 12px;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 10px;
  }
  .hero {
    flex-direction: column;
  }
  .hero-cover {
    width: 150px;
  }
  .history-item {
    flex-wrap: wrap;
  }
  .history-actions {
    width: 100%;
  }
  .content-type-tabs {
    gap: 10px;
    margin-top: 8px;
    padding: 0 12px;
  }
  .content-type-tabs button {
    flex: 1;
    min-height: 44px;
  }
  .settings-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .settings-dialog {
    width: 100%;
    max-width: none;
    max-height: min(90vh, 720px);
    max-height: min(90dvh, 720px);
    padding: 22px 20px max(20px, env(safe-area-inset-bottom));
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    animation: sheet-in 0.22s ease-out;
  }
  .settings-dialog .field input,
  .settings-dialog .btn {
    min-height: 44px;
    font-size: 16px;
  }
  @keyframes sheet-in {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .pbtn {
    padding: 10px 12px;
  }
  .player-row {
    gap: 6px;
  }
}
