:root {
  --ink: #eaf2ff;
  --ink-dim: #91a9c9;
  --gold: #ffd489;
  --gold-2: #ffb85c;
  --line: rgba(150, 190, 255, 0.14);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(120% 95% at 50% 10%, #162c4e 0%, #0b1a30 36%, #060c18 68%, #03060c 100%);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
}

/* ---------- 3D stage ---------- */
#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#stage canvas:active {
  cursor: grabbing;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(
    115% 90% at 50% 42%,
    transparent 46%,
    rgba(2, 5, 11, 0.4) 78%,
    rgba(1, 3, 7, 0.78) 100%
  );
}

#cursor-glow {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 3;
  width: 520px;
  height: 520px;
  margin: -260px 0 0 -260px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    circle,
    rgba(130, 185, 255, 0.16) 0%,
    rgba(95, 150, 255, 0.07) 34%,
    transparent 68%
  );
  mix-blend-mode: screen;
  transition: opacity 0.5s ease;
  will-change: transform;
}

/* ---------- HUD ---------- */
.hud-shell {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto 1fr auto;
  align-items: start;
  column-gap: 20px;
  row-gap: clamp(12px, 1.6vw, 18px);
  padding:
    calc(clamp(16px, 3vw, 38px) + env(safe-area-inset-top))
    clamp(16px, 3vw, 38px)
    calc(clamp(14px, 2.4vw, 28px) + env(safe-area-inset-bottom));
  pointer-events: none;
}

.brand {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 12px;
  border: 1px solid rgba(255, 212, 137, 0.28);
  background: radial-gradient(circle at 30% 20%, rgba(255, 212, 137, 0.18), rgba(255, 255, 255, 0.02));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: var(--gold);
  font-size: 19px;
  animation: spin 26s linear infinite;
}

.brand h1 {
  margin: 0;
  font-family: "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: clamp(24px, 3.2vw, 42px);
  letter-spacing: 0.02em;
  background: linear-gradient(100deg, #fff7e2 0%, #ffd489 38%, #f0a95a 64%, #fff1cf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 20px rgba(255, 184, 92, 0.22));
}

.brand p {
  margin: 7px 0 0;
  font-size: clamp(11px, 1.15vw, 13px);
  letter-spacing: 0.2em;
  color: var(--ink-dim);
}

/* ---------- blessing counter ---------- */
.blessing {
  appearance: none;
  font: inherit;
  color: inherit;
  text-align: left;
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: fit-content;
  padding: 10px 18px 10px 11px;
  border-radius: 16px;
  border: 1px solid rgba(255, 202, 130, 0.22);
  background: linear-gradient(155deg, rgba(28, 47, 74, 0.66), rgba(7, 15, 28, 0.6));
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow:
    0 18px 46px -30px rgba(0, 0, 0, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  pointer-events: auto;
  cursor: pointer;
  transition: border-color 0.24s ease, transform 0.24s var(--ease), box-shadow 0.24s ease;
}

.blessing:hover {
  border-color: rgba(255, 212, 137, 0.48);
  transform: translateY(-1px);
  box-shadow:
    0 20px 50px -28px rgba(0, 0, 0, 0.98),
    0 0 24px -10px rgba(255, 198, 120, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.blessing:active {
  transform: translateY(0);
}

.blessing:focus-visible {
  outline: 2px solid rgba(255, 212, 137, 0.75);
  outline-offset: 2px;
}

.blessing::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, rgba(255, 212, 137, 0.14), transparent 52%);
  pointer-events: none;
}

.blessing-heart {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  color: #ffd6a0;
  border: 1px solid rgba(255, 168, 126, 0.42);
  background: radial-gradient(circle at 32% 24%, rgba(255, 190, 130, 0.36), rgba(255, 118, 88, 0.14) 62%, rgba(255, 118, 88, 0.03));
  box-shadow:
    0 0 20px rgba(255, 150, 100, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
  animation: heartBeat 3.8s ease-in-out infinite;
}

.blessing-heart svg {
  display: block;
  width: 14px;
  height: 14px;
}

.blessing-copy {
  position: relative;
  min-width: 0;
}

.blessing-line {
  margin: 0;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: rgba(226, 238, 255, 0.82);
  white-space: nowrap;
}

.blessing-line b {
  margin: 0 2px;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 192, 110, 0.35);
}

.blessing-sub {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 3px 0 0;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
  white-space: nowrap;
}

.blessing-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffcf87;
  box-shadow: 0 0 9px rgba(255, 196, 110, 0.95);
  animation: pulse 2.4s ease-in-out infinite;
}

.blessing.is-offline .blessing-dot {
  background: #8aa0bb;
  box-shadow: none;
  animation: none;
  opacity: 0.7;
}

.blessing-pop {
  position: absolute;
  top: -10px;
  right: 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #93f0c4;
  opacity: 0;
  transform: translateY(7px) scale(0.9);
  transition: opacity 0.32s ease, transform 0.45s var(--ease);
  text-shadow: 0 0 12px rgba(96, 232, 173, 0.7);
}

.blessing-pop.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* ---------- progress panel ---------- */
.panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  justify-self: end;
  pointer-events: auto;
  width: min(300px, 80vw);
  padding: 15px 17px 13px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(20, 42, 72, 0.72), rgba(8, 18, 33, 0.62));
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  box-shadow:
    0 22px 60px -28px rgba(0, 0, 0, 0.95),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}

.panel-title {
  font-size: 12.5px;
  letter-spacing: 0.12em;
  color: rgba(226, 238, 255, 0.86);
}

.panel-count {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-dim);
}

.panel-count b {
  font-size: 17px;
  font-weight: 600;
  color: var(--gold);
}

.panel-count i {
  font-style: normal;
  margin: 0 2px;
  opacity: 0.5;
}

.bar {
  position: relative;
  height: 6px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(140, 180, 240, 0.12);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ffb85c, #ffe0a3 60%, #fff6dd);
  box-shadow: 0 0 12px rgba(255, 190, 100, 0.55);
  transition: width 0.55s var(--ease);
}

.all-lit .bar-fill {
  box-shadow: 0 0 20px rgba(255, 205, 125, 0.95);
}

.panel-actions {
  display: flex;
  gap: 7px;
  margin-top: 13px;
}

.btn {
  appearance: none;
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(160, 196, 255, 0.22);
  background: rgba(255, 255, 255, 0.035);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.22s ease, border-color 0.22s ease, transform 0.22s ease, box-shadow 0.22s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 212, 137, 0.45);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 2px solid rgba(255, 212, 137, 0.75);
  outline-offset: 2px;
}

.btn-primary {
  border-color: rgba(255, 196, 110, 0.5);
  background: linear-gradient(180deg, #ffe4b0, #ffc06a);
  color: #221605;
  font-weight: 600;
  box-shadow: 0 10px 26px -12px rgba(255, 180, 80, 0.8);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #ffedc6, #ffcc80);
  border-color: rgba(255, 226, 175, 0.8);
}

.btn-icon {
  flex: 0 0 38px;
  font-size: 14px;
  line-height: 1;
}

.btn-icon.is-off {
  color: rgba(180, 200, 225, 0.45);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

/* ---------- hint ---------- */
.hint {
  grid-column: 1 / -1;
  grid-row: 4;
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid rgba(150, 190, 255, 0.1);
  background: rgba(6, 13, 24, 0.42);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(208, 224, 247, 0.62);
}

.hint .dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px rgba(255, 196, 110, 0.95);
  animation: pulse 2.6s ease-in-out infinite;
}

/* ---------- story card (gift fortune / wish star) ---------- */
.story-card {
  position: fixed;
  left: 50%;
  bottom: calc(68px + env(safe-area-inset-bottom));
  z-index: 16;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: min(440px, calc(100vw - 32px));
  padding: 13px 14px 13px 16px;
  border-radius: 16px;
  border: 1px solid rgba(255, 212, 137, 0.28);
  background: linear-gradient(155deg, rgba(22, 42, 72, 0.86), rgba(7, 15, 28, 0.84));
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
  box-shadow:
    0 22px 60px -24px rgba(0, 0, 0, 0.96),
    0 0 40px -22px rgba(255, 195, 110, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transform: translate(-50%, 10px);
  opacity: 0;
  transition: transform 0.35s var(--ease), opacity 0.3s ease;
}

.story-card[hidden] {
  display: none;
}

.story-card.is-open {
  transform: translate(-50%, 0);
  opacity: 1;
}

.story-body {
  flex: 1;
  min-width: 0;
}

.story-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 212, 137, 0.3);
  background: rgba(255, 212, 137, 0.1);
  color: var(--gold);
  font-size: 10.5px;
  letter-spacing: 0.14em;
}

.story-text {
  margin: 7px 0 0;
  font-size: 13.5px;
  line-height: 1.65;
  letter-spacing: 0.03em;
  color: rgba(238, 245, 255, 0.94);
  word-break: break-word;
}

.story-close {
  appearance: none;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(160, 196, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.story-close:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 212, 137, 0.4);
  color: var(--ink);
}

/* ---------- hover tip ---------- */
.tip {
  position: fixed;
  z-index: 15;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid rgba(255, 196, 110, 0.35);
  background: rgba(10, 20, 36, 0.85);
  box-shadow: 0 12px 34px -14px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff3da;
  font-size: 12px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -145%);
}

.tip[hidden] {
  display: none;
}

/* ---------- finale ---------- */
.finale {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(80% 60% at 50% 45%, rgba(6, 12, 24, 0.36), rgba(2, 5, 11, 0.74));
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.45s var(--ease);
}

.finale[hidden] {
  display: none;
}

.finale.is-open {
  opacity: 1;
}

.finale-card {
  position: relative;
  width: min(520px, 100%);
  padding: clamp(30px, 4.5vw, 50px) clamp(22px, 4vw, 44px);
  text-align: center;
  border-radius: 26px;
  border: 1px solid rgba(255, 208, 130, 0.3);
  background: linear-gradient(165deg, rgba(24, 44, 74, 0.94), rgba(8, 16, 30, 0.95));
  box-shadow:
    0 50px 130px -45px rgba(0, 0, 0, 0.98),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 110px -40px rgba(255, 170, 80, 0.5);
  transform: translateY(26px) scale(0.94);
  opacity: 0;
  transition: transform 0.6s var(--ease), opacity 0.6s var(--ease);
}

.finale.is-open .finale-card {
  transform: none;
  opacity: 1;
}

.finale-card::before {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  top: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 212, 137, 0.9), transparent);
}

.finale-kicker {
  margin: 0 0 18px;
  font-size: 10px;
  letter-spacing: 0.42em;
  color: rgba(255, 212, 137, 0.72);
  text-indent: 0.42em;
}

.finale-title {
  margin: 0;
  font-size: clamp(48px, 9vw, 84px);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
  line-height: 1.1;
  background: linear-gradient(100deg, #fff8e6 0%, #ffd489 45%, #f5aa58 75%, #fff3d6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 28px rgba(255, 180, 90, 0.4));
}

.finale-sub {
  margin: 14px 0 0;
  font-family: "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 12px;
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  color: rgba(226, 238, 255, 0.66);
}

.finale-text {
  margin: 26px 0 0;
  font-size: 13.5px;
  line-height: 2;
  letter-spacing: 0.06em;
  color: rgba(198, 217, 240, 0.8);
}

.finale-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 30px;
}

.finale-actions .btn {
  flex: 0 1 150px;
  padding: 10px 18px;
}

/* ---------- wish composer & modal ---------- */
.wish-form {
  margin-top: 22px;
}

.wish-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.wish-input {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid rgba(160, 196, 255, 0.24);
  background: rgba(5, 12, 24, 0.62);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.02em;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wish-input::placeholder {
  color: rgba(145, 169, 201, 0.62);
}

.wish-input:focus {
  outline: none;
  border-color: rgba(255, 212, 137, 0.65);
  box-shadow: 0 0 0 3px rgba(255, 212, 137, 0.12);
}

.wish-btn {
  flex: 0 0 auto;
  padding: 10px 15px;
  white-space: nowrap;
}

.wish-feedback {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: #93f0c4;
}

.wish-feedback.is-error {
  color: #ff9c9c;
}

.wish-modal-card {
  width: min(460px, 100%);
}

.wish-modal-title {
  margin: 0;
  font-size: clamp(24px, 4.5vw, 32px);
  font-weight: 600;
  letter-spacing: 0.08em;
  background: linear-gradient(100deg, #fff8e6 0%, #ffd489 55%, #f5aa58 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.wish-modal-desc {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.7;
  color: rgba(198, 217, 240, 0.8);
}

.wish-modal-actions {
  margin-top: 16px;
}

/* ---------- loader ---------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  background: radial-gradient(90% 70% at 50% 40%, #0b1a30, #04080f 72%);
  transition: opacity 0.9s ease;
}

.loader.is-done {
  opacity: 0;
  pointer-events: none;
}

.loader-flake {
  font-size: 34px;
  color: var(--gold);
  text-shadow: 0 0 26px rgba(255, 190, 110, 0.65);
  animation: spin 6s linear infinite;
}

.loader p {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--ink-dim);
}

/* ---------- responsive ---------- */
@media (max-width: 780px) {
  .hud-shell {
    column-gap: 10px;
    row-gap: 8px;
    padding:
      calc(14px + env(safe-area-inset-top))
      14px
      calc(14px + env(safe-area-inset-bottom));
  }

  .brand-mark {
    display: none;
  }

  .brand > div {
    min-width: 0;
  }

  .brand h1 {
    font-size: clamp(19px, 5.4vw, 27px);
    line-height: 1.08;
  }

  .brand p {
    margin-top: 4px;
    font-size: 10px;
    letter-spacing: 0.06em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .blessing {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: center;
    padding: 6px 10px 6px 7px;
    gap: 7px;
    border-radius: 13px;
  }

  .blessing-heart {
    width: 24px;
    height: 24px;
  }

  .blessing-heart svg {
    width: 11px;
    height: 11px;
  }

  .blessing-line {
    font-size: 10.5px;
    letter-spacing: 0.02em;
  }

  .blessing-line b {
    font-size: 14px;
  }

  .blessing-sub {
    margin-top: 1px;
    gap: 5px;
    font-size: 9px;
    letter-spacing: 0.04em;
  }

  .blessing-pop {
    top: auto;
    bottom: -14px;
    right: 8px;
  }

  .hint {
    grid-column: 1 / -1;
    grid-row: 4;
    align-self: end;
    padding: 7px 12px;
    font-size: 10.5px;
    letter-spacing: 0.04em;
  }

  .panel {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
    width: min(480px, 100%);
    padding: 11px 13px 10px;
    border-radius: 16px;
  }

  .panel-head {
    margin-bottom: 8px;
  }

  .panel-title {
    font-size: 12px;
  }

  .panel-count b {
    font-size: 15.5px;
  }

  .bar {
    height: 5px;
  }

  .panel-actions {
    margin-top: 9px;
    gap: 6px;
  }

  .panel-actions .btn {
    padding: 7px 10px;
  }

  .finale-card {
    padding: 26px 20px;
  }

  .finale-title {
    font-size: clamp(40px, 11vw, 58px);
  }

  .finale-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .finale-actions .btn {
    flex: none;
  }

  .story-card {
    bottom: calc(56px + env(safe-area-inset-bottom));
    padding: 11px 12px 11px 14px;
    gap: 10px;
  }

  .story-text {
    font-size: 12.5px;
  }

  .wish-input-row {
    flex-direction: column;
  }
}

@media (max-height: 620px) {
  .brand p {
    display: none;
  }

  .blessing-sub {
    display: none;
  }

  .hint {
    display: none;
  }
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes heartBeat {
  0%,
  58%,
  100% {
    transform: scale(1);
  }
  12% {
    transform: scale(1.1);
  }
  24% {
    transform: scale(1);
  }
  36% {
    transform: scale(1.07);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}
