:root {
  --bg: #0f212e;
  --panel: #1a2c38;
  --panel-2: #213743;
  --input: #0f212e;
  --line: #2f4553;
  --text: #b1bad3;
  --strong: #ffffff;
  --muted: #7f8ea3;
  --green: #00e701;
  --green-ink: #05260a;
  --orange: #ff9f1c;
  --red: #ed4163;
  --gold: #ffd166;
  --gold-light: #fff0aa;
  --tile: #2f4553;
  --tile-hi: #557086;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, Consolas, monospace; }

/* ---------- topbar：返回大廳 | 標題 | 餘額 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel); box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}
.brand {
  justify-self: center; margin: 0; font-size: 22px; font-weight: 900; letter-spacing: 2px; white-space: nowrap;
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, #d89b42);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.back-btn {
  justify-self: start; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  color: var(--strong); text-decoration: none; background: var(--panel-2); border: 1px solid rgba(255, 209, 102, .45);
  border-radius: 99px; padding: 6px 14px 6px 10px; font-weight: 700; font-size: 14px;
}
.back-btn span:first-child { color: var(--gold); font-size: 18px; line-height: 1; }
.back-btn:hover { background: var(--line); }
.top-right { justify-self: end; display: flex; align-items: center; gap: 8px; }
.sound-btn { background: var(--panel-2); border: 0; border-radius: 99px; width: 36px; height: 36px; flex: none; }
.sound-btn.off { opacity: .45; }

/* ---------- 跑馬燈：會員列下方、遊戲區上方，寬 26 字 ---------- */
.marquee-bar { max-width: 1200px; margin: 0 auto; padding: 10px 12px 0; font-size: 13px; font-weight: 900; line-height: 1.8; }
.marquee {
  display: block; width: 26em; max-width: 100%; margin: 0 auto; overflow: hidden; padding: 1px 0;
  border-radius: 999px; background: linear-gradient(180deg, #1d3a4c, #0b1a24);
  box-shadow: inset 0 0 0 1px rgba(255, 209, 102, .55), 0 2px 6px rgba(0, 0, 0, .3);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent);
}
.marquee-track { display: inline-flex; white-space: nowrap; animation: marquee 20s linear infinite; }
.marquee-track span {
  background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, #d89b42);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) { .marquee-track { animation-duration: 60s !important; } }

.wallet { display: flex; align-items: center; gap: 8px; background: var(--input); border-radius: 99px; padding: 8px 14px; }
.wallet b { color: var(--strong); font-variant-numeric: tabular-nums; }
.coin { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe28a, #f5a300); display: inline-block; }
.wallet.bump b { animation: bump .5s; }
@keyframes bump { 40% { color: var(--green); transform: scale(1.12); } }

/* ---------- layout ---------- */
.layout {
  max-width: 1200px; margin: 0 auto; padding: 12px; display: grid; gap: 12px;
  grid-template-columns: 320px 1fr;
  grid-template-areas: "panel stage" "tables stage";
  align-items: start;
}
.panel { grid-area: panel; background: var(--panel); border-radius: var(--radius); padding: 14px; }
.stage { grid-area: stage; background: var(--panel); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.tables { grid-area: tables; background: var(--panel); border-radius: var(--radius); overflow: hidden; }

/* ---------- panel ---------- */
.seg { display: flex; background: var(--input); border-radius: 99px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 99px; font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--strong); }
.seg button:disabled { opacity: .45; cursor: not-allowed; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.field small { font-weight: 400; color: var(--muted); }
.input-row { display: flex; background: var(--line); border-radius: 6px; padding: 2px; gap: 2px; align-items: stretch; }
.input-row input, select, .readout {
  flex: 1; min-width: 0; width: 100%; background: var(--input); border: 2px solid transparent; border-radius: 4px;
  padding: 8px 10px; color: var(--strong); font-weight: 600; outline: none; font-variant-numeric: tabular-nums;
}
select { border: 2px solid var(--line); border-radius: 6px; padding: 8px; appearance: auto; }
.readout { border: 2px solid var(--line); border-radius: 6px; background: var(--panel-2); }
.input-row input:focus, select:focus { border-color: #557086; }
.input-row input:disabled, select:disabled { opacity: .6; }
.input-row button { border: 0; background: var(--line); padding: 0 12px; border-radius: 4px; font-weight: 700; color: var(--strong); }
.input-row button:hover { background: #3d5564; }
.input-row button:disabled { opacity: .5; cursor: not-allowed; }
.suffix { align-self: center; padding: 0 10px; color: var(--muted); }
/* 自動局數：10–100 局，滑桿或左右箭頭選 */
.count-row input[type=range] { padding: 0 6px; accent-color: var(--green); background: var(--input); }
.count-out { color: var(--strong); margin-left: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.hint b { color: var(--strong); }
.center { text-align: center; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0 12px; }
.stats div { background: var(--input); border-radius: 6px; padding: 6px 10px; display: flex; flex-direction: column; }
.stats span { font-size: 11px; color: var(--muted); }
.stats b { color: var(--strong); font-variant-numeric: tabular-nums; font-size: 15px; }
.stats b.g { color: var(--green); }

.main-btn {
  width: 100%; border: 0; border-radius: var(--radius); padding: 14px 10px;
  font-size: 16px; font-weight: 800; background: var(--green); color: var(--green-ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25); transition: transform .05s, filter .15s;
  min-height: 52px; touch-action: manipulation;
}
.main-btn:hover { filter: brightness(1.08); }
.main-btn:active { transform: translateY(2px); }
.main-btn:disabled { filter: grayscale(.8) brightness(.7); cursor: not-allowed; }
.main-btn small { display: block; font-size: 12px; font-weight: 600; opacity: .85; }
.main-btn.cash { background: var(--orange); color: #2b1600; }
.main-btn.stop { background: var(--red); color: #fff; }
.sub-btn { width: 100%; margin-top: 8px; border: 0; border-radius: var(--radius); padding: 10px; background: var(--panel-2); color: var(--strong); font-weight: 700; }
.sub-btn:hover { background: var(--line); }

/* ---------- stage ---------- */
.ladder { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; min-height: 48px; }
.ladder::-webkit-scrollbar { display: none; }
.step {
  flex: none; background: var(--panel-2); border-radius: 6px; padding: 4px 10px; text-align: center;
  font-variant-numeric: tabular-nums; min-width: 64px; transition: background .2s, color .2s;
}
.step b { display: block; color: var(--strong); font-size: 13px; }
.step span { font-size: 10px; color: var(--muted); }
.step.done { background: #173a22; }
.step.done b { color: var(--green); }
.step.next { outline: 2px solid var(--green); }

.board-wrap { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; padding: 8px 12px 16px; }
.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; width: min(100%, 560px); }
.tile {
  aspect-ratio: 1; border: 0; border-radius: 10px; background: var(--tile); position: relative;
  box-shadow: 0 5px 0 #1d313c; transition: transform .12s, background .15s, box-shadow .12s;
  display: flex; align-items: center; justify-content: center; font-size: clamp(22px, 6vw, 44px);
  touch-action: manipulation; user-select: none;
}
.tile:not(:disabled):hover { background: var(--tile-hi); transform: translateY(-3px); box-shadow: 0 8px 0 #1d313c; }
.tile:disabled { cursor: default; }
.tile.selected { background: #5b3fa0; box-shadow: 0 5px 0 #34245d; }
.tile.selected::after { content: "✓"; position: absolute; top: 4px; right: 8px; font-size: 14px; color: #fff; }
.tile.open { background: var(--input); box-shadow: none; transform: none; animation: flip .3s ease-out; }
.tile.open.gem .ico { filter: drop-shadow(0 0 10px rgba(0, 231, 1, .6)); }
.tile.open.mine { background: #3b1520; }
.tile.open.hit { background: var(--red); animation: boom .45s ease-out; }
.tile.ghost { opacity: .45; }
.tile.pending { background: var(--tile-hi); animation: pending .35s ease-in-out infinite alternate; }
@keyframes pending { from { transform: scale(.94); } to { transform: scale(1.04); box-shadow: 0 0 18px rgba(0, 231, 1, .35); } }
.tile.ghost .ico { transform: scale(.7); }
.ico { display: inline-block; transition: transform .2s; }
@keyframes flip { from { transform: rotateY(90deg) scale(.8); } }
@keyframes boom { 30% { transform: scale(1.18); } 60% { transform: scale(.94); } }
.board.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.win-pop {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(15, 33, 46, .95); border: 3px solid var(--green); border-radius: 12px;
  padding: 16px 30px; text-align: center; pointer-events: none; animation: popin .3s ease-out;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.win-pop b { display: block; font-size: 32px; color: var(--green); font-variant-numeric: tabular-nums; }
.win-pop span { color: var(--strong); font-weight: 700; }
@keyframes popin { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }

.stage-foot { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.stage-foot b { color: var(--strong); font-variant-numeric: tabular-nums; }
.link { margin-left: auto; background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 0; }
.link:hover { color: var(--strong); }
.link + .link { margin-left: 0; }
.verify-link { color: var(--green); font-weight: 800; text-decoration: none; }
.verify-link:disabled { color: var(--muted); cursor: not-allowed; opacity: .55; }

/* ---------- tables ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 10px; font-weight: 600; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--strong); border-bottom-color: var(--green); }
.tab-body { padding: 10px 12px; max-height: 360px; overflow: auto; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.summary div { background: var(--input); border-radius: 6px; padding: 6px 8px; font-size: 11px; color: var(--muted); }
.summary b { display: block; color: var(--strong); font-size: 14px; font-variant-numeric: tabular-nums; }
.summary b.g { color: var(--green); }
.summary b.r { color: var(--red); }
.list-head, .row { display: grid; grid-template-columns: 1fr .7fr 1fr 1fr 1fr; gap: 6px; font-size: 12px; padding: 5px 4px; font-variant-numeric: tabular-nums; }
.list-head.three, .row.three { grid-template-columns: 1fr 1fr 1fr; }
.list-head { color: var(--muted); }
.row { border-radius: 4px; }
.row:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.row .g { color: var(--green); }
.row .r { color: var(--red); }
.row.cur { outline: 1px solid var(--green); }
.empty { color: var(--muted); padding: 16px; text-align: center; }
.rules { font-size: 13px; }
.rules h4 { color: var(--strong); margin: 12px 0 4px; }
.rules ol { padding-left: 18px; margin: 4px 0; }
.rules code { color: var(--gold); font-size: 12px; }

/* ---------- modal ---------- */
.modal { border: 0; padding: 0; background: none; color: var(--text); max-width: min(520px, calc(100vw - 24px)); width: 100%; }
.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal-card { background: var(--panel); border-radius: 12px; padding: 16px; }
.modal h3 { margin: 0 0 12px; color: var(--strong); }
.modal h4 { margin: 8px 0; color: var(--strong); }
.modal hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.hash { display: block; word-break: break-all; background: var(--input); padding: 8px; border-radius: 6px; font-size: 12px; }
.verify-out { font-size: 12px; margin: 6px 0; word-break: break-all; }
.verify-out .g { color: var(--green); }
.verify-out .r { color: var(--red); }
.verify-intro { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.verification-checks { display: grid; gap: 8px; }
.verification-check { display: flex; justify-content: space-between; gap: 12px; padding: 10px; border-radius: 6px; background: var(--input); color: var(--strong); font-weight: 700; }
.verification-check .g { color: var(--green); }
.verification-check .r { color: var(--red); }
.advanced-verify summary { margin-bottom: 10px; color: var(--muted); cursor: pointer; font-weight: 700; }
.mini-board { display: grid; grid-template-columns: repeat(5, 28px); gap: 4px; justify-content: center; margin: 8px 0; }
.mini-board span { width: 28px; height: 28px; border-radius: 4px; background: var(--input); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.modal-actions { margin-top: 12px; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .topbar { padding: 8px 10px; gap: 6px; }
  .brand { font-size: 19px; letter-spacing: 1px; }
  .layout { grid-template-columns: 1fr; grid-template-areas: "stage" "panel" "tables"; padding: 8px; gap: 8px; }
  .board { gap: 7px; }
  .tile { border-radius: 8px; }
  .panel { padding: 12px; }
  .panel .hint.center { font-size: 11px; }
  /* 跟珠珠寶貝一致：主按鈕放在投注區塊最上方，隨下方區塊一起捲動（不固定在畫面底部） */
  .panel { display: flex; flex-direction: column; }
  .main-btn#mainBtn { order: -1; margin-bottom: 12px; }
  .layout { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
@media (min-width: 900px) {
  .marquee-bar { padding: 14px 12px 0; font-size: 16px; }
}
@media (max-width: 420px) {
  .topbar { padding-left: 8px; padding-right: 8px; }
  .back-btn { padding: 5px 9px 5px 6px; font-size: 12px; }
  .brand { font-size: 17px; }
  .top-right { gap: 4px; }
  .wallet { padding: 6px 10px; gap: 5px; }
  .wallet b { font-size: 13px; }
  .sound-btn { width: 30px; height: 30px; font-size: 13px; }
  .stats b { font-size: 13px; }
}
