:root {
  --bg: #0c1c26;
  --panel: #16303a;
  --panel-2: #1e3d48;
  --input: #0c1c26;
  --line: #2b515c;
  --text: #b1bad3;
  --strong: #ffffff;
  --muted: #7f8ea3;
  --green: #00e701;
  --green-ink: #05260a;
  --orange: #ff9f1c;
  --red: #ed4163;
  --gold: #ffd166;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
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;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
code { font-size: 12px; color: var(--strong); background: var(--input); padding: 1px 4px; border-radius: 4px; word-break: break-all; }

/* ---------- top bar ---------- */
.topbar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  height: 56px; padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  justify-self: center; margin: 0; white-space: nowrap;
  font-size: 20px; font-weight: 900; letter-spacing: 2px;
  background: linear-gradient(180deg, #fff0aa, #ffc641 55%, #d89b42);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.top-right { justify-self: end; display: flex; align-items: center; gap: 8px; min-width: 0; }
.back-btn { justify-self: start; display: inline-flex; align-items: center; gap: 4px; }
.back-btn span:first-child { font-size: 20px; line-height: 1; color: #ffc641; }

/* 跑馬燈：寬 26 個字，位置與大小同 Plinko（頂列下方置中） */
.marquee-bar { max-width: 1280px; 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, #16303a, #0c1c26);
  box-shadow: inset 0 0 0 1px rgba(255, 198, 65, .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, #fff0aa, #ffc641 55%, #d89b42);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.back-btn, .rules-btn { white-space: nowrap; flex: none; }
.back-btn { color: var(--strong); text-decoration: none; background: rgba(0, 0, 0, .25); border: 1px solid rgba(255, 198, 65, .45); border-radius: 99px; padding: 6px 12px 6px 8px; font-weight: 700; font-size: 13px; }
.rules-btn { border: 1px solid var(--line); background: none; border-radius: 99px; padding: 3px 12px; font-size: 12px; color: var(--text); }
.rules-btn:hover { color: var(--strong); border-color: var(--strong); }
.rules { padding-left: 20px; line-height: 1.7; font-size: 14px; }
.rules b, .fence-table b { color: var(--gold); }
.fence-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0 10px; }
.fence-table th, .fence-table td { border-bottom: 1px solid var(--line); padding: 7px 6px; text-align: left; }
.fence-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
#hrBtn { color: var(--gold); }
.demo-tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; }
.sound-btn {
  width: 38px; height: 38px; border: 0; border-radius: var(--radius);
  background: var(--input); font-size: 17px; line-height: 1; flex: none;
}
.sound-btn.off { opacity: .55; }
.wallet {
  display: flex; align-items: center; gap: 8px;
  background: var(--input); border-radius: var(--radius); padding: 8px 14px;
  color: var(--strong); font-variant-numeric: tabular-nums;
}
.coin { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ffe28a, #f5a623); display: inline-block; flex: none; }

/* ---------- layout ---------- */
.layout {
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "panel stage" "tables stage";
  align-items: start;
}
.stage { grid-area: stage; position: sticky; top: 68px; height: calc(100vh - 80px); height: calc(100dvh - 80px); display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.panel { grid-area: panel; background: var(--panel); border-radius: var(--radius); padding: 14px; }
.tables { grid-area: tables; height: max(420px, calc(100dvh - 80px - 460px)); background: var(--panel); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* ---------- stage ---------- */
.history { display: flex; gap: 6px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; flex: none; }
.history::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; border-radius: 99px; padding: 4px 10px; font-size: 12px; font-weight: 700;
  background: var(--panel-2); color: var(--text); font-variant-numeric: tabular-nums;
}
.chip.g { color: var(--green); }
.chip.y { color: var(--gold); background: #3a3320; }
.chip.r { color: var(--red); }
.chip.new { animation: pop .4s ease-out; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.chart-wrap { position: relative; flex: 1; min-height: 260px; margin: 0 8px; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; touch-action: manipulation; }
.live-cashouts { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
.live-cashouts div { font-size: 11px; padding: 3px 8px; background: rgba(33, 55, 67, .78); }
.live-cashouts div {
  background: rgba(33, 55, 67, .92); border-radius: 99px; padding: 4px 10px; font-size: 12px;
  display: flex; gap: 8px; align-items: center; animation: slide .3s ease-out; white-space: nowrap;
}
.live-cashouts b { color: var(--green); font-variant-numeric: tabular-nums; }
@keyframes slide { from { transform: translateX(20px); 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; flex: none;
}
.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); }
.link2 { margin-left: 0; }

/* ---------- 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 {
  flex: 1; min-width: 0; 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;
}
.input-row input:focus { border-color: #557086; }
.input-row input: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; }
.suffix { align-self: center; padding: 0 10px; color: var(--muted); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.field, .panel, .stage, .tables { min-width: 0; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.center { text-align: center; }

.profit-hint { display: flex; justify-content: space-between; font-size: 12px; margin: 6px 0 10px; }
.profit-hint b { color: var(--strong); font-variant-numeric: tabular-nums; }

.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 small { display: block; font-size: 12px; font-weight: 600; opacity: .8; }
.main-btn.cash { background: var(--orange); color: #2b1600; }
.main-btn.cancel, .main-btn.stop { background: var(--red); color: #fff; }
.main-btn.queued { background: var(--panel-2); color: var(--strong); }

.sim { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.sim summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.sim .field { margin-top: 10px; }
.range-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.range-row input { flex: 1; accent-color: var(--green); }
.ghost-btn { width: 100%; border: 1px solid var(--line); background: none; border-radius: 6px; padding: 8px; font-size: 13px; }
.ghost-btn:hover { border-color: var(--red); color: var(--red); }

/* ---------- tables ---------- */
.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); flex: none; }
.tabs button { flex: 1; border: 0; background: none; padding: 6px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.tabs button.on { background: var(--panel-2); color: var(--strong); }
.tab-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.list-head, .row {
  display: grid; grid-template-columns: minmax(0, 1.6fr) 1fr .8fr 1fr; gap: 6px; align-items: center;
  padding: 6px 12px; font-size: 12px;
}
.list-head { color: var(--muted); font-weight: 600; flex: none; }
.list-head span:not(:first-child), .row span:not(:first-child) { text-align: right; }
.list { overflow-y: auto; flex: 1; min-height: 0; font-variant-numeric: tabular-nums; }
.row:nth-child(odd) { background: rgba(255, 255, 255, .02); }
.row .name { display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--strong); }
.row .name i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.row .name.hid { color: var(--muted); }
.row.me { background: rgba(0, 231, 1, .08); }
.row.me .name { color: var(--green); font-weight: 700; }
.row .mult { color: var(--muted); }
.row.won .mult, .row.won .pay { color: var(--green); }
.row.lost .pay, .row.lost .mult { color: var(--red); }
.row .tag { font-size: 10px; background: var(--panel-2); border-radius: 4px; padding: 0 4px; color: var(--muted); }
.row .tag.in { color: var(--green); }
.pos { color: var(--green); }
.neg { color: var(--red); }
.empty { padding: 24px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 12px; width: min(560px, 100%); max-height: 85vh; overflow: auto; padding: 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 18px; color: var(--strong); }
.x { border: 0; background: none; font-size: 18px; color: var(--muted); }
.cur { background: var(--input); border-radius: 6px; padding: 10px; font-size: 12px; margin-bottom: 10px; }
.fair-list details { border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 13px; }
.fair-list summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.fair-list .kv { font-size: 12px; margin: 6px 0; }
.ok { color: var(--green); font-weight: 700; }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--panel-2); color: var(--strong); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0, 0, 0, .4); font-weight: 600; animation: slide .25s ease-out; border-left: 4px solid var(--muted); }
.toast.win { border-color: var(--green); }
.toast.err, .toast.lose { border-color: var(--red); }

/* ---------- responsive ---------- */
@media (min-width: 900px) {
  .marquee-bar { padding: 16px 20px 0; font-size: 16px; }
}
@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "stage" "panel" "tables";
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); gap: 8px;
  }
  .stage { position: static; height: auto; }
  .tables { height: 70vh; max-height: none; }
  .chart-wrap { flex: none; height: clamp(240px, 42vh, 380px); min-height: 0; }
  .demo-tag { display: none; }
  .rules-btn { padding: 3px 10px; }
  /* 手機：下注按鈕移到面板最上方，和曲線相鄰 */
  .panel { display: flex; flex-direction: column; }
  .main-btn { order: -2; margin-bottom: 4px; }
  .panel > .hint.center { display: none; }
  .seg { order: -1; margin-top: 8px; }
}
@media (max-width: 480px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .brand { font-size: 16px; white-space: nowrap; }
  .back-btn { padding: 5px 9px; font-size: 12px; }
  .rules-btn { padding: 2px 8px; }
  .wallet { padding: 7px 10px; gap: 6px; }
  .sound-btn { width: 34px; height: 34px; font-size: 15px; }
  .wallet { min-width: 0; }
  .hide-sm { display: none; }
  .live-cashouts div:nth-child(n+3) { display: none; }
  .live-cashouts div { font-size: 11px; padding: 3px 8px; }
  .panel { padding: 12px; }
  .list-head, .row { padding: 6px 10px; }
}
@media (max-width: 380px) {
  .brand { font-size: 14px; letter-spacing: 0; }
  .wallet { padding: 6px 8px; font-size: 13px; }
  .back-btn { padding: 4px 7px; }
}
