/* ========== Design tokens ========== */
:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-glow: radial-gradient(1200px 400px at 10% -10%, rgba(79, 70, 229, 0.10), transparent 60%),
    radial-gradient(900px 360px at 100% 0%, rgba(14, 165, 233, 0.10), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef1f8;
  --border: #e3e7f0;
  --border-strong: #cfd5e3;
  --text: #1c2233;
  --text-2: #4a5468;
  --text-3: #7a8499;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.09);
  --accent-ring: rgba(79, 70, 229, 0.28);
  --ok: #0f9d58;
  --ok-soft: rgba(15, 157, 88, 0.12);
  --bad: #d93025;
  --bad-soft: rgba(217, 48, 37, 0.10);
  --warn-soft: rgba(234, 179, 8, 0.14);
  --header-bg: rgba(255, 255, 255, 0.78);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --header-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1017;
    --bg-glow: radial-gradient(1200px 400px at 10% -10%, rgba(129, 140, 248, 0.10), transparent 60%),
      radial-gradient(900px 360px at 100% 0%, rgba(56, 189, 248, 0.07), transparent 60%);
    --surface: #151a24;
    --surface-2: #1a2030;
    --surface-3: #222a3b;
    --border: #262e40;
    --border-strong: #354057;
    --text: #e6e9f2;
    --text-2: #b0b8cc;
    --text-3: #7d879d;
    --accent: #8b93ff;
    --accent-hover: #a5abff;
    --accent-soft: rgba(139, 147, 255, 0.12);
    --accent-ring: rgba(139, 147, 255, 0.35);
    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, 0.14);
    --bad: #f87171;
    --bad-soft: rgba(248, 113, 113, 0.14);
    --warn-soft: rgba(234, 179, 8, 0.16);
    --header-bg: rgba(13, 16, 23, 0.78);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1017;
  --bg-glow: radial-gradient(1200px 400px at 10% -10%, rgba(129, 140, 248, 0.10), transparent 60%),
    radial-gradient(900px 360px at 100% 0%, rgba(56, 189, 248, 0.07), transparent 60%);
  --surface: #151a24;
  --surface-2: #1a2030;
  --surface-3: #222a3b;
  --border: #262e40;
  --border-strong: #354057;
  --text: #e6e9f2;
  --text-2: #b0b8cc;
  --text-3: #7d879d;
  --accent: #8b93ff;
  --accent-hover: #a5abff;
  --accent-soft: rgba(139, 147, 255, 0.12);
  --accent-ring: rgba(139, 147, 255, 0.35);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.14);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.14);
  --warn-soft: rgba(234, 179, 8, 0.16);
  --header-bg: rgba(13, 16, 23, 0.78);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ========== Base ========== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: calc(var(--header-h) + 16px);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg-glow), var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

img {
  max-width: 100%;
  vertical-align: middle;
}

/* ========== Header ========== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-h);
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand:hover {
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.nav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-2);
  font-size: 14px;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.nav a:hover {
  color: var(--text);
  background: var(--surface-3);
  text-decoration: none;
}

.nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  text-decoration: none;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ========== Layout ========== */
.layout {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

/* 目录栏和正文同在一块面板里，目录是面板左侧的浅色侧栏 */
.panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel.has-toc {
  grid-template-columns: 248px minmax(0, 1fr);
}

.toc-rail {
  border-right: 1px solid var(--border);
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--surface-2);
}

.toc-rail[hidden] {
  display: none;
}

.toc {
  position: sticky;
  top: var(--header-h);
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  padding: 36px 14px 28px;
  font-size: 13.5px;
}

.toc-title {
  margin: 0 0 10px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-3);
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
}

.toc li + li {
  margin: 0;
}

.toc li a {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-2);
  line-height: 1.45;
  transition: background 0.15s, color 0.15s;
}

.toc li.sub a {
  padding-left: 22px;
  font-size: 13px;
  color: var(--text-3);
}

.toc li a:hover {
  background: var(--surface-3);
  color: var(--text);
  text-decoration: none;
}

.toc li a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.toc-inline {
  display: none;
  margin: 0 0 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
}

.toc-inline summary {
  padding: 9px 14px;
  color: var(--text-2);
  font-weight: 600;
  cursor: pointer;
}

.toc-inline ol {
  list-style: none;
  margin: 0;
  padding: 0 14px 10px;
}

.toc-inline li a {
  display: block;
  padding: 4px 0;
  color: var(--text-2);
}

.toc-inline li.sub a {
  padding-left: 14px;
  color: var(--text-3);
}

/* ========== Content card ========== */
.content {
  min-width: 0;
  padding: 36px 44px 40px;
}

.content.is-entering {
  animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-3);
}

.breadcrumb a {
  color: var(--text-2);
}

.breadcrumb .sep {
  opacity: 0.6;
}

.content h1 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.content h1 strong {
  font-weight: inherit;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.content h2 {
  margin: 44px 0 16px;
  padding-bottom: 10px;
  font-size: 21px;
  line-height: 1.35;
  border-bottom: 1px solid var(--border);
}

.content h3 {
  margin: 30px 0 12px;
  font-size: 17px;
}

.content h4,
.content h5,
.content h6 {
  margin: 24px 0 10px;
}

.content h2 .anchor,
.content h3 .anchor {
  margin-left: 8px;
  color: var(--text-3);
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.15s;
}

.content h2:hover .anchor,
.content h3:hover .anchor {
  opacity: 1;
}

.content p,
.content ul,
.content ol {
  margin: 0 0 14px;
}

.content ul,
.content ol {
  padding-left: 1.4em;
}

.content li + li {
  margin-top: 4px;
}

.content strong {
  font-weight: 650;
}

.content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 32px 0;
}

.page-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 22px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: nowrap;
}

.chip svg {
  width: 13px;
  height: 13px;
}

/* 首页 h1 下的简介 */
.page-home .content > h1 + .page-meta + p,
.page-home .content > h1 + p {
  font-size: 16px;
  color: var(--text-2);
}

.content blockquote {
  margin: 0 0 18px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text-2);
}

.content blockquote p:last-child {
  margin-bottom: 0;
}

/* ========== Code ========== */
.content code {
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--text);
  overflow-wrap: anywhere;
}

.content pre {
  margin: 0 0 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.content pre code {
  padding: 0;
  background: none;
}

/* 可复制的 URL */
.copyable {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  vertical-align: middle;
}

.copyable code {
  display: inline-block;
  max-width: 100%;
}

.copy-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  vertical-align: middle;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.copy-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-ring);
}

.copy-btn svg {
  width: 14px;
  height: 14px;
}

.copy-btn.copied {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: transparent;
}

/* ========== Tables ========== */
.table-block {
  margin: 0 0 22px;
}

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 10px;
}

.search {
  position: relative;
  flex: 1 1 260px;
  max-width: 380px;
}

.search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

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

.search input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.table-count {
  font-size: 13px;
  color: var(--text-3);
}

/* clip 只裁圆角、不形成滚动容器，表头才能相对页面吸顶 */
.table-wrap {
  overflow: clip;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.content th,
.content td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.content th {
  position: sticky;
  top: var(--header-h);
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.content tbody tr:last-child td {
  border-bottom: 0;
}

.content tbody tr {
  transition: background 0.12s;
}

.content tbody tr:hover {
  background: var(--surface-2);
}

/* 放不下时才断行：优先在空格、标点处断开 */
.content td {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.content td:first-child {
  font-weight: 500;
}

/* 序号列 */
.content td.col-num,
.content th.col-num {
  width: 1%;
  white-space: nowrap;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.content td.col-count {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

/* 频道列表里的直链 */
.content td a.stream-link {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-2);
}

.content td a.stream-link:hover {
  color: var(--accent);
}

.content td.col-from {
  color: var(--text-3);
  font-size: 13px;
}

.content table img {
  border-radius: 4px;
  margin-right: 4px;
}

.content tr.is-hidden {
  display: none;
}

.table-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
}

.content a.nowrap {
  white-space: nowrap;
}

.file-item {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}

/* 文件链接（m3u / txt / xml …）以标签样式展示 */
.content a.file-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 2px 0;
  padding: 1px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.7;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.content a.file-link:hover {
  border-color: var(--accent-ring);
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

.ext {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* 状态徽标 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.badge-bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.badge-muted {
  color: var(--text-3);
  background: var(--surface-3);
}

/* ========== States ========== */
.skeleton {
  display: grid;
  gap: 14px;
}

.skeleton span {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}

.skeleton span:first-child {
  width: 40%;
  height: 28px;
  margin-bottom: 8px;
}

.skeleton span:nth-child(3) {
  width: 85%;
}

.skeleton span:nth-child(4) {
  width: 60%;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.state {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-2);
}

.state-code {
  margin: 0 0 6px;
  font-size: 56px;
  font-weight: 800;
  line-height: 1.1;
  background: linear-gradient(135deg, #6366f1, #0ea5e9);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.state h1 {
  font-size: 22px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

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

.state-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

/* ========== Footer / toast / back-to-top ========== */
.site-footer {
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 13px;
}

.footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 24px 24px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 20px;
}

.footer-inner a {
  color: var(--text-2);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 50;
  padding: 9px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--surface);
  font-size: 14px;
  box-shadow: var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 15;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.to-top.show {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

/* ========== Responsive ========== */
@media (max-width: 1100px) {
  .panel.has-toc {
    grid-template-columns: minmax(0, 1fr);
  }

  .toc-rail {
    display: none;
  }

  .toc-inline {
    display: block;
  }
}

@media (max-width: 768px) {
  :root {
    --header-h: 56px;
  }

  body {
    font-size: 14.5px;
  }

  .header-inner {
    padding: 0 16px;
    gap: 12px;
  }

  .brand-text {
    display: none;
  }

  .nav a {
    padding: 6px 10px;
  }

  .layout {
    padding: 16px 16px 32px;
  }

  .panel {
    border-radius: 12px;
  }

  .content {
    padding: 22px 18px 26px;
  }

  .content h1 {
    font-size: 24px;
  }

  .content h2 {
    margin-top: 34px;
    font-size: 19px;
  }

  .content th,
  .content td {
    padding: 8px 10px;
  }

  /* 窄屏下表格横向滚动，容器成了滚动容器，表头不再吸顶 */
  .table-wrap {
    overflow-x: auto;
  }

  .content th {
    position: static;
  }

  /* 窄屏下表格按内容撑开、横向滚动，避免列被挤成一两个字宽 */
  .content table {
    width: max-content;
    min-width: 100%;
  }

  .content td {
    max-width: 20em;
  }

  .content td:first-child {
    min-width: 4.5em;
    max-width: 10em;
  }

  .content td.col-num {
    min-width: 0;
  }

  .search {
    max-width: none;
  }

  .footer-inner {
    padding: 16px;
  }

  .to-top {
    right: 16px;
    bottom: 16px;
  }
}

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