/* 古神巴拉拉 測試版 — 樣式(深色古神/惡魔賭場風,金+暗紅點綴)。純 CSS,無框架。 */
:root {
  --bg: #0a0b12;
  --bg2: #12131f;
  --panel: #161826;
  --line: rgba(255, 255, 255, 0.08);
  --gold-0: #ffe3a3;
  --gold-1: #e8b96a;
  --gold-2: #b9812c;
  --text: #eef1f7;
  --dim: #8b93a7;
  --red: #d24234;
  --violet: #8a5bd0;
  --cell: rgba(255, 255, 255, 0.05);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 50% -8%, rgba(36, 19, 41, 0.8) 0%, transparent 55%),
    radial-gradient(1000px 700px at 50% 110%, rgba(26, 16, 48, 0.8) 0%, transparent 55%),
    linear-gradient(180deg, rgba(10, 11, 18, 0.6), rgba(10, 11, 18, 0.82)),
    url('../assets/ui/bg.png') center center / cover no-repeat,
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  display: flex;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  overflow-x: hidden;
}
#app { width: 100%; max-width: 480px; min-height: 100dvh; display: flex; flex-direction: column; }

/* ── 頂列 ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 800; letter-spacing: 1px; font-size: 1.05rem;
  background: linear-gradient(90deg, var(--gold-0), var(--gold-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tag {
  font-size: 0.6rem; color: #1a0c06; -webkit-text-fill-color: #1a0c06;
  background: linear-gradient(160deg, var(--gold-0), var(--gold-2));
  padding: 2px 6px; border-radius: 999px; vertical-align: middle;
}
.wallet { font-size: 0.9rem; color: var(--dim); }
.wallet b { color: var(--gold-1); font-variant-numeric: tabular-nums; }

/* ── 舞台 ── */
.stage { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 14px; }
.crest-wrap { width: 100%; display: flex; justify-content: center; margin-top: -2px; }
.crest { height: clamp(44px, 11vw, 78px); width: auto; max-width: 92%; object-fit: contain; filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.65)); }

/* HUD */
.hud { width: min(92vw, 440px); display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.slab {
  display: flex; flex-direction: column; align-items: center; line-height: 1;
  padding: 5px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: linear-gradient(160deg, #241a2e, #14101c);
}
.slab-cap { font-size: 0.55rem; color: var(--dim); letter-spacing: 2px; }
.slab-val {
  font-size: 1.25rem; font-weight: 900; font-variant-numeric: tabular-nums;
  background: linear-gradient(90deg, var(--gold-0), var(--gold-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.slab-val.hot { background: linear-gradient(90deg, #ff9a6b, var(--red)); -webkit-background-clip: text; background-clip: text; }
.slab-val.bump { animation: bump 0.28s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.fg-hud {
  font-size: 0.78rem; font-weight: 700; color: var(--gold-0);
  padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(232, 185, 106, 0.4);
  background: rgba(232, 185, 106, 0.08);
}
.win-box { min-width: 90px; text-align: right; }
.win { font-size: 1.15rem; font-weight: 900; color: var(--gold-0); font-variant-numeric: tabular-nums; text-shadow: 0 0 14px rgba(255, 210, 120, 0.5); }

/* ── 5×5 盤面 ── */
.board-wrap {
  width: min(92vw, 440px); aspect-ratio: 1 / 1; padding: 10px; border-radius: 18px;
  background: linear-gradient(160deg, #1c1526, #0d0b14);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(120, 60, 160, 0.12);
}
.board { position: relative; width: 100%; height: 100%; }
.board.shake { animation: shake 0.5s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 3px) rotate(-0.6deg); }
  35% { transform: translate(6px, -3px) rotate(0.6deg); }
  55% { transform: translate(-5px, -2px); }
  75% { transform: translate(4px, 3px); }
}

.tile { position: absolute; padding: 3px; }
.tile .face {
  width: 100%; height: 100%; border-radius: 11px; position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--col) 55%, #fff 8%) 0%, var(--col) 45%, color-mix(in srgb, var(--col) 60%, #000 40%) 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -8px 16px rgba(0, 0, 0, 0.28);
}
.tile .glyph { font-size: clamp(18px, 6.2vw, 34px); line-height: 1; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
.tile .lab { font-size: clamp(7px, 2vw, 10px); font-weight: 800; letter-spacing: 0.5px; color: rgba(255, 255, 255, 0.9); text-transform: uppercase; }
.tile.giant .glyph { font-size: clamp(40px, 16vw, 96px); }
.tile.giant .lab { font-size: clamp(10px, 3vw, 15px); }
.tile.giant .face { border-color: rgba(255, 220, 130, 0.6); box-shadow: inset 0 0 0 2px rgba(255, 220, 130, 0.35), 0 0 26px rgba(255, 200, 100, 0.35); }

/* 美術圖(有圖時疊在色塊上,並隱藏 placeholder 文字) */
.tile .art { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 6%; pointer-events: none; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5)); }
.tile.has-art { --col: #12101a; }
.tile.has-art .glyph, .tile.has-art .lab { display: none; }

/* WILD / SCATTER / JP 特別框 */
.tile[data-sym="WILD"] .face { border-color: rgba(255, 220, 130, 0.75); box-shadow: inset 0 0 0 2px rgba(255, 220, 130, 0.45), 0 0 20px rgba(255, 200, 100, 0.45); }
.tile[data-sym="SC"] .face { border-color: rgba(255, 180, 90, 0.8); box-shadow: 0 0 22px rgba(240, 150, 60, 0.55); }
.tile[data-sym="JP"] .face { border-color: rgba(255, 230, 120, 0.85); box-shadow: 0 0 22px rgba(230, 190, 60, 0.6); }

/* 動畫:落下 / 中獎 / 消除 / WILD 生成 */
.tile.dropping { animation: drop 0.5s cubic-bezier(0.2, 0.9, 0.25, 1.05) both; animation-delay: var(--delay, 0ms); }
@keyframes drop { 0% { transform: translateY(-130%); opacity: 0; } 60% { opacity: 1; } 100% { transform: translateY(0); opacity: 1; } }
.tile.win .face { animation: winpulse 0.5s ease-in-out infinite alternate; z-index: 3; }
@keyframes winpulse { from { transform: scale(1); box-shadow: inset 0 0 0 2px #fff, 0 0 20px rgba(255, 240, 180, 0.8); } to { transform: scale(1.06); box-shadow: inset 0 0 0 3px #fff, 0 0 34px rgba(255, 240, 180, 1); } }
.tile.clearing { animation: clearpop 0.36s ease forwards; z-index: 4; }
@keyframes clearpop { 0% { transform: scale(1.06); opacity: 1; } 45% { transform: scale(1.22); opacity: 1; } 100% { transform: scale(0.2); opacity: 0; } }
.tile.wild-pop .face { animation: wildpop 0.42s ease; }
@keyframes wildpop { 0% { transform: scale(0.4) rotate(-20deg); } 60% { transform: scale(1.25) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }

.status { min-height: 20px; font-size: 0.82rem; color: var(--dim); text-align: center; line-height: 1.4; padding: 0 8px; }

/* ── 控制列 ── */
.controls { display: flex; flex-direction: column; gap: 12px; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.bet-group { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bet-step {
  width: 46px; height: 46px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--gold-1); font-size: 1.4rem; font-weight: 800; cursor: pointer;
}
.bet-step:active { transform: scale(0.95); }
.bet-step:disabled { opacity: 0.4; cursor: default; }
.bet-info { flex: 1; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.bet-cap { font-size: 0.58rem; color: var(--dim); letter-spacing: 2px; }
.bet-val { font-size: 1.5rem; font-weight: 900; color: var(--text); font-variant-numeric: tabular-nums; }
.bet-base { font-size: 0.6rem; color: var(--dim); }
.bet-base b { color: var(--gold-1); }

.action-row { display: flex; align-items: stretch; gap: 10px; }
.btn-xtra, .btn-buy {
  flex: 0 0 auto; padding: 0 12px; min-width: 74px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--dim); font-size: 0.72rem; font-weight: 800; line-height: 1.05; cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, color 0.15s, background 0.15s;
}
.btn-xtra:active, .btn-buy:active { transform: scale(0.97); }
.btn-xtra.on { color: #1a0c06; background: linear-gradient(160deg, #ffd98a, #d0902f); border-color: var(--gold-1); box-shadow: 0 0 16px rgba(232, 185, 106, 0.5); }
.btn-buy { color: var(--gold-0); border-color: rgba(232, 185, 106, 0.35); background: linear-gradient(160deg, #2a1c18, #1a1220); }
.btn-xtra:disabled, .btn-buy:disabled { opacity: 0.45; cursor: default; }
.btn-spin {
  flex: 1; padding: 16px 0; border: none; border-radius: 14px; font-size: 1.1rem; font-weight: 900; color: #1a0c06;
  background: linear-gradient(160deg, var(--gold-0), var(--gold-2)); cursor: pointer;
  transition: transform 0.08s, filter 0.15s; box-shadow: 0 8px 24px rgba(184, 129, 44, 0.4);
}
.btn-spin:active { transform: scale(0.98); }
.btn-spin:disabled { filter: grayscale(0.55) brightness(0.7); cursor: default; box-shadow: none; }

.note { font-size: 0.68rem; color: var(--dim); line-height: 1.5; padding: 0 16px 14px; text-align: center; }
.note b { color: var(--gold-1); }

/* ── 右側人物立繪 ── (寬螢幕站右側;窄螢幕隱藏)。單張=solo;有分層件則升級 puppet */
.hero {
  position: fixed; bottom: 0; left: calc(50% + 215px);
  height: min(90vh, 800px); aspect-ratio: 1024 / 1536; z-index: 4; pointer-events: none;
  opacity: 0; transition: opacity 0.7s ease;
  animation: heroFloat 5.5s ease-in-out infinite alternate;
}
.hero.loaded { opacity: 1; }
@keyframes heroFloat { from { translate: 0 0; } to { translate: 0 -16px; } }
@media (max-width: 1040px) { .hero { display: none; } }

.hero .layer { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 14px 44px rgba(60, 110, 220, 0.4)); }
/* 分層件預設隱藏、只顯示 solo;偵測到分層(.layered)才切換 */
.hero .l-base, .hero .l-arm, .hero .l-eyes { display: none; }
.hero.layered .l-solo { display: none; }
.hero.layered .l-base, .hero.layered .l-arm { display: block; }
.hero.layered .l-eyes { display: block; opacity: 0; transition: opacity 0.05s; }
/* 呼吸(身體+眼睛層一起,scale) */
.hero.layered .l-base, .hero.layered .l-eyes { animation: heroBreathe 4s ease-in-out infinite; transform-origin: 50% 92%; }
@keyframes heroBreathe { 0%, 100% { scale: 1 1; } 50% { scale: 1.012 1.02; } }
/* 揮槍(持槍手臂層繞肩軸 rotate):待機小擺 + 中獎大揮 */
.hero .l-arm { transform-origin: 58% 40%; animation: armIdle 3.6s ease-in-out infinite alternate; }
@keyframes armIdle { from { rotate: -1.5deg; } to { rotate: 2deg; } }
.hero .l-arm.swing { animation: armSwing 0.7s ease; }
@keyframes armSwing { 0% { rotate: 0deg; } 28% { rotate: -13deg; } 60% { rotate: 7deg; } 100% { rotate: 0deg; } }
/* 眨眼(閉眼層 opacity 切換) */
.hero.blink .l-eyes { opacity: 1; }
/* solo(無分層時)也做輕微呼吸;中獎時反應 */
.hero .l-solo { animation: heroBreathe 4.2s ease-in-out infinite; transform-origin: 50% 92%; }
.hero .l-solo.react { animation: heroReact 0.6s ease; }
@keyframes heroReact {
  0% { scale: 1; filter: drop-shadow(0 14px 44px rgba(60, 110, 220, 0.4)) brightness(1); }
  35% { scale: 1.045; filter: drop-shadow(0 0 60px rgba(130, 175, 255, 0.95)) brightness(1.28); }
  100% { scale: 1; filter: drop-shadow(0 14px 44px rgba(60, 110, 220, 0.4)) brightness(1); }
}

/* ── Overlay 通用 ── */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(6, 5, 10, 0.72); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.22s ease;
}
.overlay.show { opacity: 1; }
.panel {
  width: 100%; max-width: 430px; max-height: 88dvh; overflow-y: auto;
  background: linear-gradient(160deg, #1d1526, #100d18); border: 1px solid rgba(232, 185, 106, 0.28);
  border-radius: 18px; padding: 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  transform: translateY(12px) scale(0.98); transition: transform 0.22s ease;
}
.overlay.show .panel { transform: translateY(0) scale(1); }
.panel-title { font-size: 1.15rem; font-weight: 900; text-align: center; background: linear-gradient(90deg, var(--gold-0), var(--gold-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.panel-sub { font-size: 0.78rem; color: var(--dim); text-align: center; margin: 6px 0 14px; line-height: 1.4; }
.btn-ghost { display: block; width: 100%; margin-top: 14px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--dim); font-weight: 700; cursor: pointer; }

/* Buy menu */
.buy-list { display: flex; flex-direction: column; gap: 10px; }
.buy-card { text-align: left; padding: 12px 14px; border-radius: 13px; border: 1px solid rgba(232, 185, 106, 0.22); background: linear-gradient(160deg, #241a24, #16121c); color: var(--text); cursor: pointer; transition: transform 0.08s, border-color 0.15s; }
.buy-card:active { transform: scale(0.98); }
.buy-card:hover { border-color: rgba(232, 185, 106, 0.6); }
.buy-name { font-size: 0.9rem; font-weight: 800; color: var(--gold-0); letter-spacing: 0.5px; }
.buy-desc { font-size: 0.72rem; color: var(--dim); margin-top: 3px; }
.buy-foot { display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.buy-x { font-size: 0.7rem; color: var(--dim); }
.buy-cost { font-size: 1.05rem; font-weight: 900; color: var(--gold-1); font-variant-numeric: tabular-nums; }

/* Banner */
.overlay.banner { background: rgba(6, 5, 10, 0.55); }
.banner-box { text-align: center; transform: scale(0.8); transition: transform 0.3s cubic-bezier(0.2, 1.3, 0.4, 1); }
.overlay.banner.show .banner-box { transform: scale(1); }
.banner-title { font-size: 2rem; font-weight: 900; letter-spacing: 2px; background: linear-gradient(90deg, #fff2c8, var(--gold-2)); -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: 0 0 40px rgba(255, 210, 120, 0.5); }
.banner-sub { font-size: 1rem; color: var(--gold-0); margin-top: 8px; font-weight: 700; }
.banner-hero { display: block; width: min(60vw, 240px); height: auto; margin: 0 auto 4px; filter: drop-shadow(0 10px 34px rgba(210, 60, 40, 0.55)); animation: heroIn 0.5s cubic-bezier(0.2, 1.2, 0.4, 1) both; }
@keyframes heroIn { 0% { transform: translateY(20px) scale(0.82); opacity: 0; } 100% { transform: translateY(0) scale(1); opacity: 1; } }

/* Treasure */
.chest { display: block; margin: 8px auto 0; font-size: 4.4rem; background: none; border: none; cursor: pointer; transition: transform 0.15s; }
.chest:active { transform: scale(0.94); }
.chest.open { animation: chestpop 0.5s ease; }
@keyframes chestpop { 0% { transform: scale(1); } 40% { transform: scale(1.3) rotate(-6deg); } 100% { transform: scale(1); } }
.treasure-prize { text-align: center; font-size: 1.6rem; font-weight: 900; color: var(--gold-0); min-height: 30px; margin-top: 8px; opacity: 0; transition: opacity 0.25s; }
.treasure-prize.show { opacity: 1; text-shadow: 0 0 24px rgba(255, 210, 120, 0.7); }

/* Jackpot */
.jp-panel.jp-won { border-color: var(--gold-1); box-shadow: 0 0 40px rgba(232, 185, 106, 0.5), 0 30px 80px rgba(0, 0, 0, 0.6); }
.jp-tracker { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.jp-tier { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; padding: 5px 8px; border-radius: 9px; background: rgba(255, 255, 255, 0.03); }
.jp-glyph { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; background: color-mix(in srgb, var(--col) 30%, #000 30%); color: var(--col); font-size: 1rem; }
.jp-name { flex: 1; color: var(--text); font-weight: 700; }
.jp-amt { color: var(--gold-1); font-weight: 800; font-variant-numeric: tabular-nums; }
.jp-dots { display: flex; gap: 4px; margin-left: 6px; }
.jp-dots .dot { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); transition: background 0.2s, box-shadow 0.2s; }
.jp-dots .dot.on { background: var(--gold-0); box-shadow: 0 0 8px rgba(255, 220, 130, 0.9); }
.jp-boxes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.jp-box { aspect-ratio: 1 / 1; border-radius: 12px; border: 1px solid rgba(232, 185, 106, 0.28); background: linear-gradient(160deg, #2a2030, #17121e); color: var(--dim); font-size: 1.5rem; font-weight: 900; cursor: pointer; transition: transform 0.1s; }
.jp-box:active { transform: scale(0.94); }
.jp-box:disabled { cursor: default; }
.jp-box.revealed { color: var(--col); border-color: var(--col); background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--col) 30%, #17121e), #17121e); box-shadow: 0 0 14px color-mix(in srgb, var(--col) 45%, transparent); animation: chestpop 0.4s ease; }
