:root {
  --bg: #1b1009;
  --panel: #23160c;
  --line: rgba(247, 222, 176, 0.14);
  --cream: #f7e6c4;
  --dim: rgba(247, 230, 196, 0.58);
  --accent: #f29a36;
  --accent2: #ffd27a;
  --sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0804; color: var(--cream); font-family: var(--sans); }
button, input, a { font-family: inherit; }
button { cursor: pointer; border: 0; }

#app {
  position: relative; margin: 0 auto; width: 100%; max-width: 480px; height: 100dvh; height: 100vh;
  display: flex; flex-direction: column; overflow: hidden; background: var(--bg);
  box-shadow: 0 0 80px rgba(0,0,0,.6);
}
@supports (height: 100dvh) { #app { height: 100dvh; } }

/* ---------- stage ---------- */
#stageWrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; touch-action: none; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.topbar {
  position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 10px; pointer-events: none;
  background: linear-gradient(rgba(10,5,2,.55), rgba(10,5,2,0));
}
.topbar > * { pointer-events: auto; }
.ghost, .primary, .secondary { white-space: nowrap; }
#app.is-intro .brand, #app.is-intro #btnHide, #app.is-intro #btnSound { opacity: 0; pointer-events: none; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.topActions { display: flex; align-items: center; gap: 7px; }
.soundBtn { min-width: 64px; transition: opacity .2s, border-color .2s, color .2s; }
.soundBtn.off { opacity: .6; color: var(--dim); }
.brand b { font-size: 17px; letter-spacing: 2px; color: var(--accent2); text-shadow: 0 0 12px rgba(255,190,90,.55); }
.brand span { font: 10px var(--mono); letter-spacing: 2px; color: var(--dim); }
.ghost {
  background: rgba(20,10,4,.45); color: var(--cream); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 999px; font-size: 12px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.corner { position: absolute; bottom: 8px; font: 11px var(--mono); color: rgba(247,230,196,.38); letter-spacing: 1px; pointer-events: none; }
.corner.l { left: 12px; } .corner.r { right: 12px; }
#toast {
  position: absolute; left: 50%; top: 64px; transform: translate(-50%, -8px); opacity: 0; transition: .35s;
  background: rgba(20,10,4,.72); border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px;
  font-size: 13px; max-width: 92%; white-space: nowrap; text-align: center; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- panel ---------- */
#panel {
  flex: 0 0 auto; position: relative; z-index: 2;
  padding: 12px 0 calc(env(safe-area-inset-bottom) + 12px);
  background:
    repeating-linear-gradient(90deg, rgba(255,220,160,.025) 0 2px, transparent 2px 5px),
    repeating-linear-gradient(0deg, rgba(0,0,0,.08) 0 2px, transparent 2px 4px),
    var(--panel);
  border-top: 1px solid var(--line);
  transition: margin-bottom .45s cubic-bezier(.2,.8,.2,1), opacity .3s;
}
#app.is-intro #panel, #app.panel-hidden #panel { margin-bottom: -340px; opacity: 0; pointer-events: none; }
.sources, .chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 14px; scrollbar-width: none; }
.sources::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.src {
  flex: 0 0 auto; width: 54px; height: 54px; border-radius: 12px; overflow: hidden; position: relative;
  border: 1.5px solid var(--line); background: #140b05; color: var(--cream); padding: 0;
}
.src img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .82; }
.src span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9.5px; background: linear-gradient(transparent, rgba(0,0,0,.75)); padding: 8px 0 3px; text-align: center; }
.src.act { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; }
.src.act i { font-style: normal; font-size: 19px; line-height: 1; color: var(--accent2); }
.src.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(242,154,54,.25), 0 0 14px rgba(242,154,54,.35); }
.src.on img { opacity: 1; }

.tabs { display: flex; gap: 18px; padding: 12px 16px 8px; }
.tab { background: none; color: var(--dim); font-size: 13px; padding: 2px 0; position: relative; }
.tab.on { color: var(--cream); font-weight: 600; }
.tab.on::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: -5px; height: 2px; background: var(--accent); border-radius: 2px; }
.tabBody { display: none; min-height: 44px; }
.tabBody.on { display: block; }
.chip {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  background: rgba(255,230,190,.06); color: var(--cream); border: 1px solid var(--line); font-size: 13px;
}
.chip.on { background: rgba(242,154,54,.18); border-color: var(--accent); color: var(--accent2); }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); }
.chip .gl { font: 700 13px var(--mono); color: var(--accent2); min-width: 16px; text-align: center; }

.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; padding: 0 16px; }
.sliders label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; height: 22px; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: rgba(247,222,176,.2); border-radius: 3px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; margin-top: -6.5px; background: var(--accent2); box-shadow: 0 0 10px rgba(255,190,90,.7); }
input[type=range]::-moz-range-track { height: 3px; background: rgba(247,222,176,.2); border-radius: 3px; }
input[type=range]::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--accent2); }

.actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px 0; }
.hint { font-size: 11.5px; color: var(--dim); }
.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  padding: 11px 20px; border-radius: 999px; font-size: 14.5px; font-weight: 600; letter-spacing: 1px;
}
.primary { color: #2a1405; background: linear-gradient(180deg, #ffd88a, #f29a36); box-shadow: 0 4px 18px rgba(242,154,54,.45), inset 0 1px 0 rgba(255,255,255,.5); }
.secondary { color: var(--cream); background: rgba(255,230,190,.08); border: 1px solid rgba(247,222,176,.3); }
.primary:disabled, .secondary:disabled { opacity: .45; }
.big { padding: 15px 44px; font-size: 17px; }

/* ---------- intro ---------- */
#intro {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 56px) 20px calc(env(safe-area-inset-bottom) + 28px);
  background: linear-gradient(rgba(12,6,2,.62), rgba(12,6,2,0) 36%, rgba(12,6,2,0) 52%, rgba(12,6,2,.86));
  transition: opacity .6s, visibility .6s;
  pointer-events: none;
}
#intro > * { pointer-events: auto; }
#app:not(.is-intro) #intro { opacity: 0; visibility: hidden; }
.introTop { text-align: center; pointer-events: none !important; }
#titleDots { width: 100%; max-width: 420px; height: auto; filter: drop-shadow(0 0 10px rgba(255,180,80,.5)); }
.sub { margin: 6px 0 0; font-size: 15px; letter-spacing: 4px; color: var(--cream); text-shadow: 0 1px 8px rgba(0,0,0,.6); }
.introBottom { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.feat { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; width: 100%; max-width: 330px; }
.feat li { font-size: 13px; color: var(--cream); display: flex; gap: 10px; align-items: center; text-shadow: 0 1px 6px rgba(0,0,0,.8); }
.feat i { font: 11px var(--mono); font-style: normal; color: var(--accent2); border: 1px solid rgba(255,210,122,.45); border-radius: 6px; padding: 2px 5px; }
.tiny { margin: 0; font: 10.5px var(--mono); color: var(--dim); letter-spacing: 1px; }

/* ---------- poster ---------- */
#poster {
  position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background:
    repeating-linear-gradient(90deg, rgba(255,220,160,.025) 0 2px, transparent 2px 5px),
    #1a0f07;
}
#poster[hidden], #result[hidden] { display: none; }
.posterHead { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--dim); }
.posterStage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
#posterCanvas { max-width: 100%; max-height: 100%; aspect-ratio: 3 / 4; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,.6), 0 0 0 1px var(--line); touch-action: none; }
.posterForm { display: flex; gap: 10px; align-items: center; }
.place { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--dim); background: rgba(255,230,190,.06); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.place input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--cream); font-size: 15px; padding: 11px 0; }
.posterActions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- result ---------- */
#result { position: absolute; inset: 0; z-index: 10; background: rgba(8,4,2,.82); display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.resultCard { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
#resultTip { margin: 0; font-size: 13px; color: var(--dim); }
#resultMedia { width: 100%; display: flex; justify-content: center; }
#resultMedia img, #resultMedia video { max-width: 100%; max-height: 62dvh; max-height: 62vh; border-radius: 6px; box-shadow: 0 0 0 1px var(--line); }
.resultBtns { display: flex; gap: 10px; }
