/* =========================================================================
   迓神季文化創意 · 擲筊 LIFF
   v3 — adds LIFF login, profile pill, friend prompt, share button
   Design constraints:
   - 直屏 portrait, adaptive phone width (iPhone SE 320 up to Pro Max 430)
   - 320×320 click area centered
   - LIFF safe-area aware (viewport-fit=cover + env(safe-area-inset-*))
   ========================================================================= */

:root {
  --brand-red:    #8b0000;
  --brand-red-2:  #c0162a;
  --brand-cream:  #fdf6e8;
  --brand-gold:   #b8862a;
  --brand-gold-deep: #6e4f1d;     /* tarnished brass for v10 frame */
  --brand-candle: #ff8c3c;        /* warm candle-glow for v10 accents */
  --ink:          #1a0d0d;
  --muted:        #6b5a5a;
  --stage-bg:     #fff7eb;
  --stage-ring:   #f0d9a8;
  --line-green:   #06c755;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC",
               "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: var(--brand-cream);
  color: var(--ink);
  overflow-x: hidden;
  -webkit-user-select: none;
          user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top:    env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ────────────────── HEADER ────────────────── */
.brand-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--brand-red) 0%, var(--brand-red-2) 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
}

.brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2px solid var(--brand-gold);
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.05em;
  /* v11: prevent the 7-char title from wrapping when profile pill
     squeezes the flex container. Truncate with ellipsis if needed
     rather than breaking the title mid-character. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
  letter-spacing: 0.3em;
  margin-top: 2px;
  white-space: nowrap;
}

/* User profile pill (populated by LIFF after login) */
.profile-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.18);
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.35);
  flex-shrink: 0;
  max-width: 130px;
}

.profile-pill[hidden] {
  display: none;
}

.profile-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.profile-name {
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ────────────────── STAGE / CLICK AREA ────────────────── */
.stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  /* v10: deep amber-brown wash so the cast-area looks like it's resting
     on a wooden altar table, not floating on a cream app background. */
  background:
    radial-gradient(ellipse at center,
      #2a1208 0%,
      #150805 70%,
      #080302 100%);
}

.cast-area {
  position: relative;
  width: min(320px, calc(100vw - 48px));
  aspect-ratio: 1 / 1;
  max-height: 60vh;
  border-radius: 24px;
  /* v10: candlelit-shrine style — match the GIF's warm chiaroscuro
     (dark wood altar + bronze oil lamp + amber candlelight bokeh).
     Layered backgrounds:
       1) outer halo: warm candle glow fading to deep brown-black
       2) inner radial: amber center mimicking oil-lamp spot
       3) corner vignette: deepens to near-black at edges */
  background:
    /* warm halo at center, fades to deep brown-black at edges */
    radial-gradient(ellipse 80% 70% at 50% 38%,
      rgba(255, 140, 60, 0.22) 0%,
      rgba(120, 50, 20, 0.10) 35%,
      rgba(20, 8, 4, 0.85) 75%,
      rgba(8, 3, 2, 1) 100%),
    /* base wood-tone darkening */
    linear-gradient(180deg, #1a0a04 0%, #0a0302 100%);
  /* v10: tarnished-brass double border — outer dim ring, inner brighter,
     creates a depth like a shrine altar frame, not a flat medal */
  border: 1px solid #3a2812;
  box-shadow:
    /* inner stroke — subtle brass highlight on the rim */
    inset 0 0 0 2px var(--brand-gold-deep),
    inset 0 0 0 3px rgba(184, 134, 42, 0.18),
    inset 0 0 50px rgba(0, 0, 0, 0.65),
    /* outer warm glow — candle flame aura */
    0 0 28px rgba(255, 140, 60, 0.18),
    0 0 60px rgba(255, 100, 40, 0.08),
    0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
  outline: none;
}

.cast-area:active {
  transform: scale(0.97);
  box-shadow:
    0 0 0 4px rgba(255,255,255,.6),
    0 4px 12px rgba(139, 0, 0, .25),
    inset 0 0 30px rgba(184, 134, 42, .15);
}

.cast-area:focus-visible {
  outline: 3px solid var(--brand-gold);
  outline-offset: 2px;
}

.cast-static,
.cast-anim,
.cast-final {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.cast-anim,
.cast-final {
  opacity: 0;
  pointer-events: none;
}

.cast-area.is-playing .cast-anim {
  opacity: 1;
  /* v28.1: fade out 250ms when transitioning to is-frozen, sync with cast-final fade in */
  transition: opacity 250ms ease-in;
}

.cast-area.is-playing .cast-static,
.cast-area.is-playing .cast-hint {
  opacity: 0;
}

.cast-area.is-frozen .cast-final {
  opacity: 1;
  /* v28.1: fade in 250ms to match GIF_OVERLAP_MS, smooth visual transition during overlap */
  transition: opacity 250ms ease-out;
}

.cast-area.is-frozen .cast-anim {
  opacity: 0;
}

.cast-area.is-frozen .cast-static,
.cast-area.is-frozen .cast-hint {
  opacity: 0;
}

.cast-area:not(.is-playing) {
  cursor: pointer;
}

.cast-area:not(.is-playing):active {
  transform: scale(0.97);
}

/* ────────────────── FOOTER ────────────────── */
.brand-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border-top: 1px solid rgba(139, 0, 0, .12);
  color: var(--muted);
}

.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.05em;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(6, 199, 85, .35);
  transition: transform .1s ease, box-shadow .1s ease;
}

.share-btn:active {
  transform: scale(0.98);
  box-shadow: 0 1px 3px rgba(6, 199, 85, .35);
}

.share-btn[hidden] {
  display: none;
}

.share-icon {
  font-size: 18px;
}

.footer-credit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-top: 4px;
}

.skytech-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.footer-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.footer-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--brand-red);
}

.footer-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.02em;
}

/* v26: BGM attribution hidden per user 2026-07-10
   (Bgm credit removed from visible page; 竹林问卦 AI-generated, no human artist,
   no attribution legal requirement) */
.bgm-credit {
  display: none;
}

/* =========================================================================
   v21: Welcome overlay — full-bleed banner image (user-supplied 2026-07-09)
   - Image (welcome_v23.jpg) is a self-contained mobile banner: 金冕媽祖
     + 「點擊擲筊」+「立即開始」CTA + 兩舊大月牙 + 「天上聖母/慈悲護佑」副標題
   - Overlay does NOT add any text on top — banner already delivers
   - Tap anywhere dismisses overlay + starts cast
   - Header (red bar) is HIDDEN during welcome so its text doesn't overlap
     banner's own title. JS re-enables after dismiss.
   - CC-BY credit kept at very bottom (smallest, lowest contrast) to satisfy
     attribution without competing with banner's own CTAs
   ========================================================================= */
.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: url('assets/welcome_v28.jpg?v=29') center / cover no-repeat;
  /* v24: cache-bust hack, 新 file name 強制 Cloudflare miss, file content 同 v23 一樣 */
  /* v23: 用戶 send 嘅新 image (720x1280 portrait 金冕媽祖 detailed 聖像, MD5 42257fb2..., 字唔出界), 取代 v21 square banner */
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top, 0px)
    16px
    calc(env(safe-area-inset-bottom, 0px) + 32px);
  animation: welcomeFadeIn 400ms ease-out;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(255, 215, 130, 0.18);
}
.welcome-overlay.is-dismissed {
  animation: welcomeFadeOut 400ms ease-in forwards;
  pointer-events: none;
}

/* v26: BGM attribution hidden per user 2026-07-10
   (Welcome overlay credit removed from visible page) */
.welcome-credits {
  display: none;
}

@keyframes welcomeFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes welcomeFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; visibility: hidden; }
}

/* v21: header hidden while welcome active (overlap fix) */
body.welcome-active .brand-header {
  visibility: hidden;
}

/* ────────────────── RESPONSIVE TWEAKS ────────────────── */
@media (max-width: 360px) {
  .brand-name    { font-size: 16px; }
  .brand-sub     { font-size: 12px; }
  .brand-logo    { width: 48px; height: 48px; }
  .profile-pill  { max-width: 100px; }
  .profile-name  { max-width: 70px; }
  .stage         { padding: 16px 12px; }
  .cast-area     { width: min(280px, calc(100vw - 32px)); }
}

@media (min-width: 480px) {
  .cast-area     { width: 320px; max-height: 50vh; }
}

@media (orientation: landscape) and (max-height: 480px) {
  .cast-area     { max-height: 70vh; }
  .share-btn     { padding: 8px 12px; font-size: 13px; }
}