:root {
  color-scheme: dark;
  --bg: #0a0c0b;
  --bg-glow: rgba(198, 243, 107, 0.07);
  --surface: #111412;
  --surface-2: #171b18;
  --text: #f2f5ef;
  --muted: #8a9389;
  --line: #252b26;
  --line-strong: #343c35;
  --accent: #c6f36b;
  --accent-ink: #0d1208;
  --danger: #ff8a80;
  --radius: 18px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 18% -10%, var(--bg-glow), transparent 65%),
    radial-gradient(700px 420px at 90% 0%, rgba(120, 170, 255, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

button,
input {
  font: inherit;
}

.shell {
  width: min(960px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 0 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--text);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 8px 18px color-mix(in srgb, var(--accent) 18%, transparent);
}

.brand-mark svg {
  display: block;
}

.brand-name {
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.04em;
  line-height: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-button:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.hero.compact-hero {
  max-width: 100%;
  padding: 8px 0 16px;
}

.compact-hero .parse-form {
  margin-top: 0;
}

.input-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
}

.clear-button {
  position: absolute;
  right: 12px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--line-strong);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

#url-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 40px 0 40px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: 14px/1 var(--sans);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#url-input::placeholder {
  color: #6a7469;
}

#url-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

#submit-button {
  flex: none;
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}

#submit-button:hover:not(:disabled) {
  filter: brightness(1.05);
}

#submit-button:active:not(:disabled) {
  transform: translateY(1px);
}

#submit-button:disabled {
  opacity: 0.55;
  cursor: progress;
}

.search-history {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.search-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px 6px;
  color: var(--muted);
  font-size: 12px;
}

.search-history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.search-history-item {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  height: 30px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface-2);
}

.search-history-query {
  min-width: 0;
  max-width: 240px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-history-remove {
  width: 22px;
  height: 22px;
  margin-left: 2px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.search-history-remove:hover,
.search-history-query:hover {
  color: var(--accent);
}

.brand:focus-visible,
#submit-button:focus-visible,
.ghost-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.status {
  min-height: 22px;
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

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

.status.loading {
  color: var(--accent);
}

.result {
  margin-top: 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  animation: rise 0.24s ease both;
}

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

.player-wrap {
  aspect-ratio: 16 / 9;
  background: #000;
}

.player {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000;
}

.result-body {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px 18px;
}

.result-copy {
  min-width: 0;
}

.result-copy h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.sources-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.source-tag:hover {
  border-color: var(--accent);
  color: var(--text);
}

.source-tag.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-weight: 600;
  cursor: default;
}

.result-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.expiry {
  font: 10.5px/1.4 var(--mono);
  color: var(--muted);
  white-space: nowrap;
}

.ghost-button {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.ghost-button:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: #454f46;
}

.ghost-button:active:not(:disabled) {
  transform: translateY(1px);
}

.ghost-button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* 选集栏样式 */
.episodes-bar {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.platform-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 10px;
  scrollbar-width: none;
}

.platform-bar::-webkit-scrollbar {
  display: none;
}

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

.episodes-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.episodes-label {
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
}

.episodes-current {
  font-size: 12px;
  color: var(--accent);
  font-family: var(--mono);
}

.mini-button {
  height: 26px;
  padding: 0 10px;
  font-size: 11px;
  border-radius: 6px;
}

.episodes-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.episode-btn {
  flex: none;
  min-width: 52px;
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.episode-btn:hover {
  border-color: var(--accent);
  color: #fff;
}

.episode-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

/* 搜索结果网格 */
.search-section {
  margin-top: 20px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

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

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.search-card {
  display: flex;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.18s ease;
}

.search-card:hover {
  border-color: var(--accent);
  background: var(--surface-2);
  transform: translateY(-2px);
}

.search-card-poster {
  flex: none;
  width: 72px;
  height: 96px;
  border-radius: 6px;
  object-fit: cover;
  background: #1e2420;
}

.search-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.search-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-card-remarks {
  font-size: 11px;
  color: var(--accent);
  margin-top: 4px;
}

.search-card-desc {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* 模态弹窗系统 */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-pane {
  width: min(480px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: #131714;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-pane-wide {
  width: min(720px, 100%);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.danger-ghost:hover {
  border-color: var(--danger) !important;
  color: var(--danger) !important;
}

.close-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.close-button:hover {
  color: var(--text);
}

/* 历史列表 */
.history-list {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.history-meta {
  flex: 1;
  min-width: 0;
}

.history-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-details {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.history-episode {
  color: var(--accent);
}

.history-empty {
  text-align: center;
  padding: 36px 0;
  color: var(--muted);
  font-size: 13px;
}

/* 全集网格 */
.episodes-grid {
  padding: 16px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: 8px;
}

.episodes-grid .episode-btn {
  min-width: unset;
  text-align: center;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 52px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.footer p {
  margin: 0;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--danger);
  color: #1a0705;
  font-size: 13px;
  text-align: center;
}

.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 (max-width: 1024px) {
  .shell {
    width: calc(100% - 24px);
    padding-top: 12px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 20px);
    padding-top: 8px;
  }

  .topbar {
    padding-bottom: 8px;
  }

  .hero.compact-hero {
    padding: 4px 0 12px;
  }

  .input-row {
    flex-direction: row;
    gap: 6px;
  }

  #url-input {
    height: 42px;
    font-size: 13px;
    padding: 0 32px 0 34px;
  }

  .search-icon {
    left: 10px;
    width: 14px;
    height: 14px;
  }

  #submit-button {
    height: 42px;
    padding: 0 14px;
    font-size: 13px;
  }

  .button-label {
    display: none;
  }

  .icon-button {
    padding: 0 8px;
  }

  .result-body {
    flex-direction: column;
    gap: 12px;
  }

  .result-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  .expiry {
    white-space: normal;
  }

  .footer {
    flex-direction: column;
    margin-top: 32px;
  }

  /* 移动端模态框自动转为底部半屏抽屉交互 */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal-pane,
  .modal-pane-wide {
    width: 100%;
    max-height: 82vh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .result {
    animation: none;
  }

  #url-input,
  #submit-button,
  .ghost-button {
    transition: none;
  }
}

.art-danmuku img {
  height: 1.4em;
  width: 1.4em;
  object-fit: contain;
  vertical-align: middle;
  pointer-events: none;
}

/* 返回顶部浮动按钮 */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 28px;
  z-index: 90;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.back-to-top:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
}

.back-to-top[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .back-to-top {
    right: 16px;
    bottom: 20px;
    width: 40px;
    height: 40px;
  }
}
