/* 介面樣式：正式設計素材（public/assets/ui/，由 tools/build-assets.py 產生）。
   設計稿是 720×1280，舞台是 375×667（見 stage.css）；--u 是「設計稿 1px」換成舞台單位的長度，
   每個元件在 HTML 上用 --x／--y／--w（設計稿像素）定位，換位置只要改數字。 */
#stage {
  --u: calc(375px / 720);
  color: #fff;
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  background: #050b3c;
}
#stage img { display: block; -webkit-user-drag: none; -webkit-touch-callout: none; }

.screen {
  position: absolute;
  inset: 0;
  text-align: center;
  animation: screen-in .22s ease-out;
}
/* 換畫面淡入：只動 opacity（不動版面、不觸發重排），也不會讓自動測試等不到元素穩定 */
@keyframes screen-in { from { opacity: 0; } }
/* 錄影畫面的 canvas 每格都在重畫，不需要再疊一層淡入 */
[data-screen="record"] { animation: none; }
/* .screen 之類設了 display 的元素，會蓋掉 hidden 屬性的預設 display:none */
.screen[hidden], .toast[hidden], .camera-error[hidden], .tag-vbg[hidden], .hint-icon[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 背景：整張鋪滿。首頁那張比畫面大一圈，置中後緩慢呼吸放大 */
.bg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; object-fit: cover; }
/* 首頁背景（含星星光效 canvas）不跟著舞台拉長：寬高固定成設計稿比例（720×1280），星星與標題的大小比例才會跟設計稿一樣；
   手機比 9:16 長時整塊往下移一點（跟標題、logo 同一個 --a）；比 9:16 寬時置中、不跟著變寬（變寬會把星星放大、頂到標題）。
   多出來的上下左右用跟圖片邊緣同色的漸層補（11-23） */
.screen[data-screen="home"] { background: linear-gradient(90deg, #000a3d, #010e57 50%, #00083c); }
.bg-home { top: calc(var(--ext, 0px) * .3 + 48 * var(--u)); /* 整張往下 48（設計稿 px），星星跟標題留點間隔（11-23 要求） */ left: calc(var(--extx, 0px) * .5); width: calc(720 * var(--u)); height: calc(1280 * var(--u)); animation: bg-breathe 9s ease-in-out infinite alternate; }
/* 11-26：首頁改放循環影片，影片本身已有動態，背景不再做呼吸縮放 */
.screen[data-screen="home"] .bg-home { animation: none; transform: scale(1.02); }
.bg-video { pointer-events: none; }
@keyframes bg-breathe { from { transform: scale(1.02); } to { transform: scale(1.1); } }

/* 金粉與星芒（js/ambient.js 畫的），在背景上面、元件下面；錄影畫面不顯示 */
#fxCanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; z-index: 1; mix-blend-mode: screen; }
#stage[data-screen="record"] #fxCanvas { display: none; }
.screen > :not(.bg) { z-index: 2; }

/* 元件：絕對定位＋進場（由下往上浮現，--d 越大越晚） */
.art {
  position: absolute;
  left: calc(var(--x) * var(--u) + var(--extx, 0px) * var(--ax, .5)); /* --extx＝偏寬的手機舞台多出的寬度；--ax 0 貼左、.5 置中、1 貼右 */
  top: calc(var(--y) * var(--u) + var(--ext, 0px) * var(--a, 0)); /* --ext＝手機比 9:16 長時舞台多出的高度（stage-fit.js）；--a 0 貼上、.5 跟著中間、1 貼底 */
  width: calc(var(--w) * var(--u));
  margin: 0;
  animation: art-in .5s cubic-bezier(.2, .9, .3, 1.15) both;
  animation-delay: calc(var(--d, 0) * 90ms + 60ms);
}
.art > img { width: 100%; height: auto; }
img.art { height: auto; }
@keyframes art-in { from { opacity: 0; transform: translateY(calc(26 * var(--u))) scale(.96); } }

/* 圖片按鈕：按下去立刻有反饋（手機沒有 hover，沒反饋會以為沒點到）。
   無限循環的動畫只掛在裡面的 .shine，不掛在按鈕本身（按鈕一直在動會讓自動測試等不到它穩定） */
.art-btn { display: block; padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; overflow: visible; }
.art-btn > img { width: 100%; height: auto; transition: transform .08s ease-out, filter .08s ease-out; }
.art-btn:active > img { transform: scale(.95); filter: brightness(.88); }
/* 金色按鈕上每隔幾秒掃過一道光 */
.shine { position: absolute; left: 6%; right: 6%; top: 12%; bottom: 22%; border-radius: calc(12 * var(--u)); overflow: hidden; pointer-events: none; }
.shine::after {
  content: ""; position: absolute; top: -20%; bottom: -20%; left: -40%; width: 32%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, .75), transparent);
  transform: skewX(-20deg); animation: shine 3.6s ease-in-out infinite;
}
@keyframes shine { 0%, 62% { left: -40%; } 100% { left: 120%; } }

/* 標題字：進場後偶爾閃一下亮度 */
h1.art > img, h2.art > img { animation: title-glint 4.5s ease-in-out 1s infinite; }
@keyframes title-glint { 0%, 78%, 100% { filter: brightness(1); } 88% { filter: brightness(1.35) drop-shadow(0 0 calc(10 * var(--u)) rgba(255, 214, 120, .7)); } }

/* 03 相框瀏覽 */
.frame-preview { overflow: visible; }
.frame-preview > img { width: 100%; height: auto; filter: drop-shadow(0 calc(10 * var(--u)) calc(22 * var(--u)) rgba(0, 0, 0, .5)); }
.frame-preview.is-next > img { animation: slide-next .28s cubic-bezier(.2, .9, .3, 1.1); }
.frame-preview.is-prev > img { animation: slide-prev .28s cubic-bezier(.2, .9, .3, 1.1); }
@keyframes slide-next { from { opacity: 0; transform: translateX(22%) scale(.94); } }
@keyframes slide-prev { from { opacity: 0; transform: translateX(-22%) scale(.94); } }
.tag-vbg { position: absolute; top: calc(-34 * var(--u)); right: 0; padding: calc(4 * var(--u)) calc(16 * var(--u)); border-radius: calc(20 * var(--u)); background: linear-gradient(#ffe08a, #e9a93a); color: #1a1140; font-size: calc(22 * var(--u)); font-weight: 700; }
.arrow > img { animation: arrow-nudge 1.6s ease-in-out infinite; }
.arrow[data-action="frame-prev"] > img { --dir: -1; }
@keyframes arrow-nudge { 50% { transform: translateX(calc(var(--dir, 1) * 8 * var(--u))); } }
.dots { position: absolute; left: 0; right: 0; top: calc(1014 * var(--u) + var(--ext, 0px)); display: flex; justify-content: center; gap: calc(14 * var(--u)); }
.dots i { width: calc(17 * var(--u)); height: calc(17 * var(--u)); border-radius: 50%; border: calc(1.5 * var(--u)) solid #e9ae3c; transition: background .2s, transform .2s; }
.dots i.is-on { background: #e9ae3c; transform: scale(1.15); }

/* 04 轉場頁 */
.loading-star > img { display: block; width: 100%; } /* 11-26：動態已做進 AE 動畫，不再用 CSS 浮動 */
@keyframes star-float { 0%, 100% { transform: translateY(0) rotate(-3deg) scale(1); filter: brightness(1); } 50% { transform: translateY(calc(-18 * var(--u))) rotate(3deg) scale(1.06); filter: brightness(1.25); } }
.loading-title {
  position: absolute; left: 0; right: 0; top: calc(590 * var(--u) + var(--ext, 0px) * .5); margin: 0; padding: 0 calc(40 * var(--u));
  font-size: calc(40 * var(--u)); font-weight: 800; font-style: italic; letter-spacing: calc(3 * var(--u)); color: #f2c468; text-shadow: 0 calc(3 * var(--u)) calc(8 * var(--u)) rgba(0, 0, 0, .6);
}
/* 預設文案用設計的標題圖（字還在，只是透明，給讀屏與測試用） */
.loading-title.is-art { top: calc(500 * var(--u) + var(--ext, 0px) * .5); height: calc(244 * var(--u)); padding: 0; color: transparent; text-shadow: none; background: url(../assets/ui/loading-title.webp) center / calc(665 * var(--u)) auto no-repeat; animation: loading-pulse 1.6s ease-in-out infinite; }
@keyframes loading-pulse { 50% { opacity: .65; } }
.camera-error { position: absolute; left: calc(60 * var(--u)); right: calc(60 * var(--u)); top: calc(760 * var(--u) + var(--ext, 0px) * .5); font-size: calc(28 * var(--u)); line-height: 1.6; }
.camera-error p { margin: 0 0 calc(30 * var(--u)); }
/* 前面有 #stage img { display: block }，這裡要帶 #stage 才蓋得過 */
#stage .camera-error:not([hidden]) + .notice-art { display: none; }
.text-btn { padding: calc(18 * var(--u)) calc(60 * var(--u)); border: calc(2 * var(--u)) solid #e9ae3c; border-radius: calc(12 * var(--u)); background: rgba(10, 10, 20, .7); color: #f6d48a; font: inherit; font-size: calc(30 * var(--u)); font-weight: 700; letter-spacing: calc(4 * var(--u)); cursor: pointer; }
.text-btn:active { transform: scale(.95); }

/* 05 相框錄影：鏡頭＋相框畫在 canvas（錄下來的就是這張），按鈕與提示是疊在上面的 DOM，不會被錄進去 */
/* 手機比 9:16 長時預覽用 cover 填滿（左右各裁一點）；錄下來的影片仍是完整的 720×1280 */
#recCanvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
#stage[data-fit="wide"] #recCanvas { object-fit: contain; background: #050b3c; } /* 偏寬時 cover 會裁掉上下的標題，改完整顯示 */
/* 動作示意圖：進畫面時出現幾秒就淡掉，不要一直擋著臉；錄影中不顯示 */
.hint-icon { position: absolute; left: 50%; top: calc(500 * var(--u) + var(--ext, 0px) * .5); width: calc(170 * var(--u)); height: auto; margin-left: calc(-85 * var(--u)); pointer-events: none; opacity: 0; filter: drop-shadow(0 0 calc(6 * var(--u)) rgba(0, 0, 0, .6)); }
.hint-icon.is-on { animation: hint-show 4.2s ease-in-out both; }
@keyframes hint-show {
  0% { opacity: 0; transform: scale(.7); }
  10% { opacity: 1; transform: scale(1) rotate(-8deg); }
  30% { transform: rotate(8deg); } 50% { transform: rotate(-8deg); } 70% { transform: rotate(8deg); }
  85% { opacity: 1; transform: rotate(0); }
  100% { opacity: 0; transform: scale(.9); }
}
.hint {
  position: absolute; left: 50%; top: calc(900 * var(--u) + var(--ext, 0px) * .75); transform: translateX(-50%);
  margin: 0; padding: calc(20 * var(--u)) calc(36 * var(--u)); border-radius: calc(12 * var(--u)); white-space: nowrap;
  background: rgba(17, 17, 17, .92); color: #fff; font-size: calc(32 * var(--u)); font-weight: 700; letter-spacing: calc(2 * var(--u)); pointer-events: none;
  animation: hint-bob 2.2s ease-in-out infinite;
}
/* 有設計圖的提示語：用圖，文字透明 */
.hint.has-art { width: calc(520 * var(--u)); height: calc(92 * var(--u)); padding: 0; background-color: transparent; background-position: center; background-size: 100% auto; background-repeat: no-repeat; color: transparent; }
@keyframes hint-bob { 50% { transform: translateX(-50%) translateY(calc(-8 * var(--u))); } }
.is-recording .hint { top: calc(960 * var(--u) + var(--ext, 0px) * .75); opacity: .9; animation: hint-bob 2.2s ease-in-out infinite, hint-fade .6s ease-out 3s forwards; } /* 錄影 3 秒後淡出，免得一直蓋住 04、05 底部標題（11-20） */
@keyframes hint-fade { to { opacity: 0; visibility: hidden; } }
.is-recording .hint-icon { display: none; }
.rec-status { position: absolute; left: 0; right: 0; top: calc(1222 * var(--u) + var(--ext, 0px)); margin: 0; font-size: calc(24 * var(--u)); font-weight: 600; letter-spacing: calc(2 * var(--u)); text-shadow: 0 1px 3px #000; }
/* 返回鍵（11-23 設計追加）：鏡頭畫面左上角，半透明白底＋金棕色返回箭頭（設計給的圖示）。DOM 疊層，不會錄進影片 */
.btn-back {
  position: absolute; left: calc(24 * var(--u) + var(--extx, 0px) * 0); top: calc(24 * var(--u)); width: calc(84 * var(--u)); height: calc(84 * var(--u));
  display: flex; align-items: center; justify-content: center; padding: 0; border: 0; border-radius: calc(20 * var(--u)); background: rgba(255, 255, 255, .55); cursor: pointer; z-index: 3;
  -webkit-tap-highlight-color: transparent; transition: transform .08s ease-out, background .08s;
}
.btn-back > img { width: 72%; height: auto; margin: 0 auto; }
.btn-back:active { transform: scale(.93); background: rgba(255, 255, 255, .75); }
.is-recording .btn-back { display: none; } /* 錄影中不顯示，免得誤觸中斷 */
.btn-switch { animation: none; display: none; } /* 先隱藏（使用者 11-20 要求）；要恢復就拿掉 display: none */
.is-recording .btn-switch { display: none; }
/* 錄影鈕：待機是設計的白色圓鈕；錄影中變成紅色方塊＋紅色進度環 */
.btn-rec {
  position: absolute; left: calc(294 * var(--u) + var(--extx, 0px) * .5); top: calc(1076 * var(--u) + var(--ext, 0px)); width: calc(132 * var(--u)); height: calc(132 * var(--u));
  padding: 0; border: 0; border-radius: 50%; background: url(../assets/ui/rec-idle.webp) center / 100% 100% no-repeat; cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease-out;
}
.btn-rec:active { transform: scale(.93); }
/* 進度環：寬高與位置要寫死（不要 inset＋width:auto）。iOS Safari／部分 App 內建瀏覽器對絕對定位的 SVG
   不會照 inset 撐開，改用 SVG 預設比例，環變大又往右下偏（11-23 實機回報）；旋轉中心也明確指定 */
.btn-rec svg { position: absolute; left: calc(-8 * var(--u)); top: calc(-8 * var(--u)); width: calc(100% + 16 * var(--u)); height: calc(100% + 16 * var(--u)); display: block; overflow: visible; transform: rotate(-90deg); transform-origin: 50% 50%; opacity: 0; }
.ring { fill: none; stroke-width: 5; stroke: #e60012; stroke-linecap: round; stroke-dasharray: 282.74; stroke-dashoffset: 282.74; }
.rec-dot { position: absolute; left: 50%; top: 50%; width: 0; height: 0; border-radius: calc(8 * var(--u)); background: #e60012; transform: translate(-50%, -50%); transition: width .15s, height .15s; }
.is-recording .btn-rec { background: #fff; }
.is-recording .btn-rec svg { opacity: 1; }
.is-recording .rec-dot { width: 42%; height: 42%; }

/* 06 結尾頁 */
.result-frame { aspect-ratio: 9 / 16; padding: calc(3 * var(--u)); background: linear-gradient(160deg, #f6d27a, #b8791f 45%, #ffe7a3 70%, #c98a2a); box-shadow: 0 calc(10 * var(--u)) calc(30 * var(--u)) rgba(0, 0, 0, .5); }
.result-video { display: block; width: 100%; height: 100%; object-fit: cover; background: #0a0f2e; }

.toast { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); max-width: 300px; padding: 8px 16px; border-radius: 8px; background: rgba(0, 0, 0, .85); font-size: 13px; z-index: 10; }

@media (prefers-reduced-motion: reduce) {
  .bg-home, .shine::after, h1.art > img, h2.art > img, .arrow > img, .loading-star > img, .hint { animation: none; }
}

/* ?tune 現場調校面板（不在舞台裡，不會被縮放；也不會被錄進影片） */
.tune-panel { position: fixed; top: 8px; left: 8px; z-index: 99; margin: 0; padding: 6px 8px; border-radius: 6px; background: rgba(0, 0, 0, .7); color: #9f9; font: 11px/1.4 ui-monospace, Menlo, monospace; pointer-events: none; white-space: pre; }
.tune-panel.is-hit { background: rgba(200, 40, 40, .85); color: #fff; }
