:root {
  --bg-app: #0b0f1a;
  --panel: #12161f;
  --panel-raised: #1b202c;
  --panel-line: #262c3a;

  --red-trail: #ff3b30;
  --red: #ff3b30;
  --gold-top: #ffb020;
  --gold-bottom: #e08e00;

  --chip-low: #4f8cff;
  --chip-mid: #cfcbe6;
  --chip-high: #ff53d0;

  --green: #1fae59;
  --green-dark: #158543;
  --orange: #ff8a00;

  --text-primary: #ffffff;
  --text-dim: #8a94a6;
  --text-faint: #4d5568;

  --font-display: "Nunito", -apple-system, sans-serif;
  --font-logo: "Pacifico", cursive;
}

* { box-sizing: border-box; }

/* Several elements toggle visibility via the `hidden` attribute from JS
   (auth gate, login/register forms, countdown overlay). Without this rule,
   any later selector that sets `display` on those same elements (e.g.
   `#authGate { display: flex; }`, `.auth-form { display: flex; }`) silently
   overrides the browser's default `[hidden] { display: none }` — because
   author CSS always wins over the user-agent stylesheet regardless of
   specificity. That was the actual bug: the register form and the login
   form rendered stacked on top of each other, and the auth gate never
   disappeared after a successful login. This rule guarantees `hidden`
   always wins, full stop. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-display);
  min-height: 100vh;
}

body {
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
}

/* ---- Go back bar ---- */

.go-back-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: #0e1119;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}

.back-arrow { font-size: 16px; }

/* ---- App header ---- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: #131722;
}

.logo {
  font-family: var(--font-logo);
  font-size: 22px;
  color: var(--red);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.header-right {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.balance-value {
  font-weight: 800;
  font-size: 15px;
  color: var(--green);
}

.balance-currency {
  font-size: 11px;
  color: var(--text-dim);
  margin-right: 8px;
}

.menu-btn {
  width: 26px;
  height: 22px;
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  align-self: center;
  text-decoration: none;
}

.menu-btn span {
  width: 16px;
  height: 2px;
  background: var(--text-dim);
  border-radius: 2px;
}

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

.history-strip-wrap {
  display: flex;
  align-items: center;
  background: #0d1017;
  border-bottom: 1px solid var(--panel-line);
}

.history-strip {
  flex: 1;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 7px 10px;
  scrollbar-width: none;
}

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

.log-chip {
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
}

.log-chip.tier-low { color: var(--chip-low); }
.log-chip.tier-mid { color: var(--chip-mid); }
.log-chip.tier-high { color: var(--chip-high); }

.history-more {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 1px;
  padding: 0 12px;
  cursor: pointer;
}

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

.stage {
  position: relative;
  height: 300px;
  overflow: hidden;
  background:
    repeating-conic-gradient(
      from 0deg at 50% 118%,
      rgba(255, 255, 255, 0.05) 0deg 4deg,
      transparent 4deg 12deg
    ),
    radial-gradient(ellipse at 50% 118%, #1c2436 0%, #0a0c12 55%, #060709 100%);
}

#flightCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.crash-flash {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(255, 59, 48, 0.4), transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.crash-flash.show { animation: flashRed 0.6s ease-out; }

@keyframes flashRed {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

.multiplier-wrap {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
  text-align: center;
  pointer-events: none;
}

.multiplier {
  font-weight: 900;
  font-size: clamp(46px, 13vw, 68px);
  color: #ffffff;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.25);
  transition: color 0.15s ease;
  letter-spacing: -0.01em;
}

.multiplier .x { font-size: 0.55em; opacity: 0.8; }
.multiplier.state-crashed { color: var(--red); text-shadow: 0 0 30px rgba(255, 59, 48, 0.55); }
.multiplier.state-cashed { color: var(--green); text-shadow: 0 0 30px rgba(31, 174, 89, 0.55); }

.multiplier-caption {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}

.countdown-wrap {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  text-align: center;
}

.countdown-num {
  font-weight: 900;
  font-size: 44px;
  color: #fff;
}

.countdown-label {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
}

.countdown-sub {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold-top);
}

.players-badge {
  position: absolute;
  bottom: 10px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 20px;
  padding: 4px 10px 4px 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  z-index: 2;
}

.players-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #2b3245;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* ---- Bet panels ---- */

.bet-panels {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--panel-line);
}

.bet-panel {
  position: relative;
  background: var(--panel);
  padding: 12px;
}

.panel-collapse {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  font-size: 10px;
  cursor: pointer;
}

.stake-row {
  display: flex;
  gap: 10px;
}

.stake-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.stake-stepper {
  display: flex;
  align-items: stretch;
  background: var(--panel-raised);
  border-radius: 8px;
  overflow: hidden;
}

.step-btn {
  width: 36px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.step-btn:hover { background: rgba(255, 255, 255, 0.06); }
.step-btn:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.step-btn:disabled { opacity: 0.4; cursor: default; }

.stake-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  outline: none;
}

.quick-amounts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.quick-amounts button {
  background: var(--panel-raised);
  border: none;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 12px;
  padding: 7px 4px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.quick-amounts button:hover { background: rgba(255, 255, 255, 0.08); color: var(--text-primary); }
.quick-amounts button:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
.quick-amounts button:disabled { opacity: 0.4; cursor: default; }

.bet-btn {
  flex: 0 0 128px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.bet-btn:active { transform: scale(0.98); }
.bet-btn:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.bet-btn:disabled { cursor: default; }

.bet-btn-main {
  font-weight: 900;
  font-size: 17px;
  color: #fff;
}

.bet-btn-sub {
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
}

.bet-idle {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  box-shadow: 0 6px 16px rgba(31, 174, 89, 0.3);
}

.bet-active {
  background: linear-gradient(180deg, var(--orange) 0%, #d96f00 100%);
  box-shadow: 0 6px 16px rgba(255, 138, 0, 0.4);
  animation: pulse 1.3s ease-in-out infinite;
}

.bet-win {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  box-shadow: 0 6px 16px rgba(31, 174, 89, 0.4);
}

.bet-disabled {
  background: var(--panel-raised);
  box-shadow: none;
  animation: none;
  opacity: 0.55;
}

.bet-disabled .bet-btn-main,
.bet-disabled .bet-btn-sub { color: var(--text-faint); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 16px rgba(255, 138, 0, 0.32); }
  50% { box-shadow: 0 6px 24px rgba(255, 138, 0, 0.55); }
}

.error-line {
  min-height: 14px;
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  text-align: center;
}

.footer-note {
  text-align: center;
  font-size: 10px;
  color: var(--text-faint);
  padding: 12px 14px;
}

@media (prefers-reduced-motion: reduce) {
  .bet-active { animation: none; }
  .crash-flash.show { animation: none; }
}

/* ---- Account page ---- */

.account-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.account-card {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
}

.account-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 800;
}

.account-desc {
  margin: 0 0 14px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}

.account-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.account-input {
  width: 100%;
  background: var(--panel-raised);
  border: none;
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}

.account-input:focus {
  box-shadow: 0 0 0 2px var(--green);
}

.account-charge-btn {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 14px;
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  color: #fff;
  font-weight: 900;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(31, 174, 89, 0.3);
  transition: transform 0.1s ease, opacity 0.15s ease;
}

.account-charge-btn:active { transform: scale(0.98); }
.account-charge-btn:disabled { opacity: 0.6; cursor: default; }

.charge-status {
  min-height: 16px;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--text-dim);
}

.charge-status-pending { color: var(--gold-top, #f5a623); }
.charge-status-success { color: var(--green); }
.charge-status-error { color: var(--red); }

.charge-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.charge-empty {
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  padding: 10px 0;
}

.charge-row {
  background: var(--panel-raised);
  border-radius: 8px;
  padding: 10px 12px;
}

.charge-row-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.charge-amount {
  font-weight: 800;
  font-size: 13px;
}

.charge-badge {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
}

.charge-badge-pending { background: rgba(245, 166, 35, 0.18); color: #f5a623; }
.charge-badge-completed { background: rgba(31, 174, 89, 0.18); color: var(--green); }
.charge-badge-failed { background: rgba(255, 65, 54, 0.18); color: var(--red); }

.charge-row-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-faint);
}

/* ---- Auth gate (login / register) ---- */

#authGate {
  position: relative;
}

.auth-backdrop {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 36px 18px;
  overflow: hidden;
  background:
    repeating-conic-gradient(from 0deg at 50% 130%, rgba(255, 255, 255, 0.05) 0deg 4deg, transparent 4deg 12deg),
    radial-gradient(ellipse at 50% 125%, #241a5c 0%, #120e35 45%, #08070f 100%);
}

.auth-stars {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 10% 20%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1.5px 1.5px at 80% 15%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(1px 1px at 40% 60%, rgba(255, 255, 255, 0.4), transparent),
    radial-gradient(1.5px 1.5px at 65% 78%, rgba(255, 255, 255, 0.3), transparent),
    radial-gradient(1px 1px at 25% 88%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(1.5px 1.5px at 90% 55%, rgba(255, 255, 255, 0.3), transparent);
  background-repeat: repeat;
  background-size: 320px 320px;
  opacity: 0.7;
  pointer-events: none;
}

.auth-hero {
  position: relative;
  z-index: 1;
  text-align: center;
}

.auth-plane {
  font-size: 42px;
  display: inline-block;
  transform: rotate(45deg);
  filter: drop-shadow(0 0 16px rgba(255, 59, 54, 0.55));
  animation: authPlaneFloat 3s ease-in-out infinite;
}

@keyframes authPlaneFloat {
  0%, 100% { transform: rotate(45deg) translateY(0); }
  50% { transform: rotate(45deg) translateY(-8px); }
}

.auth-title {
  margin: 12px 0 6px;
  font-weight: 900;
  font-size: 30px;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, #ffd27a 0%, var(--red-trail) 55%, #ff53d0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-tagline {
  margin: 0 auto;
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 260px;
  line-height: 1.5;
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  background: rgba(18, 22, 38, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
}

.auth-card-title {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 900;
  color: var(--text-primary);
}

.auth-card-subtitle {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.auth-bonus-banner {
  background: rgba(31, 174, 89, 0.1);
  border: 1px solid rgba(31, 174, 89, 0.35);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.auth-bonus-title {
  font-weight: 800;
  font-size: 13px;
  color: var(--green);
  margin-bottom: 4px;
}

.auth-bonus-line {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.auth-bonus-note {
  font-size: 10.5px;
  color: var(--text-faint);
}

.auth-field-hint {
  margin: -6px 0 2px 2px;
  font-size: 10.5px;
  color: var(--text-faint);
}

.auth-switch-line {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
}

.auth-switch-link {
  color: var(--gold-top, #f5a623);
  font-weight: 700;
  text-decoration: none;
}

.auth-switch-link:hover {
  text-decoration: underline;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--panel-raised);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-field:focus-within {
  border-color: var(--red-trail);
  box-shadow: 0 0 0 3px rgba(255, 59, 54, 0.15);
}

.auth-field-icon {
  padding: 0 4px 0 12px;
  font-size: 14px;
  opacity: 0.7;
}

.auth-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  padding: 12px 12px 12px 8px;
  color: var(--text-primary);
  font-weight: 600;
  font-size: 14px;
}

.auth-input::placeholder { color: var(--text-faint); }

.auth-submit-btn {
  margin-top: 4px;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-weight: 900;
  font-size: 14.5px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, var(--red-trail) 0%, var(--gold-top, #f5a623) 100%);
  box-shadow: 0 10px 24px rgba(255, 59, 54, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.auth-submit-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(255, 59, 54, 0.4); }
.auth-submit-btn:active { transform: translateY(0); }

.auth-footnote {
  position: relative;
  z-index: 1;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

.auth-success {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  text-align: center;
  padding: 12px;
  animation: authSuccessIn 0.35s ease;
}

@keyframes authSuccessIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.auth-success-check {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 3px solid var(--green);
  color: var(--green);
  font-size: 28px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(31, 174, 89, 0.4);
}

.auth-success-title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 900;
  color: var(--text-primary);
}

.auth-success-message {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text-dim);
  line-height: 1.5;
}

.auth-success-note {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

@media (prefers-reduced-motion: reduce) {
  .auth-plane { animation: none; }
  .auth-success { animation: none; }
}

/* ---- Account logout ---- */

.account-logout-btn {
  margin-top: 10px;
  width: 100%;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 13px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
}

.account-logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
}
