* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif; color: #fff; cursor: none; }
body.panel-open { cursor: auto; }

#stage { position: fixed; inset: 0; background: #000; }
#avatarVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; transition: opacity .6s ease; }
#avatarVideo.prestart { opacity: 0; } /* hidden start: Vidu's forced opening is never seen */

#logo { position: absolute; top: 3vh; right: 3vw; height: 6vh; max-width: 18vw; object-fit: contain; opacity: .9; pointer-events: none; }

#captions {
  position: absolute; left: 50%; bottom: 7vh; transform: translateX(-50%);
  width: min(80vw, 1400px); text-align: center; pointer-events: none;
}
#captionText {
  font-size: clamp(20px, 2.6vw, 44px); line-height: 1.3; font-weight: 500; letter-spacing: .01em;
  text-shadow: 0 1px 2px rgba(0,0,0,.9), 0 0 12px rgba(0,0,0,.7);
  transition: opacity .3s;
}
#captionText.fade { opacity: 0; }

#micDot {
  position: absolute; left: 18px; bottom: 18px; width: 10px; height: 10px; border-radius: 50%;
  background: #444; opacity: .75; transition: background .1s;
}
#micDot[data-state="muted"] { background: #c0392b; }
#micDot[data-state="live"] { background: #2ecc71; box-shadow: 0 0 8px #2ecc71; }
#micDot[data-state="open"] { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46,204,113,.35); }
#micDot[data-state="warming"] { background: #f1c40f; animation: pulse 1s infinite; }
#micDot.error { outline: 2px solid #f39c12; outline-offset: 3px; }
#micDot.hidden { display: none; }
@keyframes pulse { 50% { opacity: .3; } }

#panel {
  position: fixed; top: 12px; right: 12px; width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
  background: rgba(18,18,20,.94); border: 1px solid #333; border-radius: 10px; font-size: 13px; z-index: 10;
}
#panel[hidden] { display: none; }
/* round icon buttons: grid-centred inline SVG, so glyph metrics can't push the icon off-centre */
#panelClose, #panelToggle { display: grid; place-items: center; padding: 0; line-height: 1; cursor: pointer; }
#panelClose svg, #panelToggle svg, .sc-close svg { display: block; pointer-events: none; }
#panelClose { order: 99; margin-left: auto; flex: none; align-self: center; width: 26px; height: 26px; border-radius: 50%; border: 1px solid #444;
  background: #222; color: #ddd; }
#panelClose { position: relative; }
#panelClose::before, #panelClose::after { content: ''; position: absolute; left: 50%; top: 50%; width: 13px; height: 2px;
  border-radius: 1px; background: #ddd; transform: translate(-50%, -50%) rotate(45deg); }
#panelClose::after { transform: translate(-50%, -50%) rotate(-45deg); }
#panelClose:hover { background: #333; }
/* corner toggle: clearly visible while rehearsing, near-invisible on stage until hovered */
#panelToggle { position: fixed; right: 12px; bottom: 12px; z-index: 11; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.25); background: rgba(20,20,22,.7); color: #eee;
  opacity: .9; transition: opacity .3s; }
#panelToggle svg { width: 18px; height: 18px; }
body:not(.panel-open) #panelToggle { opacity: .08; }
body:not(.panel-open) #panelToggle:hover { opacity: .9; }
#panel header { display: flex; gap: 10px; align-items: center; }
#statusLabel { color: #9ad; }
#timer { margin-left: auto; font-variant-numeric: tabular-nums; color: #bbb; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
button { background: #2a2a30; color: #fff; border: 1px solid #444; border-radius: 6px; padding: 6px 10px; font: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.active, #pttBtn:active { background: #2e7d4f; }
.check { display: inline-flex; gap: 4px; align-items: center; color: #ccc; }
#textInput { flex: 1; min-width: 0; background: #111; color: #fff; border: 1px solid #444; border-radius: 6px; padding: 6px 8px; font: inherit; }
#errorBox { background: #4a1d1d; border: 1px solid #a33; border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; }
#log { margin: 0; padding: 0 0 0 16px; overflow: auto; flex: 1; min-height: 80px; max-height: 45vh; font: 11px/1.4 ui-monospace, Menlo, monospace; color: #bbb; word-break: break-word; }
#log li.err { color: #f88; }
#langToggle { display: inline-flex; flex: 1; border: 1px solid #555; border-radius: 8px; overflow: hidden; }
#langToggle button { flex: 1; border: 0; border-radius: 0; padding: 9px 12px; font-weight: 600; font-size: 1.05em; background: #1b1b20; color: #aaa; }
#langToggle button + button { border-left: 1px solid #555; }
#langToggle button.on { background: #2e7d4f; color: #fff; }
#langHint { color: #999; font-size: .9em; width: 100%; }
#saveBtn { margin-left: auto; }
#textLabel { color: #ddd; font-weight: 600; }
.notice { background: #3a3417; border: 1px solid #8a7a2a; border-radius: 6px; padding: 4px 8px; color: #f1e3a0; }
#log li.yunai { color: #e6e6f0; }
#log li .tr { color: #8fd1a8; padding-left: 1em; }
#panel footer { color: #777; font-size: 11px; }
#directorRow { border-top: 1px solid #333; padding-top: 8px; }
.dir-title { color: #ddd; }
#beatLabel { color: #f1e3a0; font-variant-numeric: tabular-nums; }
#directorRow .check { margin-left: auto; }
#beatRow button[hidden] { display: none; }
#beatRow button.done { opacity: .55; text-decoration: line-through; }
#beatRow button.done:disabled { opacity: .3; }

/* ---------- song card (yunai.music glass) ---------- */
/* Layer matches the contained 16:9 video box so placement is frame-relative, not window-relative. */
#songLayer, #igLayer {
  --paper: #f6efe6; --muted: rgba(246,239,230,.62); --pale: 197,223,233; --teal: 64,132,145;
  --glass: rgba(255,255,255,.026); --glass-2: rgba(255,255,255,.008);
  --edge: rgba(255,255,255,.13); --lip: rgba(255,255,255,.28); --ease: cubic-bezier(.22,.61,.36,1);
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: min(100vw, 177.78vh); aspect-ratio: 16 / 9; container-type: inline-size;
  pointer-events: none; z-index: 5;
}
.sc-card {
  position: absolute; right: 4%; top: 50%; width: 24%;
  display: flex; flex-direction: column; align-items: center; gap: .9cqw; padding: 1.5cqw 1.5cqw 1.3cqw;
  color: var(--paper); font: 1cqw/1.45 ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  background: linear-gradient(160deg, rgba(255,255,255,.07), var(--glass) 40%, var(--glass-2)), rgba(12,9,7,.28);
  border: 1px solid var(--edge); border-radius: 18px;
  box-shadow: inset 0 1px 0 var(--lip), 0 0 0 1px rgba(var(--pale),.06), 0 24px 60px -24px rgba(0,0,0,.7), 0 10px 40px -20px rgba(var(--teal),.55);
  backdrop-filter: blur(22px) saturate(1.6); -webkit-backdrop-filter: blur(22px) saturate(1.6);
  opacity: 0; translate: 3cqw -50%; visibility: hidden;
  transition: opacity .4s var(--ease), translate .4s var(--ease), visibility 0s linear .4s;
}
#songLayer.show .sc-card { opacity: 1; translate: 0 -50%; visibility: visible; pointer-events: auto; transition-delay: 0s; cursor: auto; }
.sc-close {
  position: absolute; top: .7cqw; right: .7cqw; width: 1.9cqw; height: 1.9cqw; min-width: 22px; min-height: 22px; padding: 0;
  display: grid; place-items: center; line-height: 1; color: var(--muted);
  background: rgba(255,255,255,.04); border: 1px solid var(--edge); border-radius: 999px;
}
.sc-close svg { width: 1cqw; height: 1cqw; min-width: 11px; min-height: 11px; }
.sc-close:hover { color: var(--paper); border-color: rgba(var(--pale),.55); }
.sc-logo { height: 1.7cqw; width: auto; opacity: .95; margin-bottom: .2cqw; }
.sc-thumb {
  width: 100%; aspect-ratio: 5 / 4; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--edge); box-shadow: inset 0 1px 0 var(--lip), 0 12px 30px -16px rgba(0,0,0,.8);
}
.sc-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 45%; display: block; }
.sc-title { font-size: 1.75cqw; font-weight: 600; letter-spacing: .01em; white-space: nowrap; margin-top: .3cqw; }
.sc-sub { font-size: .95cqw; color: var(--muted); letter-spacing: .06em; margin-top: -.5cqw; }
.sc-pills { display: flex; gap: .6cqw; width: 100%; }
.sc-pill {
  flex: 1; display: flex; justify-content: center; align-items: center; gap: .45cqw;
  padding: .65cqw .9cqw; border-radius: 999px; font-size: 1.05cqw; font-weight: 500;
  color: var(--paper); text-decoration: none;
  background: linear-gradient(160deg, var(--glass), var(--glass-2)); border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--lip), 0 6px 20px -12px rgba(0,0,0,.6);
  transition: border-color .3s var(--ease), background .35s var(--ease), box-shadow .35s var(--ease);
}
.sc-pill span { opacity: .45; transition: opacity .3s var(--ease), translate .3s var(--ease); }
.sc-pill:hover {
  background: linear-gradient(160deg, rgba(var(--pale),.13), rgba(var(--teal),.06)); border-color: rgba(var(--pale),.55);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.42), 0 0 0 1px rgba(var(--pale),.12), 0 10px 30px -14px rgba(var(--teal),.6);
}
.sc-pill:hover span { opacity: 1; translate: 3px 0; color: rgb(var(--pale)); }
.sc-qr { display: flex; align-items: center; gap: .8cqw; width: 100%; padding-top: .7cqw; border-top: 1px solid rgba(255,255,255,.08); }
.sc-qr[hidden] { display: none; }
.sc-qr-code { width: 5.2cqw; flex: none; padding: .25cqw; background: var(--paper); border-radius: 8px; line-height: 0; }
.sc-qr-code svg { width: 100%; height: auto; display: block; }
.sc-qr-note { font-size: .9cqw; color: var(--muted); letter-spacing: .06em; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .sc-card { background: rgba(28,24,22,.86); }
}
/* Music-video mode: card grows to ~34% of the frame (still right of her centered face), 16:9 video on top. */
.sc-card { transition: opacity .4s var(--ease), translate .4s var(--ease), width .5s var(--ease), right .5s var(--ease), visibility 0s linear .4s; }
.sc-mv { display: none; position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000;
  border: 1px solid var(--edge); box-shadow: inset 0 1px 0 var(--lip), 0 12px 30px -16px rgba(0,0,0,.8); transition: opacity 1.2s var(--ease); }
.sc-mv.fading { opacity: 0; }
.sc-mv-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.sc-mv-unmute {
  position: absolute; left: 50%; bottom: 8%; translate: -50% 0; padding: .45cqw 1cqw; border-radius: 999px;
  font: inherit; font-size: .95cqw; font-weight: 500; line-height: 1.2; color: var(--paper); background: rgba(12,9,7,.72); border: 1px solid rgba(var(--pale),.55); cursor: pointer;
}
.sc-mv-unmute[hidden] { display: none; }
.sc-card.mv { width: 34%; right: 3%; gap: .6cqw; padding: 1.1cqw 1.1cqw 1cqw; }
.sc-card.mv .sc-thumb { display: none; }
.sc-card.mv .sc-mv { display: block; }
.sc-card.mv .sc-logo { height: 1.3cqw; margin-bottom: 0; }
.sc-card.mv .sc-title { font-size: 1.35cqw; margin-top: .1cqw; }
.sc-card.mv .sc-sub { font-size: .8cqw; margin-top: -.45cqw; }
.sc-card.mv .sc-pill { padding: .45cqw .7cqw; font-size: .85cqw; }
.sc-card.mv .sc-qr { padding-top: .45cqw; gap: .6cqw; }
.sc-card.mv .sc-qr-code { width: 3.8cqw; }
.sc-card.mv .sc-qr-note { font-size: .8cqw; }
@media (prefers-reduced-motion: reduce) { .sc-card, .sc-mv { transition: none; } }

/* ---------- Instagram card (same glass, taller: 9:16 clip) ---------- */
.ig-card {
  position: absolute; right: 3.5%; top: 50%; width: 22%; max-height: 94%;
  display: flex; flex-direction: column; gap: .75cqw; padding: 1.1cqw 1.1cqw 1.1cqw;
  color: var(--paper); font: 1cqw/1.45 ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif;
  background: linear-gradient(160deg, rgba(255,255,255,.07), var(--glass) 40%, var(--glass-2)), rgba(12,9,7,.28);
  border: 1px solid var(--edge); border-radius: 18px;
  box-shadow: inset 0 1px 0 var(--lip), 0 0 0 1px rgba(var(--pale),.06), 0 24px 60px -24px rgba(0,0,0,.7), 0 10px 40px -20px rgba(var(--teal),.55);
  backdrop-filter: blur(22px) saturate(1.6); -webkit-backdrop-filter: blur(22px) saturate(1.6);
  opacity: 0; translate: 3cqw -50%; visibility: hidden;
  transition: opacity .4s var(--ease), translate .4s var(--ease), visibility 0s linear .4s;
}
#igLayer.show .ig-card { opacity: 1; translate: 0 -50%; visibility: visible; pointer-events: auto; transition-delay: 0s; cursor: auto; }
.ig-head { display: flex; align-items: center; gap: .6cqw; padding-right: 2.4cqw; min-height: 1.9cqw; }
.ig-logo { height: 1.25cqw; width: auto; opacity: .95; flex: none; }
.ig-handle { font-size: 1cqw; font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.ig-label { margin-left: auto; font-size: .78cqw; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
.ig-frame {
  position: relative; width: 100%; aspect-ratio: 9 / 16; border-radius: 12px; overflow: hidden; background: rgba(0,0,0,.35);
  border: 1px solid var(--edge); box-shadow: inset 0 1px 0 var(--lip), 0 12px 30px -16px rgba(0,0,0,.8);
}
.ig-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .4s var(--ease); }
.ig-frame[data-state="ready"] .ig-video { opacity: 1; }
.ig-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .8cqw;
  font-size: .95cqw; color: var(--muted); letter-spacing: .14em; text-transform: lowercase;
  background: radial-gradient(120% 80% at 50% 30%, rgba(var(--teal),.28), transparent 70%), linear-gradient(180deg, rgba(var(--pale),.06), rgba(0,0,0,.25));
}
.ig-ph-dot { width: 1.1cqw; height: 1.1cqw; border-radius: 50%; border: 1px solid rgba(var(--pale),.55); animation: igPulse 2.4s ease-in-out infinite; }
@keyframes igPulse { 50% { opacity: .35; transform: scale(.8); } }
.ig-frame[data-state="ready"] .ig-placeholder { display: none; }
.ig-sound {
  position: absolute; right: .7cqw; bottom: .7cqw; width: 2.2cqw; height: 2.2cqw; min-width: 24px; min-height: 24px; padding: 0;
  display: grid; place-items: center; color: var(--paper);
  background: rgba(12,9,7,.45); border: 1px solid var(--edge); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.ig-frame:not([data-state="ready"]) .ig-sound { display: none; }
.ig-sound svg { width: 58%; height: 58%; }
.ig-sound[data-muted="true"] .ig-waves, .ig-sound[data-muted="false"] .ig-x { display: none; }
.ig-sound:hover { border-color: rgba(var(--pale),.55); }
.ig-tapsound {
  position: absolute; left: 50%; bottom: 12%; translate: -50% 0; padding: .5cqw 1.1cqw; border-radius: 999px; white-space: nowrap;
  font: inherit; font-size: .95cqw; font-weight: 600; line-height: 1.2; color: var(--paper);
  background: rgba(12,9,7,.72); border: 1px solid rgba(var(--pale),.6); cursor: pointer; animation: igTap 1.6s ease-in-out infinite;
}
@keyframes igTap { 50% { opacity: .6; } }
.ig-tapsound[hidden] { display: none; }
.ig-replay {
  position: absolute; left: .7cqw; bottom: .7cqw; width: 2.2cqw; height: 2.2cqw; min-width: 24px; min-height: 24px; padding: 0;
  display: none; place-items: center; color: var(--paper);
  background: rgba(12,9,7,.45); border: 1px solid var(--edge); border-radius: 999px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.ig-frame[data-state="ready"][data-ended="true"] .ig-replay { display: grid; }
.ig-replay svg { width: 55%; height: 55%; }
.ig-replay:hover { border-color: rgba(var(--pale),.55); }
.ig-caption { font-size: .95cqw; color: var(--muted); letter-spacing: .04em; text-align: center; }
.ig-foot { display: flex; align-items: center; gap: .7cqw; }
.ig-follow { font-size: .95cqw; white-space: nowrap; }
.ig-qr { width: 3.8cqw; flex: none; padding: .2cqw; background: var(--paper); border-radius: 6px; line-height: 0; }
.ig-qr[hidden] { display: none; }
.ig-qr svg { width: 100%; height: auto; display: block; }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ig-card { background: rgba(28,24,22,.86); }
}
@media (prefers-reduced-motion: reduce) { .ig-card { transition: none; } }

/* ---------- drop screen: black over the whole stage, panel stays on top ---------- */
#dropCover { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 50; transition: opacity 600ms ease; }
#dropCover.on { opacity: 1; pointer-events: auto; }

/* ---------- overlays: film look (K) + noticing bubbles (N), mock5 ---------- */
/* Paint order: video < #filmLayer < bubbles (3) < logo / captions / mic dot (4) < cards (5) < drop screen (50). */
#logo, #captions, #micDot { z-index: 4; }
/* Film layer matches the contained 16:9 video box. No transform / z-index / containment on purpose:
   it must not form a stacking context, so its screen / soft-light blends reach the video beneath. */
#filmLayer {
  display: none; position: absolute; left: 50%; top: 50%; pointer-events: none;
  width: min(100vw, 177.78vh); height: min(56.25vw, 100vh);
  margin-left: calc(min(100vw, 177.78vh) / -2); margin-top: calc(min(56.25vw, 100vh) / -2);
}
#filmLayer > * { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
body.film #filmLayer { display: block; }
body.film #avatarVideo { filter: brightness(1.03) contrast(.9) saturate(.9) sepia(.1); }
.fl-bloom { filter: blur(18px) brightness(1.15) saturate(1.1); mix-blend-mode: screen; opacity: .2; }
.fl-lift { background: rgba(40,28,18,.10); mix-blend-mode: lighten; }
.fl-warm { background: linear-gradient(180deg, rgba(255,196,120,.07), rgba(255,160,90,.05)); mix-blend-mode: soft-light; }
.fl-fine { opacity: .045; mix-blend-mode: overlay; }
.fl-leak {
  mix-blend-mode: screen; opacity: .3; animation: flBreath 9s ease-in-out infinite;
  background: radial-gradient(30% 42% at 73% 20%, rgba(255,220,160,.85), rgba(255,175,95,.4) 45%, transparent 75%),
              radial-gradient(55% 16% at 80% 0%, rgba(255,95,55,.55), transparent 72%);
}
@keyframes flBreath { 50% { opacity: .24; } }
.fl-gate { border-radius: calc(min(100vw, 177.78vh) * .022);
  box-shadow: inset 0 0 0 calc(min(100vw, 177.78vh) * .005) #000, inset 0 0 calc(min(100vw, 177.78vh) * .032) calc(min(100vw, 177.78vh) * .012) rgba(0,0,0,.5); }

#bubbleLayer {
  --paper: #f6efe6; --pale: 197,223,233; --glass: rgba(255,255,255,.07); --glass-2: rgba(255,255,255,.02);
  --edge: rgba(255,255,255,.16); --lip: rgba(255,255,255,.32); --ease: cubic-bezier(.22,.61,.36,1);
  position: absolute; left: 50%; top: 50%; translate: -50% -50%;
  width: min(100vw, 177.78vh); aspect-ratio: 16 / 9; container-type: inline-size;
  pointer-events: none; z-index: 3; display: none; transition: opacity .5s var(--ease);
}
#bubbleLayer.on { display: block; }
#bubbleLayer.hush { opacity: 0; }
.bb-list { position: absolute; left: 3.2%; bottom: 6%; width: 31%; display: flex; flex-direction: column; gap: .6cqw; align-items: flex-start; }
.bb-pill {
  position: relative; display: flex; align-items: center; gap: .8cqw; max-width: 100%;
  padding: .85cqw 1.3cqw .85cqw 1cqw; border-radius: 999px; color: var(--paper);
  font: 400 clamp(13px, 1.2cqw, 22px)/1.3 ui-sans-serif, -apple-system, 'Hiragino Sans', 'Segoe UI', Inter, system-ui, sans-serif; letter-spacing: .02em;
  background: linear-gradient(160deg, var(--glass), var(--glass-2)); border: 1px solid var(--edge);
  box-shadow: inset 0 1px 0 var(--lip), inset 0 -1px 0 rgba(0,0,0,.18), 0 8px 22px -14px rgba(0,0,0,.7);
  -webkit-backdrop-filter: blur(22px) saturate(1.6); backdrop-filter: blur(22px) saturate(1.6);
  overflow: hidden; opacity: 0; transform: translateY(10px); transition: opacity .5s var(--ease), transform .5s var(--ease);
}
.bb-pill.in { opacity: 1; transform: none; }
.bb-pill.old { opacity: .55; }
.bb-pill.older { opacity: .28; }
.bb-pill::before { content: ''; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 30%, rgba(255,248,238,.13) 48%, transparent 66%);
  translate: -110% 0; transition: translate .9s var(--ease); }
.bb-pill.in::before { translate: 110% 0; }
.bb-dot { flex: none; width: .55cqw; height: .55cqw; min-width: 7px; min-height: 7px; border-radius: 50%; background: rgb(var(--pale)); box-shadow: 0 0 10px rgba(var(--pale),.8); }
.bb-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bb-caret { display: inline-block; width: .07em; height: 1em; margin-left: .08em; vertical-align: -.12em; background: var(--paper); animation: bbBlink 1s steps(1) infinite; }
@keyframes bbBlink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .fl-leak { animation: none; } .bb-pill, .bb-pill::before { transition: none; } }
