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

html { background: #07070C; }

body {
  margin: 0;
  min-height: 100vh;
  background: #07070C;
  color: #EDEAE3;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.serif {
  font-family: "Songti SC", "SimSun", "Source Han Serif SC", "Noto Serif SC", serif;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

/* 全屏辉光已搬到 WebGL 里画（engine.js 的 glowScene）。
   原因：mix-blend-mode:screen 要求浏览器合成器每帧重新读取画布做全屏混合，
   实测让 800 万粒子从 60 帧掉到 38.8 帧（-45%）。WebGL 版是加色四边形，
   视觉效果等价、开销几乎为零。此元素保留但不再显示。 */
.glow {
  display: none;
}

.vignette {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(118% 96% at 50% 48%, transparent 40%, rgba(0, 0, 0, .76) 100%);
}

.grain {
  position: fixed;
  inset: -60%;
  z-index: 4;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grainShift 5.5s steps(6) infinite;
}
@keyframes grainShift {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-3%, 2%); }
  40%  { transform: translate(2%, -3%); }
  60%  { transform: translate(-2%, -2%); }
  80%  { transform: translate(3%, 1%); }
  100% { transform: translate(0, 0); }
}

/* ============ 门面 ============ */

.gate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .9s ease, transform .9s ease, visibility .9s;
  pointer-events: none;
}
.gate-body { pointer-events: auto; }
.gate.off {
  opacity: 0;
  visibility: hidden;
  transform: scale(1.06);
  pointer-events: none;
}

.gate-frame {
  position: absolute;
  inset: 30px;
  border: 1px solid rgba(255, 194, 71, .2);
  pointer-events: none;
}
.gate-frame::before {
  content: "";
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(255, 194, 71, .1);
}
.corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 194, 71, .75);
}
.corner.tl { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.corner.tr { top: -1px; right: -1px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: -1px; left: -1px; border-right: 0; border-top: 0; }
.corner.br { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }

.gate-body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  text-align: center;
  animation: gateIn 1.4s cubic-bezier(.22, 1, .36, 1) both;
}
.gate-body::before {
  content: "";
  position: absolute;
  inset: -10% -22%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(7, 7, 12, .88), rgba(7, 7, 12, .58) 60%, transparent 100%);
}
@keyframes gateIn {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}

.seal {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 2px solid rgba(255, 194, 71, .8);
  background: linear-gradient(158deg, #E60012, #8E000B);
  box-shadow: 0 0 46px rgba(230, 0, 18, .55), inset 0 0 18px rgba(0, 0, 0, .35);
  transform: rotate(-4deg);
}
.seal span {
  font-family: "Songti SC", "SimSun", "Source Han Serif SC", serif;
  font-size: 40px;
  font-weight: 700;
  color: #FFE9B8;
  line-height: 1;
}

.gate-title {
  margin: 0;
  font-family: "Songti SC", "SimSun", "Source Han Serif SC", "Noto Serif SC", serif;
  font-size: clamp(50px, 9vw, 128px);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: .14em;
  text-indent: .14em;
  background: linear-gradient(178deg, #FFF9E6 0%, #FFE29A 34%, #FFC247 58%, #FF7A2F 78%, #E60012 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 38px rgba(255, 170, 50, .4)) drop-shadow(0 8px 44px rgba(230, 0, 18, .28));
}

.gate-en {
  margin: 0;
  font-size: clamp(9px, 1.2vw, 13px);
  letter-spacing: .68em;
  text-indent: .68em;
  color: rgba(255, 209, 102, .58);
}

.gate-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  width: min(360px, 70vw);
}
.gate-divider i {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 194, 71, .5));
}
.gate-divider i:last-child { background: linear-gradient(270deg, transparent, rgba(255, 194, 71, .5)); }
.gate-divider b {
  width: 6px;
  height: 6px;
  background: #FFC247;
  transform: rotate(45deg);
  box-shadow: 0 0 14px rgba(255, 194, 71, .8);
}

.gate-sub {
  margin: 0;
  font-size: clamp(12px, 1.3vw, 15px);
  letter-spacing: .3em;
  color: rgba(237, 234, 227, .58);
}

.enter-btn {
  margin-top: 10px;
  padding: 15px 48px;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: .34em;
  text-indent: .34em;
  color: #FFE9B8;
  background: transparent;
  border: 1px solid rgba(255, 194, 71, .5);
  border-radius: 2px;
  cursor: pointer;
  transition: color .35s, background .35s, border-color .35s, box-shadow .35s;
}
.enter-btn:hover {
  color: #1A0E02;
  border-color: #FFD166;
  background: linear-gradient(180deg, #FFE29A, #FFB300);
  box-shadow: 0 0 46px rgba(255, 180, 50, .55);
}

.gate-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  letter-spacing: .16em;
  color: rgba(237, 234, 227, .42);
}
.gate-meta .dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(255, 194, 71, .55);
}

.gate-side {
  position: absolute;
  right: 62px;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  font-family: "Songti SC", "SimSun", "Source Han Serif SC", serif;
  font-size: 15px;
  letter-spacing: .55em;
  color: rgba(255, 194, 71, .38);
}

/* ============ 工作室 ============ */

.studio {
  position: fixed;
  inset: 0;
  z-index: 8;
  opacity: 0;
  visibility: hidden;
  transition: opacity .8s ease, visibility .8s;
  /* 关键：整屏容器不吞事件，让拖动旋转能落到 canvas 上 */
  pointer-events: none;
}
.studio.on { opacity: 1; visibility: visible; }
.panel,
.panel-toggle,
.studio-hud,
.studio-tip { pointer-events: auto; }

.panel {
  position: absolute;
  top: 22px;
  left: 22px;
  bottom: 22px;
  width: 306px;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  border: 1px solid rgba(255, 194, 71, .16);
  background: rgba(10, 10, 18, .74);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  /* 参数项变多后底部控件会被裁掉（"辉光叠加按钮不见了"），
     所以面板必须可滚动 */
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  transform: translateX(-118%);
  transition: transform .6s cubic-bezier(.22, 1, .36, 1);
  z-index: 12;
}
.studio.on .panel { transform: translateX(0); }
.studio.on .panel.folded { transform: translateX(-118%); }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 194, 71, .12);
  flex: none;
}
.panel-logo {
  font-family: "Songti SC", "SimSun", serif;
  font-size: 16px;
  letter-spacing: .16em;
  color: #FFC247;
}
.panel-back {
  font-family: inherit;
  font-size: 11px;
  letter-spacing: .1em;
  color: rgba(237, 234, 227, .5);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  transition: .25s;
}
.panel-back:hover { color: #FFE9B8; border-color: rgba(255, 194, 71, .5); }

.panel-acts { display: flex; gap: 6px; }
.icon-btn {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  color: rgba(237, 234, 227, .55);
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px;
  cursor: pointer;
  transition: color .22s, background .22s, border-color .22s;
}
.icon-btn:hover {
  color: #FFE9B8;
  border-color: rgba(255, 194, 71, .5);
  background: rgba(255, 194, 71, .12);
}

.custom-colors {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 13px;
  flex-wrap: wrap;
}
.cc-label { font-size: 11px; color: rgba(237, 234, 227, .45); }
.custom-colors input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 27px;
  height: 27px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}
.custom-colors input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.custom-colors input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }
.mini-btn {
  font-family: inherit;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 5px;
  color: rgba(237, 234, 227, .7);
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .12);
  cursor: pointer;
  transition: .22s;
}
.mini-btn:hover {
  color: #1A0E02;
  background: linear-gradient(180deg, #FFE29A, #FFB300);
  border-color: #FFD166;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 194, 71, .3) transparent;
}
.panel-scroll::-webkit-scrollbar { width: 6px; }
.panel-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 194, 71, .25);
  border-radius: 3px;
}

.panel-group { margin-bottom: 24px; }
.panel-group h3 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .24em;
  color: rgba(255, 194, 71, .75);
}

.shape-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.shape-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 11px 6px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 7px;
  background: rgba(255, 255, 255, .02);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: .04em;
  color: rgba(237, 234, 227, .68);
  transition: border-color .22s, background .22s, color .22s;
}
.shape-item:hover { border-color: rgba(255, 194, 71, .42); color: #FFE9B8; }
.shape-item.on {
  border-color: #FFC247;
  background: rgba(255, 194, 71, .13);
  color: #FFC247;
}
.shape-item .ic {
  font-size: 15px;
  line-height: 1;
  opacity: .9;
}
.shape-item.locked {
  opacity: .32;
  cursor: not-allowed;
}
.shape-item.locked:hover {
  border-color: rgba(255, 255, 255, .1);
  color: rgba(237, 234, 227, .68);
}

.hint-text b {
  color: rgba(255, 194, 71, .68);
  font-weight: 500;
}

.theme-row { display: flex; gap: 10px; }
.theme-dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: border-color .22s, transform .22s;
}
.theme-dot:hover { transform: scale(1.08); }
.theme-dot.on { border-color: #FFC247; }
.theme-dot::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: inherit;
  filter: brightness(1.3);
}

.slider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 12px;
  color: rgba(237, 234, 227, .62);
}
.slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 132px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .14);
  outline: none;
}
.slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(180deg, #FFE29A, #FFB300);
  box-shadow: 0 0 12px rgba(255, 180, 50, .7);
  cursor: pointer;
}
.slider input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: #FFC247;
  cursor: pointer;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 11px;
  font-size: 12px;
  color: rgba(237, 234, 227, .62);
  cursor: pointer;
}
.switch input {
  -webkit-appearance: none;
  appearance: none;
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: rgba(255, 255, 255, .13);
  position: relative;
  cursor: pointer;
  transition: background .25s;
  margin: 0;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(237, 234, 227, .65);
  transition: transform .25s, background .25s;
}
.switch input:checked { background: rgba(255, 194, 71, .35); }
.switch input:checked::after {
  transform: translateX(16px);
  background: #FFC247;
}

.text-input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-family: inherit;
  font-size: 13px;
  color: #FFE9B8;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px;
  outline: none;
  transition: border-color .25s;
}
.text-input:focus { border-color: rgba(255, 194, 71, .55); }

.text-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.text-chips button {
  font-family: inherit;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  color: rgba(237, 234, 227, .65);
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12);
  cursor: pointer;
  transition: color .22s, background .22s, border-color .22s;
}
.text-chips button:hover {
  color: #1A0E02;
  background: linear-gradient(180deg, #FFE29A, #FFB300);
  border-color: #FFD166;
}

.apply-btn,
.upload {
  display: block;
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: .1em;
  text-align: center;
  color: rgba(237, 234, 227, .78);
  background: rgba(255, 255, 255, .03);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 6px;
  cursor: pointer;
  transition: .25s;
}
.apply-btn:hover,
.upload:hover {
  color: #1A0E02;
  background: linear-gradient(180deg, #FFE29A, #FFB300);
  border-color: #FFD166;
}
.upload input[type="file"] { display: none; }

.hint-text {
  margin: 4px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(237, 234, 227, .35);
}

.panel-toggle {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 11;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: .16em;
  color: #FFE9B8;
  background: rgba(10, 10, 18, .74);
  border: 1px solid rgba(255, 194, 71, .28);
  border-radius: 7px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: opacity .3s, visibility .3s, border-color .25s, background .25s;
  opacity: 0;
  visibility: hidden;
}
.studio.on .panel.folded ~ .panel-toggle,
.panel-toggle.show { opacity: 1; visibility: visible; }
.panel-toggle:hover { border-color: #FFC247; background: rgba(255, 194, 71, .14); }

.studio-hud {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255, 194, 71, .14);
  background: rgba(10, 10, 18, .6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-size: 12px;
  letter-spacing: .1em;
  color: rgba(237, 234, 227, .6);
  z-index: 11;
}
.studio-hud #hudShape { color: #FFC247; }
.hud-sep { width: 1px; height: 12px; background: rgba(255, 194, 71, .28); }

.studio-tip {
  position: absolute;
  right: 28px;
  bottom: 30px;
  font-size: 11px;
  letter-spacing: .18em;
  color: rgba(237, 234, 227, .28);
  z-index: 11;
}

/* ============ 启动遮罩 ============ */

.boot {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: #07070C;
  transition: opacity .6s ease, visibility .6s;
  animation: bootAutoHide .6s ease 1.8s forwards;
}
@keyframes bootAutoHide {
  to { opacity: 0; visibility: hidden; }
}
.boot.off { opacity: 0; visibility: hidden; }
.boot span {
  font-size: 12px;
  letter-spacing: .5em;
  text-indent: .5em;
  color: rgba(255, 194, 71, .7);
  animation: bootPulse 1.5s ease-in-out infinite;
}
@keyframes bootPulse {
  0%, 100% { opacity: .3; }
  50%      { opacity: 1; }
}

/* ============ 响应式 ============ */

@media (max-width: 860px) {
  .gate-frame { inset: 16px; }
  .gate-side { display: none; }
  .gate-meta { flex-wrap: wrap; justify-content: center; gap: 8px 12px; font-size: 11px; }
  .panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 58vh;
    transform: translateY(130%);
  }
  .studio.on .panel { transform: translateY(0); }
  .studio.on .panel.folded { transform: translateY(130%); }
  .panel-toggle { top: 14px; left: 14px; }
  .studio-hud { bottom: auto; top: 14px; left: 50%; }
  .studio-tip {
    display: block;
    top: 50px;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translateX(-50%);
    font-size: 10px;
    letter-spacing: .12em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .boot span { animation: none; }
}

/* 粒子数量输入框（原为滑块，容易拖过头导致卡死） */
.slider input.num {
  width: 132px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 194, 71, .35);
  border-radius: 6px;
  background: rgba(0, 0, 0, .35);
  color: #FFD166;
  font: 12px/1.4 ui-monospace, Consolas, Menlo, monospace;
  text-align: right;
  outline: none;
}
.slider input.num:focus { border-color: rgba(255, 194, 71, .8); }

/* 粒子数量下方的推荐范围（只做提示，不干预） */
.rec {
  margin: 4px 0 2px;
  font: 11px/1.5 ui-monospace, Consolas, Menlo, monospace;
  color: rgba(255, 209, 102, .62);
  letter-spacing: .02em;
}

/* 粒子数量输入框后面的「万」单位 */
.slider .unit {
  font-style: normal;
  font-size: 12px;
  color: rgba(255, 209, 102, .8);
  margin-left: 6px;
}

/* 粒子数量：输入框与「万颗」单位做成一个整体 */
.slider .num-wrap {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(255, 194, 71, .35);
  border-radius: 6px;
  background: rgba(0, 0, 0, .35);
  overflow: hidden;
}
.slider .num-wrap:focus-within { border-color: rgba(255, 194, 71, .8); }
.slider .num-wrap input.num {
  border: 0;
  border-radius: 0;
  background: transparent;
  width: 96px;
}
.slider .num-wrap .unit {
  font-style: normal;
  font-size: 12px;
  color: rgba(255, 209, 102, .85);
  padding: 0 8px 0 4px;
  border-left: 1px solid rgba(255, 194, 71, .22);
}
.slider .num-abs {
  display: block;
  margin-top: 3px;
  font: 11px/1.4 ui-monospace, Consolas, Menlo, monospace;
  font-weight: 400;
  color: rgba(255, 209, 102, .62);
}
