/* ============ 天灯祈愿 · SKY LANTERN PRAYER ============ */
:root {
  --night:          #0a0e1a;
  --lantern:        #ff8c42;
  --lantern-bright: #ffb066;
  --star:           #e8e4d0;
  --mist:           #4a5568;
  --gold:           #d4a847;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  background: var(--night);
  overflow: hidden;
  font-family: "Noto Serif SC", serif;
  color: var(--star);
  user-select: none;
  height: 100dvh;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  height: 100dvh;
  display: block;
}

/* ---------- 氛围层 ---------- */
#vignette {
  position: fixed; inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 46%,
    transparent 30%, rgba(5,8,16,.55) 72%, rgba(3,5,12,.92) 100%);
  z-index: 3;
}

#grain {
  position: fixed; inset: -100px;
  pointer-events: none;
  z-index: 4;
  opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain-jitter .42s steps(4) infinite;
}
@keyframes grain-jitter {
  0% { transform: translate(0,0); }
  25% { transform: translate(-32px,18px); }
  50% { transform: translate(22px,-26px); }
  75% { transform: translate(-14px,-30px); }
  100% { transform: translate(0,0); }
}

#flash {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 5;
  background: #ffd9a0;
  opacity: 0;
}
#flash.ignite { animation: ignite-flash .6s ease-out; }
@keyframes ignite-flash {
  0% { opacity: 0; }
  10% { opacity: .7; }
  100% { opacity: 0; }
}

/* 3:4 竖屏录制画框 */
#recordFrame {
  position: fixed;
  z-index: 5;
  pointer-events: none;
  display: none;
  box-shadow: 0 0 0 100vmax #000;
}
body.record #recordFrame { display: block; }

body.shake #scene, body.shake #ui { animation: cam-shake .45s linear; }
@keyframes cam-shake {
  0%,100% { transform: translate(0,0); }
  15% { transform: translate(-9px,6px); }
  30% { transform: translate(8px,-7px); }
  45% { transform: translate(-6px,-5px); }
  60% { transform: translate(6px,4px); }
  75% { transform: translate(-3px,3px); }
}

/* ---------- 图标按钮（音乐 / 语言） ---------- */
.icon-btn {
  position: absolute;
  top: 24px; right: 24px;
  z-index: 10;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(212,168,71,.45);
  background: rgba(10,14,26,.55);
  color: var(--star);
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(2px);
  transition: all .35s ease;
}
.icon-btn:hover {
  border-color: rgba(212,168,71,.85);
  background: rgba(212,168,71,.18);
  box-shadow: 0 0 18px rgba(212,168,71,.35);
}
.icon-btn.off {
  opacity: .45;
  border-color: rgba(74,85,104,.4);
}
.icon-btn.off svg {
  display: none;
}
.icon-btn.off::after {
  content: "\\2715";
  font-size: 13px;
  letter-spacing: 0;
  color: var(--star);
}

/* 中英切换 */
.lang-toggle {
  top: 76px;
  font-family: "IM Fell English SC", serif;
  font-size: 15px;
  line-height: 1;
  letter-spacing: .02em;
  padding: 0;
}
body.lang-en .lang-toggle {
  font-family: "Noto Serif SC", serif;
  font-size: 16px;
  letter-spacing: 0;
}

/* ---------- UI ---------- */
#ui {
  position: fixed; inset: 0;
  z-index: 6;
  pointer-events: none;
}

#ui-canvas {
  position: absolute;
  top: 50%; left: 50%;
  width: 1600px;
  height: 1000px;
  transform-origin: center center;
  pointer-events: auto;
}

/* ---------- 标题（中文在上，英文在下） ---------- */
#title {
  position: absolute;
  top: 7%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  opacity: 0;
  animation: fade-down 2.4s ease .6s forwards;
}
@keyframes fade-down {
  from { opacity: 0; transform: translateX(-50%) translateY(-18px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#title .cn-title {
  font-family: "Ma Shan Zheng", "Noto Serif SC", serif;
  font-size: clamp(22px, 5vw, 38px);
  letter-spacing: .15em;
  color: var(--lantern-bright);
  text-shadow: 0 0 20px rgba(255,140,66,.4);
  white-space: nowrap;
}
#title .en-sub {
  font-family: "IM Fell English SC", serif;
  font-size: clamp(11px, 2.4vw, 16px);
  letter-spacing: .42em;
  color: var(--mist);
  margin-top: 6px;
  white-space: nowrap;
}
#title .tag {
  margin-top: 12px;
  font-size: clamp(12px, 2.2vw, 15px);
  letter-spacing: .4em;
  color: var(--mist);
}

/* ---------- 祭坛面板坞 ---------- */
#altar {
  display: grid;
  place-items: end center;
  position: absolute;
  bottom: 8.5%;
  left: 50%;
  transform: translateX(-50%);
}
#altar .rite-panel { grid-area: 1 / 1; }
body.record #altar { bottom: 11%; }
body.record #title { top: 6%; }

.rite-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  pointer-events: auto;
  transition: opacity .8s ease, transform .8s ease;
}
.rite-panel.hidden {
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  visibility: hidden;
}

/* ---------- 印章风格按钮 ---------- */
.seal-btn {
  font-family: "Noto Serif SC", serif;
  font-weight: 700;
  font-size: clamp(15px, 3.6vw, 17px);
  letter-spacing: .3em;
  text-indent: .3em;
  color: var(--star);
  background: rgba(10,14,26,.65);
  border: 2px solid rgba(212,168,71,.5);
  border-radius: 2px;
  padding: 14px 50px;
  cursor: pointer;
  position: relative;
  transition: all .35s ease;
  backdrop-filter: blur(3px);
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(212,168,71,.12), 0 4px 20px rgba(0,0,0,.3);
}
.seal-btn:hover {
  border-color: var(--lantern-bright);
  background: rgba(255,140,66,.12);
  box-shadow: inset 0 0 0 1px rgba(255,176,102,.4), 0 0 24px rgba(255,140,66,.3);
  text-shadow: 0 0 10px rgba(255,220,180,.7);
}
.seal-btn:active { transform: scale(.97); }
.seal-btn:disabled { opacity: .35; cursor: default; }
.seal-btn.hidden { display: none; }

/* 许愿面板 */
#wishPanel { margin-bottom: 10vh; }

#wishPanel .lead {
  font-size: clamp(12px, 3vw, 15px);
  letter-spacing: .28em;
  color: var(--star);
  opacity: .85;
  margin: 0;
  position: relative;
  z-index: 5;
}
#wishText {
  width: min(460px, 70%);
  font-family: "Noto Serif SC", serif;
  font-size: 16px;
  letter-spacing: .12em;
  line-height: 1.9;
  text-align: center;
  color: var(--star);
  background: rgba(10,14,26,.66);
  border: none;
  border-bottom: 1px solid rgba(212,168,71,.5);
  outline: none;
  resize: none;
  padding: 12px 16px;
  caret-color: var(--lantern-bright);
  transition: border-color .3s, box-shadow .3s;
}
#wishText::placeholder { color: rgba(74,85,104,.8); }
#wishText:focus {
  border-bottom-color: var(--lantern-bright);
  box-shadow: 0 14px 30px -18px rgba(255,140,66,.5);
}
#wishPanel .hint {
  font-size: clamp(10px, 2.4vw, 11.5px);
  letter-spacing: .3em;
  line-height: 2.0;
  text-align: center;
  color: var(--mist);
}

/* ---------- 违规内容黑屏 ---------- */
body.blackout #scene,
body.blackout #ui,
body.blackout #vignette,
body.blackout #grain,
body.blackout #flash,
body.blackout #judging { display: none; }
body.blackout::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #000;
  animation: blackout-in .45s ease forwards;
}
@keyframes blackout-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ---------- 自定义编辑模式 ---------- */
#editBadge {
  position: absolute;
  top: 28px; left: 24px;
  z-index: 10;
  display: none;
  padding: 5px 12px;
  font-size: 11px;
  letter-spacing: .3em;
  text-indent: .3em;
  color: var(--star);
  border: 1px solid rgba(212,168,71,.55);
  background: rgba(255,140,66,.15);
  backdrop-filter: blur(2px);
}
body.edit #editBadge { display: block; }

#editToast {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 11;
  padding: 14px 26px;
  font-size: 13px;
  letter-spacing: .22em;
  text-align: center;
  color: var(--star);
  background: rgba(10,14,26,.85);
  border: 1px solid rgba(212,168,71,.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease;
}
#editToast.show { opacity: 1; }

body.edit #resultTitle,
body.edit #resultSub {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  outline: 1px dashed rgba(212,168,71,.45);
  outline-offset: 8px;
}
body.edit #resultTitle:focus,
body.edit #resultSub:focus {
  outline-style: solid;
  outline-color: rgba(232,228,208,.55);
}
body.edit #resultTitle { white-space: normal; }

/* ---------- 结果面板 ---------- */
#resultPanel.center {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 18px;
  padding: 38% 20px 6%;
  pointer-events: auto;
  transition: opacity .8s ease, transform .8s ease, visibility .8s;
}
#resultPanel.center.hidden {
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  visibility: hidden;
  z-index: -1;
}

#resultTitle {
  font-size: clamp(30px, 8vw, 50px);
  font-weight: 900;
  letter-spacing: .32em;
  text-indent: .32em;
  text-align: center;
  white-space: nowrap;
}

/* rise = 灯升星河 */
#resultTitle.rise {
  color: var(--star);
  text-shadow: 0 0 40px rgba(232,228,208,.6), 0 0 90px rgba(255,140,66,.5);
  animation: rise-in 1.6s ease forwards;
}
@keyframes rise-in {
  from { opacity: 0; letter-spacing: .8em; filter: blur(8px); }
  to { opacity: 1; letter-spacing: .32em; filter: blur(0); }
}

/* crash = 灯坠尘埃 */
#resultTitle.crash {
  color: var(--mist);
  text-shadow: 0 0 30px rgba(74,85,104,.8);
  animation: crash-in 2.4s ease forwards;
}
@keyframes crash-in {
  0% { opacity: 0; filter: blur(10px); transform: scale(1.15); }
  40% { opacity: .9; }
  55% { opacity: .25; }
  70% { opacity: 1; }
  100% { opacity: 1; filter: blur(0); transform: scale(1); }
}

/* stray = 灯入歧途 */
#resultTitle.stray {
  color: var(--lantern);
  text-shadow: 0 0 30px rgba(255,140,66,.6);
  animation: stray-in 1.8s ease forwards;
}
@keyframes stray-in {
  0% { opacity: 0; transform: rotate(-2deg) translateY(-10px); filter: blur(6px); }
  50% { opacity: .8; transform: rotate(1deg) translateY(5px); }
  100% { opacity: 1; transform: rotate(0) translateY(0); filter: blur(0); }
}

/* fade = 灯化星光 */
#resultTitle.fade {
  color: var(--gold);
  text-shadow: 0 0 50px rgba(212,168,71,.7), 0 0 100px rgba(255,200,100,.4);
  animation: fade-in-title 2.2s ease forwards;
}
@keyframes fade-in-title {
  0% { opacity: 0; filter: blur(15px) brightness(2); letter-spacing: .6em; }
  40% { opacity: .5; filter: blur(8px) brightness(1.5); }
  100% { opacity: 1; filter: blur(0) brightness(1); letter-spacing: .32em; }
}

#resultSub {
  font-size: clamp(12px, 3vw, 14px);
  letter-spacing: .34em;
  text-align: center;
  line-height: 2.4;
  color: var(--mist);
  opacity: 0;
  animation: fade-in 1.6s ease 1.2s forwards;
}
#resultSub .ln {
  white-space: nowrap;
}

#resultPanel .seal-btn {
  opacity: 0;
  animation: fade-in 1.2s ease 2.2s forwards;
}

@keyframes fade-in { to { opacity: 1; } }

/* ---------- 裁决加载层 ---------- */
#judging {
  position: fixed; inset: 0;
  z-index: 7;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 26px;
  background: rgba(6,10,20,.28);
  backdrop-filter: none;
  opacity: 0; pointer-events: none;
  transition: opacity .6s ease;
}
#judging.visible { opacity: 1; pointer-events: auto; }
#judging p {
  font-size: 13px; letter-spacing: .5em;
  color: var(--star);
  text-shadow: 0 0 16px rgba(10,14,26,.9), 0 0 8px rgba(10,14,26,.9);
  animation: pulse-text 1.6s ease-in-out infinite;
}
@keyframes pulse-text {
  0%,100% { opacity: .4; }
  50% { opacity: 1; }
}
.loader {
  width: 42px; height: 42px;
  border: 2px solid rgba(212,168,71,.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 手机竖屏 ---------- */
@media (max-width: 640px) {
  #title { top: 8.5%; max-width: 92vw; }
  #title .cn-title { font-size: min(5.5vw, 28px); letter-spacing: .08em; }
  #title .en-sub { font-size: min(2.8vw, 14px); letter-spacing: .3em; }
  #title .tag { font-size: min(3.2vw, 13px); letter-spacing: .3em; margin-top: 8px; }

  .icon-btn { width: 34px; height: 34px; top: 12px; right: 12px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .lang-toggle { top: 54px; font-size: 13px; }
  body.lang-en .lang-toggle { font-size: 14px; }

  .rite-panel { gap: 14px; }
  #wishPanel { margin-bottom: 7vh; width: min(460px, 90vw); }

  #wishPanel .lead { font-size: min(3.5vw, 14px); letter-spacing: .1em; white-space: nowrap; }
  #wishText { font-size: 16px; width: 90vw; }
  #wishPanel .hint { font-size: min(2.8vw, 11.5px); letter-spacing: .2em; }

  .seal-btn { padding: 13px 40px; font-size: min(3.8vw, 16px); }

  #resultTitle { font-size: min(8vw, 36px); }
  #resultSub { font-size: min(2.8vw, 12px); letter-spacing: .2em; }
  #resultPanel.center { padding: 34% 16px 6%; }
}

/* ---------- 底部版权小字 ---------- */
#footer {
  position: fixed;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-size: 10px;
  letter-spacing: .12em;
  color: rgba(74,85,104,.5);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  animation: fade-in 2s ease 3s forwards;
}
@media (max-width: 640px) {
  #footer { font-size: 9px; bottom: 4px; }
}
