/* ===== 主题变量：暗色（默认） ===== */
:root {
  --bg: #0a0b0d;
  --panel: #121418;
  --panel-2: #181b20;
  --panel-hover: #1d2027;
  --sidebar-bg: #0d0f12;
  --footer-bg: rgba(10, 11, 13, 0.98);
  --footer-grad: rgba(10, 11, 13, 0.6);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.22);
  --ink: #e9e7e2;
  --title: #f3f0e8;
  --muted: #8b8c90;
  --faint: #5f6165;
  --placeholder: #5a5c60;
  --gold: #c9a24a;
  --gold-soft: #cfc5a8;
  --gold-bright: #f0dfb6;
  --gold-dim: rgba(201, 162, 74, 0.35);
  --gold-wash: rgba(201, 162, 74, 0.07);
  --gold-line: rgba(201, 162, 74, 0.22);
  --gold-glow-1: rgba(201, 162, 74, 0.25);
  --gold-glow-2: rgba(201, 162, 74, 0.4);
  --glow-far: rgba(201, 162, 74, 0.18);
  --glow-far-2: rgba(201, 162, 74, 0.3);
  --sigil-line: rgba(201, 162, 74, 0.14);
  --sigil-dash: rgba(201, 162, 74, 0.12);
  --link-line: rgba(201, 162, 74, 0.22);
  --link-dot: rgba(201, 162, 74, 0.4);
  --dot-grid: rgba(255, 255, 255, 0.045);
  --scroll-thumb: rgba(255, 255, 255, 0.14);
  --chip-bg: #1a1d22;
  --chip-border: rgba(255, 255, 255, 0.14);
  --chip-shadow: rgba(0, 0, 0, 0.28);
  --chip-shadow-drag: rgba(0, 0, 0, 0.45);
  --chip-rank: #d5c89e;
  --jin: #d9b45a;
  --mu: #6fbf8f;
  --shui: #6fa8d9;
  --huo: #e07a5f;
  --tu: #c69a6d;
  --el-jin-bg: #242015;
  --el-mu-bg: #15241b;
  --el-shui-bg: #15202b;
  --el-huo-bg: #2a1a17;
  --el-tu-bg: #251e16;
  --rare: #78aadc;
  --epic: #be8cdc;
  --legend-ink: #e8d5a4;
  --toast-bg: rgba(24, 26, 31, 0.96);
  --toast-shadow: rgba(0, 0, 0, 0.4);
  --modal-bg: rgba(0, 0, 0, 0.86);
  --hint-bg: rgba(17, 19, 23, 0.82);
  --hint-title: rgba(255, 255, 255, 0.62);
  --hint-sub: rgba(255, 255, 255, 0.28);
  --zoom-bg: rgba(22, 25, 30, 0.92);
  --danger: #b4413c;
  --quota-out: #c9736e;
  --aura-1: rgba(201, 162, 74, 0.12);
  --aura-2: rgba(201, 162, 74, 0.3);
  --bg-glow-1: rgba(201, 162, 74, 0.10);
  --bg-glow-2: rgba(90, 120, 150, 0.09);
}

/* ===== 主题变量：浅色（宣纸） ===== */
[data-theme="light"] {
  --bg: #f6f3ec;
  --panel: #fffdf8;
  --panel-2: #faf7f0;
  --panel-hover: #f2ede2;
  --sidebar-bg: #fbf8f1;
  --footer-bg: rgba(246, 243, 236, 0.98);
  --footer-grad: rgba(246, 243, 236, 0.6);
  --line: rgba(80, 66, 42, 0.14);
  --line-strong: rgba(80, 66, 42, 0.3);
  --ink: #2c2a25;
  --title: #211e17;
  --muted: #7d776c;
  --faint: #a39b8c;
  --placeholder: #aaa296;
  --gold: #9a782e;
  --gold-soft: #7d6a3f;
  --gold-bright: #6d5220;
  --gold-dim: rgba(154, 120, 46, 0.45);
  --gold-wash: rgba(154, 120, 46, 0.06);
  --gold-line: rgba(154, 120, 46, 0.28);
  --gold-glow-1: rgba(154, 120, 46, 0.2);
  --gold-glow-2: rgba(154, 120, 46, 0.35);
  --glow-far: rgba(154, 120, 46, 0.1);
  --glow-far-2: rgba(154, 120, 46, 0.2);
  --sigil-line: rgba(154, 120, 46, 0.18);
  --sigil-dash: rgba(154, 120, 46, 0.14);
  --link-line: rgba(154, 120, 46, 0.25);
  --link-dot: rgba(154, 120, 46, 0.45);
  --dot-grid: rgba(80, 66, 42, 0.07);
  --scroll-thumb: rgba(80, 66, 42, 0.2);
  --chip-bg: #fffdf8;
  --chip-border: rgba(80, 66, 42, 0.18);
  --chip-shadow: rgba(80, 66, 42, 0.12);
  --chip-shadow-drag: rgba(80, 66, 42, 0.2);
  --chip-rank: #9a782e;
  --jin: #b08b2a;
  --mu: #3f8f61;
  --shui: #3e7fb5;
  --huo: #c4543c;
  --tu: #9a7442;
  --el-jin-bg: #fbf4df;
  --el-mu-bg: #eaf5ed;
  --el-shui-bg: #eaf2f9;
  --el-huo-bg: #fbece8;
  --el-tu-bg: #f7efe3;
  --rare: #4a80b8;
  --epic: #8d5fae;
  --legend-ink: #9a782e;
  --toast-bg: rgba(255, 253, 248, 0.97);
  --toast-shadow: rgba(80, 66, 42, 0.18);
  --modal-bg: rgba(40, 36, 28, 0.7);
  --hint-bg: rgba(255, 253, 248, 0.9);
  --hint-title: rgba(44, 42, 37, 0.78);
  --hint-sub: rgba(44, 42, 37, 0.45);
  --zoom-bg: rgba(255, 253, 248, 0.94);
  --danger: #a63a34;
  --quota-out: #b04842;
  --aura-1: rgba(154, 120, 46, 0.1);
  --aura-2: rgba(154, 120, 46, 0.25);
  --bg-glow-1: rgba(201, 162, 74, 0.16);
  --bg-glow-2: rgba(120, 150, 180, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  overscroll-behavior: none;
  transition: background-color 0.3s, color 0.3s;
}

body::before {
  content: "";
  position: fixed;
  inset: -12%;
  background:
    radial-gradient(1100px 620px at 50% -18%, var(--bg-glow-1), transparent 65%),
    radial-gradient(760px 460px at 82% 108%, var(--bg-glow-2), transparent 70%),
    radial-gradient(620px 520px at 18% 84%, var(--bg-glow-2), transparent 70%);
  pointer-events: none;
  z-index: 0;
  animation: drift 26s ease-in-out infinite alternate;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(1.5%, -1%, 0) scale(1.04); }
  100% { transform: translate3d(-1%, 1.5%, 0) scale(1.02); }
}

#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
}

header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
}

.brand { display: flex; align-items: baseline; gap: 10px; }

h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--title);
}

.sub { font-size: 11px; color: var(--muted); letter-spacing: 0.14em; }
.head-right { display: flex; align-items: center; gap: 8px; }
.count { font-size: 12px; color: var(--muted); }
.count b { color: var(--gold); font-weight: 600; font-size: 14px; }

/* 主题切换按钮 */
.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  background: transparent;
  border: 0.5px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.2s;
}
.theme-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.6; }
.theme-btn:hover { color: var(--gold); border-color: var(--gold-line); background: var(--gold-wash); }
.theme-btn:active { transform: scale(0.9); }
[data-theme="light"] .theme-btn .ico-moon,
:root:not([data-theme="light"]) .theme-btn .ico-sun { display: none; }

.mockbar {
  flex: 0 0 auto;
  margin: 0 18px 6px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--gold-wash);
  border: 0.5px solid var(--gold-line);
  color: var(--gold);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

button.ghost {
  background: transparent;
  border: 0.5px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
button.ghost:hover { color: var(--ink); border-color: var(--line-strong); background: var(--gold-wash); }
button.ghost.small { padding: 5px 10px; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background-image: radial-gradient(var(--dot-grid) 0.8px, transparent 0.8px);
  background-size: 26px 26px;
}
#stage.grabbing { cursor: grabbing; }

/* 环境星图：漂浮的粒子与自动连线，纯装饰不挡交互 */
#ambient {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

.links {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 100%;
  overflow: visible;
  pointer-events: none;
}
.links line { stroke: var(--link-line); stroke-width: 1; stroke-dasharray: 3 5; }
.links circle { fill: var(--link-dot); }

.sigil {
  position: absolute;
  width: 400px; height: 400px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.5;
  transition: opacity 0.6s;
}
.sigil circle, .sigil path { fill: none; stroke: var(--sigil-line); stroke-width: 1; }
.sigil path { stroke-dasharray: 3 7; stroke: var(--sigil-dash); }
.sigil .nodes circle { stroke: none; }
.sigil .n-jin { fill: var(--jin); }
.sigil .n-mu { fill: var(--mu); }
.sigil .n-shui { fill: var(--shui); }
.sigil .n-huo { fill: var(--huo); }
.sigil .n-tu { fill: var(--tu); }
#stage.touched .sigil { opacity: 0.18; }

.hint {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 14px 12px;
  border-radius: 14px;
  background: var(--hint-bg);
  border: 0.5px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  transition: opacity 0.4s, transform 0.4s;
  text-align: center;
  z-index: 10;
}
.hint-title { font-size: 13px; color: var(--hint-title); letter-spacing: 0.04em; }
.hint-sub { font-size: 11px; color: var(--hint-sub); }
.ideas { display: flex; gap: 6px; margin-top: 2px; }
.idea {
  pointer-events: auto;
  background: var(--gold-wash);
  border: 0.5px solid var(--gold-line);
  color: var(--gold-soft);
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  white-space: nowrap;
}
.idea i { font-style: normal; color: var(--gold); padding: 0 2px; }
.idea:hover { background: var(--gold-dim); border-color: var(--gold); transform: translateY(-1px); }
.hint.gone { opacity: 0; transform: translate(-50%, -8px); pointer-events: none; }
.hint.gone .idea { pointer-events: none; }

#chips {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.zoombar {
  position: absolute;
  right: 14px; bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 20;
}
.zoombar button {
  min-width: 34px; height: 34px;
  padding: 0 9px;
  border-radius: 9px;
  background: var(--zoom-bg);
  border: 0.5px solid var(--line);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.zoombar button:hover { color: var(--ink); border-color: var(--line-strong); }
.zoombar #zoom-reset { font-size: 11px; letter-spacing: 0.02em; min-width: 48px; }
.zoombar #zoom-fit { font-size: 11px; padding: 0 8px; }

.chip {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 14px;
  white-space: nowrap;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border: 0.5px solid var(--chip-border);
  background: var(--chip-bg);
  color: var(--ink);
  box-shadow: 0 6px 18px var(--chip-shadow);
  transition: transform 0.12s ease, opacity 0.18s, box-shadow 0.2s, background-color 0.3s, border-color 0.3s;
  will-change: transform;
  animation: pop 0.26s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chip[data-el="金"] { --chip-bg: var(--el-jin-bg); --chip-border: rgba(217, 180, 90, 0.5); }
.chip[data-el="木"] { --chip-bg: var(--el-mu-bg); --chip-border: rgba(111, 191, 143, 0.5); }
.chip[data-el="水"] { --chip-bg: var(--el-shui-bg); --chip-border: rgba(111, 168, 217, 0.5); }
.chip[data-el="火"] { --chip-bg: var(--el-huo-bg); --chip-border: rgba(224, 122, 95, 0.5); }
.chip[data-el="土"] { --chip-bg: var(--el-tu-bg); --chip-border: rgba(198, 154, 109, 0.5); }
.chip .ico { font-size: 17px; line-height: 1; }
.chip .rank {
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--chip-rank);
  border-left: 0.5px solid var(--line);
  padding-left: 7px;
  margin-left: 2px;
  opacity: 0.9;
}
.chip.dragging { cursor: grabbing; transform: scale(1.08); z-index: 99; transition: none; box-shadow: 0 12px 28px var(--chip-shadow-drag); }
.chip.armed { outline: 1px solid var(--gold); outline-offset: 3px; }
.chip.rare { border-color: var(--rare); }
.chip.epic { border-color: var(--epic); }
.chip.legend {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold-glow-1), 0 0 24px var(--glow-far);
  animation: pop 0.26s cubic-bezier(0.34, 1.56, 0.64, 1), aura 2.6s ease-in-out infinite 0.3s;
}
.chip.merging { transform: scale(0.2); opacity: 0; }
.chip.spawn { animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
.chip.cooking {
  animation: cooking 1.1s ease-in-out infinite;
  pointer-events: none;
  border-color: var(--gold-dim);
}
@keyframes aura {
  0%, 100% { box-shadow: 0 0 0 1px var(--gold-glow-1), 0 0 18px var(--aura-1); }
  50% { box-shadow: 0 0 0 1px var(--gold-glow-2), 0 0 32px var(--aura-2); }
}
@keyframes cooking {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.97); }
}
@keyframes pop {
  from { transform: scale(0.55); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

footer {
  flex: 0 0 auto;
  background: linear-gradient(to top, var(--footer-bg) 55%, var(--footer-grad));
  border-top: 0.5px solid var(--line);
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  transition: background-color 0.3s;
}
.side-brand, .side-foot { display: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
#search {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--panel);
  border: 0.5px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
}
#search:focus { border-color: var(--gold-dim); }
#search::placeholder { color: var(--placeholder); }
.quota { font-size: 11px; color: var(--muted); white-space: nowrap; }
.quota.out { color: var(--quota-out); }
.pool {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.pool::-webkit-scrollbar { display: none; }
.pill {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 0.5px solid var(--line);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.pill:hover { background: var(--panel-hover); border-color: var(--line-strong); transform: translateY(-1px); }
.pill .ico { font-size: 15px; }
.pill .rank { font-size: 9px; color: var(--gold); }
.pill.legend { border-color: var(--gold-dim); color: var(--legend-ink); background: var(--gold-wash); }
.pill.epic { border-color: var(--epic); }
.pill[data-el="金"] { border-color: rgba(217, 180, 90, 0.5); }
.pill[data-el="木"] { border-color: rgba(111, 191, 143, 0.5); }
.pill[data-el="水"] { border-color: rgba(111, 168, 217, 0.5); }
.pill[data-el="火"] { border-color: rgba(224, 122, 95, 0.5); }
.pill[data-el="土"] { border-color: rgba(198, 154, 109, 0.5); }

.toast {
  position: fixed;
  left: 50%; bottom: 132px;
  transform: translate(-50%, 16px);
  max-width: min(88vw, 420px);
  background: var(--toast-bg);
  border: 0.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s, transform 0.24s;
  z-index: 50;
  box-shadow: 0 12px 32px var(--toast-shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.gold { border-color: var(--gold-dim); color: var(--gold-bright); }
.toast strong { color: var(--gold); font-weight: 600; }
.toast em { display: block; font-style: normal; color: var(--muted); font-size: 12px; margin-top: 3px; }
.toast .rank-tag {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.1em;
  padding: 1px 7px;
  margin-right: 6px;
  border-radius: 999px;
  vertical-align: 1px;
  border: 0.5px solid currentColor;
}
.rank-tag.rare { color: var(--rare); }
.rank-tag.epic { color: var(--epic); }
.rank-tag.legend { color: var(--gold); }

.modal {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  z-index: 90;
  padding: 24px;
}
.modal.show { display: flex; }
.modal-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#shot { max-width: 82vw; max-height: 74vh; border-radius: 12px; }
.modal-tip { color: var(--muted); font-size: 12px; margin: 0; }

@media (min-width: 980px) {
  #app {
    max-width: none;
    margin: 0;
    border: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    grid-template-rows: 100%;
  }
  header { display: none; }
  .mockbar {
    position: absolute;
    top: 12px; left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    margin: 0;
    width: max-content;
  }
  #stage { grid-column: 1; grid-row: 1; }
  .hint { top: 20px; }
  .zoombar { right: 20px; bottom: 20px; }
  .zoombar button { height: 38px; min-width: 38px; }

  footer {
    grid-column: 2; grid-row: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--sidebar-bg);
    border-top: 0;
    border-left: 0.5px solid var(--line);
    padding: 22px 18px 14px;
    gap: 14px;
  }
  .side-brand { display: flex; flex-direction: column; align-items: stretch; gap: 12px; }
  .side-brand .brand { flex-direction: column; align-items: flex-start; gap: 4px; }
  .side-brand h1 { font-size: 21px; }
  .side-brand .sub { display: block; margin-top: 0; letter-spacing: 0.1em; white-space: nowrap; }
  .side-brand .head-right { justify-content: space-between; width: 100%; }
  .side-brand .count { display: block; margin: 0; }
  .theme-btn { width: 32px; height: 32px; }
  .drawer-head { margin: 0; flex: 0 0 auto; }
  #search { flex: 1 1 auto; min-width: 0; font-size: 13px; padding: 9px 11px; }
  .drawer-head button { flex: 0 0 auto; white-space: nowrap; }
  .quota { flex: 0 0 auto; font-size: 11px; }
  .pool {
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: min-content;
    gap: 7px;
    overflow-x: hidden;
    overflow-y: auto;
    align-content: start;
    padding: 2px 4px 2px 2px;
    min-height: 0;
  }
  .pool::-webkit-scrollbar { display: block; width: 4px; }
  .pool::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 4px; }
  .pill { width: 100%; min-width: 0; font-size: 12px; padding: 0 9px; }
  .pill .txt { overflow: hidden; text-overflow: ellipsis; }
  .side-foot {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 5px;
    font-size: 10px;
    color: var(--faint);
    padding-top: 10px;
    border-top: 0.5px solid var(--line);
  }
  .legend-dots { display: flex; align-items: center; gap: 5px; }
  .legend-dots i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-left: 6px; }
  .legend-dots i:first-child { margin-left: 0; }
  .d-rare { background: var(--rare); }
  .d-epic { background: var(--epic); }
  .d-legend { background: var(--gold); }
  .chip { height: 46px; font-size: 15px; }
  .toast { bottom: 40px; }
}

@media (max-width: 420px) {
  h1 { font-size: 19px; letter-spacing: 0.12em; }
  .sub { display: none; }
  .chip { height: 40px; font-size: 13px; padding: 0 12px; }
  .hint-title { font-size: 12px; }
  .idea { font-size: 11px; padding: 5px 8px; }
  .drawer-head { gap: 6px; }
  button.ghost.small { padding: 5px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
