:root {
  --bg-deep: #090d1c;
  --bg-mid: #111831;
  --panel: rgba(18, 25, 48, 0.92);
  --panel-border: rgba(99, 130, 210, 0.22);
  --cyan: #22d3ee;
  --emerald: #10b981;
  --emerald-bright: #34d399;
  --gold: #fbbf24;
  --gold-bright: #fde047;
  --rose: #f43f5e;
  --slate: #94a3b8;
  --text: #f8fafc;
  --tile-idle: #1a2444;
  --tile-idle-top: #24315a;
  --tile-active: #163a59;
  --tile-active-top: #1d577c;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, #1a2550 0%, var(--bg-deep) 70%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}

.bg-stars {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1.5px 1.5px at 15% 20%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 80% 15%, rgba(56,189,248,0.55), transparent),
    radial-gradient(1.5px 1.5px at 40% 55%, rgba(251,191,36,0.35), transparent),
    radial-gradient(1px 1px at 90% 65%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1.5px 1.5px at 22% 82%, rgba(52,211,153,0.4), transparent);
  background-size: 260px 260px;
  opacity: 0.7;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) 8px env(safe-area-inset-bottom, 6px);
  gap: 5px;
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  flex-shrink: 0;
}

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

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #132245, #1e3a5f);
  border: 1px solid rgba(34, 211, 238, 0.35);
  display: grid;
  place-items: center;
}

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

.brand-title {
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.08em;
  background: linear-gradient(90deg, #fff, #7dd3fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 2px 5px;
  border-radius: 5px;
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #0b1020;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.balance-pill {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(9, 13, 28, 0.85);
  border: 1px solid rgba(52, 211, 153, 0.35);
}

.bal-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--slate);
  letter-spacing: 0.05em;
}

.bal-val {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--emerald-bright);
  font-variant-numeric: tabular-nums;
}

.bal-delta {
  position: absolute;
  right: 8px;
  top: -12px;
  font-size: 11px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
}

.bal-delta.show-plus {
  color: var(--gold-bright);
  animation: deltaPop 1.1s ease-out forwards;
}

.bal-delta.show-minus {
  color: var(--rose);
  animation: deltaPop 0.9s ease-out forwards;
}

@keyframes deltaPop {
  0% { opacity: 0; transform: translateY(4px) scale(0.9); }
  20% { opacity: 1; transform: translateY(-2px) scale(1.05); }
  100% { opacity: 0; transform: translateY(-16px) scale(0.95); }
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid var(--panel-border);
  background: rgba(25, 36, 68, 0.9);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn:active { transform: scale(0.93); }

/* ─── History Strip ─── */
.history-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 24px;
  padding: 2px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.history-strip::-webkit-scrollbar { display: none; }

.history-placeholder {
  font-size: 11px;
  color: var(--slate);
  letter-spacing: 0.02em;
}

.hist-pill {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.hist-pill.win {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.4);
}

.hist-pill.jackpot {
  background: rgba(251, 191, 36, 0.24);
  color: #fde047;
  border: 1px solid rgba(251, 191, 36, 0.55);
}

.hist-pill.loss {
  background: rgba(244, 63, 94, 0.16);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.35);
}

/* ─── Staircase Arena ─── */
.arena-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(20, 31, 64, 0.92) 0%, rgba(11, 17, 36, 0.96) 100%);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 6px 6px 8px;
  overflow: hidden;
  box-shadow: inset 0 0 36px rgba(34, 211, 238, 0.06);
}

.arena-wrap.shake {
  animation: arenaShake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes arenaShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.summit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  margin-bottom: 4px;
  border-radius: 9px;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.18), rgba(245, 158, 11, 0.06), rgba(251, 191, 36, 0.18));
  border: 1px solid rgba(251, 191, 36, 0.35);
  flex-shrink: 0;
}

.summit-crown { font-size: 13px; }
.summit-text {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fde68a;
}
.summit-mult {
  font-size: 11.5px;
  font-weight: 900;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.staircase-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.staircase-grid {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 3px;
}

.stair-row {
  display: grid;
  grid-template-columns: 54px repeat(10, 1fr);
  align-items: center;
  gap: 3px;
  flex: 1 1 0;
  min-height: 0;
  padding: 1px 2px;
  border-radius: 7px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.stair-row.active-row {
  background: rgba(34, 211, 238, 0.13);
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, 0.45), 0 0 14px rgba(34, 211, 238, 0.16);
}

.stair-row.cleared-row {
  background: rgba(16, 185, 129, 0.07);
}

.row-mult {
  font-size: 10.5px;
  font-weight: 800;
  text-align: right;
  padding-right: 5px;
  color: var(--slate);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stair-row.active-row .row-mult {
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(34, 211, 238, 0.6);
}

.stair-row.cleared-row .row-mult {
  color: var(--emerald-bright);
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 22px;
  border: none;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--tile-idle-top) 0%, var(--tile-idle) 100%);
  box-shadow: 0 2px 0 #0b1024, inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: default;
  display: grid;
  place-items: center;
  font-size: 13px;
  transition: transform 0.12s ease, background 0.18s ease, box-shadow 0.18s ease;
  padding: 0;
}

.stair-row.active-row .tile {
  cursor: pointer;
  background: linear-gradient(180deg, var(--tile-active-top) 0%, var(--tile-active) 100%);
  box-shadow: 0 2px 0 #0b2238, inset 0 1px 0 rgba(125, 211, 252, 0.45);
  animation: tilePulse 1.6s ease-in-out infinite;
}

.stair-row.active-row .tile:hover {
  transform: translateY(-1px);
  background: linear-gradient(180deg, #2574a3 0%, #1a4d70 100%);
}

.stair-row.active-row .tile:active {
  transform: translateY(1px) scale(0.95);
}

@keyframes tilePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.16); }
}

.tile.safe-picked {
  animation: none !important;
  background: linear-gradient(180deg, #34d399 0%, #059669 100%) !important;
  box-shadow: 0 2px 0 #064e3b, 0 0 12px rgba(52, 211, 153, 0.55) !important;
}

.tile.stone-hit {
  animation: none !important;
  background: linear-gradient(180deg, #f43f5e 0%, #9f1239 100%) !important;
  box-shadow: 0 2px 0 #4c0519, 0 0 14px rgba(244, 63, 94, 0.7) !important;
}

.tile.stone-reveal {
  animation: none !important;
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%) !important;
  box-shadow: 0 2px 0 #0f172a !important;
  opacity: 0.78;
}

.tile.safe-dim {
  opacity: 0.45;
}

.tile-icon {
  display: inline-block;
  line-height: 1;
  font-size: 13px;
}

.tile.safe-picked .tile-icon {
  animation: starPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
  0% { transform: scale(0.2) rotate(-35deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ─── Climber Character ─── */
.climber {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 36px;
  pointer-events: none;
  z-index: 10;
  transform: translate(-50%, -82%);
  transition: left 0.28s cubic-bezier(0.22, 1, 0.36, 1), top 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
}

.climber.jumping .climber-svg {
  animation: climberHop 0.3s ease-out;
}

.climber.celebrate .climber-svg {
  animation: climberCelebrate 0.65s ease-in-out 2;
}

.climber.tumble .climber-svg {
  animation: climberTumble 0.45s ease-in forwards;
}

@keyframes climberHop {
  0% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-14px) scale(0.92, 1.12); }
  100% { transform: translateY(0) scale(1.06, 0.94); }
}

@keyframes climberCelebrate {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(6deg); }
}

@keyframes climberTumble {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(20px) rotate(-85deg); opacity: 0.35; }
}

/* ─── Falling Boulder FX ─── */
.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: hidden;
}

.falling-boulder {
  position: absolute;
  font-size: 24px;
  transform: translate(-50%, -50%);
  animation: boulderDrop 0.34s cubic-bezier(0.55, 0.06, 0.68, 0.19) forwards;
  filter: drop-shadow(0 4px 10px rgba(244, 63, 94, 0.65));
}

@keyframes boulderDrop {
  0% { transform: translate(-50%, -130px) rotate(-60deg) scale(1.25); opacity: 0.8; }
  85% { transform: translate(-50%, -45%) rotate(20deg) scale(1.05); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(0deg) scale(0.9); opacity: 0; }
}

.float-mult {
  position: absolute;
  font-size: 13px;
  font-weight: 900;
  color: var(--gold-bright);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
  transform: translate(-50%, -50%);
  animation: floatUp 0.8s ease-out forwards;
}

@keyframes floatUp {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.85); }
  100% { opacity: 0; transform: translate(-50%, -95px) scale(1.15); }
}

/* ─── Result Toast ─── */
.result-toast {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%) scale(0.85);
  z-index: 20;
  padding: 12px 20px;
  border-radius: 14px;
  text-align: center;
  font-weight: 900;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(8px);
  min-width: 210px;
}

.result-toast.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.result-toast.win {
  background: rgba(6, 78, 59, 0.94);
  border: 2px solid var(--emerald-bright);
  color: #ecfdf5;
  box-shadow: 0 10px 30px rgba(16, 185, 129, 0.45);
}

.result-toast.jackpot {
  background: rgba(120, 53, 15, 0.95);
  border: 2px solid var(--gold-bright);
  color: #fefce8;
  box-shadow: 0 10px 36px rgba(251, 191, 36, 0.55);
}

.result-toast.loss {
  background: rgba(136, 19, 55, 0.94);
  border: 2px solid var(--rose);
  color: #fff1f2;
  box-shadow: 0 10px 30px rgba(244, 63, 94, 0.45);
}

.toast-title { font-size: 13px; letter-spacing: 0.08em; opacity: 0.92; }
.toast-amount { font-size: 22px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.toast-sub { font-size: 11px; opacity: 0.85; margin-top: 2px; }

/* ─── Bottom Control Dock ─── */
.control-dock {
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dock-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bet-row {
  flex-wrap: nowrap;
}

.bet-input-group {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  background: rgba(9, 13, 28, 0.9);
  border: 1px solid rgba(99, 130, 210, 0.3);
  border-radius: 10px;
  padding: 3px 4px 3px 8px;
  gap: 4px;
}

.input-prefix {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
}

.bet-input {
  width: 100%;
  min-width: 44px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.bet-input::-webkit-inner-spin-button,
.bet-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.mini-btn {
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid rgba(99, 130, 210, 0.25);
  background: #1c284d;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.mini-btn:active { transform: scale(0.94); }
.mini-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.preset-chips {
  display: flex;
  gap: 4px;
}

.chip-btn {
  padding: 6px 7px;
  border-radius: 8px;
  border: 1px solid rgba(99, 130, 210, 0.25);
  background: #162040;
  color: #e2e8f0;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.chip-btn:active { transform: scale(0.94); }
.chip-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Stones selector */
.stones-row {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
}

.stones-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.stones-label { color: #cbd5e1; }
.stones-risk { color: var(--cyan); }

.stones-selector {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.stone-opt {
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(99, 130, 210, 0.25);
  background: #141d3a;
  color: #cbd5e1;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
}

.stone-opt.active {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  color: #0b1020;
  border-color: #fde047;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.45);
}

.stone-opt:disabled { opacity: 0.45; cursor: not-allowed; }

/* Action Row */
.action-row {
  gap: 6px;
}

.btn-primary {
  flex: 1 1 auto;
  height: 46px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  transition: transform 0.12s ease, filter 0.15s ease, box-shadow 0.2s ease;
}

.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-start {
  background: linear-gradient(180deg, #34d399 0%, #059669 100%);
  color: #042f2e;
  box-shadow: 0 4px 0 #065f46, 0 6px 20px rgba(16, 185, 129, 0.35);
}

.btn-cashout {
  background: linear-gradient(180deg, #fde047 0%, #f59e0b 100%);
  color: #451a03;
  box-shadow: 0 4px 0 #92400e, 0 6px 24px rgba(251, 191, 36, 0.48);
  animation: cashoutGlow 1.4s ease-in-out infinite;
}

.btn-waiting {
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
  color: #cbd5e1;
  box-shadow: 0 3px 0 #0f172a;
}

@keyframes cashoutGlow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.1); }
}

.btn-title {
  font-size: 14.5px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.btn-sub {
  font-size: 10.5px;
  font-weight: 800;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.btn-random {
  width: 66px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(34, 211, 238, 0.45);
  background: linear-gradient(180deg, #164e63 0%, #0e3a4d 100%);
  color: #cffafe;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  box-shadow: 0 4px 0 #082f49;
}

.btn-random span { font-size: 9px; letter-spacing: 0.08em; }
.btn-random:active { transform: scale(0.95); }

.hidden { display: none !important; }

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 8, 18, 0.78);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: #121b38;
  border: 1px solid rgba(99, 130, 210, 0.35);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

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

.modal-head h2 {
  font-size: 15px;
  font-weight: 900;
  color: var(--gold-bright);
}

.modal-body {
  font-size: 13px;
  line-height: 1.5;
  color: #cbd5e1;
}

.modal-body ul {
  margin: 8px 0 10px 18px;
}

.modal-body li { margin-bottom: 4px; }

.formula-box {
  background: rgba(9, 13, 28, 0.85);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 9px;
  padding: 8px 10px;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--cyan);
  margin-bottom: 8px;
}

.modal-meta {
  font-size: 11px;
  color: var(--slate);
  text-align: center;
}
