/* ───────────── 基础 ───────────── */
:root {
  --night: #0c1730;
  --night-2: #16294f;
  --night-3: #22386b;
  --gold: #ffd166;
  --gold-deep: #f0a63a;
  --red: #e5484d;
  --red-dark: #b73439;
  --green: #2e6b50;
  --green-light: #47a075;
  --cream: #fff8ec;
  --cream-2: #fffdf7;
  --ink: #233046;
  --muted: #6b7488;
  --line: #eadfc9;
  --shadow: 0 24px 60px rgba(4, 10, 26, 0.45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: "Nunito", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, #22386b 0%, var(--night-2) 38%, var(--night) 78%);
  color: var(--ink);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

/* ───────────── 背景 ───────────── */
.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.sky::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 78% 10%, #fff 50%, transparent 52%),
    radial-gradient(2px 2px at 56% 26%, #ffe9b8 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 32% 8%, #fff 50%, transparent 52%),
    radial-gradient(2px 2px at 88% 34%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 6% 52%, #ffe9b8 50%, transparent 52%),
    radial-gradient(2px 2px at 68% 48%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 45% 62%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 92% 72%, #ffe9b8 50%, transparent 52%),
    radial-gradient(2px 2px at 20% 82%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 62% 88%, #fff 50%, transparent 52%);
  opacity: 0.9;
  animation: twinkle 4s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.45; }
  to { opacity: 0.95; }
}

.moon {
  position: absolute;
  top: 7%;
  right: 10%;
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6d8, #ffe4a3 65%, #ffd166);
  box-shadow: 0 0 46px 18px rgba(255, 209, 102, 0.28);
  opacity: 0.9;
}

.moon::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  filter: blur(6px);
}

.snow {
  position: absolute;
  inset: 0;
}

.snow span {
  position: absolute;
  top: -10px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.75;
  animation: fall linear infinite;
}

@keyframes fall {
  0% { transform: translate3d(0, -5vh, 0); }
  100% { transform: translate3d(var(--drift, 30px), 108vh, 0); }
}

/* ───────────── 布局 ───────────── */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  z-index: 1;
}

.tree-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
}

.stage-glow {
  position: absolute;
  width: 78vmin;
  height: 78vmin;
  max-width: 560px;
  max-height: 560px;
  left: 50%;
  bottom: -18%;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255, 209, 102, 0.22), rgba(255, 209, 102, 0.05) 45%, transparent 68%);
  pointer-events: none;
}

.tree {
  width: 100%;
  height: 100%;
  max-width: min(94vw, 430px);
  max-height: 100%;
  margin-bottom: -6px;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.38));
}

.stage-caption {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(10, 20, 40, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #ffe9b8;
  font-size: 12px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  backdrop-filter: blur(6px);
}

/* ───────────── 面板 ───────────── */
.panel {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 22px 22px calc(20px + env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 90% at 80% -20%, rgba(255, 209, 102, 0.16), transparent 55%),
    var(--cream);
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -16px 40px rgba(3, 8, 20, 0.32);
  max-height: 60dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #d9cbb0 transparent;
}

.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-thumb { background: #d9cbb0; border-radius: 3px; }

.panel::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 5px;
  border-radius: 99px;
  background: #d9cbb0;
  opacity: 0.7;
}

.loading {
  padding: 34px 0 26px;
  text-align: center;
  color: var(--muted);
}

.loading-tree {
  font-size: 42px;
  animation: bob 1.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* ───────────── 通用文字 / 控件 ───────────── */
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
  background: rgba(46, 107, 80, 0.1);
  border-radius: 999px;
  padding: 5px 11px;
}

h1, h2, h3, p { margin: 0; }

.title {
  margin-top: 10px;
  font-size: clamp(23px, 6vw, 29px);
  font-weight: 900;
  line-height: 1.22;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.title .owner {
  color: var(--red);
  position: relative;
  white-space: nowrap;
}

.title .owner::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 1px;
  height: 7px;
  background: rgba(255, 209, 102, 0.55);
  border-radius: 4px;
  z-index: -1;
}

.mood {
  margin-top: 8px;
  display: inline-block;
  font-size: 13px;
  color: #7a5a2c;
  background: #fff1cf;
  border: 1px dashed #efd49a;
  border-radius: 12px;
  padding: 6px 10px;
}

.welcome {
  margin-top: 12px;
  font-size: 14px;
  line-height: 1.7;
  color: #55607a;
}

.invite-stats {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 13px;
  color: #55607a;
}

.invite-stats b { color: var(--ink); }

.resume-note {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 13px;
  background: #eef8f1;
  border: 1px dashed #b8dfc7;
  color: #2c6b4d;
  font-size: 13px;
  font-weight: 700;
}

.panel-inner { animation: panelIn 0.3s ease; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}

.crown-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--night-2);
  color: #ffe9b8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}

.field-label {
  display: block;
  margin: 18px 0 7px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #7a8599;
}

.name-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border-radius: 16px;
  border: 2px solid var(--line);
  background: var(--cream-2);
  font-size: 16px;
  font-weight: 700;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

.name-input::placeholder { color: #b3b9c6; font-weight: 600; }

.name-input:focus {
  border-color: var(--green-light);
  box-shadow: 0 0 0 4px rgba(71, 160, 117, 0.14);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 54px;
  margin-top: 14px;
  border: 0;
  border-radius: 17px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.02em;
  transition: transform 0.12s, box-shadow 0.18s, filter 0.18s;
  user-select: none;
}

.btn:active { transform: translateY(2px) scale(0.99); }

.btn-primary {
  color: #3a2304;
  background: linear-gradient(180deg, #ffe08a, var(--gold) 40%, var(--gold-deep));
  box-shadow: 0 6px 0 #b9771c, 0 14px 26px rgba(240, 166, 58, 0.32);
}

.btn-primary:hover { filter: brightness(1.03); }
.btn-primary:active { box-shadow: 0 3px 0 #b9771c, 0 8px 16px rgba(240, 166, 58, 0.3); }

.btn-green {
  color: #fff;
  background: linear-gradient(180deg, #58b389, var(--green) 55%, #235441);
  box-shadow: 0 6px 0 #173c2c, 0 14px 26px rgba(46, 107, 80, 0.3);
}

.btn-green:active { box-shadow: 0 3px 0 #173c2c; }

.btn-ghost {
  width: auto;
  height: 42px;
  margin: 0;
  padding: 0 16px;
  color: #55607a;
  background: #fff;
  border: 1.5px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  border-radius: 13px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.04);
}

.btn-ghost:hover { border-color: #cdbfa3; }

.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.5);
  opacity: 0.65;
  box-shadow: none;
  transform: none;
}

.sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
}

.foot-note {
  margin-top: 14px;
  text-align: center;
  font-size: 11.5px;
  color: #98a0b0;
  line-height: 1.7;
}

/* ───────────── 进度 / 题目 ───────────── */
.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #7a8599;
}

.quiz-top .climb {
  color: var(--green);
  background: rgba(46, 107, 80, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
}

.progress {
  margin-top: 10px;
  height: 9px;
  border-radius: 99px;
  background: #f0e6d2;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.progress i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green-light), var(--gold));
  transition: width 0.35s ease;
}

.question {
  margin: 16px 0 4px;
  font-size: clamp(18px, 4.6vw, 21px);
  font-weight: 900;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

.options {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--line);
  border-radius: 15px;
  background: #fff;
  text-align: left;
  font-size: 14.5px;
  font-weight: 700;
  color: #3c465c;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}

.option:hover:not(:disabled) {
  border-color: #d8c8a6;
  transform: translateY(-1px);
}

.option .key {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: #f5eddc;
  color: #8b7444;
  font-size: 12px;
  font-weight: 900;
}

.option:disabled { cursor: default; }

.option.is-right {
  border-color: var(--green-light);
  background: #eefaf3;
  color: #1f5c41;
}

.option.is-right .key { background: var(--green-light); color: #fff; }

.option.is-wrong {
  border-color: #f0a9ac;
  background: #fff1f1;
  color: #a02b2f;
}

.option.is-wrong .key { background: #efa1a4; color: #fff; }

.option.is-faded { opacity: 0.55; }

.feedback {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.5;
  animation: pop 0.32s ease;
}

.feedback.show { display: block; }

.feedback.ok {
  background: #eaf8f0;
  color: #22694a;
  border: 1px solid #bfe6d2;
}

.feedback.no {
  background: #fff2ee;
  color: #a4543c;
  border: 1px solid #f6cfc2;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ───────────── 结果 ───────────── */
.result-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 6px;
}

.score-ring {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) var(--pct, 80%), #f1e6d1 0);
  position: relative;
}

.score-ring::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--cream-2);
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, 0.06);
}

.score-ring span {
  position: relative;
  font-size: 38px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
}

.score-ring small {
  position: relative;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 800;
  color: #9aa2b2;
}

.score-ring .ring-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.result-copy h2 {
  font-size: clamp(21px, 5.4vw, 26px);
  font-weight: 900;
  letter-spacing: -0.01em;
}

.result-copy p {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.6;
  color: #6b7488;
}

.result-copy .rank-line {
  margin-top: 8px;
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  color: #7a5a2c;
  background: #fff1cf;
  border-radius: 999px;
  padding: 4px 11px;
}

.share-btn {
  margin-top: 16px;
}

/* ───────────── 排行榜 ───────────── */
.board {
  margin-top: 20px;
  border-top: 1px dashed #e6d9c0;
  padding-top: 15px;
}

.board-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.board-head h3 {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.board-head span {
  font-size: 11.5px;
  color: #98a0b0;
}

.board-list {
  list-style: none;
  margin: 9px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.board-list li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 12px;
  background: #fffdf8;
  border: 1px solid #f1e8d7;
  font-size: 13px;
}

.board-list li:nth-child(1) {
  background: linear-gradient(90deg, #fff4d6, #fffdf8);
  border-color: #f0d9a1;
}

.board-list .r {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: #f2e8d4;
  color: #8b7444;
  font-size: 11px;
  font-weight: 900;
}

.board-list li:nth-child(1) .r {
  background: var(--gold);
  color: #53350a;
}

.board-list .n {
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-list .n em {
  font-style: normal;
  font-size: 10.5px;
  font-weight: 700;
  color: #9aa2b2;
  margin-left: 5px;
}

.board-list .s {
  font-weight: 900;
  color: var(--green);
  font-size: 12.5px;
}

.empty {
  padding: 18px 6px;
  text-align: center;
  font-size: 12.5px;
  color: #9aa2b2;
}

/* ───────────── 提示 ───────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  z-index: 30;
  max-width: calc(100vw - 40px);
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(17, 27, 48, 0.94);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ───────────── 圣诞树 SVG ───────────── */
.tree .tier { animation: tierIn 0.6s backwards; }
.tree .tier:nth-child(1) { animation-delay: 0.02s; }
.tree .tier:nth-child(2) { animation-delay: 0.06s; }
.tree .tier:nth-child(3) { animation-delay: 0.1s; }
.tree .tier:nth-child(4) { animation-delay: 0.14s; }
.tree .tier:nth-child(5) { animation-delay: 0.18s; }
.tree .tier:nth-child(6) { animation-delay: 0.22s; }

@keyframes tierIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.tree .bulb { transition: fill 0.4s, opacity 0.4s; }
.tree .bulb.lit { animation: bulbGlow 1.8s ease-in-out infinite alternate; }
.tree .bulb.lit:nth-of-type(2n) { animation-delay: 0.4s; }
.tree .bulb.lit:nth-of-type(3n) { animation-delay: 0.8s; }

@keyframes bulbGlow {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

.tree .star {
  transform-box: fill-box;
  transform-origin: center;
  animation: starPulse 2.6s ease-in-out infinite;
}

@keyframes starPulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 5px rgba(255, 209, 102, 0.7)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 16px rgba(255, 209, 102, 1)); }
}

.ball {
  transition: transform 0.75s cubic-bezier(0.2, 0.9, 0.25, 1.15);
}

.ball .ball-body {
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 1;
}

.ball .ball-shine {
  fill: rgba(255, 255, 255, 0.75);
}

.ball.mine .ball-ring {
  animation: ringPulse 1.8s ease-in-out infinite;
}

@keyframes ringPulse {
  0%, 100% { opacity: 0.55; r: 18; }
  50% { opacity: 0.95; r: 20; }
}

.ball .label-bg {
  fill: rgba(12, 23, 48, 0.82);
}

.ball .label-text {
  fill: #fff;
  font-size: 9px;
  font-weight: 800;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  text-anchor: middle;
}

.ball.drop-in {
  animation: dropIn 0.7s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes dropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ───────────── 桌面 ───────────── */
@media (min-width: 900px) {
  .app {
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    padding: 22px;
    max-width: 1040px;
    margin: 0 auto;
    height: 100dvh;
  }

  .tree-stage {
    flex: 1 1 52%;
    align-items: center;
  }

  .tree {
    width: 100%;
    height: 100%;
    max-width: 460px;
    max-height: 100%;
  }

  .stage-caption {
    top: 26px;
    left: 24px;
  }

  .panel {
    flex: 0 0 420px;
    max-width: 420px;
    margin: 0;
    border-radius: 30px;
    max-height: calc(100dvh - 44px);
    padding: 26px 26px 24px;
    align-self: center;
    max-height: 92dvh;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255, 255, 255, 0.35);
  }

  .panel::before { display: none; }

  .moon {
    top: 8%;
    right: 14%;
    width: 90px;
    height: 90px;
  }
}

@media (max-width: 380px) {
  .panel {
    padding: 20px 17px calc(16px + env(safe-area-inset-bottom));
  }

  .option { padding: 12px; }
}

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