/* ============ 随便选 · 样式 ============ */
:root {
  --bg: #f5f2ff;
  --bg-grad-1: #f5f2ff;
  --bg-grad-2: #fff6ef;
  --card: #ffffff;
  --card-soft: #f4f1fd;
  --text: #2d2a3e;
  --text-soft: #8b87a0;
  --primary: #7c5cfc;
  --primary-deep: #5f3df0;
  --primary-soft: #ece6ff;
  --orange: #ff9f43;
  --green: #00b894;
  --red: #ff6b6b;
  --border: #e8e4f7;
  --shadow: 0 8px 30px rgba(124, 92, 252, .12);
  --shadow-sm: 0 3px 12px rgba(124, 92, 252, .10);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17151f;
    --bg-grad-1: #17151f;
    --bg-grad-2: #221a1a;
    --card: #211e2c;
    --card-soft: #2a2638;
    --text: #eceaf6;
    --text-soft: #9894ac;
    --primary: #9b83ff;
    --primary-deep: #7c5cfc;
    --primary-soft: #332a52;
    --border: #332f45;
    --shadow: 0 8px 30px rgba(0, 0, 0, .4);
    --shadow-sm: 0 3px 12px rgba(0, 0, 0, .35);
  }
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, var(--bg-grad-1) 0%, var(--bg-grad-2) 100%);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 40px;
  line-height: 1.6;
}

/* ---------- 顶部 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 10px;
  max-width: 640px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 48px; height: 48px;
  border-radius: 15px;
  background: linear-gradient(135deg, var(--primary), var(--orange));
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  box-shadow: var(--shadow);
  animation: float 3.5s ease-in-out infinite;
}
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.brand-text h1 { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.slogan { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: transform .15s;
}
.icon-btn:active { transform: scale(.9); }

/* ---------- 标签导航 ---------- */
.tabs {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 6px;
  overflow-x: auto;
  padding: 10px 16px;
  max-width: 640px;
  margin: 8px auto 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--card);
  cursor: pointer;
  transition: all .2s;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.tab.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  box-shadow: 0 6px 18px rgba(124, 92, 252, .35);
}

/* ---------- 面板 ---------- */
main { max-width: 640px; margin: 0 auto; padding: 16px 16px 0; }
.panel { display: none; }
.panel.active { display: block; animation: fadeUp .35s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.panel-head { text-align: center; margin: 8px 0 16px; }
.panel-head h2 { font-size: 20px; font-weight: 800; }
.panel-sub { font-size: 13px; color: var(--text-soft); margin-top: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

/* ---------- 按钮 ---------- */
.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 22px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s, opacity .2s;
  font-family: inherit;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-sm { padding: 9px 16px; font-size: 13px; border-radius: 12px; }
.btn-big {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 17px;
  border-radius: 16px;
  margin-top: 14px;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(124,92,252,.35); }
.btn-gradient {
  background: linear-gradient(135deg, var(--primary), #b06af0 55%, var(--orange));
  color: #fff;
  box-shadow: 0 8px 24px rgba(124, 92, 252, .4);
  background-size: 150% 150%;
  animation: gradShift 4s ease infinite;
}
@keyframes gradShift { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
.btn-ghost { background: var(--card-soft); color: var(--text-soft); }
.btn-ghost-solid { background: var(--card-soft); color: var(--text); }
.btn-warn { background: #ffe3e3; color: #e05a5a; }
@media (prefers-color-scheme: dark) { .btn-warn { background: #4a2a2e; color: #ff8f8f; } }

/* ---------- 输入 ---------- */
input[type="text"], textarea {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
  transition: border-color .2s;
  resize: none;
}
input[type="text"]:focus, textarea:focus { border-color: var(--primary); }

/* ---------- 面板操作行 ---------- */
.panel-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }

/* ---------- 转盘 ---------- */
.wheel-input-row { display: flex; gap: 8px; margin-bottom: 12px; }
.wheel-input-row input { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; min-height: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  font-weight: 600;
  animation: popIn .25s ease;
}
@keyframes popIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.chip-del {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(124, 92, 252, .18);
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.wheel-wrap { position: relative; display: flex; flex-direction: column; align-items: center; }
.wheel-wrap canvas {
  width: min(78vw, 340px);
  height: min(78vw, 340px);
  border-radius: 50%;
  box-shadow: var(--shadow), 0 0 0 10px var(--card), 0 0 0 12px var(--border);
  transition: transform 4.2s cubic-bezier(.12, .85, .16, 1);
  background: var(--card-soft);
}
.wheel-pointer {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  color: var(--red);
  z-index: 5;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.25));
}
.wheel-wrap .btn { max-width: 260px; width: 100%; }

/* ---------- 二选一 ---------- */
.binary-cards { display: flex; align-items: stretch; gap: 8px; }
.binary-card {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 40px 10px 14px;
  transition: transform .15s, border-color .2s, box-shadow .3s;
}
.binary-card.win-a { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); transform: scale(1.03); }
.binary-card.win-b { border-color: var(--orange); box-shadow: 0 0 0 4px #ffe9d2; transform: scale(1.03); }
@media (prefers-color-scheme: dark) { .binary-card.win-b { box-shadow: 0 0 0 4px #4a3a22; } }
.binary-card.shake { animation: shake .5s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.binary-card input {
  border: none; background: transparent; text-align: center;
  font-size: 15px; font-weight: 700; color: var(--text); padding: 4px;
  width: 100%; min-width: 0;
}
.binary-card input:focus { border: none; }
.binary-card input::placeholder { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.binary-tag {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff;
}
.tag-a { background: var(--primary); }
.tag-b { background: var(--orange); }
.binary-vs {
  align-self: center;
  font-size: 15px; font-weight: 900;
  color: var(--text-soft);
  background: var(--card-soft);
  border-radius: 999px;
  padding: 8px 10px;
}
.binary-result { text-align: center; margin-top: 14px; min-height: 30px; font-size: 15px; font-weight: 700; }

/* ---------- 抽一个 ---------- */
.picker-box {
  margin-top: 16px;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px;
  min-height: 110px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.picker-slot { font-size: 22px; font-weight: 800; text-align: center; color: var(--primary); word-break: break-all; transition: transform .08s; }
.picker-slot.rolling { animation: slotShake .1s linear infinite; }
@keyframes slotShake { 0% { transform: translateY(0); } 50% { transform: translateY(-6px); } 100% { transform: translateY(0); } }
.picker-slot.final { animation: popIn .4s cubic-bezier(.2, 1.6, .4, 1); font-size: 26px; }

/* ---------- 硬币 ---------- */
.coin-stage { display: flex; justify-content: center; padding: 30px 0; perspective: 600px; }
.coin {
  width: 130px; height: 130px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .2s linear;
}
.coin.flipping { animation: coinFlip 1.2s ease-in-out; }
@keyframes coinFlip {
  0% { transform: rotateY(0) rotateX(8deg); }
  100% { transform: rotateY(2160deg) rotateX(8deg); }
}
.coin.show-front { transform: rotateY(0) rotateX(8deg); }
.coin.show-back { transform: rotateY(180deg) rotateX(8deg); }
.coin-face {
  position: absolute; inset: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; font-weight: 900; color: #fff;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,.25), 0 10px 24px rgba(0,0,0,.25);
}
.coin-front {
  background: radial-gradient(circle at 35% 30%, #ffd36e, #ff9f43 70%);
  transform: rotateY(0deg);
}
.coin-back {
  background: radial-gradient(circle at 35% 30%, #b39dff, #7c5cfc 70%);
  transform: rotateY(180deg);
}
.coin-history { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; min-height: 34px; }
.coin-history span {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; color: #fff;
}
.coin-history .h-front { background: linear-gradient(135deg, #ffd36e, #ff9f43); }
.coin-history .h-back { background: linear-gradient(135deg, #b39dff, #7c5cfc); }

/* ---------- 骰子 ---------- */
.dice-stage { display: flex; justify-content: center; gap: 26px; padding: 26px 0; }
.die {
  width: 96px; height: 96px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 22px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 12px;
  gap: 0;
  box-shadow: var(--shadow-sm);
  transition: transform .15s;
  color: var(--text);
}
.die-dot {
  display: flex; align-items: center; justify-content: center;
}
.die-dot::before {
  content: '';
  width: 14px; height: 14px;
  border-radius: 50%;
  background: transparent;
  transition: background .15s;
}
.die-dot.on::before { background: var(--text); }
@media (prefers-color-scheme: dark) { .die-dot.on::before { background: #eceaf6; } }
.die.rolling { animation: dieRoll .5s ease-in-out infinite; }
@keyframes dieRoll {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-14deg) scale(1.12); }
  50% { transform: rotate(8deg) scale(.96); }
  75% { transform: rotate(-6deg) scale(1.08); }
  100% { transform: rotate(0) scale(1); }
}
.die.rolling:nth-child(2) { animation-delay: .12s; }
.dice-sum { text-align: center; margin-top: 12px; font-size: 16px; font-weight: 800; min-height: 24px; }

/* ---------- 排除法 ---------- */
.elim-stage { margin-top: 16px; }
.elim-tip { font-size: 13px; color: var(--text-soft); text-align: center; margin-bottom: 12px; }
.elim-chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.elim-chip {
  padding: 10px 18px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 999px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  animation: popIn .25s ease;
}
.elim-chip.marked {
  background: #ffe3e3;
  border-color: var(--red);
  color: #e05a5a;
  animation: markPulse .5s ease infinite alternate;
}
@media (prefers-color-scheme: dark) { .elim-chip.marked { background: #4a2a2e; color: #ff8f8f; } }
@keyframes markPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
.elim-chip.removed { animation: flyOut .4s ease forwards; }
@keyframes flyOut { to { transform: scale(0) rotate(20deg); opacity: 0; } }
.elim-chip.winner {
  background: linear-gradient(135deg, var(--primary), var(--orange));
  color: #fff;
  border: none;
  font-size: 18px;
  padding: 14px 28px;
  animation: popIn .5s cubic-bezier(.2, 1.6, .4, 1);
}
.elim-stage .btn { margin: 14px auto 0; display: block; }
.elim-winner { text-align: center; margin-top: 16px; min-height: 30px; }

/* ---------- 历史 ---------- */
.history {
  max-width: 640px;
  margin: 24px auto 0;
  padding: 0 16px;
}
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.history-head h3 { font-size: 15px; color: var(--text-soft); }
.history-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.history-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.history-emoji { font-size: 20px; }
.history-main { flex: 1; min-width: 0; }
.history-result { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.history-empty { text-align: center; color: var(--text-soft); font-size: 13px; padding: 14px; }

.footer { text-align: center; color: var(--text-soft); font-size: 12px; margin-top: 30px; padding: 0 20px; line-height: 1.8; }
.deploy-stamp { font-size: 11px !important; opacity: .65; letter-spacing: .3px; }
.deploy-stamp #deployStamp { color: var(--primary); font-weight: 700; }

/* ---------- 弹层 ---------- */
.overlay {
  position: fixed; inset: 0;
  z-index: 100;
  background: rgba(30, 25, 50, .55);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.overlay-card {
  background: var(--card);
  border-radius: 24px;
  padding: 34px 28px 26px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  animation: popIn .4s cubic-bezier(.2, 1.6, .4, 1);
}
.overlay-emoji { font-size: 56px; margin-bottom: 6px; animation: float 2s ease-in-out infinite; }
.overlay-card h2 { font-size: 20px; font-weight: 800; }
.overlay-card p { font-size: 22px; font-weight: 800; color: var(--primary); margin: 10px 0 20px; word-break: break-all; }
.overlay-actions { display: flex; flex-direction: column; gap: 10px; }
.overlay-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px;
  border: none; border-radius: 50%;
  background: var(--card-soft);
  color: var(--text-soft);
  font-size: 14px;
  cursor: pointer;
}

/* ---------- 彩带画布 ---------- */
#confettiCanvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 99;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  background: rgba(45, 42, 62, .92);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  transition: opacity .3s, transform .3s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); pointer-events: none; }

/* ---------- 通用 ---------- */
.hidden { display: none !important; }
