/* ─────────────────────────────────────────────────────────────────────────
   Build Coins web top-up.

   Tokens mirror BuildGym/src/theme/colors.js ("Elite Noir / Holographic") and
   the type scale in src/theme/typography.js, so the page reads as part of the
   member app rather than a separate site.

   Mobile-first throughout: this page is opened from an email or a QR code at
   reception, so phones are the primary target and the desktop view is just a
   centred column.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Canvas / surfaces */
  --background:      #080608;
  --background-alt:  #100D10;
  --surface:         #151215;
  --surface-low:     #1E1B1D;
  --surface-2:       #221F21;
  --surface-3:       #2C292C;

  --glass:        rgba(255, 255, 255, 0.05);
  --glass-dim:    rgba(255, 255, 255, 0.03);
  --glass-bright: rgba(255, 255, 255, 0.08);

  /* Accent · holographic purple → cyan */
  --primary:        #7F2982;
  --primary-bright: #7C3AED;
  --primary-light:  #A78BFA;
  --cyan:           #06B6D4;
  --cyan-neon:      #00F2FF;

  --primary-soft:   rgba(127, 41, 130, 0.15);
  --primary-border: rgba(127, 41, 130, 0.40);
  --selected-fill:  rgba(124, 58, 237, 0.15);

  /* Text */
  --text-primary:   #E8E0E4;
  --text-secondary: #D4C1CF;
  --text-muted:     #9D8C99;
  --white:          #FFFFFF;

  /* Status */
  --success:      #4CAF50;
  --success-soft: rgba(76, 175, 80, 0.15);
  --error:        #FFB4AB;
  --error-soft:   rgba(244, 67, 54, 0.12);
  --warning:      #FFC107;
  --warning-soft: rgba(255, 193, 7, 0.08);

  /* Borders */
  --border:        rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);

  --gold: #FFD700;

  /* Type — Anybody for display, Hanken Grotesk for body, matching the app */
  --font-display: 'Anybody', 'Segoe UI', system-ui, sans-serif;
  --font-body:    'Hanken Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;

  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-2xl: 20px;
  --radius-full: 9999px;
}

* { box-sizing: border-box; }

html {
  /* Stops iOS bumping text up when the phone is turned sideways. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  /* No rubber-band bounce revealing white behind the void-black canvas. */
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

/* The purple wash behind the top of the screen — the app's `glowTop`. */
body::before {
  content: '';
  position: fixed;
  inset: 0 0 auto 0;
  height: 280px;
  background: linear-gradient(180deg, rgba(127, 41, 130, 0.30) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: 460px;
  margin: 0 auto;
  /* Safe-area insets keep content clear of the notch and the home indicator. */
  padding:
    calc(env(safe-area-inset-top, 0px) + 20px)
    calc(env(safe-area-inset-right, 0px) + 20px)
    calc(env(safe-area-inset-bottom, 0px) + 32px)
    calc(env(safe-area-inset-left, 0px) + 20px);
  min-height: 100vh;
  min-height: 100dvh; /* dvh tracks the collapsing mobile browser chrome */
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Brand header ──────────────────────────────────────────────────────── */

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--primary-bright), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ── Card ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-low);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  padding: 26px 22px;
}

.card[hidden] { display: none; }

h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  line-height: 1.27;
  letter-spacing: 1px;
  color: var(--text-primary);
}

h2 {
  margin: 26px 0 14px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--primary-light);
}

.sub {
  margin: 0 0 22px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
}

.sub strong { color: var(--text-secondary); font-weight: 700; }

.hint {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
}

.center-text { text-align: center; }

/* ── Forms ─────────────────────────────────────────────────────────────── */

label {
  display: block;
  margin: 0 0 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-muted);
}

input {
  width: 100%;
  background: var(--background-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px 16px;
  color: var(--text-primary);
  /* 16px exactly: anything smaller makes iOS Safari zoom the page on focus. */
  font-size: 16px;
  font-family: var(--font-body);
  margin-bottom: 18px;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--primary-bright);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

input::placeholder { color: #50434E; }

/* Chrome/Safari number spinners are useless on a coin field. */
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type='number'] { -moz-appearance: textfield; }

.phone-row { display: flex; align-items: stretch; gap: 10px; }

.phone-row .cc {
  display: flex;
  align-items: center;
  padding: 0 14px;
  margin-bottom: 18px;
  background: var(--background-alt);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 16px;
  flex: none;
}

.phone-row input { flex: 1; min-width: 0; }

#code {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 10px;
  /* letter-spacing adds a trailing gap; pull it back so digits look centred. */
  text-indent: 10px;
  font-variant-numeric: tabular-nums;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  /* 52px clears the 44px minimum touch target on every phone. */
  min-height: 52px;
  padding: 15px 24px;
  background: linear-gradient(90deg, var(--primary-bright) 0%, var(--cyan) 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1.2px;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.08s;
  touch-action: manipulation; /* kills the 300ms double-tap-zoom delay */
}

.primary:active:not(:disabled) { transform: scale(0.985); }
.primary:disabled { opacity: 0.4; cursor: not-allowed; }

.link-btn {
  background: none;
  border: none;
  color: var(--primary-light);
  font-family: var(--font-body);
  font-size: 13px;
  cursor: pointer;
  /* Padding rather than a bigger font, so the tap target clears 44px without
     the link visually shouting. */
  padding: 12px 8px;
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 3px;
  touch-action: manipulation;
}

.link-btn.center { display: block; margin: 8px auto 0; }
.link-btn[hidden] { display: none; }

/* ── Balance ───────────────────────────────────────────────────────────── */

.balance {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 6px 0 22px;
  border-bottom: 1px solid var(--border);
}

.balance-label {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.balance-num {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
  color: var(--white);
  font-variant-numeric: tabular-nums;
}

.coin { color: var(--gold); font-size: 26px; }

/* ── Packs ─────────────────────────────────────────────────────────────── */

.packs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.pack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 108px;
  padding: 20px 10px 16px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-family: var(--font-body);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
  touch-action: manipulation;
}

.pack:active { transform: scale(0.98); }

.pack.selected {
  border-color: var(--primary-bright);
  background: var(--selected-fill);
}

.pack-badge {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  background: linear-gradient(90deg, var(--primary-bright), var(--cyan));
  color: var(--white);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.pack-coins {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  color: var(--white);
}

.pack-bonus {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--primary-light);
  min-height: 14px;
}

.pack-price {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
}

/* ── Custom amount ─────────────────────────────────────────────────────── */

.custom {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.custom summary {
  /* Native marker looks wrong against the app's flat surfaces. */
  list-style: none;
  cursor: pointer;
  padding: 6px 0 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-size: 13px;
  color: var(--primary-light);
  touch-action: manipulation;
}

.custom summary::-webkit-details-marker { display: none; }
.custom summary::after {
  content: '＋';
  margin-left: auto;
  font-size: 16px;
  color: var(--text-muted);
}
.custom[open] summary::after { content: '−'; }

.custom-price {
  margin: -8px 0 0;
  min-height: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

#pay { margin-top: 22px; }

/* ── Result ────────────────────────────────────────────────────────────── */

.result-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  margin: 4px auto 22px;
  border-radius: 50%;
  font-size: 32px;
  font-weight: 700;
}

.result-icon.ok {
  background: var(--success-soft);
  border: 2px solid var(--success);
  color: var(--success);
}

.result-icon.bad {
  background: var(--error-soft);
  border: 2px solid var(--error);
  color: var(--error);
}

.result-icon.wait {
  background: var(--warning-soft);
  border: 2px solid var(--warning);
  color: var(--warning);
}

/* ── Status ────────────────────────────────────────────────────────────── */

.status {
  margin: 0;
  padding: 13px 16px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.status.error {
  background: var(--error-soft);
  border-color: rgba(255, 180, 171, 0.35);
  color: var(--error);
}

.status[hidden] { display: none; }

/* ── Legal footer ──────────────────────────────────────────────────────── */

.legal {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
}

.legal a {
  padding: 8px 2px;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: none;
}

.legal a:active { color: var(--primary-light); }

/* ── Narrow phones ─────────────────────────────────────────────────────── */

@media (max-width: 360px) {
  .card { padding: 22px 16px; }
  .balance-num { font-size: 34px; }
  .pack-coins { font-size: 19px; }
  #code { font-size: 22px; letter-spacing: 8px; text-indent: 8px; }
}

/* ── Short landscape (phone on its side, keyboard up) ──────────────────── */

@media (max-height: 520px) {
  .shell { gap: 12px; }
  .card { padding: 20px 18px; }
  .balance { padding: 2px 0 14px; }
  .balance-num { font-size: 30px; }
}

/* ── Respect reduced-motion ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
