/* =========================================================
   A. 语义变量（不要在别处再定义这些名字）
   ========================================================= */

/* -------- Light mode (default) -------- */
:root {
  color-scheme: light;

  --bg: #ffffff;
  --panel: #f3f4f6;

  --text: #0f172a;
  --muted: #475569;

  --line: rgba(15, 23, 42, .12);

  /* 主题色（由 channel 覆盖） */
  --brand: #60a5fa;

  /* UI */
  --radius: 14px;
  --w: 1040px;
}

/* -------- Dark mode (follow system) -------- */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #292a2e;
    --panel: #111827;

    --text: #e5e7eb;
    --muted: #9ca3af;

    --line: rgba(255,255,255,.10);
  }
}

/* =========================================================
   B. 全站基础 reset + 落地（你原本已有，保持）
   ========================================================= */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Arial,
    "Noto Sans",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;

  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

/* 链接 */
a {
  color: inherit;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* 容器 */
.container {
  max-width: var(--w);
  margin: 0 auto;
  padding: 0 16px;
}
/* =========================================================
   C. Manual Theme Toggle
   ========================================================= */

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f8fc;
  --panel: #eef2f7;
  --text: #0f172a;
  --muted: #526077;
  --line: rgba(15, 23, 42, .14);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #292a2e;
  --panel: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --line: rgba(255,255,255,.10);
}

:root[data-theme='light'] .site-header {
  background: rgba(255, 255, 255, 0.84);
}

:root[data-theme='light'] .nav-btn,
:root[data-theme='light'] .nav-link {
  border-color: rgba(15, 23, 42, 0.14);
}

.theme-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(20, 28, 48, 0.88);
  color: #eef5ff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.theme-toggle:hover {
  background: rgba(35, 49, 82, 0.92);
}

:root[data-theme='light'] .theme-toggle {
  background: rgba(255, 255, 255, 0.92);
  color: #0f172a;
}

.theme-toggle-icon {
  font-size: 14px;
  line-height: 1;
}

.theme-toggle-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
}

/* =========================================================
   D. Subsite Switcher (dynamic from wagtail Site table)
   ========================================================= */
.site-switcher {
  position: relative;
}

.site-switcher-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
  justify-content: space-between;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.site-switcher-trigger::-webkit-details-marker {
  display: none;
}

.site-switcher-caret {
  opacity: 0.72;
  transition: transform .16s ease;
}

.site-switcher[open] .site-switcher-caret {
  transform: rotate(180deg);
}

.site-switcher-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 170px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(18, 27, 44, 0.96);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28);
  z-index: 130;
}

.site-switcher-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.site-switcher-item:hover {
  text-decoration: none;
  background: rgba(255, 255, 255, 0.08);
}

.site-switcher-item.is-current {
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
}

:root[data-theme='light'] .site-switcher-trigger {
  background: rgba(255, 255, 255, 0.84);
}

:root[data-theme='light'] .site-switcher-menu {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 28px rgba(23, 46, 81, 0.16);
}

:root[data-theme='light'] .site-switcher-item:hover {
  background: rgba(15, 23, 42, 0.06);
}

:root[data-theme='light'] .site-switcher-item.is-current {
  background: rgba(15, 23, 42, 0.10);
}
