:root {
  --red: #e8503a;
  --red-d: #b8371f;
  --gold: #d4a636;
  --gold-l: #f2c14e;
  --ink: #2a2320;
  --navy: #26384f;
  --paper: #f6efe2;
  --panel: #fffaf0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background:
    radial-gradient(circle at 50% -10%, #4a2f2a, #1a1210 70%),
    #1a1210;
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.app {
  width: min(1180px, 100%);
  background: var(--paper);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
  overflow: hidden;
  border: 3px solid var(--gold);
}

header {
  background: linear-gradient(135deg, var(--red), var(--red-d));
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--gold);
}
header h1 { font-family: "Noto Serif TC", serif; font-size: 24px; letter-spacing: 3px; }
header h1 small { font-size: 12px; opacity: .85; font-weight: 400; letter-spacing: 0; margin-left: 8px; }
header .tag { background: rgba(255,255,255,.18); padding: 5px 12px; border-radius: 20px; font-size: 12px; letter-spacing: 1px; }

/* ── 開始畫面 ── */
.setup { padding: 28px; }
.setup h2 { font-family: "Noto Serif TC", serif; color: var(--red-d); margin-bottom: 6px; letter-spacing: 2px; }
.setup p.hint { color: #8a7a68; font-size: 13px; margin-bottom: 20px; }

.chars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.char-card {
  border: 2px solid #e4d8c4;
  border-radius: 14px;
  padding: 14px 12px 12px;
  cursor: pointer;
  background: linear-gradient(180deg, #fffdf7, #f7efe0);
  transition: .15s;
  position: relative;
  text-align: center;
}
.char-card:hover { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 8px 20px rgba(0,0,0,.12); }
.char-card.sel { border-color: var(--red); box-shadow: 0 0 0 3px rgba(232,80,58,.2); }
.char-card .char-face {
  width: 84px; height: 100px; margin: 0 auto 8px;
  border-radius: 12px; overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #fff, #f0e6d2);
  border: 2px solid var(--gold);
  display: flex; align-items: flex-end; justify-content: center;
}
.char-card .char-face svg { width: 100%; height: 118%; }
.char-card .char-face img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; }
.char-card b { font-size: 15px; color: var(--ink); }
.char-card b small { color: #aa9; font-weight: 400; }
.char-card .desc { font-size: 12px; color: #7a6a58; margin-top: 6px; line-height: 1.5; }
.char-card .chosen { font-size: 12px; font-weight: 700; margin-top: 6px; }
.char-card .role {
  position: absolute; top: 10px; right: 10px; font-size: 11px;
  background: var(--gold); color: #fff; padding: 2px 8px; border-radius: 10px;
}

.opts { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 22px; align-items: center; }
.opts label { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.opts select { padding: 6px 10px; border-radius: 8px; border: 1px solid #d8c9b2; background: #fff; }

.btn {
  background: linear-gradient(180deg, var(--red), var(--red-d));
  color: #fff; border: none;
  padding: 12px 28px; border-radius: 10px;
  font-size: 16px; cursor: pointer; font-weight: 700; letter-spacing: 1px;
  transition: .15s; box-shadow: 0 4px 12px rgba(184,55,31,.3);
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn:disabled { background: #c9bca8; cursor: not-allowed; box-shadow: none; transform: none; }
.btn.ghost { background: transparent; color: var(--red); border: 2px solid var(--red); box-shadow: none; }
.btn.small { padding: 9px 16px; font-size: 14px; }

/* ── 遊戲畫面（三欄：立繪 / 台灣島地圖 / 側欄）── */
.game { display: none; grid-template-columns: 210px 1fr 320px; min-height: 660px; }
.game.on { display: grid; }

.hero {
  background: linear-gradient(180deg, #2c3e56, #1b2838);
  padding: 18px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 20%, rgba(242,193,78,.18), transparent 60%);
}
.hero-art {
  width: 100%; max-width: 180px; flex: 1;
  display: flex; align-items: flex-end; justify-content: center;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.4));
  animation: floaty 4s ease-in-out infinite;
}
.hero-art svg { width: 100%; height: auto; }
.hero-art img { width: 100%; height: auto; border-radius: 14px; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
.hero-name {
  margin-top: 14px; color: #fff; font-weight: 700; font-size: 17px;
  padding: 8px 18px; border-radius: 20px; text-align: center; letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.hero-name span { display: block; font-size: 11px; font-weight: 400; opacity: .9; }

.board-wrap {
  position: relative;
  background: #1f4e6b;
  padding: 0;
  display: block;
  overflow: hidden;
  min-height: 560px;
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
  cursor: grab;
}
#board:active { cursor: grabbing; }
.map-hint {
  position: absolute;
  left: 14px; top: 12px;
  background: rgba(20,40,55,0.72);
  color: #f2e4c8;
  font-size: 12px;
  letter-spacing: .5px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(212,166,54,.5);
  pointer-events: none;
}

.side {
  background: var(--panel);
  padding: 16px;
  display: flex; flex-direction: column;
  border-left: 3px solid var(--gold);
  max-height: 690px;
}

.players-panel { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.pl {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 12px; background: #fff;
  border: 2px solid #eee3cf; transition: .15s;
}
.pl.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212,166,54,.25); background: #fffdf3; }
.pl.dead { opacity: .45; }
.pl.dead .pl-name { text-decoration: line-through; }
.pl-face {
  width: 34px; height: 40px; border-radius: 8px; overflow: hidden;
  border: 2px solid; background: #f0e6d2; flex-shrink: 0;
  display: flex; align-items: flex-end; justify-content: center;
}
.pl-face svg { width: 100%; height: 120%; }
.pl-face img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 10%; }
.pl-face.token { width: 38px; height: 38px; border-radius: 50%; }
.pl-face.token svg { width: 100%; height: 100%; }
.pl-face.token img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; }
.pl-face.sm { width: 26px; height: 30px; }
.pl-face.sm.token { width: 30px; height: 30px; }
.pl-info { flex: 1; }
.pl-name { font-size: 14px; font-weight: 700; }
.pl-name .who { font-size: 10px; color: #aa9; font-weight: 400; }
.pl .money { font-weight: 900; color: var(--navy); font-size: 15px; }

.yuan-say {
  background: linear-gradient(180deg, #fff2ec, #ffe1d6);
  border: 3px solid var(--red);
  border-radius: 14px; padding: 14px 14px 14px 16px;
  font-size: 16.5px; font-weight: 700; color: #a5391f; min-height: 64px;
  margin-bottom: 12px; line-height: 1.6; position: relative;
  box-shadow: 0 6px 18px rgba(184,55,31,.22), inset 0 0 0 1px rgba(255,255,255,.5);
}
.yuan-say.pulse { animation: sayPulse .5s ease-out; }
@keyframes sayPulse {
  0% { transform: scale(1); box-shadow: 0 6px 18px rgba(184,55,31,.22); }
  40% { transform: scale(1.04); box-shadow: 0 8px 26px rgba(232,80,58,.5); border-color: var(--gold); }
  100% { transform: scale(1); box-shadow: 0 6px 18px rgba(184,55,31,.22); }
}
.say-name {
  display: inline-block; background: linear-gradient(180deg, var(--red), var(--red-d)); color: #fff;
  font-size: 13px; font-weight: 900; padding: 3px 12px; border-radius: 10px; margin-right: 8px;
  letter-spacing: 1px; box-shadow: 0 2px 6px rgba(0,0,0,.2);
}

.dice-view {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; margin-bottom: 10px;
}
.die { width: 40px; height: 40px; }
.die.rolling { animation: shake .1s infinite; }
@keyframes shake { 0%{transform:rotate(-8deg)} 50%{transform:rotate(8deg)} 100%{transform:rotate(-8deg)} }
.dice-note { font-weight: 700; color: var(--navy); font-size: 15px; margin-left: 4px; }

.log {
  flex: 1; overflow-y: auto;
  background: #fff; border-radius: 10px;
  padding: 10px 12px; font-size: 13px; line-height: 1.7;
  border: 1px solid #eaddc7; margin-bottom: 12px;
}
.log div { padding: 3px 0; border-bottom: 1px dashed #f0e6d2; color: #5a4f43; }

.controls { display: flex; gap: 8px; flex-wrap: wrap; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center; z-index: 20;
  backdrop-filter: blur(2px);
}
.modal-bg.on { display: flex; }
.modal {
  background: linear-gradient(180deg, #fffdf7, var(--panel));
  border-radius: 18px; padding: 26px; width: min(420px, 92%); text-align: center;
  border: 3px solid var(--gold); box-shadow: 0 20px 60px rgba(0,0,0,.5);
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { font-family: "Noto Serif TC", serif; color: var(--red-d); margin-bottom: 12px; letter-spacing: 1px; }
.modal p { margin-bottom: 20px; line-height: 1.7; color: #5a4f43; }
.modal .row { display: flex; gap: 10px; justify-content: center; }
.modal.good { border-color: #4a9e5c; }
.modal.good h3 { color: #2e7e42; }
.modal.bad { border-color: var(--red); }

.result-list { text-align: left; margin: 16px 0; }
.result-list .r {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 10px; margin-bottom: 7px; background: #fff;
  border: 1px solid #eee3cf;
}
.result-list .r.win { background: linear-gradient(90deg, #fff3d0, #ffe6a0); border-color: var(--gold); font-weight: 700; }
.result-list .r-left { display: flex; align-items: center; gap: 8px; }
.result-list .place { color: var(--red-d); font-weight: 700; font-size: 13px; }
.result-list .r-asset { font-weight: 900; color: var(--navy); }
.modal.result .crown {
  width: 54px; height: 40px; margin: 0 auto 8px;
  background: var(--gold-l);
  clip-path: polygon(0 100%, 15% 30%, 35% 60%, 50% 15%, 65% 60%, 85% 30%, 100% 100%);
}

@media (max-width: 860px) {
  .game { grid-template-columns: 1fr; }
  .hero { flex-direction: row; gap: 14px; padding: 12px; }
  .hero-art { max-width: 90px; }
  .board-wrap, #board { min-height: 420px; }
}

/* ── 廟宇拜訪 / 認捐彈窗 ── */
.pl .money .props { font-size: 11px; color: #9a8a6c; font-weight: 700; margin-left: 4px; }

.modal.temple { text-align: left; }
.temple-head { text-align: center; margin-bottom: 12px; }
.temple-head h3 { margin: 4px 0 2px; }
.temple-meta { font-size: 12px; color: #8a7a62; letter-spacing: .5px; }
.temple-desc {
  background: #fff6e6; border-left: 3px solid var(--gold);
  padding: 8px 12px; border-radius: 8px; font-size: 13.5px;
  color: #5a4f43; line-height: 1.7; margin-bottom: 8px;
}
.temple-story {
  font-size: 13px; color: #8a5a3a; line-height: 1.7;
  font-style: italic; margin-bottom: 8px;
}
.temple-extra {
  text-align: center; font-weight: 700; color: var(--red-d);
  margin: 6px 0 4px;
}
.buy-price {
  text-align: center; font-weight: 700; color: var(--navy);
  margin-top: 10px; font-size: 14px;
}

.region-tag {
  display: inline-block; color: #fff; font-size: 12px; font-weight: 700;
  padding: 2px 12px; border-radius: 12px; letter-spacing: 2px;
}
.region-tag.r-north { background: #c9482e; }
.region-tag.r-central { background: #d98a2e; }
.region-tag.r-south { background: #c2371f; }
.region-tag.r-east { background: #2e8f7e; }
.region-tag.r-island { background: #3a72b0; }

/* ── 升級敘事框（拜訪彈窗顯示目前等級） ── */
.temple-level {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(90deg, #fff7e0, #ffeec4);
  border: 1px solid var(--gold); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 8px;
}
.temple-level .lv-badge {
  background: var(--red-d); color: #fff; font-weight: 900;
  font-size: 12px; padding: 2px 9px; border-radius: 8px; white-space: nowrap;
}
.temple-level .lv-text { font-size: 13px; color: #7a5230; line-height: 1.5; }

/* ══════════ 直播明顯演出層 ══════════ */
.fx-layer {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 6;
}
/* 飛出的金幣/紅字 */
.fly {
  position: absolute; font-weight: 900; font-size: 26px;
  text-shadow: 0 2px 6px rgba(0,0,0,.5); white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: flyUp 1.2s cubic-bezier(.2,.7,.3,1) forwards;
}
.fly.gain { color: #ffe14d; }
.fly.loss { color: #ff5a3c; }
@keyframes flyUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  18% { opacity: 1; transform: translate(-50%, -60%) scale(1.25); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1); }
}
.coin {
  position: absolute; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff2b0, #f2c14e 55%, #c99a2e);
  border: 2px solid #a97c1e; box-shadow: 0 2px 6px rgba(0,0,0,.4);
  transform: translate(-50%, -50%);
}

/* 大骰子演出（畫面中央） */
.big-dice {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%,-50%);
  display: none; gap: 20px; z-index: 8; pointer-events: none;
}
.big-dice.on { display: flex; animation: diceEnter .25s ease-out; }
@keyframes diceEnter { from { transform: translate(-50%,-50%) scale(.3); opacity:0; } to { transform: translate(-50%,-50%) scale(1); opacity:1; } }
.big-dice .bdie {
  width: 92px; height: 92px; filter: drop-shadow(0 10px 20px rgba(0,0,0,.55));
}
.big-dice .bdie.spin { animation: diceSpin .12s infinite linear; }
@keyframes diceSpin { from { transform: rotate(-12deg) scale(.95); } to { transform: rotate(12deg) scale(1.05); } }
.big-dice .bsum {
  align-self: center; font-family: "Noto Serif TC", serif;
  font-size: 40px; font-weight: 900; color: #fff;
  background: linear-gradient(180deg, var(--red), var(--red-d));
  padding: 6px 22px; border-radius: 16px; border: 3px solid var(--gold-l);
  box-shadow: 0 8px 22px rgba(0,0,0,.5); letter-spacing: 2px;
  animation: sumPop .3s ease-out;
}
@keyframes sumPop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* 大字事件橫幅（神明/上上籤/下下籤/破產） */
.event-banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%,-50%) scale(.4);
  display: none; z-index: 9; pointer-events: none; text-align: center;
  opacity: 0;
}
.event-banner.on { display: block; animation: bannerShow 1.7s ease-out forwards; }
@keyframes bannerShow {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.3) rotate(-6deg); }
  14% { opacity: 1; transform: translate(-50%,-50%) scale(1.18) rotate(2deg); }
  30% { transform: translate(-50%,-50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-58%) scale(1.05); }
}
.event-banner .eb-title {
  font-family: "Noto Serif TC", serif; font-weight: 900; font-size: 60px;
  letter-spacing: 6px; -webkit-text-stroke: 3px #fff;
  text-shadow: 0 6px 0 rgba(0,0,0,.35), 0 0 30px currentColor;
}
.event-banner .eb-sub {
  margin-top: 6px; font-size: 18px; font-weight: 700; color: #fff;
  background: rgba(0,0,0,.55); padding: 6px 16px; border-radius: 20px;
  display: inline-block; letter-spacing: 1px;
}
.event-banner.good .eb-title { color: #ffd84d; }
.event-banner.bad .eb-title { color: #ff5233; }
.event-banner.god .eb-title { color: #ffe08a; }
/* 神明光芒放射 */
.event-banner .rays {
  position: absolute; left: 50%; top: 40%; width: 460px; height: 460px;
  transform: translate(-50%,-50%); z-index: -1;
  background: repeating-conic-gradient(from 0deg, rgba(255,224,120,.5) 0deg 8deg, transparent 8deg 20deg);
  border-radius: 50%; animation: raySpin 6s linear infinite;
  mask: radial-gradient(circle, #000 20%, transparent 62%);
  -webkit-mask: radial-gradient(circle, #000 20%, transparent 62%);
}
@keyframes raySpin { to { transform: translate(-50%,-50%) rotate(360deg); } }

/* 全螢幕閃光（好/壞事件色調） */
.screen-flash {
  position: absolute; inset: 0; z-index: 5; pointer-events: none; opacity: 0;
}
.screen-flash.on { animation: flash .6s ease-out; }
.screen-flash.good { background: radial-gradient(circle at 50% 45%, rgba(120,220,120,.55), transparent 70%); }
.screen-flash.bad { background: radial-gradient(circle at 50% 45%, rgba(230,70,50,.55), transparent 70%); }
.screen-flash.god { background: radial-gradient(circle at 50% 40%, rgba(255,224,120,.7), transparent 72%); }
@keyframes flash { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }

/* 破產畫面震動 */
.board-wrap.quake { animation: quake .5s ease-in-out; }
@keyframes quake {
  0%,100% { transform: translate(0,0); }
  15% { transform: translate(-8px,4px); }
  30% { transform: translate(7px,-5px); }
  45% { transform: translate(-6px,3px); }
  60% { transform: translate(5px,-3px); }
  75% { transform: translate(-3px,2px); }
}

