/* style.css — MARBLE RUSH
   Premium, high-saturation, "international AAA level" visual polish per
   the client's explicit brief: real gradients, glow, satisfying press
   states, premium typography on every control. Err toward MORE spectacle.
*/

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Nunito:wght@500;700;800;900&display=swap');

:root {
  --bg-deep: #120a33;
  --bg-mid: #1e1248;
  --gold: #ffd84a;
  --gold-deep: #ff9f1c;
  --cyan: #5ef7ff;
  --magenta: #ff5ec8;
  --lime: #8dff5e;
  --red: #ff4d6a;
  --blue: #3fd0ff;
  --green: #52ff8a;
  --panel-glass: rgba(18, 10, 51, 0.72);
  --panel-border: rgba(255, 255, 255, 0.14);
  --text-main: #fff7e6;
  --text-dim: rgba(255, 247, 230, 0.68);
  --shadow-deep: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, #2a1a5e 0%, var(--bg-deep) 55%, #0a0620 100%);
  color: var(--text-main);
  font-family: 'Nunito', system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 10px) 12px env(safe-area-inset-bottom, 14px);
  gap: 10px;
  position: relative;
}

/* ---------------- Topbar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 2px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex-wrap: wrap;
  row-gap: 4px;
}

.brand-mark {
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(255, 216, 74, 0.5));
}

.brand-name {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.28rem;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--gold) 0%, var(--magenta) 55%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
  text-shadow: 0 0 18px rgba(255, 216, 74, 0.25);
}

.demo-badge {
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 3px 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  margin-left: auto;
}

.balance-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 6px 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255, 216, 74, 0.18), rgba(255, 94, 200, 0.12));
  border: 1px solid rgba(255, 216, 74, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  min-width: 92px;
  line-height: 1.1;
}

.balance-label {
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  white-space: nowrap;
}

.balance-value {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--gold);
  text-shadow: 0 0 10px rgba(255, 216, 74, 0.4);
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02));
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.9);
  background: rgba(255, 255, 255, 0.2);
}

/* ---------------- RNG badge ---------------- */

.rng-row {
  display: flex;
  justify-content: center;
  min-height: 22px;
}

.rng-badge {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 4px 11px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(94, 247, 255, 0.18), rgba(94, 247, 255, 0.06));
  border: 1px solid rgba(94, 247, 255, 0.4);
  color: var(--cyan);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 10px rgba(94, 247, 255, 0.15);
}

.rng-badge.pending {
  color: var(--text-dim);
  border-color: var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
  animation: pulse-pending 1s ease-in-out infinite;
}

@keyframes pulse-pending {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ---------------- Stage ---------------- */

.stage-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-deep), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: #0c0726;
}

.status-area {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  z-index: 3;
  pointer-events: none;
}

.subtitle {
  font-weight: 800;
  font-size: 0.86rem;
  letter-spacing: 0.3px;
  padding: 6px 16px;
  border-radius: 20px;
  background: rgba(10, 6, 26, 0.55);
  backdrop-filter: blur(4px);
  color: var(--text-main);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  touch-action: none;
}

.feedback-slot {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 3;
}

.feedback-slot .pill {
  font-weight: 800;
  font-size: 0.82rem;
  padding: 7px 16px;
  border-radius: 20px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.feedback-slot.show .pill {
  opacity: 1;
  transform: translateY(0);
}

/* ---------------- Marble picker cards ---------------- */

.marble-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.marble-card {
  position: relative;
  border-radius: var(--radius-md);
  padding: 10px 6px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  border: 2px solid var(--panel-border);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.01));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}

.marble-card:active {
  transform: scale(0.95);
}

.marble-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(255, 216, 74, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  background: linear-gradient(160deg, rgba(255, 216, 74, 0.18), rgba(255, 216, 74, 0.03));
}

.marble-card.disabled {
  opacity: 0.55;
  pointer-events: none;
}

.marble-card-icon {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.4));
}

.marble-card-name {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  text-transform: uppercase;
}

.marble-card-odds {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 216, 74, 0.35);
}

.marble-card.color-0 .marble-card-odds { color: var(--red); text-shadow: 0 0 8px rgba(255, 77, 106, 0.4); }
.marble-card.color-1 .marble-card-odds { color: var(--blue); text-shadow: 0 0 8px rgba(63, 208, 255, 0.4); }
.marble-card.color-2 .marble-card-odds { color: var(--green); text-shadow: 0 0 8px rgba(82, 255, 138, 0.4); }
.marble-card.color-3 .marble-card-odds { color: var(--gold); text-shadow: 0 0 8px rgba(255, 216, 74, 0.4); }

/* ---------------- Controls panel ---------------- */

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: var(--panel-glass);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-deep);
}

.bet-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bet-label {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.bet-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.amount-input {
  width: 84px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text-main);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  outline: none;
}

.amount-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 216, 74, 0.25);
}

.quick-amounts {
  display: flex;
  gap: 6px;
  flex: 1;
}

.quick-amt {
  flex: 1;
  padding: 10px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.02));
  color: var(--text-main);
  font-weight: 800;
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.quick-amt:active {
  transform: scale(0.92);
}

.quick-amt.active {
  border-color: var(--cyan);
  background: linear-gradient(160deg, rgba(94, 247, 255, 0.25), rgba(94, 247, 255, 0.05));
  box-shadow: 0 0 10px rgba(94, 247, 255, 0.3);
}

.action-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0) 55%);
  pointer-events: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
  filter: brightness(0.92);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

.btn-launch {
  padding: 16px;
  font-size: 1.15rem;
  letter-spacing: 0.4px;
  color: #2a1304;
  background: linear-gradient(135deg, #ffe97a 0%, var(--gold) 45%, var(--gold-deep) 100%);
  box-shadow: 0 6px 0 #c9780a, 0 10px 24px rgba(255, 159, 28, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.btn-launch:active:not(:disabled) {
  box-shadow: 0 3px 0 #c9780a, 0 6px 14px rgba(255, 159, 28, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transform: translateY(3px) scale(0.98);
}

.btn-launch-sub {
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.75;
}

.btn-refill {
  padding: 13px;
  font-size: 0.92rem;
  color: var(--text-main);
  background: linear-gradient(135deg, rgba(94, 247, 255, 0.28), rgba(94, 247, 255, 0.1));
  border: 1px solid rgba(94, 247, 255, 0.4);
  box-shadow: 0 0 14px rgba(94, 247, 255, 0.2);
}

.btn-continue {
  padding: 14px 28px;
  font-size: 1.02rem;
  color: #2a1304;
  background: linear-gradient(135deg, #ffe97a 0%, var(--gold) 45%, var(--gold-deep) 100%);
  box-shadow: 0 5px 0 #c9780a, 0 8px 18px rgba(255, 159, 28, 0.4);
}

.btn-close-help {
  padding: 10px 20px;
  font-size: 0.9rem;
  color: var(--bg-deep);
  background: var(--gold);
  margin-top: 12px;
}

/* ---------------- History ---------------- */

.history-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 2px 2px;
}

.history-title {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin: 0;
  padding-left: 2px;
}

.history-list {
  display: flex;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0 0 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.history-list::-webkit-scrollbar {
  display: none;
}

.history-item {
  flex-shrink: 0;
  min-width: 92px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.72rem;
}

.history-item.win {
  border-color: rgba(82, 255, 138, 0.45);
  background: rgba(82, 255, 138, 0.1);
}

.history-item.lose {
  border-color: rgba(255, 77, 106, 0.4);
  background: rgba(255, 77, 106, 0.08);
}

.history-item .h-mult {
  font-weight: 800;
  font-size: 0.86rem;
}

.history-item .h-result {
  font-weight: 700;
  color: var(--text-dim);
  font-size: 0.62rem;
  letter-spacing: 0.3px;
}

.history-item .h-net {
  font-weight: 800;
}

.history-item.win .h-net { color: var(--green); }
.history-item.lose .h-net { color: var(--red); }

.history-item .h-proof {
  margin-top: 2px;
  font-size: 0.58rem;
  color: var(--cyan);
  text-decoration: none;
  opacity: 0.8;
}

.history-empty {
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 10px 4px;
}

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: rgba(20, 12, 46, 0.95);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
  max-width: 85%;
  text-align: center;
  box-shadow: var(--shadow-deep);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------- Win celebration overlay ---------------- */

.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 216, 74, 0.22), rgba(10, 4, 26, 0.92) 70%);
  animation: fade-in 0.3s ease;
}

.win-overlay[hidden] {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.win-overlay-content {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
}

.win-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 3rem;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #fff7d6 0%, var(--gold) 35%, var(--magenta) 70%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 22px rgba(255, 216, 74, 0.65));
  animation: win-title-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1), win-title-shine 2.4s ease-in-out infinite 0.7s;
}

@keyframes win-title-pop {
  0% { transform: scale(0.2) rotate(-8deg); opacity: 0; }
  60% { transform: scale(1.18) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes win-title-shine {
  0%, 100% { filter: drop-shadow(0 0 22px rgba(255, 216, 74, 0.65)); }
  50% { filter: drop-shadow(0 0 38px rgba(255, 94, 200, 0.75)); }
}

.win-amount {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 2.2rem;
  color: var(--green);
  text-shadow: 0 0 20px rgba(82, 255, 138, 0.6);
  animation: win-amount-pop 0.5s ease 0.25s both;
}

@keyframes win-amount-pop {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.win-sub {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  opacity: 0.9;
}

/* ---------------- Loss overlay (lighter touch) ---------------- */

.lose-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 4, 26, 0.88);
  animation: fade-in 0.25s ease;
}

.lose-overlay[hidden] {
  display: none;
}

.lose-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
}

.lose-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.lose-sub {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-dim);
}

/* ---------------- Help dialog ---------------- */

.help-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 420px;
  width: 88vw;
  background: linear-gradient(165deg, #241653, #150c38);
  color: var(--text-main);
  box-shadow: var(--shadow-deep);
}

.help-dialog::backdrop {
  background: rgba(5, 2, 16, 0.7);
  backdrop-filter: blur(3px);
}

.help-dialog h2 {
  font-family: 'Baloo 2', sans-serif;
  margin-top: 0;
  color: var(--gold);
}

.help-dialog p {
  line-height: 1.5;
  font-size: 0.92rem;
}

.help-disclaimer {
  font-size: 0.74rem;
  opacity: 0.65;
}

@media (max-width: 380px) {
  .win-title { font-size: 2.3rem; }
  .win-amount { font-size: 1.7rem; }
  .marble-card-icon { width: 34px; height: 34px; }
  .marble-card-odds { font-size: 0.92rem; }
}
