@import url('panels.css');

:root {
  --bg: #03040c;
  --ink: #eef3ff;
  --ink-dim: rgba(220, 230, 255, 0.62);
  --gold-1: #fff3c4;
  --gold-2: #ffd36b;
  --gold-3: #e79a2b;
  --glow-rgb: 107, 228, 255;
  --glass: rgba(14, 22, 48, 0.55);
  --glass-strong: rgba(10, 15, 34, 0.92);
  --line: rgba(160, 200, 255, 0.18);
  --danger: #ff5a6a;
  --font: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
  --num: 'Bahnschrift', 'DIN Alternate', 'Roboto Condensed', 'Segoe UI', sans-serif;
}

body[data-theme='festive'] {
  --bg: #0c0204;
  --glow-rgb: 255, 140, 90;
  --glass: rgba(48, 8, 14, 0.55);
  --glass-strong: rgba(34, 6, 10, 0.94);
  --line: rgba(255, 190, 150, 0.2);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
button { font: inherit; color: inherit; }
body.calm { cursor: none; }

#gl, #confetti { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { z-index: 0; }
#confetti { z-index: 45; pointer-events: none; }
.bg-fallback {
  position: fixed; inset: 0; z-index: 0; display: none;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(91, 43, 255, 0.35), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(31, 91, 255, 0.3), transparent 55%),
    var(--bg);
}
body.no-gl .bg-fallback { display: block; }
.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
}

/* ---------- 标题 ---------- */
.top {
  position: fixed; top: clamp(12px, 3.2vh, 40px); left: 50%; z-index: 10;
  width: min(92vw, 1200px); transform: translateX(-50%);
  text-align: center; pointer-events: none;
  transition: opacity 0.5s, transform 0.6s;
}
.title {
  margin: 0;
  font-size: clamp(26px, 4.6vw, 72px); font-weight: 900; letter-spacing: 0.06em; line-height: 1.15;
  background: linear-gradient(100deg, var(--gold-3) 0%, var(--gold-2) 25%, var(--gold-1) 45%, #fff 50%, var(--gold-1) 55%, var(--gold-2) 75%, var(--gold-3) 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px rgba(255, 196, 80, 0.45)) drop-shadow(0 2px 0 rgba(120, 60, 0, 0.6));
  animation: shimmer 6s linear infinite;
}
@keyframes shimmer { to { background-position: -250% 0; } }
.subtitle {
  margin: 0.35em 0 0;
  font-family: var(--num); font-size: clamp(11px, 1.2vw, 18px); letter-spacing: 0.6em;
  color: var(--ink-dim); text-transform: uppercase;
}
.subtitle:empty { display: none; }
body[data-phase='rolling'] .top, body[data-phase='stopping'] .top { opacity: 0.3; transform: translateX(-50%) scale(0.92); }
body[data-phase='reveal'] .top { opacity: 0; }

/* ---------- 工具栏 / 统计 / 名单来源 ---------- */
.toolbar { position: fixed; top: 14px; right: 16px; z-index: 12; display: flex; gap: 8px; transition: opacity 0.4s; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 40px; min-width: 40px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(10, 16, 36, 0.35); backdrop-filter: blur(8px);
  color: var(--ink-dim); cursor: pointer; transition: 0.2s;
}
.icon-btn:hover { color: var(--ink); border-color: rgba(255, 211, 107, 0.5); background: rgba(255, 211, 107, 0.08); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn span { font-size: 13px; }
.icon-btn .off, body.muted .icon-btn .on { display: none; }
body.muted .icon-btn .off { display: block; }

.stats { position: fixed; left: 20px; bottom: 18px; z-index: 10; display: flex; gap: 22px; pointer-events: none; transition: opacity 0.4s; }
.stat { display: flex; flex-direction: column; }
.stat b { font-family: var(--num); font-size: clamp(20px, 2.2vw, 32px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { margin-top: 5px; font-size: 12px; letter-spacing: 0.1em; color: var(--ink-dim); }

.source-chip {
  position: fixed; right: 16px; bottom: 18px; z-index: 10;
  max-width: 40vw; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: rgba(10, 16, 36, 0.35);
  color: var(--ink-dim); font-size: 12px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity 0.4s;
}
.source-chip::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #7d8597; vertical-align: 1px; }
.source-chip.live::before { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
.source-chip.warn::before { background: #fbbf24; }

body:not([data-phase='idle']) :is(.toolbar, .stats, .source-chip) { opacity: 0; pointer-events: none; }
body.calm :is(.toolbar, .source-chip) { opacity: 0.12; }

/* ---------- 底部控制区 ---------- */
.control {
  position: fixed; left: 50%; bottom: clamp(14px, 3.5vh, 44px); z-index: 10;
  width: min(94vw, 720px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 1.6vh, 18px);
  transition: opacity 0.45s, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body[data-phase='reveal'] .control { opacity: 0; pointer-events: none; transform: translate(-50%, 40px); }
body:not([data-phase='idle']) :is(.stepper, .hint, #prizePrev, #prizeNext) { opacity: 0; pointer-events: none; }

.prize-bar { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; }
.icon-btn.round { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; font-size: 26px; line-height: 1; }
.prize-info { flex: 0 1 460px; min-width: 0; text-align: center; }
.prize-name {
  font-size: clamp(26px, 3.4vw, 50px); font-weight: 900; letter-spacing: 0.12em; line-height: 1.1;
  color: var(--gold-1); text-shadow: 0 0 24px rgba(255, 190, 80, 0.55), 0 0 2px rgba(255, 255, 255, 0.8);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.prize-desc { margin-top: 4px; font-size: clamp(13px, 1.3vw, 18px); color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prize-desc:empty { display: none; }
.prize-progress { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 8px; font-size: 13px; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.prize-progress .bar { width: 120px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.prize-progress .bar em { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold-3), var(--gold-1)); box-shadow: 0 0 10px var(--gold-2); transition: width 0.6s; }

.action-row { display: flex; align-items: center; gap: 18px; }
.stepper {
  display: flex; align-items: center; gap: 4px; height: 52px; padding: 0 6px;
  border: 1px solid var(--line); border-radius: 26px; background: var(--glass); backdrop-filter: blur(10px);
  transition: opacity 0.3s;
}
.stepper button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-dim); font-size: 22px; cursor: pointer; }
.stepper button:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }
.stepper output { min-width: 2.2ch; text-align: center; font-family: var(--num); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper small { margin-right: 4px; font-size: 13px; color: var(--ink-dim); }

.main-btn {
  position: relative; overflow: hidden; isolation: isolate;
  min-width: clamp(200px, 20vw, 300px); height: clamp(58px, 7vh, 76px); padding: 0 36px;
  border: 0; border-radius: 999px; cursor: pointer;
  font-size: clamp(20px, 2vw, 28px); font-weight: 900; letter-spacing: 0.2em; color: #3a1d00;
  background: linear-gradient(180deg, #fff6d5 0%, var(--gold-2) 45%, var(--gold-3) 100%);
  box-shadow: 0 0 0 2px rgba(255, 236, 180, 0.5) inset, 0 8px 30px rgba(255, 170, 40, 0.45), 0 0 60px rgba(255, 190, 60, 0.35);
  animation: btn-pulse 2.2s ease-in-out infinite;
  transition: transform 0.15s, filter 0.3s, opacity 0.3s;
}
.main-btn::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -60%; width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  transform: skewX(-20deg); animation: sweep 3.2s ease-in-out infinite; pointer-events: none;
}
@keyframes sweep { 0%, 55% { left: -60%; } 100% { left: 130%; } }
@keyframes btn-pulse {
  50% { box-shadow: 0 0 0 2px rgba(255, 236, 180, 0.75) inset, 0 8px 40px rgba(255, 170, 40, 0.6), 0 0 90px rgba(255, 190, 60, 0.55); }
}
.main-btn:hover { transform: translateY(-2px) scale(1.02); filter: brightness(1.06); }
.main-btn:active { transform: scale(0.97); }
.main-btn.done { animation: none; filter: saturate(0.6); }
body[data-phase='rolling'] .main-btn {
  color: #fff;
  background: linear-gradient(180deg, #ffd0d6 0%, #ff5a6a 50%, #c81e3a 100%);
  box-shadow: 0 0 0 2px rgba(255, 200, 210, 0.5) inset, 0 8px 30px rgba(255, 60, 90, 0.5), 0 0 70px rgba(255, 60, 90, 0.45);
}
body[data-phase='stopping'] .main-btn { opacity: 0.55; pointer-events: none; }
.hint { margin: 0; font-size: 12px; letter-spacing: 0.08em; color: rgba(220, 230, 255, 0.4); transition: opacity 0.3s; }

/* ---------- 滚动中的名字 ---------- */
.slots {
  position: fixed; left: 50%; top: 46%; z-index: 11;
  width: min(94vw, 1300px); transform: translate(-50%, -50%);
  display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(8px, 1.4vw, 20px);
  pointer-events: none; opacity: 0; transition: opacity 0.3s;
}
body:is([data-phase='rolling'], [data-phase='stopping']) .slots { opacity: 1; }
.slot {
  min-width: 3.6em; padding: 0.18em 0.5em; border-radius: 14px;
  text-align: center; font-weight: 900; letter-spacing: 0.06em; white-space: nowrap; color: #fff;
  background: linear-gradient(180deg, rgba(20, 30, 70, 0.5), rgba(8, 12, 30, 0.5));
  border: 1px solid rgba(var(--glow-rgb), 0.35);
  box-shadow: 0 0 30px rgba(var(--glow-rgb), 0.25), inset 0 0 20px rgba(var(--glow-rgb), 0.15);
  text-shadow: 0 0 18px rgba(var(--glow-rgb), 0.9), 0 0 2px #fff;
}
.slots[data-size='xl'] .slot { font-size: clamp(56px, 10vw, 150px); }
.slots[data-size='l'] .slot { font-size: clamp(34px, 5.2vw, 80px); }
.slots[data-size='m'] .slot { font-size: clamp(24px, 3.4vw, 50px); }
.slots[data-size='s'] .slot { font-size: clamp(18px, 2.2vw, 34px); }
.slot.landed {
  color: var(--gold-1); border-color: rgba(255, 211, 107, 0.8);
  text-shadow: 0 0 24px rgba(255, 190, 60, 1), 0 0 2px #fff;
  box-shadow: 0 0 50px rgba(255, 190, 60, 0.5), inset 0 0 24px rgba(255, 190, 60, 0.25);
  animation: land 0.45s cubic-bezier(0.2, 1.6, 0.4, 1);
}
@keyframes land { from { transform: scale(1.35); } }
.slot-counter { width: 100%; text-align: center; font-size: clamp(16px, 1.6vw, 24px); letter-spacing: 0.3em; color: var(--ink-dim); }

.empty-cta {
  position: fixed; left: 50%; top: 46%; z-index: 11; transform: translate(-50%, -50%);
  padding: 28px 40px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--glass); backdrop-filter: blur(12px); text-align: center;
}
.empty-cta p { margin: 0 0 16px; font-size: 20px; }

/* ---------- 揭晓 ---------- */
.reveal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: clamp(16px, 4vh, 48px) 16px; }
.reveal[hidden] { display: none; }
.reveal::before { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(10, 6, 30, 0.3), rgba(0, 0, 0, 0.72)); animation: fade-in 0.5s both; }
.rays {
  position: absolute; left: 50%; top: 50%; width: 160vmax; height: 160vmax; margin: -80vmax 0 0 -80vmax;
  background: repeating-conic-gradient(from 0deg, rgba(255, 214, 120, 0.16) 0deg 6deg, transparent 6deg 18deg);
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  mask-image: radial-gradient(circle, #000 0%, transparent 55%);
  animation: rays-spin 40s linear infinite, fade-in 1s both; pointer-events: none;
}
@keyframes rays-spin { to { transform: rotate(360deg); } }
@keyframes fade-in { from { opacity: 0; } }
.reveal-inner { position: relative; display: flex; flex-direction: column; align-items: center; gap: clamp(14px, 3vh, 36px); width: min(96vw, 1500px); max-height: 100%; }
.reveal-head { text-align: center; animation: drop-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
@keyframes drop-in { from { opacity: 0; transform: translateY(-40px) scale(0.9); } }
.reveal-kicker { font-size: clamp(14px, 1.6vw, 22px); letter-spacing: 0.6em; color: var(--ink-dim); }
.reveal-prize {
  font-size: clamp(40px, 6.4vw, 104px); font-weight: 900; letter-spacing: 0.12em; line-height: 1.15;
  background: linear-gradient(180deg, #fff 0%, var(--gold-1) 30%, var(--gold-2) 60%, var(--gold-3) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 30px rgba(255, 180, 50, 0.6));
}
.reveal-desc { font-size: clamp(14px, 1.6vw, 24px); color: var(--gold-1); opacity: 0.85; }
.reveal-desc:empty { display: none; }
.winner-grid {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: var(--gap, 18px);
  width: 100%; min-height: 0; padding: 10px; overflow-y: auto; scrollbar-width: thin;
}
.winner {
  position: relative; overflow: hidden;
  /* 每行最多 --cols 张，最后一行居中 */
  width: min(var(--w, 260px), calc((100% - (var(--cols, 5) - 1) * var(--gap, 18px)) / var(--cols, 5) - 1px));
  padding: var(--pad, 22px) 12px; border-radius: 18px; text-align: center;
  background: linear-gradient(160deg, rgba(255, 220, 140, 0.22), rgba(120, 50, 0, 0.25) 40%, rgba(30, 10, 40, 0.55)), rgba(20, 10, 30, 0.6);
  border: 1.5px solid rgba(255, 211, 107, 0.75);
  box-shadow: 0 0 0 1px rgba(255, 240, 200, 0.15) inset, 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 40px rgba(255, 180, 50, 0.35);
  animation: card-in 0.7s cubic-bezier(0.2, 1.3, 0.35, 1) both; animation-delay: var(--delay, 0s);
}
@keyframes card-in {
  0% { opacity: 0; transform: perspective(800px) rotateY(-90deg) scale(0.6); }
  60% { opacity: 1; }
  100% { transform: perspective(800px) rotateY(0) scale(1); }
}
.winner::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -80%; width: 50%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-20deg); animation: sweep 3.5s ease-in-out infinite; animation-delay: calc(var(--delay, 0s) + 0.8s);
  pointer-events: none;
}
.winner-name {
  font-size: var(--fs, 44px); font-weight: 900; letter-spacing: 0.08em; line-height: 1.2; color: #fff7dc;
  text-shadow: 0 0 20px rgba(255, 190, 60, 0.9), 0 2px 0 rgba(120, 60, 0, 0.5);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.winner-dept { margin-top: 6px; font-size: max(12px, calc(var(--fs, 44px) * 0.34)); color: rgba(255, 236, 190, 0.75); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.winner-dept:empty { display: none; }
.winner-no { position: absolute; top: 8px; left: 10px; font-family: var(--num); font-size: 12px; color: rgba(255, 236, 190, 0.6); }
.winner-redo {
  position: absolute; top: 6px; right: 6px; z-index: 2; padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 8px; background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.75); font-size: 12px; cursor: pointer; opacity: 0; transition: opacity 0.2s;
}
.winner:hover .winner-redo, .winner:focus-within .winner-redo, .winner-redo.confirm { opacity: 1; }
.winner-redo.confirm { border-color: transparent; background: var(--danger); color: #fff; }
@media (hover: none) { .winner-redo { opacity: 0.8; } }
.winner.rolling .winner-name { color: #fff; text-shadow: 0 0 18px rgba(var(--glow-rgb), 0.9); }
.winner.replaced { animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes pop { from { transform: scale(1.2); } }
.reveal-foot { animation: fade-in 0.6s 1s both; }

.flash {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 46%, #fff 0%, rgba(255, 240, 200, 0.85) 25%, rgba(255, 200, 120, 0) 70%);
}
.flash.go { animation: flash 0.9s ease-out; }
@keyframes flash { 8% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- 提示条 ---------- */
.toasts { position: fixed; top: 70px; left: 50%; z-index: 70; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  max-width: 90vw; padding: 10px 18px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--glass-strong); color: var(--ink); font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0; transform: translateY(-10px); transition: 0.3s;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(74, 222, 128, 0.5); }
.toast.warn { border-color: rgba(251, 191, 36, 0.6); }
.toast.err { border-color: rgba(255, 90, 106, 0.7); }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font-size: 14px; white-space: nowrap; cursor: pointer; transition: 0.2s;
}
.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn.primary { border: 0; font-weight: 700; color: #3a1d00; background: linear-gradient(180deg, #fff1c2, var(--gold-2) 55%, var(--gold-3)); box-shadow: 0 4px 16px rgba(255, 170, 40, 0.3); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { border-color: rgba(255, 90, 106, 0.5); background: rgba(255, 90, 106, 0.1); color: #ffb3bc; }
.btn.danger:hover { background: rgba(255, 90, 106, 0.22); }
.btn.ghost { background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; border-radius: 8px; font-size: 13px; }
.btn.lg { height: 48px; padding: 0 28px; border-radius: 14px; font-size: 17px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn-row.end { justify-content: flex-end; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; font-size: 20px; }

@media (max-width: 720px) {
  .icon-btn span, .stats { display: none; }
  .top { top: 62px; }
  .source-chip { top: 14px; right: auto; bottom: auto; left: 12px; max-width: calc(100vw - 210px); }
  .action-row { gap: 10px; }
  .main-btn { min-width: 150px; padding: 0 18px; letter-spacing: 0.1em; }
  .prize-progress .bar { width: 80px; }
}
