/* 彈玻璃珠 — 自寫樣式（紙感白底 + 墨綠點綴） */
:root {
  --ink: #1f2a2a;
  --ink-soft: #51625f;
  --teal: #1e4f4b;
  --teal-bright: #2c7a72;
  --paper: #fbfbfb;
  --card: #ffffff;
  --line: rgba(31, 42, 42, 0.14);
  --shadow: 0 10px 28px rgba(31, 42, 42, 0.12);
  --radius-lg: 18px;
  --radius-pill: 999px;
  font-family: "Avenir Next", "PingFang TC", "Noto Sans TC", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
}

.board {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

#glass-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}
#glass-canvas.is-holding { cursor: grabbing; }

/* 瞄準線 */
.guide-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}
.guide-layer.is-live { opacity: 1; }
.guide-layer line {
  stroke: rgba(30, 79, 75, 0.62);
  stroke-width: 2.5;
  stroke-dasharray: 3 7;
  stroke-linecap: round;
}
.guide-layer #guide-tail {
  stroke: rgba(184, 85, 47, 0.6);
  stroke-width: 4;
  stroke-dasharray: none;
}
.guide-layer circle { fill: rgba(30, 79, 75, 0.78); }

/* 出圈/進洞飄字 */
.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 800;
  color: var(--teal-bright);
  text-shadow: 0 1px 0 #fff, 0 2px 6px rgba(31, 42, 42, 0.25);
  pointer-events: none;
  z-index: 9;
  animation: float-up 0.9s ease-out forwards;
}
.float-text.is-big { font-size: 28px; color: #b8552f; }
.float-text.is-minus { color: #9a4030; font-size: 18px; }
@keyframes float-up {
  0% { opacity: 0; margin-top: 6px; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -46px; }
}

/* 洞口分數標籤 */
.hole-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: rgba(31, 42, 42, 0.62);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 99px;
  padding: 2px 9px;
  pointer-events: none;
  z-index: 4;
}

/* 力度條 */
.power-bar {
  position: absolute;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
  z-index: 6;
}
.power-rail {
  width: 130px;
  height: 8px;
  border-radius: 99px;
  background: rgba(31, 42, 42, 0.10);
  overflow: hidden;
}
.power-rail i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(0);
  background: linear-gradient(90deg, #7fc6b8, var(--teal-bright), #b8552f);
  border-radius: inherit;
}
.power-bar strong { min-width: 2.4em; text-align: right; font-variant-numeric: tabular-nums; }

/* 頂欄 */
.topbar {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 8;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  font-size: 19px;
}
.brand-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #ffffff 6%, #9fd8cd 34%, #2c7a72 78%);
  box-shadow: inset -1px -2px 3px rgba(20, 50, 46, 0.35), 0 1px 3px rgba(31, 42, 42, 0.25);
}

.mode-tabs {
  display: flex;
  padding: 4px;
  gap: 2px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
}
.mode-tabs button {
  border: 0;
  background: transparent;
  padding: 8px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.mode-tabs button[aria-pressed="true"] {
  background: var(--ink);
  color: #fff;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.round-button,
.pill-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 13.5px;
  padding: 9px 15px;
}
.round-button {
  width: 38px;
  height: 38px;
  justify-content: center;
  padding: 0;
  font-weight: 700;
}
.round-button:hover, .pill-button:hover { border-color: rgba(31, 42, 42, 0.32); }

/* 闖關 HUD */
.game-hud {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 56px);
  left: max(14px, env(safe-area-inset-left)); /* 靠左，避免擋住中央的黑心商人 LIVE 框 */
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 7;
}
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.hud-stat span {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
}
.hud-stat strong { font-size: 21px; font-variant-numeric: tabular-nums; }
.hud-divider { width: 1px; height: 30px; background: var(--line); }
.game-hud button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}
.game-hud button:hover { border-color: rgba(31, 42, 42, 0.32); }

/* 自由玩控制 */
.free-hud {
  position: absolute;
  top: calc(max(14px, env(safe-area-inset-top)) + 56px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 7;
}
.bg-tabs, .free-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.bg-tabs span { color: var(--ink-soft); padding: 0 4px; }
.bg-tabs button, .free-row button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 7px 13px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.bg-tabs button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.free-row button[aria-pressed="true"] { background: var(--teal); color: #fff; border-color: var(--teal); }
.count-box { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); }
.count-box input { accent-color: var(--teal); width: 130px; }
.count-box output { min-width: 2em; text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }

/* 結果卡：縮小＋往下移，避免蓋住上方的黑心商人（Pizza 7/22 回報） */
.result-card {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: min(64vw, 260px);
  max-width: min(80vw, 300px);
  padding: 16px 20px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 40px rgba(31, 42, 42, 0.20);
  z-index: 35; /* 高於爆炸圖層(30)，結算卡要壓在油漬上 */
  text-align: center;
}
.result-card h1 { margin: 0; font-size: 18px; }
.result-stars { font-size: 19px; letter-spacing: 0.16em; color: #d8a013; }
.result-card > strong { font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.result-buttons { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 4px; }
.result-buttons button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.result-buttons .result-next {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.result-buttons button:hover { border-color: rgba(31, 42, 42, 0.34); }
.result-buttons .result-next:hover { background: var(--teal-bright); }

/* 說明彈窗 */
.help-veil {
  position: absolute;
  inset: 0;
  background: rgba(240, 244, 243, 0.55);
  backdrop-filter: blur(7px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 18px;
}
.help-card {
  position: relative;
  width: min(92vw, 480px);
  max-height: min(86vh, 640px);
  overflow: auto;
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 26px 64px rgba(31, 42, 42, 0.24);
  padding: 26px 28px 22px;
}
.help-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: #fff;
  font-size: 19px;
  cursor: pointer;
}
.help-kicker {
  margin: 0 0 2px;
  font-size: 11px;
  letter-spacing: 0.34em;
  color: var(--ink-soft);
}
.help-card h1 { margin: 0 0 16px; font-size: 27px; }
.help-block {
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 13px;
}
.help-block h2 { margin: 0 0 8px; font-size: 16.5px; }
.help-block p { margin: 0 0 8px; font-size: 14.5px; line-height: 1.55; }
.help-note { color: var(--ink-soft); font-size: 13px !important; }
.help-ok {
  width: 100%;
  margin-top: 6px;
  padding: 13px;
  font-size: 15.5px;
  font-weight: 700;
  border-radius: 13px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
}
.help-ok:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 66px));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 10px 18px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 30;
  white-space: nowrap;
}

/* debug 面板 */
.debug-panel {
  position: absolute;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border-radius: var(--radius-pill);
  background: var(--card);
  border: 1px solid var(--line);
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 11px;
  color: var(--ink-soft);
  z-index: 5;
}
.debug-panel i { width: 1px; height: 12px; background: var(--line); }
.debug-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #35b489;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.gl-error {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 28px;
  font-size: 15px;
  z-index: 40;
}

/* 收起選單 */
.board.is-folded .mode-tabs,
.board.is-folded .game-hud,
.board.is-folded .free-hud,
.board.is-folded #help-open,
.board.is-folded #bg-button,
.board.is-folded #music-button,
.board.is-folded #sound-button { display: none; }

/* 窄螢幕 */
@media (max-width: 720px) {
  .pill-label { display: none; }
  .pill-button, .round-button { padding: 9px 12px; }
  .brand strong { display: none; }
  .game-hud { gap: 10px; padding: 9px 12px; }
  .hud-stat { min-width: 52px; }
  .free-hud { width: calc(100vw - 24px); }
  .free-row { flex-wrap: wrap; justify-content: center; }
  .count-box input { width: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .guide-layer { transition: none; }
}

/* ========== 餵黑心商人：新增元件 ========== */

/* 黑心商人（無框角色本體，跟著嘴巴 x/y 移動＋隨餵食量放大） */
.boss-frame {
  position: absolute;
  top: max(52px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  transition: left 0.05s linear;
}
/* 咀嚼/升級/爆炸 動畫（套用對象見下方 v3 區塊：.boss-frame > img） */
@keyframes boss-chew {
  0% { transform: scale(1); }
  35% { transform: scale(1.16) rotate(-3deg); }
  70% { transform: scale(0.95) rotate(2deg); }
  100% { transform: scale(1); }
}
@keyframes boss-stage {
  0% { transform: scale(1); }
  50% { transform: scale(1.28); }
  100% { transform: scale(1); }
}
@keyframes boss-burst {
  0% { transform: scale(1.4); filter: brightness(3); }
  100% { transform: scale(1); filter: none; }
}

/* 今日速報跑馬燈 */
.ticker {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  background: #16161a;
  color: #ffd23f;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  padding: 5px 0;
  pointer-events: none;
}
.ticker-text {
  display: inline-block;
  padding-left: 100%;
  animation: ticker-roll 26s linear infinite;
}
@keyframes ticker-roll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-100%); }
}

/* 開場重生文 */
.intro-veil {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #2a2118 0%, #0d0b08 70%);
  padding: 18px;
}
.intro-card {
  max-width: 420px;
  text-align: center;
  color: #f5eeda;
}
.intro-kicker {
  font-size: 13px;
  letter-spacing: 0.5em;
  color: #b8a888;
  margin: 0 0 10px;
}
.intro-title {
  font-size: clamp(1.5rem, 6.5vw, 2.3rem);
  line-height: 1.35;
  margin: 0 0 18px;
  color: #ffd23f;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45);
}
.intro-line {
  font-size: clamp(0.95rem, 4vw, 1.1rem);
  margin: 6px 0;
  color: #e8dfc8;
}
.intro-punch {
  font-size: clamp(1.3rem, 5.5vw, 1.7rem);
  font-weight: 900;
  color: #ff5a3c;
  margin-top: 12px;
}
.intro-start {
  margin-top: 22px;
  font-size: 1.15rem;
  font-weight: 900;
  padding: 13px 40px;
  border: 3px solid #16161a;
  border-radius: 999px;
  background: #ffd23f;
  color: #16161a;
  cursor: pointer;
  box-shadow: 0 5px 0 #b8912a;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.intro-start:active { transform: translateY(4px); box-shadow: 0 1px 0 #b8912a; }
.intro-note {
  margin-top: 20px;
  font-size: 11px;
  color: #8d8266;
  line-height: 1.6;
}

/* 爆炸圖層 */
.boom-layer {
  position: absolute;
  inset: 0;
  z-index: 30;
  overflow: hidden;
  pointer-events: none;
}
.boom-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  animation: boom-flash 0.55s ease-out forwards;
}
@keyframes boom-flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}
.boom-splat {
  position: absolute;
  background: radial-gradient(ellipse at 45% 40%, #1c1611 0%, #0e0b08 68%, transparent 70%);
  border-radius: 48% 52% 55% 45% / 50% 46% 54% 50%;
  opacity: 0;
  animation: boom-splat 0.5s ease-out forwards;
}
@keyframes boom-splat {
  0% { opacity: 0; transform: scale(0.1); }
  60% { opacity: 0.9; transform: scale(1.15); }
  100% { opacity: 0.72; transform: scale(1); }
}
.boom-bill {
  position: absolute;
  top: -12%;
  background: #fff;
  color: #d21f2c;
  border: 2.5px solid #16161a;
  border-radius: 6px;
  font-weight: 900;
  font-size: clamp(13px, 3.2vw, 19px);
  padding: 5px 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  animation-name: bill-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  --rot: 180deg;
}
@keyframes bill-fall {
  0% { transform: translateY(0) rotate(0deg); }
  82% { transform: translateY(var(--fall, 78vh)) rotate(var(--rot)); }
  91% { transform: translateY(calc(var(--fall, 78vh) - 3vh)) rotate(var(--rot)); }
  100% { transform: translateY(var(--fall, 78vh)) rotate(var(--rot)); }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-text { animation: none; }
  .boom-bill { animation-duration: 0.9s !important; }
}

/* 商人台詞泡泡 */
.boss-say {
  margin-top: 6px;
  position: relative;
  background: #fff;
  border: 2px solid #16161a;
  border-radius: 10px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  color: #16161a;
  text-align: center;
  line-height: 1.35;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
  animation: say-pop 0.18s ease-out;
}
.boss-say::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-bottom-color: #16161a;
  border-top: 0;
}
@keyframes say-pop {
  from { transform: scale(0.7); opacity: 0; }
}

/* 商人膨脹（scale 以頂端中央為基準往下長大）＋狂餵模式按鈕 */
.boss-frame { transform-origin: 50% 45%; } /* 縮放基準＝嘴巴錨點 */
.intro-start-alt {
  display: block;
  margin: 12px auto 0;
  background: #ff5a3c;
  color: #fff;
  box-shadow: 0 5px 0 #a83318;
}
.intro-start-alt:active { box-shadow: 0 1px 0 #a83318; }

/* ===== v3 無框商人本體 ＋ 餵食油花 ===== */
.boss-frame { width: clamp(120px, 28vmin, 200px); }
.boss-frame > img {
  width: 100%;
  display: block;
  filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.28));
}
.boss-frame .boss-noimg-emoji {
  position: static;
  display: none;
  font-size: 4rem;
  text-align: center;
  background: none;
}
.boss-frame.is-noimg .boss-noimg-emoji { display: block; }
.boss-frame.is-chew > img { animation: boss-chew 0.34s ease-out; }
.boss-frame.is-stagepop > img { animation: boss-stage 0.42s cubic-bezier(0.2, 1.6, 0.4, 1); }
.boss-frame.is-burst > img { animation: boss-burst 0.5s ease-out; }
.feed-splat {
  position: absolute;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 45% 40%, #221a12 0%, #0d0a07 60%, transparent 62%);
  border-radius: 46% 54% 52% 48% / 52% 44% 56% 48%;
  pointer-events: none;
  z-index: 8;
  animation: splat-pop 0.45s ease-out forwards;
}
@keyframes splat-pop {
  0% { opacity: 0.95; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.7); }
}

/* 狂餵模式：數量滑桿移到左下角（頂部留給商人、避開力度條） */
.free-hud {
  top: auto;
  bottom: 92px;
  left: 12px;
  right: auto;
  transform: none;
  align-items: flex-start;
}

/* 桌機版面收窄：置中直式欄，兩側收黑 */
html, body { background: #14100b; }
.board {
  max-width: min(100vw, calc(100vh * 0.66));
  margin: 0 auto;
  box-shadow: 0 0 70px rgba(0, 0, 0, 0.5);
}

/* 收起選單時也收配音鈕 */
.board.is-folded #voice-button { display: none; }
