:root {
  --ink: #1b1b1f;
  --paper: #ffffff;
  --pixel: "Press Start 2P", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Game-over panel palette — every surface and button follows these. */
  --panel-bg: #14161c;
  --panel-border: #000000;
  --gold: #ffd23f;
  --gold-dim: #c99a10;
  --muted: #9aa3b2;
  --loss: #ff6b6b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #b8e7f4;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  font-family: var(--pixel);
  color: var(--paper);
  padding: max(8px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.wallet-bar,
.bet-bar,
.stake-hud,
.run-bar,
.modal,
.gameover {
  pointer-events: auto;
}

/* One header: balance + deposit on top, smaller bet chips underneath. */
.wallet-bar {
  width: min(560px, 100%);
  margin-inline: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
}

.wallet-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.wallet-label,
.bet-label {
  display: block;
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 4px;
}

.wallet-balance {
  font-size: clamp(11px, 3.4vw, 15px);
  letter-spacing: 1px;
  color: var(--gold);
}

.wallet-actions {
  display: flex;
  gap: 8px;
}

.wallet-btn {
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 1px;
  border: 0;
  border-radius: 6px;
  padding: 11px 13px;
  cursor: pointer;
  background: var(--gold);
  color: var(--panel-bg);
  box-shadow: 0 4px 0 var(--gold-dim);
}

.wallet-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--gold-dim);
}

.wallet-btn.ghost {
  background: transparent;
  color: var(--gold);
  border: 2px solid var(--gold-dim);
  box-shadow: none;
}

.bet-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 2px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  touch-action: pan-x;
}

.bet-bar[hidden] {
  display: none;
}

.bet-bar::-webkit-scrollbar {
  display: none;
}

.bet-chips {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.bet-bar .bet-label {
  margin-bottom: 0;
}

.bet-bar .chip {
  flex-shrink: 0;
  font-size: 7px;
  padding: 8px 7px;
  border-radius: 5px;
}

.deposit-grid .chip {
  font-size: 9px;
  padding: 12px 8px;
}

.chip {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 0;
  padding: 10px 8px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: #1e2129;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.chip.on {
  border-color: var(--gold);
  background: var(--gold);
  color: var(--panel-bg);
  box-shadow: 0 3px 0 var(--gold-dim);
}

.chip:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.stake-hud {
  position: absolute;
  top: calc(max(8px, env(safe-area-inset-top)) + 118px);
  left: 12px;
  display: flex;
  gap: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--muted);
}

.stake-hud strong {
  color: var(--gold);
  margin-left: 5px;
}

/* A run hides the wallet header; the cash-out bar takes its place up top. */
#ui.playing .wallet-bar {
  display: none;
}

/*
 * During a run the header is replaced by this bar: live numbers plus a gold
 * CASH OUT button that matches DEPOSIT.
 */
.run-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: min(480px, calc(100vw - 24px));
  top: calc(max(10px, env(safe-area-inset-top)) + 42px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 10px;
  border: 3px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--muted);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
}

.run-bar[hidden],
.stake-hud[hidden] {
  display: none !important;
}

.run-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.cashout-bet {
  font-size: 7px;
  letter-spacing: 0;
  white-space: nowrap;
}

.cashout-bet strong {
  font-weight: inherit;
  color: var(--gold);
  margin-left: 4px;
}

.cashout-mult {
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--gold);
  white-space: nowrap;
}

.cashout-win {
  font-size: 7px;
  letter-spacing: 0;
  color: var(--gold);
  white-space: nowrap;
}

.cashout-btn {
  flex-shrink: 0;
  font-size: 7px;
  letter-spacing: 0;
  padding: 9px 10px;
  white-space: nowrap;
}

.cashout-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

@media (max-width: 430px) {
  .run-bar {
    flex-wrap: wrap;
  }

  .run-stats {
    width: 100%;
    flex: 1 0 100%;
  }

  .cashout-btn {
    width: 100%;
  }
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.65);
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: min(92dvh, 920px);
  overflow-y: auto;
  padding: 24px 22px 22px;
  border-radius: 10px;
  background: var(--panel-bg);
  border: 4px solid var(--panel-border);
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.3);
  color: #e2e8f0;
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.modal-title {
  font-size: clamp(14px, 4vw, 18px);
  letter-spacing: 2px;
  color: var(--gold);
  margin-bottom: 12px;
}

.modal-copy {
  font-size: 9px;
  line-height: 1.8;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 0 0 16px;
}

.deposit-qr {
  display: grid;
  place-items: center;
  padding: 10px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: #1e2129;
  border: 2px solid rgba(255, 255, 255, 0.14);
}

.deposit-qr img {
  display: block;
  width: min(180px, 42vw);
  height: auto;
  border-radius: 6px;
}

@media (max-height: 700px) {
  .deposit-qr {
    padding: 8px;
    margin-bottom: 10px;
  }

  .deposit-qr img {
    width: 120px;
  }

  .modal-card {
    padding: 18px 16px 16px;
  }
}

.deposit-address {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.deposit-address code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--gold);
  padding: 9px 10px;
  border-radius: 6px;
  background: #1e2129;
  border: 2px solid rgba(255, 255, 255, 0.14);
}

.deposit-address .wallet-btn {
  flex-shrink: 0;
}

.deposit-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.field {
  display: grid;
  gap: 8px;
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 16px;
}

.field input,
.field select {
  font-family: var(--pixel);
  font-size: 11px;
  padding: 13px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: #1e2129;
  color: #fff;
}

.field select {
  cursor: pointer;
  appearance: none;
  /* Gold chevron so the dropdown reads as part of the black-and-gold kit. */
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.field select:focus {
  outline: none;
  border-color: var(--gold-dim);
}

.modal-confirm {
  width: 100%;
}

.panel-payout {
  font-size: clamp(10px, 3vw, 13px);
  letter-spacing: 1px;
  color: var(--loss);
  min-height: 1.2em;
}

.panel-payout.win {
  color: var(--gold);
}

.hud {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-top: auto;
}

.score {
  font-size: clamp(30px, 8vw, 54px);
  letter-spacing: 2px;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.score.on {
  opacity: 1;
}

.best {
  font-size: clamp(9px, 2.6vw, 13px);
  letter-spacing: 1px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.32);
}

.hint {
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(520px, 100%);
  text-align: center;
  animation: bob 1.6s ease-in-out infinite;
  transition: opacity 0.3s ease;
}

.hint-line {
  font-size: clamp(9px, 2.8vw, 15px);
  letter-spacing: 1px;
  line-height: 1.6;
  background: rgba(0, 0, 0, 0.72);
  padding: 12px 14px;
  border-radius: 4px;
}

.hint-sub {
  font-size: clamp(7px, 2.2vw, 10px);
  letter-spacing: 1px;
  line-height: 1.7;
  color: #e9f6ff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
  padding: 0 8px;
}

.hint[hidden] {
  display: none;
}

@keyframes bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.gameover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 16, 22, 0.45);
  pointer-events: auto;
}

.gameover[hidden] {
  display: none;
}

.panel {
  width: min(360px, calc(100vw - 32px));
  background: var(--panel-bg);
  border: 4px solid var(--panel-border);
  border-radius: 10px;
  padding: 26px 22px;
  text-align: center;
  display: grid;
  gap: 16px;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.3);
}

.panel-title {
  font-size: clamp(22px, 7vw, 34px);
  letter-spacing: 3px;
  color: var(--gold);
}

.panel-score {
  font-size: clamp(10px, 3vw, 14px);
  letter-spacing: 2px;
}

.btn {
  font-family: var(--pixel);
  font-size: clamp(10px, 3vw, 14px);
  letter-spacing: 2px;
  color: var(--panel-bg);
  background: var(--gold);
  border: 0;
  border-radius: 6px;
  padding: 14px 18px;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--gold-dim);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--gold-dim);
}
