:root {
  color-scheme: dark;
  --bg: #0a1628;
  --panel: #122038;
  --border: #243049;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hot: #f472b6;
  --success: #4ade80;
  --danger: #f87171;
  --balloon: #ef4444;
  --balloon-shine: #fca5a5;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: radial-gradient(ellipse at 50% 0%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 20px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.balance-wrap {
  text-align: right;
}

.balance-wrap .label {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.balance {
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 42vh;
  position: relative;
}

.multiplier {
  font-size: clamp(2.5rem, 12vw, 3.5rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 40px rgba(56, 189, 248, 0.35);
  margin-bottom: 8px;
  transition: transform 0.15s ease, color 0.15s ease;
}

.multiplier.win {
  color: var(--success);
}

.multiplier.pop {
  color: var(--danger);
  transform: scale(1.08);
}

.balloon-scene {
  position: relative;
  width: min(280px, 88vw);
  height: min(300px, 48vh);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  margin: 0 auto;
  border: none;
  background: transparent;
  padding: 12px 24px 0;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.balloon-scene.is-playable {
  cursor: pointer;
}

.balloon-scene.is-playable:active .balloon-body {
  filter: brightness(1.08);
}

.balloon {
  position: relative;
  transform-origin: 50% 92%;
  --balloon-scale: 0.2;
  transform: scale(var(--balloon-scale));
  transition: transform 0.35s cubic-bezier(0.34, 1.4, 0.64, 1);
  pointer-events: none;
}

.balloon-body {
  width: 120px;
  height: 150px;
  margin: 0 auto;
  border-radius: 50% 50% 48% 48%;
  background: radial-gradient(circle at 35% 28%, var(--balloon-shine), var(--balloon) 55%, #991b1b);
  box-shadow: inset -12px -16px 24px rgba(0, 0, 0, 0.25);
}

.balloon-knot {
  width: 14px;
  height: 10px;
  margin: -2px auto 0;
  background: #7f1d1d;
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.balloon-string {
  width: 2px;
  height: 48px;
  margin: 0 auto;
  background: linear-gradient(#64748b, #334155);
}

.balloon.pulse {
  animation: balloonPulse 0.35s ease;
}

.balloon.popped {
  opacity: 0;
  transform: scale(calc(var(--balloon-scale) * 1.35));
  transition: opacity 0.2s, transform 0.25s;
}

@keyframes balloonPulse {
  0% { transform: scale(var(--balloon-scale)); }
  45% { transform: scale(calc(var(--balloon-scale) * 1.08)); }
  100% { transform: scale(var(--balloon-scale)); }
}

.pop-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle, rgba(248, 113, 113, 0.55) 0%, transparent 65%);
  animation: popFlash 0.45s ease-out forwards;
}

@keyframes popFlash {
  from { opacity: 1; transform: scale(0.6); }
  to { opacity: 0; transform: scale(1.4); }
}

.status-text {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  min-height: 1.4em;
}

.bet-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-top: 8px;
}

.bet-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 14px;
}

.bet-display {
  text-align: center;
  min-width: 100px;
}

.bet-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
}

.bet-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: #1e293b;
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #2563eb, #1d4ed8);
}

.btn-accent {
  background: linear-gradient(180deg, #0ea5e9, #0284c7);
}

.btn-success {
  background: linear-gradient(180deg, #16a34a, #15803d);
}

.footer-bar {
  display: flex;
  justify-content: space-between;
  padding: 14px 4px 0;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px;
}

.lightning {
  color: #fbbf24;
}

.overlay[hidden] {
  display: none !important;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
}

.modal-wide {
  max-width: 420px;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0f172a;
  color: var(--text);
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.fair-pre {
  background: #020617;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 11px;
  overflow: auto;
  max-height: 240px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 200;
  max-width: 90%;
  text-align: center;
}

.toast.error {
  border-color: var(--danger);
  color: #fecaca;
}

.app.busy {
  pointer-events: none;
  opacity: 0.92;
}
