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

:root {
  --bg-deep: #0a1512;
  --purple: #6a3fb5;
  --purple-deep: #3d1f73;
  --gold: #ffcf5c;
  --gold-bright: #ffe8a3;
  --gold-deep: #c98a2b;
  --emerald: #2bd49a;
  --crimson: #e2495a;
  --warm-white: #fff6e6;

  --font-display: 'Cinzel Decorative', 'Georgia', serif;
  --font-ui: 'Mulish', 'Segoe UI', system-ui, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--warm-white);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  gap: 8px;
}

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

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex: 0 0 auto;
  gap: 6px;
  min-height: 42px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 1px;
  white-space: nowrap;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 45%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 18px rgba(255, 207, 92, 0.35);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
  line-height: 1.1;
}

.demo-badge {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(255, 207, 92, 0.12);
  border: 1px solid rgba(255, 207, 92, 0.4);
  color: var(--gold-bright);
  white-space: nowrap;
  align-self: flex-start;
}

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

.balance-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 10px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(40, 20, 70, 0.75), rgba(15, 30, 26, 0.75));
  border: 1px solid rgba(255, 207, 92, 0.45);
  min-width: 84px;
  flex: 0 0 auto;
}

.balance-label {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: rgba(255, 246, 230, 0.6);
}

.balance-value {
  font-size: 15px;
  font-weight: 800;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255, 207, 92, 0.4);
  background: rgba(20, 15, 35, 0.6);
  color: var(--gold-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

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

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

.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  border-radius: 18px;
  overflow: hidden;
}

.game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.free-spin-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 7px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(110, 60, 190, 0.92), rgba(60, 25, 110, 0.92));
  border: 1.5px solid var(--gold-bright);
  box-shadow: 0 0 22px rgba(170, 100, 255, 0.55);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.6px;
  color: var(--gold-bright);
  animation: freeSpinPulse 1.8s ease-in-out infinite;
}

@keyframes freeSpinPulse {
  0%, 100% { box-shadow: 0 0 18px rgba(170, 100, 255, 0.45); }
  50% { box-shadow: 0 0 30px rgba(170, 100, 255, 0.8); }
}

.rng-badge {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(10, 30, 20, 0.85);
  border: 1.5px solid var(--emerald);
  color: #baffdf;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-decoration: none;
  box-shadow: 0 0 14px rgba(43, 212, 154, 0.4);
  max-width: calc(100% - 24px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rng-badge.pending {
  border-color: #ffcf5c;
  color: #ffe8a3;
  box-shadow: 0 0 14px rgba(255, 207, 92, 0.4);
  animation: rngPulse 0.9s ease-in-out infinite;
}

@keyframes rngPulse {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}

.feedback-slot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  z-index: 5;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(16px, 6.5vw, 30px);
  letter-spacing: 1px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 24px rgba(0,0,0,0.6), 0 2px 4px rgba(0,0,0,0.8);
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: normal;
  width: 90%;
  max-width: 420px;
}

.feedback-slot.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.feedback-slot.win { color: var(--gold-bright); }
.feedback-slot.big { color: #ff9e4a; }
.feedback-slot.scatter { color: #c9a6ff; }
.feedback-slot.loss { color: rgba(255,255,255,0.65); font-size: 20px; }

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

.controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

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

.bet-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 0 0 auto;
  min-width: 58px;
}

.bet-label {
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: rgba(255, 246, 230, 0.6);
}

.bet-input {
  width: 100%;
  padding: 6px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255, 207, 92, 0.4);
  background: rgba(15, 10, 28, 0.7);
  color: var(--warm-white);
  font-weight: 800;
  font-size: 13px;
}

.quick-bets {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick-bets::-webkit-scrollbar { display: none; }

.quick-bet {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 4px;
  border-radius: 10px;
  border: 1px solid rgba(255, 207, 92, 0.3);
  background: rgba(30, 20, 50, 0.55);
  color: var(--warm-white);
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}

.quick-bet.active {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold-deep));
  color: #2a1a05;
  border-color: var(--gold-bright);
}

.btn-paytable {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(201, 166, 255, 0.4);
  background: rgba(60, 30, 100, 0.5);
  color: #e6d6ff;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-row { justify-content: center; }

.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-ui);
}

.btn-spin {
  position: relative;
  flex: 1 1 auto;
  max-width: 420px;
  height: 58px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ff9d47 0%, #ff7a1f 45%, #d9500a 100%);
  border: 2px solid var(--gold-bright);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3), 0 6px 0 rgba(130, 40, 0, 0.6), 0 0 28px rgba(255, 150, 50, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-spin-label {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 1.4px;
  color: #fff6e6;
  text-shadow: 0 2px 3px rgba(80, 20, 0, 0.6);
}

.btn-spin:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3), 0 3px 0 rgba(130, 40, 0, 0.6), 0 0 20px rgba(255, 150, 50, 0.45);
}

.btn-spin:disabled {
  filter: grayscale(0.5) brightness(0.75);
  cursor: default;
}

.btn-spin.spinning .btn-spin-label {
  animation: spinLabelPulse 0.6s ease-in-out infinite;
}

@keyframes spinLabelPulse {
  0%, 100% { opacity: 0.75; }
  50% { opacity: 1; }
}

.btn-refill {
  flex: 1 1 auto;
  max-width: 420px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(180deg, #4fd9ac, #1a9d73);
  border: 2px solid rgba(255,255,255,0.4);
  color: #06241a;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.4px;
}

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

.history-row {
  flex: 0 0 auto;
}

.history-title {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: rgba(255, 246, 230, 0.5);
  margin-bottom: 4px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.history-empty {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  padding: 8px 2px;
  white-space: nowrap;
}

.history-item {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(20, 14, 34, 0.6);
  border: 1px solid rgba(255,255,255,0.12);
  min-width: 56px;
}

.history-item.win { border-color: rgba(43, 212, 154, 0.5); }
.history-item.loss { border-color: rgba(255,255,255,0.1); opacity: 0.85; }
.history-item.scatter { border-color: rgba(201, 166, 255, 0.6); }

.h-net {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.history-item.win .h-net { color: #6bf0bf; }
.history-item.loss .h-net { color: rgba(255,255,255,0.5); }

.h-bet {
  font-size: 8.5px;
  color: rgba(255,255,255,0.45);
}

.h-proof {
  font-size: 8.5px;
  color: #baffdf;
  text-decoration: none;
  white-space: nowrap;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  background: rgba(15, 10, 25, 0.95);
  border: 1px solid rgba(255, 207, 92, 0.4);
  color: var(--warm-white);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 50;
}

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

/* ---------------- Dialogs ---------------- */

dialog {
  border: 1.5px solid rgba(255, 207, 92, 0.5);
  border-radius: 18px;
  background: linear-gradient(180deg, #1b1230, #0d1a16);
  color: var(--warm-white);
  padding: 20px;
  max-width: 420px;
  width: calc(100vw - 40px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(201, 166, 255, 0.15);
}

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

dialog h2 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0 0 12px;
  color: var(--gold-bright);
}

dialog p {
  font-size: 13.5px;
  line-height: 1.5;
  color: rgba(255,246,230,0.85);
}

.help-disclaimer {
  font-size: 11px !important;
  color: rgba(255,255,255,0.5) !important;
  margin-top: 14px !important;
}

.btn-close-help {
  margin-top: 14px;
  padding: 10px 18px;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold-deep));
  color: #2a1a05;
  font-weight: 800;
}

.paytable-grid {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 2px 10px;
  align-items: center;
  max-height: 55vh;
  overflow-y: auto;
}

.paytable-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  grid-row: span 2;
  align-self: center;
}

.paytable-name {
  font-size: 12.5px;
  font-weight: 700;
  align-self: end;
}

.paytable-pays {
  font-size: 10.5px;
  color: rgba(255, 207, 92, 0.85);
  text-align: left;
  white-space: normal;
  line-height: 1.3;
  align-self: start;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

/* ---------------- Responsive ---------------- */

@media (max-width: 420px) {
  .brand-name { font-size: 16px; }
  .balance-value { font-size: 13px; }
  .btn-spin { height: 52px; }
  .btn-spin-label { font-size: 19px; }
}

@media (max-height: 640px) {
  .app { gap: 5px; padding-top: 6px; padding-bottom: 6px; }
  .topbar { min-height: 34px; }
}
