:root {
  --bg: #05060d;
  --ink: #f6eef7;
  --muted: #9d93a9;
  --pink: #ff9ec4;
  --pink-2: #ff6f9c;
  --gold: #ffd27a;
  --mint: #9be8cf;
  --lav: #b8b5ff;
  --glass: rgba(16, 14, 26, 0.74);
  --glass-2: rgba(22, 19, 34, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 34%, #18122b 0%, #0b0916 42%, #05060d 74%, #030308 100%);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }
button { cursor: pointer; }

#app { position: fixed; inset: 0; overflow: hidden; }

#canvasWrap { position: absolute; inset: 0; z-index: 1; }

#vignette {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: radial-gradient(circle at 50% 46%, transparent 38%, rgba(3, 4, 10, 0.58) 100%);
}

/* ---------------- 顶栏 ---------------- */
#topbar {
  position: absolute; top: 18px; left: 22px; right: 22px; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  pointer-events: none;
}
.brand { min-width: 150px; }
.brand-title {
  font-size: 22px; font-weight: 700; letter-spacing: 0.24em;
  background: linear-gradient(100deg, #fff 0%, var(--pink) 45%, var(--gold) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 26px rgba(255, 120, 170, 0.25);
}
.brand-sub {
  margin-top: 3px; font-size: 8.5px; letter-spacing: 0.32em; color: var(--muted);
}

.progress { display: flex; gap: 7px; align-items: center; }
.progress .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: 0.25s ease;
}
.progress .dot.on {
  background: linear-gradient(135deg, var(--pink), var(--gold));
  border-color: transparent;
  box-shadow: 0 0 14px rgba(255, 140, 180, 0.8);
  transform: scale(1.18);
}

.status {
  margin-left: auto; max-width: 48vw;
  padding: 8px 14px; border-radius: 999px;
  background: rgba(12, 10, 20, 0.62);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  font-size: 11.5px; letter-spacing: 0.05em; color: rgba(255, 238, 246, 0.82);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.camera-btn {
  position: fixed; right: 22px; top: 64px; z-index: 120;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(12, 10, 20, 0.72);
  color: #fff; font-size: 10px; letter-spacing: 0.08em;
  backdrop-filter: blur(12px);
  cursor: pointer;
}
.camera-btn:hover { background: rgba(255, 140, 180, 0.22); }

/* ---------------- 章节（左上） ---------------- */
.chapter {
  position: absolute; left: 22px; top: 82px; z-index: 26;
  max-width: 270px; pointer-events: none;
}
.chapter-kicker {
  font-size: 8px; letter-spacing: 0.34em;
  color: rgba(255, 180, 210, 0.58);
}
.chapter-title {
  margin-top: 5px;
  font-size: 22px; font-weight: 700; letter-spacing: 0.12em;
  color: rgba(255, 245, 250, 0.94);
  text-shadow: 0 0 24px rgba(255, 120, 170, 0.25);
}
.chapter-desc {
  margin-top: 7px;
  font-size: 10px; line-height: 1.75;
  color: rgba(220, 205, 230, 0.55);
}
.hand-state {
  display: inline-block; margin-top: 9px;
  padding: 3px 8px; border-radius: 20px;
  background: rgba(12, 10, 20, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 8px; letter-spacing: 0.12em;
  color: rgba(255, 220, 235, 0.55);
}

/* ---------------- 底部章节说明卡 ---------------- */
.chapter-card {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 25; width: min(92vw, 560px);
  padding: 11px 18px 10px;
  border-radius: 12px;
  background: rgba(12, 10, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
  text-align: center; pointer-events: none;
}
.cc-kicker { font-size: 7.5px; letter-spacing: 0.3em; color: rgba(255, 180, 210, 0.5); }
.cc-title {
  margin-top: 3px; font-size: 14px; font-weight: 600;
  letter-spacing: 0.12em; color: rgba(255, 235, 245, 0.9);
}
.cc-text {
  margin-top: 4px; font-size: 10px; line-height: 1.7;
  color: rgba(215, 200, 225, 0.55);
}
.cc-tip {
  margin-top: 4px; font-size: 8.5px; letter-spacing: 0.04em;
  color: rgba(255, 210, 122, 0.55);
}

/* ---------------- 画中画 ---------------- */
.pip {
  position: absolute; left: 18px; bottom: 18px; z-index: 30;
  width: 240px; height: 180px;
  border-radius: 16px; overflow: hidden;
  background: #0b0d16;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
#cam {
  position: absolute; left: 0; top: 0;
  width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
}
#pipCanvas { display: block; width: 100%; height: 100%; }
.pip-label {
  position: absolute; left: 10px; bottom: 8px;
  display: flex; align-items: center; gap: 5px;
  padding: 3px 7px; border-radius: 6px;
  background: rgba(5, 6, 12, 0.62);
  font-size: 8px; letter-spacing: 0.14em; color: rgba(255, 240, 246, 0.72);
}
.pip-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: #7dffb0; box-shadow: 0 0 8px #7dffb0;
}

/* ---------------- 参数面板 ---------------- */
.panel {
  position: absolute; right: 18px; top: 86px; bottom: 18px;
  width: 312px; max-height: calc(100vh - 104px);
  z-index: 50;
  display: flex; flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.panel.collapsed {
  transform: translateX(calc(100% + 26px));
  opacity: 0; pointer-events: none;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.panel-title b { display: block; font-size: 13px; letter-spacing: 0.14em; }
.panel-title small {
  display: block; margin-top: 3px;
  font-size: 7.5px; letter-spacing: 0.28em; color: var(--muted);
}
.panel-close {
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7); font-size: 15px; line-height: 1;
}
.panel-close:hover { background: rgba(255, 255, 255, 0.13); color: #fff; }

.panel-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 14px 16px 8px;
  scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}
.panel-body::-webkit-scrollbar { width: 5px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 4px; }

.ctl { display: block; margin-bottom: 16px; }
.ctl-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px; color: rgba(255, 238, 246, 0.84); letter-spacing: 0.05em;
}
.ctl-label em { font-style: normal; color: var(--gold); font-size: 11px; }
.ctl small {
  display: block; margin-top: 5px;
  font-size: 9.5px; line-height: 1.55; color: rgba(157, 147, 169, 0.86);
}

/* ---------------- 文字编辑 / 照片环 ---------------- */
.text-input {
  width: 100%; margin-top: 6px;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: #fff; font-size: 11px; outline: none;
}
.text-input:focus { border-color: rgba(255, 140, 180, 0.55); }
.text-input::placeholder { color: rgba(255, 255, 255, 0.32); }

.photo-list {
  display: flex; flex-direction: column; gap: 7px;
  margin-top: 8px;
}
.photo-row { display: flex; align-items: center; gap: 7px; }
.photo-thumb {
  position: relative;
  width: 46px; height: 56px; flex: 0 0 46px;
  border-radius: 7px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(135deg, #ff9ec4, #7b5cff);
  cursor: pointer;
}
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.photo-placeholder {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 18px; font-weight: 700;
  color: rgba(255, 255, 255, 0.88);
  pointer-events: none;
}
.photo-pick {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 2px 0; text-align: center;
  font-size: 7px; letter-spacing: 0.08em;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.82);
  pointer-events: none;
}
.photo-fields {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.photo-fields .text-input {
  margin-top: 0; font-size: 10px; padding: 5px 7px;
}
.photo-del {
  width: 20px; height: 20px; flex: 0 0 20px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px; line-height: 1; padding: 0;
}
.photo-del:hover { background: rgba(255, 80, 120, 0.25); color: #fff; }

input[type="range"] {
  width: 100%; height: 4px; margin: 10px 0 2px;
  appearance: none; -webkit-appearance: none;
  border-radius: 4px; outline: none;
  background: linear-gradient(90deg, rgba(255, 158, 196, 0.55), rgba(255, 210, 122, 0.35), rgba(255, 255, 255, 0.12));
  accent-color: var(--pink);
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff;
  border: 2px solid var(--pink-2);
  box-shadow: 0 0 12px rgba(255, 111, 156, 0.8);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 2px solid var(--pink-2);
  box-shadow: 0 0 12px rgba(255, 111, 156, 0.8);
}

.color-list { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 8px; }
.color-row { display: flex; align-items: center; gap: 3px; }
.color-row input[type="color"] {
  width: 28px; height: 28px; padding: 0; border: none; border-radius: 50%;
  background: none; cursor: pointer; overflow: hidden;
}
.color-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-row input[type="color"]::-webkit-color-swatch {
  border: 2px solid rgba(255, 255, 255, 0.35); border-radius: 50%;
}
.color-del {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.55); font-size: 10px; line-height: 1;
  padding: 0;
}
.color-del:hover { background: rgba(255, 80, 120, 0.25); color: #fff; }

.add-color {
  width: 100%; padding: 7px 10px; margin-top: 2px;
  border-radius: 8px; border: 1px dashed rgba(255, 255, 255, 0.2);
  background: transparent; color: rgba(255, 235, 245, 0.62);
  font-size: 10.5px; letter-spacing: 0.06em;
}
.add-color:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.switch-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0 4px; font-size: 11px; color: rgba(255, 238, 246, 0.78);
}
.switch-row input { accent-color: var(--pink-2); width: 15px; height: 15px; }

.panel-foot { padding: 10px 16px 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.reset {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255, 160, 190, 0.35);
  background: linear-gradient(135deg, rgba(255, 111, 156, 0.9), rgba(255, 158, 196, 0.72));
  color: #2a0a18; font-size: 11.5px; font-weight: 700; letter-spacing: 0.16em;
  box-shadow: 0 10px 26px rgba(255, 90, 140, 0.24);
}
.reset:hover { filter: brightness(1.08); }
.reset:active { transform: translateY(1px); }

.panel-toggle {
  position: absolute; right: 18px; top: 86px; z-index: 49;
  padding: 9px 18px; border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(14, 12, 24, 0.82);
  color: rgba(255, 238, 246, 0.82); font-size: 11px; letter-spacing: 0.16em;
  backdrop-filter: blur(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.panel:not(.collapsed) ~ .panel-toggle {
  opacity: 0; pointer-events: none; transform: translateX(10px);
}

/* ---------------- 提示 / 锁定 ---------------- */
.help {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  z-index: 20; pointer-events: none;
  font-size: 9.5px; letter-spacing: 0.14em; color: rgba(255, 235, 245, 0.38);
  white-space: nowrap;
}

.lock {
  position: absolute; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: rgba(4, 4, 10, 0.52);
  backdrop-filter: blur(6px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s;
  pointer-events: none;
}
.lock.show { opacity: 1; visibility: visible; }
.lock-inner { text-align: center; transform: translateY(-3vh); }
.lock-kicker {
  font-size: 8.5px; letter-spacing: 0.42em; color: rgba(255, 180, 210, 0.6);
}
.lock-title {
  margin: 10px 0 6px;
  font-size: clamp(42px, 8vw, 76px); font-weight: 800; letter-spacing: 0.14em;
  background: linear-gradient(180deg, #fff 0%, #ffd6e6 38%, #ff6f9c 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 34px rgba(255, 90, 140, 0.4));
}
.lock-sub { font-size: 10.5px; letter-spacing: 0.12em; color: rgba(255, 235, 245, 0.55); }
.lock-bar {
  width: 220px; height: 3px; margin: 20px auto 8px;
  border-radius: 3px; overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
}
.lock-bar i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, var(--pink-2), var(--gold));
  box-shadow: 0 0 14px rgba(255, 140, 180, 0.7);
}
.lock-time {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px; color: rgba(255, 235, 245, 0.65); letter-spacing: 0.1em;
}

/* ---------------- 加载 / 错误 ---------------- */
.overlay {
  position: absolute; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: rgba(4, 5, 12, 0.88);
  backdrop-filter: blur(8px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s;
}
.overlay.show { opacity: 1; visibility: visible; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--pink);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 24px rgba(255, 140, 180, 0.25);
}
@keyframes spin { to { transform: rotate(360deg); } }
#loadingText { font-size: 11.5px; letter-spacing: 0.12em; color: rgba(255, 235, 245, 0.7); }
.loading-hint {
  margin-top: -8px;
  font-size: 9.5px; letter-spacing: 0.06em; color: rgba(255, 235, 245, 0.4);
}
.skip-btn {
  margin-top: 4px; padding: 8px 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 235, 245, 0.78);
  font-size: 11px; letter-spacing: 0.06em;
}
.skip-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }

.error { z-index: 110; }
.file-warning { z-index: 200; }
.file-warning pre {
  margin: 0 0 16px; padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffd27a;
  font-size: 12px; text-align: left;
  overflow-x: auto;
}
.file-warning .error-card p { margin-bottom: 10px; }
.file-warning .error-card b { color: #fff; }
.error-card {
  width: min(90vw, 440px); padding: 26px 24px 22px;
  border-radius: 16px;
  background: rgba(22, 18, 32, 0.96);
  border: 1px solid rgba(255, 160, 190, 0.22);
  box-shadow: var(--shadow);
  text-align: center;
}
.error-card h3 { margin: 0 0 10px; font-size: 16px; letter-spacing: 0.08em; }
.error-card p {
  margin: 0 0 18px; white-space: pre-wrap;
  font-size: 11.5px; line-height: 1.8; color: rgba(255, 230, 240, 0.7);
}
.error-card button {
  padding: 9px 22px; border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #fff; font-size: 11.5px;
}
.error-card button:hover { background: rgba(255, 255, 255, 0.16); }

/* ---------------- 响应式 ---------------- */
@media (max-width: 720px) {
  #topbar { top: 10px; left: 12px; right: 12px; gap: 10px; }
  .brand { min-width: 0; }
  .brand-title { font-size: 17px; letter-spacing: 0.18em; }
  .brand-sub { font-size: 7px; letter-spacing: 0.22em; }
  .progress { gap: 5px; }
  .progress .dot { width: 6px; height: 6px; }
  .status {
    max-width: 46vw; padding: 6px 10px;
    font-size: 9.5px; letter-spacing: 0.02em;
  }

  .pip { width: 132px; height: 99px; left: 12px; bottom: 12px; border-radius: 12px; }
  .pip-label { font-size: 6.5px; left: 7px; bottom: 5px; padding: 2px 5px; }

  .panel {
    left: 12px; right: 12px; top: auto; bottom: 12px;
    width: auto; max-height: 54vh;
    border-radius: 16px;
  }
  .panel.collapsed { transform: translateY(calc(100% + 26px)); }
  .panel-toggle { right: 12px; top: auto; bottom: 12px; }
  .panel:not(.collapsed) ~ .panel-toggle { transform: translateY(10px); }

  .help { display: none; }
  .camera-btn { top: 54px; right: 12px; font-size: 9px; padding: 6px 9px; }
  .chapter { top: 62px; left: 12px; max-width: 190px; }
  .chapter-title { font-size: 16px; }
  .chapter-desc { display: none; }
  .chapter-card { display: none; }
  .lock-title { font-size: 44px; }
  .lock-sub { font-size: 9.5px; }
}

@media (max-height: 520px) {
  .pip { width: 150px; height: 112px; }
  .panel { max-height: 62vh; }
}
