/* =====================================================================
   WorldSim · 主题系统
   5 套整站主题：通过 [data-theme="xxx"] 覆盖 CSS 变量
   - nebula  星云（默认·深空青蓝品红）
   - cyber   赛博（霓虹电青/品红/警示黄·扫描线）
   - ink     水墨（浅色宣纸·墨黑朱砂）
   - aurora  极光（明亮柔和·粉紫蓝·大圆角）
   - emerald 翡翠（深森林黑绿·翡翠金）
===================================================================== */

/* 默认主题 = nebula（已在 base.css 的 :root 定义） */
html[data-theme="nebula"] { /* 与 :root 一致，显式声明便于阅读 */ }

/* =====================================================================
   主题 2 · CYBER 赛博朋克
   纯黑底 + 电青/品红/警示黄，强对比，扫描线装饰
===================================================================== */
html[data-theme="cyber"] {
  --bg-0: #050208;
  --bg-1: #0c0414;
  --bg-2: #160826;
  --bg-3: #1f0a35;
  --surface: rgba(28, 8, 48, 0.6);
  --surface-strong: rgba(38, 10, 64, 0.88);
  --surface-hover: rgba(52, 14, 84, 0.75);

  --border: rgba(0, 240, 255, 0.22);
  --border-strong: rgba(0, 240, 255, 0.6);

  --text-0: #f0fbff;
  --text-1: #b8c8e8;
  --text-2: #7a86b0;
  --text-3: #4d527a;

  --c-primary: #00f0ff;
  --c-primary-2: #00a3b8;
  --c-primary-glow: rgba(0, 240, 255, 0.6);

  --c-accent: #ff2e88;
  --c-accent-2: #c026d3;
  --c-accent-glow: rgba(255, 46, 136, 0.6);

  --c-gold: #ffea00;
  --c-mint: #00ff9d;
  --c-coral: #ff5e3a;

  --grad-primary: linear-gradient(90deg, var(--c-primary) 0%, var(--c-accent) 100%);
  --grad-accent: linear-gradient(90deg, var(--c-accent) 0%, var(--c-gold) 100%);
  --grad-text: linear-gradient(90deg, var(--c-primary) 0%, var(--c-accent) 50%, var(--c-gold) 100%);

  --glow-a: rgba(255, 46, 136, 0.3);
  --glow-b: rgba(0, 240, 255, 0.22);
  --glow-c: rgba(255, 234, 0, 0.1);
  --grid-color: rgba(0, 240, 255, 0.06);
  --grid-size: 48px;

  --shadow-card: 0 18px 50px -20px rgba(255, 46, 136, 0.25), 0 0 0 1px rgba(0,240,255,0.08);
  --font-display: "Orbitron", "Microsoft YaHei", sans-serif;

  --particle-colors: "0,240,255 | 255,46,136 | 255,234,0";
  --is-light: 0;
}

/* 赛博扫描线装饰 */
html[data-theme="cyber"] body::after {
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px),
    repeating-linear-gradient(0deg, rgba(0,240,255,0.025) 0px, rgba(0,240,255,0.025) 1px, transparent 1px, transparent 3px);
  background-size: var(--grid-size) var(--grid-size), var(--grid-size) var(--grid-size), 100% 4px;
}
html[data-theme="cyber"] .card,
html[data-theme="cyber"] .glass,
html[data-theme="cyber"] .feature-card {
  border-color: rgba(0, 240, 255, 0.18);
  clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 14px 100%, 0 calc(100% - 14px));
}
html[data-theme="cyber"] .btn-primary { letter-spacing: 0.04em; }
html[data-theme="cyber"] .eyebrow { text-shadow: 0 0 8px var(--c-primary-glow); }

/* =====================================================================
   主题 3 · INK 水墨（浅色）
   宣纸米白底 + 浓墨主文 + 朱砂红强调 + 金点缀，毛笔印章感
===================================================================== */
html[data-theme="ink"] {
  --bg-0: #f4f0e6;
  --bg-1: #ece6d6;
  --bg-2: #e4dcc8;
  --bg-3: #ddd2ba;
  --surface: rgba(255, 252, 244, 0.7);
  --surface-strong: rgba(255, 253, 247, 0.92);
  --surface-hover: rgba(250, 245, 232, 0.95);

  --border: rgba(60, 50, 35, 0.16);
  --border-strong: rgba(40, 30, 20, 0.4);

  --text-0: #1a1612;
  --text-1: #3d352a;
  --text-2: #6b5f4d;
  --text-3: #9a8d76;

  --c-primary: #b8332a;       /* 朱砂 */
  --c-primary-2: #8c1f1a;
  --c-primary-glow: rgba(184, 51, 42, 0.35);

  --c-accent: #5a4a8c;        /* 青紫 */
  --c-accent-2: #3d3160;
  --c-accent-glow: rgba(90, 74, 140, 0.3);

  --c-gold: #b8862e;          /* 古金 */
  --c-mint: #4a7c59;          /* 松绿 */
  --c-coral: #c75d3a;         /* 赭石 */

  --grad-primary: linear-gradient(120deg, var(--c-primary) 0%, var(--c-accent) 100%);
  --grad-accent: linear-gradient(120deg, var(--c-accent) 0%, var(--c-gold) 100%);
  --grad-text: linear-gradient(110deg, var(--c-primary) 0%, var(--c-accent) 60%, var(--c-gold) 100%);

  --glow-a: rgba(184, 51, 42, 0.1);
  --glow-b: rgba(90, 74, 140, 0.08);
  --glow-c: rgba(184, 134, 46, 0.08);
  --grid-color: rgba(60, 50, 35, 0.05);
  --grid-size: 56px;

  --shadow-card: 0 12px 40px -18px rgba(60, 40, 20, 0.25);
  --shadow-pop: 0 20px 60px -20px rgba(60, 40, 20, 0.35);

  --font-sans: "PingFang SC", "Songti SC", "STSong", "Microsoft YaHei", serif;
  --font-display: "Songti SC", "STSong", "Microsoft YaHei", serif;
  --font-mono: "STKaiti", "KaiTi", "PingFang SC", monospace;

  --particle-colors: "184,51,42 | 90,74,140 | 184,134,46";
  --is-light: 1;
}

/* 水墨：宣纸纹理 + 毛笔感装饰 */
html[data-theme="ink"] body::after {
  background-image:
    radial-gradient(circle at 20% 30%, rgba(60,50,35,0.025) 0%, transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(60,50,35,0.02) 0%, transparent 50%);
  background-size: 100% 100%;
  mask-image: none;
  -webkit-mask-image: none;
}
html[data-theme="ink"] .card,
html[data-theme="ink"] .glass {
  border-color: rgba(60, 50, 35, 0.14);
  box-shadow: var(--shadow-card);
}
html[data-theme="ink"] .logo span,
html[data-theme="ink"] .gradient-text {
  font-family: var(--font-display);
  font-weight: 700;
}
html[data-theme="ink"] .btn-primary { color: #fff7ec; }

/* =====================================================================
   主题 4 · AURORA 极光（浅色·柔和）
   月光白底 + 粉/紫/蓝渐变，超大圆角，柔软发光
===================================================================== */
html[data-theme="aurora"] {
  --bg-0: #faf7ff;
  --bg-1: #f3eefc;
  --bg-2: #ece4f8;
  --bg-3: #e2d6f3;
  --surface: rgba(255, 255, 255, 0.65);
  --surface-strong: rgba(255, 255, 255, 0.88);
  --surface-hover: rgba(255, 255, 255, 0.95);

  --border: rgba(120, 80, 200, 0.16);
  --border-strong: rgba(120, 80, 200, 0.4);

  --text-0: #2a1840;
  --text-1: #4a3568;
  --text-2: #7a6a98;
  --text-3: #a89bc0;

  --c-primary: #8b5cf6;       /* 紫 */
  --c-primary-2: #6d28d9;
  --c-primary-glow: rgba(139, 92, 246, 0.35);

  --c-accent: #ec4899;        /* 粉 */
  --c-accent-2: #be185d;
  --c-accent-glow: rgba(236, 72, 153, 0.35);

  --c-gold: #f59e0b;
  --c-mint: #10b981;
  --c-coral: #f97316;

  --grad-primary: linear-gradient(120deg, #8b5cf6 0%, #ec4899 100%);
  --grad-accent: linear-gradient(120deg, #ec4899 0%, #f59e0b 100%);
  --grad-text: linear-gradient(110deg, #8b5cf6 0%, #ec4899 50%, #f59e0b 100%);

  --glow-a: rgba(139, 92, 246, 0.18);
  --glow-b: rgba(236, 72, 153, 0.16);
  --glow-c: rgba(59, 130, 246, 0.14);
  --grid-color: rgba(120, 80, 200, 0.04);
  --grid-size: 64px;

  --radius: 20px;
  --radius-lg: 30px;
  --radius-xl: 42px;

  --shadow-card: 0 18px 50px -22px rgba(139, 92, 246, 0.3);
  --shadow-pop: 0 24px 70px -20px rgba(236, 72, 153, 0.3);

  --font-display: "Orbitron", "PingFang SC", sans-serif;

  --particle-colors: "139,92,246 | 236,72,153 | 59,130,246";
  --is-light: 1;
}

/* 极光：圆点纹理代替网格 */
html[data-theme="aurora"] body::after {
  background-image: radial-gradient(circle, rgba(139,92,246,0.08) 1.2px, transparent 1.4px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at 50% 40%, #000, transparent 80%);
  -webkit-mask-image: radial-gradient(circle at 50% 40%, #000, transparent 80%);
}
html[data-theme="aurora"] .card,
html[data-theme="aurora"] .glass {
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow-card);
}
html[data-theme="aurora"] .btn-primary { color: #fff; }

/* =====================================================================
   主题 5 · EMERALD 翡翠（深森林）
   近黑深绿底 + 翡翠绿 + 暖金，沉稳奢华
===================================================================== */
html[data-theme="emerald"] {
  --bg-0: #04100c;
  --bg-1: #07180f;
  --bg-2: #0a2018;
  --bg-3: #0e2a20;
  --surface: rgba(14, 42, 32, 0.6);
  --surface-strong: rgba(18, 54, 40, 0.88);
  --surface-hover: rgba(24, 68, 50, 0.78);

  --border: rgba(80, 200, 150, 0.18);
  --border-strong: rgba(100, 230, 170, 0.45);

  --text-0: #ecfff5;
  --text-1: #b8d8c8;
  --text-2: #7fa896;
  --text-3: #4d7064;

  --c-primary: #10d984;       /* 翡翠绿 */
  --c-primary-2: #0a9e61;
  --c-primary-glow: rgba(16, 217, 132, 0.5);

  --c-accent: #e5b94e;        /* 暖金 */
  --c-accent-2: #c89730;
  --c-accent-glow: rgba(229, 185, 78, 0.5);

  --c-gold: #e5b94e;
  --c-mint: #4ade80;
  --c-coral: #f87171;

  --grad-primary: linear-gradient(120deg, #10d984 0%, #e5b94e 100%);
  --grad-accent: linear-gradient(120deg, #e5b94e 0%, #f87171 100%);
  --grad-text: linear-gradient(110deg, #ecfff5 0%, #4ade80 50%, #e5b94e 100%);

  --glow-a: rgba(16, 217, 132, 0.18);
  --glow-b: rgba(229, 185, 78, 0.14);
  --glow-c: rgba(74, 222, 128, 0.12);
  --grid-color: rgba(80, 200, 150, 0.05);
  --grid-size: 64px;

  --shadow-card: 0 18px 50px -20px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(16,217,132,0.06);
  --shadow-pop: 0 24px 70px -20px rgba(0, 0, 0, 0.9);

  --font-display: "Orbitron", "PingFang SC", sans-serif;

  --particle-colors: "16,217,132 | 229,185,78 | 74,222,128";
  --is-light: 0;
}

/* =====================================================================
   浅色主题通用适配（ink / aurora）
   原本面向深色设计的元素需要调整：输入框、轨迹、描边文字
===================================================================== */
html[data-theme="ink"] .slider,
html[data-theme="aurora"] .slider {
  background: rgba(0,0,0,0.08);
}
html[data-theme="ink"] .input,
html[data-theme="aurora"] .input {
  background: rgba(255,255,255,0.7);
}
html[data-theme="ink"] .input::placeholder,
html[data-theme="aurora"] .input::placeholder { color: var(--text-3); }
html[data-theme="ink"] .nav.scrolled,
html[data-theme="aurora"] .nav.scrolled {
  background: rgba(244, 240, 230, 0.75);
}
html[data-theme="aurora"] .nav.scrolled { background: rgba(250, 247, 255, 0.78); }

/* 渐变文字描边在浅色下需更淡 */
html[data-theme="ink"] .logo-mark::after,
html[data-theme="aurora"] .logo-mark::after { background: #fff; }

/* 浅色主题下世界卡的渐变蒙层需要更深才能压住浅底 */
html[data-theme="ink"] .world-overlay,
html[data-theme="aurora"] .world-overlay {
  background: linear-gradient(180deg, transparent 20%, rgba(0,0,0,0.35) 55%, rgba(0,0,0,0.8) 100%);
}
html[data-theme="ink"] .world-meta h3,
html[data-theme="aurora"] .world-meta h3,
html[data-theme="ink"] .world-meta p,
html[data-theme="aurora"] .world-meta p,
html[data-theme="ink"] .world-stats,
html[data-theme="aurora"] .world-stats { color: #fff; }
html[data-theme="ink"] .world-meta p,
html[data-theme="aurora"] .world-meta p { color: rgba(255,255,255,0.78); }
html[data-theme="ink"] .world-stats,
html[data-theme="aurora"] .world-stats { color: rgba(255,255,255,0.65); border-top-color: rgba(255,255,255,0.15); }
html[data-theme="ink"] .world-stats b,
html[data-theme="aurora"] .world-stats b { color: #fff; }
html[data-theme="ink"] .world-trend,
html[data-theme="aurora"] .world-trend {
  background: rgba(0,0,0,0.45);
  color: #fff;
}

/* 浅色主题下 auth-aside 侧栏文字保持亮（它本身是深渐变底） */
html[data-theme="ink"] .auth-aside,
html[data-theme="aurora"] .auth-aside { color: var(--text-0); }
html[data-theme="ink"] .auth-aside h2,
html[data-theme="aurora"] .auth-aside h2 { color: #fff; }
html[data-theme="ink"] .auth-aside p,
html[data-theme="aurora"] .auth-aside p { color: rgba(255,255,255,0.85); }

/* 浅色下 footer */
html[data-theme="ink"] .footer,
html[data-theme="aurora"] .footer {
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.04));
}

/* 浅色下 graph-wrap 背景需调亮些避免太黑 */
html[data-theme="ink"] .graph-wrap,
html[data-theme="aurora"] .graph-wrap {
  background:
    radial-gradient(circle at 30% 20%, rgba(139,92,246,0.08), transparent 60%),
    radial-gradient(circle at 70% 80%, rgba(236,72,153,0.08), transparent 60%),
    rgba(255,255,255,0.4);
}
html[data-theme="ink"] .graph-wrap { background: radial-gradient(circle at 30% 20%, rgba(184,51,42,0.06), transparent 60%), rgba(255,253,247,0.5); }

/* =====================================================================
   主题切换器 UI
===================================================================== */
.theme-switcher {
  position: relative;
}
.theme-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  color: var(--text-1);
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}
.theme-btn:hover { border-color: var(--border-strong); color: var(--c-primary); transform: rotate(15deg); }
.theme-btn .swatch {
  position: absolute;
  inset: 0;
  opacity: 0.18;
}
.theme-btn svg { position: relative; z-index: 1; }

.theme-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 300px;
  padding: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow: var(--shadow-pop);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.96);
  transform-origin: top right;
  transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.theme-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}
.theme-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 8px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.theme-panel-head h4 {
  font-size: 13px; font-weight: 700; color: var(--text-0);
  letter-spacing: 0.04em;
}
.theme-panel-head .sub { font-size: 11px; color: var(--text-3); }

.theme-options { display: flex; flex-direction: column; gap: 6px; }
.theme-option {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  position: relative;
}
.theme-option:hover { background: var(--surface); }
.theme-option.active {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.theme-option.active::after {
  content: "";
  position: absolute;
  right: 12px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--grad-primary);
  display: grid; place-items: center;
}
.theme-option.active::before {
  content: "✓";
  position: absolute;
  right: 16px;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  z-index: 1;
}

.theme-swatch {
  width: 40px; height: 40px;
  border-radius: 12px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
}
.theme-swatch::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 40%;
}
.theme-info { flex: 1; min-width: 0; }
.theme-info .name { font-size: 14px; font-weight: 600; color: var(--text-0); }
.theme-info .desc { font-size: 11.5px; color: var(--text-3); margin-top: 1px; }

/* 各主题色板预览 */
.sw-nebula  { background: linear-gradient(135deg, #0a1244 0%, #1a2046 50%, #05060f 100%); }
.sw-nebula::after  { background: linear-gradient(90deg, #38e1ff, #ff5dc8); }

.sw-cyber   { background: linear-gradient(135deg, #0c0414 0%, #1f0a35 50%, #050208 100%); }
.sw-cyber::after   { background: linear-gradient(90deg, #00f0ff, #ff2e88, #ffea00); }

.sw-ink     { background: linear-gradient(135deg, #f4f0e6 0%, #e4dcc8 50%, #ece6d6 100%); }
.sw-ink::after     { background: linear-gradient(90deg, #b8332a, #5a4a8c); }

.sw-aurora  { background: linear-gradient(135deg, #faf7ff 0%, #ece4f8 50%, #f3eefc 100%); }
.sw-aurora::after  { background: linear-gradient(90deg, #8b5cf6, #ec4899, #f59e0b); }

.sw-emerald { background: linear-gradient(135deg, #07180f 0%, #0e2a20 50%, #04100c 100%); }
.sw-emerald::after { background: linear-gradient(90deg, #10d984, #e5b94e); }

/* 移动端切换器适配 */
@media (max-width: 720px) {
  .theme-panel { width: 280px; right: -40px; }
}
