:root {
  color-scheme: dark;
  --bg: #121016;
  --panel: #1c1922;
  --panel-border: rgba(255, 224, 165, 0.14);
  --text: #f5efe6;
  --muted: #b5aa9d;
  --gold: #f0b84b;
  --red: #d9382c;
  --red-dark: #9c1f17;
  font-family: "PingFang HK", "Noto Sans TC", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(circle at top, #241b2e 0%, var(--bg) 62%);
  color: var(--text);
}

.arcade-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(240, 184, 75, 0.16);
  color: var(--gold);
  border: 1px solid rgba(240, 184, 75, 0.35);
}

.brand h1 {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.2;
}

.brand small {
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 600;
  margin-left: 6px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.view-switch {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 9px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.view-switch button,
.tool-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.view-switch button[aria-pressed="true"],
.tool-btn[aria-pressed="true"] {
  background: rgba(240, 184, 75, 0.22);
  color: var(--gold);
  border-color: rgba(240, 184, 75, 0.4);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(290px, 360px);
  gap: 14px;
  align-items: start;
}

.cabinet-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.canvas-frame {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: #0a090d;
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.55);
  touch-action: none;
  user-select: none;
}

#cabinet-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(14, 12, 18, 0.88);
  font-size: 0.95rem;
  color: var(--gold);
}

.pull-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 14, 18, 0.88);
  border: 1px solid rgba(240, 184, 75, 0.55);
  color: var(--text);
  font-size: 0.85rem;
  pointer-events: none;
}

.pull-badge b {
  color: var(--gold);
  margin-left: 4px;
}

.result-toast {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(22, 16, 20, 0.92);
  border: 1px solid rgba(240, 184, 75, 0.65);
  color: #fff6dc;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.result-toast.jackpot {
  background: linear-gradient(135deg, #9b1a1a, #c73c18);
  border-color: #ffe07d;
}

.status-bar {
  margin: 0;
  width: 100%;
  max-width: 560px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 0.86rem;
  color: #e6dfd5;
  text-align: center;
}

.control-deck {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-card span {
  font-size: 0.74rem;
  color: var(--muted);
}

.stat-card output {
  font-size: 1.38rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-card.accent output {
  color: var(--gold);
}

.stat-card.jackpot output {
  color: #ff5a47;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.primary-btn {
  appearance: none;
  border: 0;
  border-radius: 11px;
  padding: 11px 14px;
  background: linear-gradient(180deg, #e5493a, var(--red-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 4px 14px rgba(217, 56, 44, 0.35);
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn b {
  font-size: 0.98rem;
}

.primary-btn small {
  font-size: 0.72rem;
  opacity: 0.9;
}

.secondary-btn {
  appearance: none;
  border: 1px solid rgba(240, 184, 75, 0.35);
  border-radius: 11px;
  padding: 0 12px;
  background: rgba(240, 184, 75, 0.12);
  color: var(--gold);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}

.plunger-pad {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 11px;
  padding: 10px 12px;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

.plunger-pad.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.plunger-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.plunger-head b {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.plunger-track {
  position: relative;
  height: 36px;
  border-radius: 999px;
  background: #100e14;
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.plunger-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(217, 56, 44, 0.45), rgba(240, 184, 75, 0.75));
}

.plunger-knob {
  position: absolute;
  top: 3px;
  left: 0%;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #e74c3c, #991c15);
  color: #fff;
  font-size: 0.76rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
}

.payout-board {
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  padding: 10px 12px;
}

.payout-board h2 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--gold);
  font-weight: 700;
}

.payout-board ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.payout-board li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}

.payout-board b {
  font-variant-numeric: tabular-nums;
  color: #fff3d6;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot.red { background: #d62d30; }
.dot.blue { background: #1481c8; }
.dot.green { background: #1ea14b; }
.dot.pink { background: #d63b7e; }
.dot.purple { background: #96205d; }
.dot.white { background: #ece8de; border: 1px solid #888; }

.meta-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

dialog {
  max-width: 460px;
  width: calc(100% - 28px);
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: #1a1721;
  color: var(--text);
  padding: 16px 18px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.dlg-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.dlg-head h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--gold);
}

.close-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
}

dialog ol {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.86rem;
  line-height: 1.5;
}

dialog kbd {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 0.78rem;
}

.dlg-note {
  margin: 12px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 820px) {
  .arcade-shell {
    padding: 8px 10px 16px;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .canvas-frame {
    max-width: 460px;
  }
}

html { overscroll-behavior: none; }
body { touch-action: pan-y; -webkit-touch-callout: none; }
.arcade-shell {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.start-game {
  position: absolute;
  bottom: 3%; left: 50%; transform: translateX(-50%);
  padding: .65rem 1.4rem; min-height: 44px; white-space: nowrap;
  border: 1px solid #f0b84b; border-radius: 8px;
  background: #231a10; color: #ffe4ad; font: inherit; font-weight: 700; cursor: pointer;
}
@media (orientation: landscape) and (max-height: 580px) {
  .workspace { grid-template-columns: minmax(200px, 1fr) minmax(260px, 1fr); }
  .canvas-frame { max-width: max(210px, calc((100dvh - 78px) * .75)); }
}

.canvas-frame[data-view="playfield"] { aspect-ratio: 3 / 4.48; }
@media (max-width: 520px) {
  .topbar { gap: 7px; padding: 8px; }
  .toolbar { gap: 4px; }
  .view-switch button, .tool-btn { padding: 6px; }
}

/* Keep touch capture on the stationary control as the knob moves. */
.plunger-pad * { pointer-events: none; }
