/* ============================================================
   RUN·润 移居手册 · 组件层
   顶栏/侧边栏/TOC/卡片/徽章/callout/表格/按钮 等骨架与组件，
   结构与配色移植自 grokbot.yin.wiki 的 design-system/components.css，
   按本站内容类型（徽章 chip、警示块 callout、数据表、流程图）做等价映射。
   ============================================================ */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 76px;
}

body {
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

code,
kbd,
pre {
  font-family: var(--font-mono);
}

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

/* ---------- 骨架：顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--background) 82%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--foreground);
  margin-right: 16px;
  white-space: nowrap;
}
.topbar__brand:hover {
  text-decoration: none;
}
.topbar__mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-foreground);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  flex: none;
}

.topbar__nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1 1 auto;
  min-width: 0;
}
.topbar__nav::-webkit-scrollbar {
  display: none;
}
.topbar__nav a {
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--foreground-secondary);
  white-space: nowrap;
  transition: color 0.15s, background 0.15s;
}
.topbar__nav a:hover {
  color: var(--foreground);
  background: var(--muted);
  text-decoration: none;
}
.topbar__nav a[aria-current="page"] {
  color: var(--foreground);
  background: var(--muted);
  font-weight: 500;
}

.topbar__end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ---------- 骨架：三栏布局 ---------- */
.shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 188px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
  gap: 40px;
}

/* ---------- 侧边栏（分组） ---------- */
.sidebar {
  position: sticky;
  top: 52px;
  height: calc(100vh - 52px);
  overflow-y: auto;
  padding: 28px 0 40px;
  font-size: var(--text-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar__group + .sidebar__group {
  margin-top: 24px;
}
/* 一级标题 = 折叠开关（button，非 p） */
.sidebar__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  margin: 0 0 6px;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--foreground-tertiary);
  transition: color 0.15s, background 0.15s;
}
.sidebar__label:hover {
  color: var(--foreground-secondary);
  background: var(--muted);
}
.sidebar__label:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.sidebar__chevron {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  transition: transform 0.18s ease;
}
.sidebar__group.is-collapsed .sidebar__chevron {
  transform: rotate(-90deg);
}
.sidebar__group.is-collapsed .sidebar__items {
  display: none;
}
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  color: var(--foreground-secondary);
  transition: color 0.15s, background 0.15s;
}
.sidebar__item:hover {
  color: var(--foreground);
  background: var(--muted);
  text-decoration: none;
}
.sidebar__item[aria-current="page"] {
  color: var(--foreground);
  background: var(--muted);
  font-weight: 500;
}
.sidebar__item[aria-current="page"]::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
  margin-left: -10px;
  margin-right: 7px;
}
.sidebar__item--sub {
  padding-left: 22px;
  font-size: var(--text-xs);
  color: var(--foreground-tertiary);
}
.sidebar__item--sub:hover,
.sidebar__item--sub[aria-current="page"] {
  color: var(--foreground);
}

/* ---------- 内容区 ---------- */
.content {
  min-width: 0;
  max-width: 720px;
  padding: 48px 0 120px;
}

/* 页头 */
.page-head {
  margin-bottom: 40px;
}
.page-head__eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 10px;
}
.page-head h1 {
  margin: 0 0 14px;
  font-size: var(--text-hero);
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 700;
  text-wrap: balance;
}
.page-head__lede {
  margin: 0;
  font-size: var(--text-md);
  line-height: 1.65;
  color: var(--foreground-secondary);
  max-width: 60ch;
  text-wrap: pretty;
}

/* 正文排版 */
.prose section {
  margin-top: 56px;
}
.prose h1 {
  font-size: var(--text-hero);
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 700;
  margin: 0 0 18px;
  text-wrap: balance;
}
.prose h2 {
  margin: 56px 0 16px;
  font-size: var(--text-xl);
  line-height: 1.3;
  letter-spacing: -0.02em;
  font-weight: 650;
  scroll-margin-top: 76px;
}
.prose h3 {
  margin: 32px 0 10px;
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: -0.01em;
  scroll-margin-top: 76px;
}
.prose h4 {
  margin: 24px 0 8px;
  font-size: var(--text-base);
  font-weight: 600;
  scroll-margin-top: 76px;
}
.prose p {
  margin: 0 0 14px;
  color: var(--foreground-secondary);
  max-width: 68ch;
}
.prose strong,
.prose b {
  color: var(--foreground);
  font-weight: 550;
}
.prose ul,
.prose ol {
  margin: 0 0 14px;
  padding-left: 20px;
  color: var(--foreground-secondary);
}
.prose li {
  margin-bottom: 6px;
}
.prose li::marker {
  color: var(--foreground-tertiary);
}
.prose :not(pre) > code {
  font-size: 0.86em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--muted);
  border: 1px solid var(--border);
  color: var(--foreground);
}
.prose hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 48px 0;
}
.prose img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
}
.prose p:has(> img:only-child),
.prose p > img:only-child {
  text-align: center;
}
.prose a {
  text-underline-offset: 3px;
}

/* 表格内小字注释（上游文档的 <sub> 用法） */
.prose td sub,
.prose th sub {
  display: block;
  font-size: 11.5px;
  color: var(--foreground-tertiary);
  font-weight: 400;
  vertical-align: baseline;
  margin-bottom: 2px;
  font-family: var(--font-sans);
}
.prose p > sub,
.prose div > sub {
  display: block;
  font-size: 12px;
  color: var(--foreground-tertiary);
  margin: 4px 0 0;
}

/* 徽章 → chip（对应 grokbot 的 .badge） */
.duo-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 2px 4px 2px 0;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--foreground-secondary);
  background: var(--surface);
  vertical-align: middle;
}
.duo-chip b {
  font-weight: 600;
  margin-right: 4px;
  color: var(--foreground);
}
.duo-chip--green {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  background: var(--success-muted);
}
.duo-chip--green b {
  color: var(--success);
}
.duo-chip--blue {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-muted);
}
.duo-chip--blue b {
  color: var(--accent);
}
.duo-chip--gold {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
  background: var(--warning-muted);
}
.duo-chip--gold b {
  color: var(--warning);
}
.duo-chip--purple {
  color: var(--tok-k);
  border-color: color-mix(in srgb, var(--tok-k) 30%, transparent);
  background: color-mix(in srgb, var(--tok-k) 8%, transparent);
}
.duo-chip--purple b {
  color: var(--tok-k);
}
.duo-chip--red {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  background: var(--danger-muted);
}
.duo-chip--red b {
  color: var(--danger);
}
.duo-chip--wolf {
  color: var(--foreground-tertiary);
  background: var(--muted);
}
.duo-chip--wolf b {
  color: var(--foreground-secondary);
}

/* GitHub 警示块 → callout（对应 grokbot 的 .callout） */
.duo-callout {
  display: block;
  margin: 20px 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-sm);
  color: var(--foreground-secondary);
}
.duo-callout > p:first-of-type {
  margin-top: 0;
}
.duo-callout > p:last-of-type {
  margin-bottom: 0;
}
.duo-callout p:empty,
.duo-callout p:first-child:empty {
  display: none;
}
.duo-callout p {
  margin: 0 0 8px;
  font-size: var(--text-sm);
}
.duo-callout strong {
  color: var(--foreground);
}
.duo-callout::before {
  display: block;
  margin-bottom: 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--foreground-tertiary);
}
.duo-callout--tip {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-muted);
}
.duo-callout--tip::before {
  content: "💡 小贴士 TIP";
  color: var(--accent);
}
.duo-callout--note {
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-muted);
}
.duo-callout--note::before {
  content: "📝 注意 NOTE";
  color: var(--accent);
}
.duo-callout--important {
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  background: var(--success-muted);
}
.duo-callout--important::before {
  content: "⭐ 划重点 IMPORTANT";
  color: var(--success);
}
.duo-callout--warning {
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
  background: var(--warning-muted);
}
.duo-callout--warning::before {
  content: "⚠️ 当心 WARNING";
  color: var(--warning);
}
.duo-callout--caution {
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  background: var(--danger-muted);
}
.duo-callout--caution::before {
  content: "🚨 警告 CAUTION";
  color: var(--danger);
}

/* 非警示块的普通引用 */
.prose blockquote:not([class]) {
  margin: 14px 0;
  padding: 4px 16px;
  border-left: 2px solid var(--border-strong);
  color: var(--foreground-tertiary);
}

/* ---------- 表格（对应 grokbot 的 .table-wrap） ---------- */
.duo-tablewrap {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.duo-tablewrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  margin: 0;
}
.prose table {
  width: 100%;
  margin: 20px 0;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.duo-tablewrap table,
.prose .duo-tablewrap table {
  margin: 0;
}
.prose th,
.duo-tablewrap th {
  text-align: left;
  padding: 9px 14px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--foreground-tertiary);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.prose td,
.duo-tablewrap td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--foreground-secondary);
  vertical-align: top;
}
.prose tr:last-child td,
.duo-tablewrap tr:last-child td {
  border-bottom: 0;
}
.prose tr:hover td,
.duo-tablewrap tr:hover td {
  background: var(--surface-hover);
}
.prose td b,
.duo-tablewrap td b {
  color: var(--foreground);
  font-weight: 550;
}

/* ---------- 代码块 ---------- */
.prose pre {
  margin: 20px 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.7;
  color: var(--foreground-secondary);
}
.prose pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* ---------- mermaid 流程图容器（预渲染 SVG 为浅色底图，双主题下都垫白底） ---------- */
.duo-mermaid {
  margin: 20px 0;
  padding: 18px;
  text-align: center;
  background: #f7f7f8;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.duo-mermaid img,
.duo-mermaid svg {
  max-width: 100%;
  height: auto;
}
.duo-mermaid pre {
  border: none;
  background: none;
  padding: 0;
  text-align: left;
}

/* ---------- 页内 TOC ---------- */
.toc {
  position: sticky;
  top: 52px;
  height: calc(100vh - 52px);
  overflow-y: auto;
  padding: 76px 0 40px;
  font-size: var(--text-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.toc__label {
  margin: 0 0 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--foreground-tertiary);
}
.toc a {
  display: block;
  padding: 3px 0 3px 12px;
  border-left: 1px solid var(--border);
  color: var(--foreground-tertiary);
  transition: color 0.15s, border-color 0.15s;
}
.toc a:hover {
  color: var(--foreground);
  text-decoration: none;
}
.toc a.is-active {
  color: var(--foreground);
  border-left-color: var(--accent);
}
.toc a.toc__l3 {
  padding-left: 24px;
  font-size: var(--text-xs);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}
a.card:hover,
.card--hover:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  text-decoration: none;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.card-grid .card h4 {
  margin: 0 0 6px;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--foreground);
}
.card-grid .card p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--foreground-secondary);
}
.card__num {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent);
  margin-bottom: 10px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  text-decoration: none;
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-foreground);
}
.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, white);
  border-color: transparent;
}
.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--foreground-secondary);
}
.btn--ghost:hover {
  background: var(--muted);
  color: var(--foreground);
}

/* ---------- 图标按钮（顶栏右侧） ---------- */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--foreground-secondary);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.icon-btn:hover {
  color: var(--foreground);
  background: var(--muted);
}
.icon-btn svg {
  width: 16px;
  height: 16px;
}
[data-theme="dark"] .icon-btn .icon-moon {
  display: none;
}
html:not([data-theme="dark"]) .icon-btn .icon-sun {
  display: none;
}
/* 暗色下显示太阳图标（亮白，替代原先被内联 display:none 锁死的空按钮） */
[data-theme="dark"] .icon-btn .icon-sun {
  display: block;
}
[data-theme="dark"] .icon-btn {
  color: var(--foreground);
}

/* ---------- 首页 hero（grokbot 页头式，替代旧绿色大块） ---------- */
.hero {
  margin: 0 0 28px;
  padding: 32px 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-muted) 0%, transparent 55%),
    var(--surface);
}
.hero h1 {
  margin: 0 0 10px;
}
.hero p {
  margin: 0;
  font-size: var(--text-md);
  color: var(--foreground-secondary);
  max-width: 62ch;
}

/* ---------- 页脚 ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  color: var(--foreground-tertiary);
  font-size: var(--text-xs);
  line-height: 1.8;
}
.site-footer p {
  margin: 0 0 4px;
}
.site-footer b {
  color: var(--foreground-secondary);
  font-weight: 550;
}
.site-footer nav {
  margin-top: 8px;
}
.site-footer nav a {
  color: var(--foreground-tertiary);
  margin-right: 14px;
}
.site-footer nav a:hover {
  color: var(--foreground);
}

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) {
  .shell {
    grid-template-columns: 232px minmax(0, 1fr);
  }
  .toc {
    display: none;
  }
}
@media (max-width: 800px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 16px;
  }
  .sidebar {
    display: none;
  }
  .content {
    padding: 32px 0 80px;
  }
  .topbar__brand span.brand-text {
    display: none;
  }
}
@media (max-width: 640px) {
  .topbar {
    padding: 0 12px;
  }
  .topbar__nav a {
    padding: 5px 8px;
  }
}

/* ---------- 打印（买家可转 PDF） ---------- */
@media print {
  .topbar,
  .sidebar,
  .toc,
  .site-footer nav {
    display: none;
  }
  .shell {
    display: block;
    max-width: none;
    padding: 0;
  }
  body {
    background: #ffffff;
    color: #18181b;
    font-size: 12px;
  }
  .content {
    max-width: none;
    padding: 0;
  }
  .duo-mermaid,
  .prose pre {
    page-break-inside: avoid;
  }
  .prose h2 {
    page-break-after: avoid;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- 国家页地图卡（世界轻档案页） ---------- */
.country-map{height:340px;border-radius:var(--radius-lg);border:1px solid var(--border);overflow:hidden;position:relative;z-index:0;margin:.4rem 0 1.4rem;background:var(--muted)}
.country-map .leaflet-container{height:100%;width:100%;font:inherit;z-index:0}
.leaflet-container{background:var(--muted)} /* 瓦片未加载（离线）时的兜底底色，随主题走 */
.country-map .leaflet-control-zoom a{background:var(--surface);color:var(--foreground);border-color:var(--border)}
.country-map .leaflet-control-attribution{background:color-mix(in srgb,var(--surface) 82%,transparent);color:var(--foreground-tertiary);font-size:11px}
[data-theme="dark"] .country-map .leaflet-tile-pane{filter:invert(1) hue-rotate(180deg) brightness(.85) contrast(.95) saturate(.55)} /* 高德瓦片无暗色版，反色近似暗色地图 */

/* ---------- 首页「世界全貌」（内联 SVG，Equal Earth 投影；大国国界随机轮流亮起） ---------- */
.world-carousel{margin:.6rem 0 1.6rem}
.world-carousel .wc-svg{display:block;width:100%;height:auto;border-radius:var(--radius-lg);border:1px solid var(--border);background:color-mix(in srgb,var(--foreground) 4%,transparent)}
.world-carousel .wc-land{fill:color-mix(in srgb,var(--foreground) 13%,transparent);stroke:color-mix(in srgb,var(--foreground) 9%,transparent);stroke-width:.4}
.world-carousel .wc-c{fill:color-mix(in srgb,var(--foreground) 13%,transparent);stroke:color-mix(in srgb,var(--foreground) 9%,transparent);stroke-width:.4;transition:fill .3s ease,stroke .3s ease}
.world-carousel .wc-c.wc-on{fill:color-mix(in srgb,#1a9e6f 30%,transparent);stroke:#1a9e6f;stroke-width:1.1}
@media (prefers-reduced-motion: reduce) {
  .world-carousel .wc-c{transition:none}
}
