/* =========================================================
 * 骰子電玩城 — 樣式（可愛電玩風）
 * ========================================================= */
:root {
  --bg: #1d1a3a;
  --bg2: #2a2556;
  --panel: #fffaf0;
  --ink: #2b2645;
  --muted: #7a7398;
  --line: #e6dcf5;
  --primary: #ff5d8f;
  --primary-dark: #d93d70;
  --skill: #8f5cff;
  --end: #22b8a5;
  --gain: #1fae5b;
  --loss: #e5484d;
  --warn: #f08c00;
  --radius: 14px;
  --shadow: 0 4px 0 rgba(0, 0, 0, .18);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, #3b2f7a 0, transparent 40%),
    radial-gradient(circle at 90% 80%, #4a1f5c 0, transparent 40%),
    var(--bg);
  background-attachment: fixed;
}
button { font-family: inherit; }

/* ---------- 按鈕 ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: .55em 1.1em;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .08s, filter .15s, opacity .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.18); }
.btn:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.skill { background: var(--skill); color: #fff; }
.btn.end { background: var(--end); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.small { font-size: 13px; padding: .4em .8em; }
.btn small { font-weight: 400; font-size: .8em; }
.btn.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(255, 93, 143, .6); }
  50% { box-shadow: var(--shadow), 0 0 0 8px rgba(255, 93, 143, 0); }
}

/* ---------- 頂部列 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  color: #fff;
}
.logo { font-size: 22px; font-weight: 900; letter-spacing: 1px; text-shadow: 0 3px 0 #ff5d8f; }
.round-chip { background: #ffd43b; color: var(--ink); font-weight: 800; padding: 4px 12px; border-radius: 999px; box-shadow: var(--shadow); }
.top-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 版面 ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 0 16px 24px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
}
.turn-info { font-size: clamp(14px, 2.2vw, 22px); font-weight: 800; display: flex; align-items: center; gap: 6px; }
.turn-info .dot { display: inline-grid; place-items: center; width: 1.6em; height: 1.6em; border-radius: 50%; border: 2px solid #fff; }
.prompt {
  margin: 0;
  max-width: 90%;
  min-height: 2.6em;
  font-size: clamp(11px, 1.5vw, 15px);
  color: #d7d1ff;
}
.prompt.your-turn { color: #ffe066; font-weight: 700; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.actions .btn { font-size: clamp(12px, 1.7vw, 17px); }
.item-bar { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.btn.item { font-size: clamp(11px, 1.4vw, 14px); padding: .35em .8em; display: inline-flex; align-items: center; gap: 4px; background: #fff7d6; }
.btn.item b { color: var(--primary-dark); }

/* 骰子 */
.dice-area { display: flex; align-items: center; gap: 10px; min-height: clamp(40px, 7vw, 66px); }
.die {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: clamp(40px, 7vw, 64px);
  height: clamp(40px, 7vw, 64px);
  padding: 15%;
  background: #fff;
  border-radius: 22%;
  box-shadow: 0 5px 0 #c9c2e8;
}
.die span { display: block; }
.die .pip { background: var(--ink); border-radius: 50%; margin: 12%; }
.die.idle { opacity: .5; }
.die.rolling { animation: shake .16s infinite; }
.die.landed { animation: land .3s ease-out; }
.die.remote { background: #ffe8f0; box-shadow: 0 5px 0 var(--primary); }
@keyframes shake { 0% { transform: rotate(-12deg); } 50% { transform: rotate(12deg) translateY(-4px); } 100% { transform: rotate(-12deg); } }
@keyframes land { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.dice-total { font-size: clamp(14px, 2vw, 20px); font-weight: 800; color: #ffe066; }

/* ---------- 特效層 ---------- */
.fx-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.float {
  position: absolute;
  transform: translate(-50%, 0);
  white-space: nowrap;
  font-weight: 900;
  font-size: clamp(12px, 1.8vw, 18px);
  padding: 2px 8px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: floatUp 1.6s ease-out forwards;
  z-index: 5;
}
.float-gain { color: var(--gain); }
.float-loss { color: var(--loss); }
.float-warn { color: var(--warn); }
.float-item { color: var(--skill); }
.float-land { color: var(--primary-dark); }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50px) scale(1); }
}
.banner {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  padding: 12px 28px;
  border-radius: 18px;
  font-size: clamp(18px, 3.5vw, 32px);
  font-weight: 900;
  white-space: nowrap;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 6px 0 var(--primary-dark);
  animation: bannerIn .95s ease-out forwards;
  z-index: 6;
}
.banner-skill { background: var(--skill); box-shadow: 0 6px 0 #5d36c4; }
.banner-bankrupt { background: var(--loss); box-shadow: 0 6px 0 #9b1c20; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  30% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* ---------- 側欄：玩家卡 ---------- */
.side { display: flex; flex-direction: column; gap: 12px; }
.player-list { display: flex; flex-direction: column; gap: 10px; }
.pcard {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px 12px;
  border-left: 8px solid var(--pc);
  box-shadow: var(--shadow);
  transition: transform .2s;
}
.pcard.current { transform: scale(1.02); box-shadow: 0 0 0 3px #ffd43b, var(--shadow); }
.pcard.dead { opacity: .5; filter: grayscale(.8); }
.pc-head { display: flex; align-items: center; gap: 8px; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; font-size: 22px; border-radius: 50%; background: var(--pc); border: 2px solid #fff; box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.pc-name { display: flex; flex-direction: column; flex: 1; }
.pc-name small { color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; color: #fff; }
.badge.bad { background: var(--loss); }
.badge.warn { background: var(--warn); }
.badge.on { background: var(--gain); }
.badge.off { background: #868e96; }
.badge.rank { background: #fff3bf; color: var(--ink); }
.pc-stats { display: grid; grid-template-columns: 1.2fr 1.2fr .6fr; gap: 6px; margin: 8px 0 6px; }
.pc-stats div { background: #f3eefc; border-radius: 8px; padding: 3px 6px; display: flex; flex-direction: column; }
.pc-stats small { color: var(--muted); font-size: 11px; }
.pc-stats b { font-size: 15px; }
.pc-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.skill-tag { padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.skill-tag.ready { background: #e5dbff; color: #5f3dc4; }
.skill-tag.cd { background: #eee; color: #888; }
.mini-item { margin-left: 4px; }

.log-box { background: var(--panel); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.log-box h3 { margin: 0 0 6px; font-size: 15px; }
#log { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; font-size: 13px; }
#log li { padding: 4px 2px; border-bottom: 1px dashed var(--line); }
#log .lr { display: inline-block; min-width: 30px; margin-right: 4px; color: var(--muted); font-size: 11px; }
#log .log-gain { color: var(--gain); }
#log .log-loss { color: var(--loss); }
#log .log-warn { color: var(--warn); }
#log .log-skill, #log .log-item { color: #6741d9; }
#log .log-land { color: var(--primary-dark); }
#log .log-bankrupt, #log .log-system { font-weight: 800; }

/* ---------- 彈出視窗 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(16, 12, 40, .65);
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.modal-card, .setup-card {
  width: min(520px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 8px 0 rgba(0,0,0,.25);
  animation: pop .2s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-card h2 { margin: 0 0 10px; font-size: 20px; }
.modal-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal-buttons .btn.num { min-width: 48px; font-size: 18px; background: #ffe8f0; }
.event-text { font-size: 18px; font-weight: 700; }
.hint { color: var(--muted); font-size: 13px; }
.win { font-size: 20px; font-weight: 900; color: var(--primary-dark); }
.group-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; color: #fff; font-weight: 700; font-size: 13px; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.rent-table, .rank-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.rent-table th, .rent-table td, .rank-table th, .rank-table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.rent-table tr.hl, .rank-table tr.me { background: #fff3bf; font-weight: 700; }
.step-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 14px; }
.step-preview b { color: var(--primary-dark); }
.help { padding-left: 20px; line-height: 1.6; font-size: 14px; }
.modal-card h4 { margin: 10px 0 0; }

/* 開場 */
.setup-card { width: min(820px, 100%); text-align: center; }
.setup-card h1 { margin: 4px 0; color: var(--primary-dark); }
.setup-card .sub { color: var(--muted); margin-top: 0; }
.setup-card h3 { margin: 14px 0 8px; text-align: left; }
.char-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.char-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 10px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.char-card.selected { border-color: var(--pc); background: color-mix(in srgb, var(--pc) 10%, #fff); transform: translateY(-3px); }
.big-avatar { display: grid; place-items: center; width: 64px; height: 64px; font-size: 38px; border-radius: 50%; background: var(--pc); border: 3px solid #fff; box-shadow: 0 3px 0 rgba(0,0,0,.2); }
.char-card small { color: var(--muted); }
.char-card p { margin: 4px 0; font-size: 13px; }
.skill-box { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 6px; border-radius: 10px; background: #f3eefc; font-size: 12px; }
.skill-box em { color: var(--muted); font-style: normal; }
.name-input { width: 100%; max-width: 280px; display: block; padding: 10px 14px; font-size: 16px; border: 2px solid var(--line); border-radius: 12px; font-family: inherit; }
.setup-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.setup-buttons .btn { font-size: 18px; padding: .6em 1.6em; }

/* ---------- 提示訊息 ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; }
.toast { max-width: min(360px, calc(100vw - 32px)); padding: 8px 14px; border-radius: 12px; background: #fff; box-shadow: var(--shadow); font-size: 14px; font-weight: 700; border-left: 6px solid #adb5bd; transition: opacity .4s, transform .4s; }
.toast.out { opacity: 0; transform: translateX(20px); }
.toast-gain { border-color: var(--gain); }
.toast-loss { border-color: var(--loss); }
.toast-warn { border-color: var(--warn); }
.toast-skill, .toast-item { border-color: var(--skill); }
.toast-land { border-color: var(--primary); }

/* ---------- 手機 / 平板 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: grid; grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar { padding: 8px 16px; gap: 8px; }
  .logo { font-size: 18px; }
  .top-actions { margin-left: 0; width: 100%; }
  .top-actions .btn { flex: 1; padding: .4em .3em; }
  .actions { gap: 4px; }
  .actions .btn { padding: .45em .7em; }
  .item-bar .item-name { display: none; }
  .char-cards { grid-template-columns: 1fr; }
  .char-card { flex-direction: row; flex-wrap: wrap; text-align: left; justify-content: flex-start; }
  .char-card .big-avatar { width: 48px; height: 48px; font-size: 28px; }
  .char-card p { flex-basis: 100%; }
  .toasts { left: 16px; right: 16px; align-items: stretch; }
}
