/* Star Ledger */

*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg:      #080808;
  --surf:    #141414;
  --surf2:   #1E1E1E;
  --border:  rgba(255,255,255,0.09);
  --border2: rgba(255,255,255,0.16);
  --text:    #FFFFFF;
  --sub:     rgba(255,255,255,0.62);
  --muted:   rgba(255,255,255,0.30);
  --error:   #FF3B30;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Shell ───────────────────────────────────────────────────────────────── */

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.screen-wrap { flex: 1; overflow: hidden; position: relative; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
}
.screen.active { display: block; }

.scroll-body {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  -webkit-overflow-scrolling: touch;
}
.scroll-body::-webkit-scrollbar { display: none; }

/* ── Ledger above-fold layout ────────────────────────────────────────────── */

.ledger-above-fold {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.ledger-above-fold > * { flex-shrink: 0; }
.ledger-spacer {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;
  max-height: 44px;
}

/* ── App header ──────────────────────────────────────────────────────────── */

.app-header {
  padding: 12px 18px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header-left { flex: 1; min-width: 0; }

.app-header-right {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-headline {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.app-tagline {
  font-size: 13px;
  color: var(--sub);
  margin-top: 4px;
}

/* ── Section cards ───────────────────────────────────────────────────────── */

.section {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 16px;
  margin: 0 14px 10px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.section-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.section-desc {
  font-size: 12px;
  color: var(--sub);
  line-height: 1.45;
  margin-bottom: 10px;
}
.section-desc strong {
  color: var(--text);
  font-weight: 700;
}

.sh-lottie {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Amount input ────────────────────────────────────────────────────────── */

.amount-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surf2);
  border-radius: 13px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.amount-star {
  font-size: 15px;
  color: var(--muted);
  flex-shrink: 0;
  line-height: 1;
}

.amount-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}
.amount-input::placeholder { color: rgba(255,255,255,0.16); }
.amount-input::-webkit-inner-spin-button,
.amount-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.amount-usd {
  font-size: 14px;
  font-weight: 600;
  color: var(--sub);
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Chips ───────────────────────────────────────────────────────────────── */

.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  flex: 1;
  padding: 8px 4px;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--sub);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
}
.chip:active { opacity: 0.6; }
.chip.active {
  background: #FFFFFF;
  border-color: #FFFFFF;
  color: #000000;
}

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

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  background: #FFFFFF;
  color: #000000;
  border: none;
  border-radius: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.22; cursor: not-allowed; }
.btn-primary:active:not(:disabled) { opacity: 0.72; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 50px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border2);
  border-radius: 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}
.btn-secondary:active { background: rgba(255,255,255,0.04); }

.btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  background: none;
  color: var(--sub);
  border: none;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:active { opacity: 0.6; }

.gift-btns {
  display: flex;
  flex-direction: row;
  gap: 7px;
}

.gift-btn-half {
  flex: 1;
}

/* ── Row links group card ────────────────────────────────────────────────── */

.row-links-card {
  background: var(--surf);
  border: 1px solid var(--border2);
  border-radius: 18px;
  margin: 0 14px 10px;
  overflow: hidden;
}

.row-link {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background 0.12s;
}
.row-link:last-child { border-bottom: none; }
.row-link:active { background: rgba(255,255,255,0.03); }

.rl-lottie {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rl-ico {
  font-size: 14px;
  color: var(--sub);
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.rl-label {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.rl-arr {
  font-size: 11px;
  color: var(--muted);
}

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

.balance-card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 18px;
  margin: 14px 14px 8px;
  padding: 26px 20px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.balance-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  margin-bottom: 6px;
}

.balance-amount-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.balance-ton {
  font-size: 40px;
  font-weight: 300;
  letter-spacing: -0.025em;
  line-height: 1;
}

.balance-usd {
  font-size: 17px;
  font-weight: 500;
  color: var(--sub);
  margin-top: 6px;
}

.balance-stats-line {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  width: 100%;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* ── Withdraw section ────────────────────────────────────────────────────── */

.withdraw-section {
  padding: 0 14px 10px;
}

.withdraw-row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 18px 20px;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 18px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: opacity 0.15s;
}
.withdraw-row-btn:active { opacity: 0.7; }

.withdraw-row-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.withdraw-row-sub {
  font-size: 12px;
  color: var(--sub);
  margin-top: 3px;
}

.withdraw-arrow {
  width: 44px;
  height: 44px;
  background: var(--surf2);
  border: 1px solid var(--border2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

/* ── Referral section ────────────────────────────────────────────────────── */

.referral-section {
  padding: 0 14px 20px;
}

.referral-card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.referral-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.referral-info { flex: 1; min-width: 0; }

.referral-head {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.referral-meta {
  font-size: 13px;
  color: var(--sub);
  margin-top: 3px;
}

.ref-pct-badge {
  display: inline-block;
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0;
  vertical-align: middle;
  margin: 0 1px;
}

.ref-callout {
  font-size: 13px;
  color: var(--sub);
  text-align: center;
  line-height: 1.5;
}

.ref-callout-num {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-right: 3px;
}

.ref-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ref-stat-box {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.ref-stat-val {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 3px;
}

.ref-stat-lbl {
  font-size: 11px;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Referral link box (in modal) */
.ref-link-box {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 13px;
  color: var(--sub);
  word-break: break-all;
  line-height: 1.55;
}

/* ── Bottom nav ──────────────────────────────────────────────────────────── */

.bottom-nav {
  display: flex;
  background: var(--surf);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  position: relative;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 13px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.15s;
  position: relative;
}
.nav-btn.active { color: var(--text); }

.nav-ico { font-size: 21px; line-height: 1; }
.nav-lbl { line-height: 1; }

/* ── Modals ──────────────────────────────────────────────────────────────── */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  z-index: 900;
}
.modal-bg.active { opacity: 1; pointer-events: auto; }

.modal-sheet {
  width: 100%;
  background: #141414;
  border: 1px solid var(--border2);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom, 18px) + 22px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateY(32px);
  transition: transform 0.30s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 92dvh;
  overflow-y: auto;
}
.modal-bg.active .modal-sheet { transform: translateY(0); }

.modal-handle {
  width: 36px;
  height: 4px;
  background: rgba(255,255,255,0.10);
  border-radius: 2px;
  margin: 4px auto 4px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.025em;
  flex-shrink: 0;
}

.modal-sub {
  font-size: 14px;
  color: var(--sub);
  line-height: 1.55;
  margin-top: -6px;
  flex-shrink: 0;
}

.modal-rows {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-row:last-child { border-bottom: none; }
.modal-row > span:first-child { color: var(--sub); }

.modal-cta { flex-shrink: 0; }

/* ── Field input ─────────────────────────────────────────────────────────── */

.field-row { position: relative; }

.field-input {
  width: 100%;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 42px 14px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.field-input::placeholder { color: var(--muted); }
.field-input:focus { border-color: var(--border2); }

.field-spin-wrap {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.spin-dot {
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.07);
  border-top-color: var(--sub);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.field-note {
  font-size: 13px;
  color: var(--sub);
  line-height: 1.55;
}

/* ── How It Works ────────────────────────────────────────────────────────── */

.how-steps {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.how-step {
  display: flex;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.how-step:last-child { border-bottom: none; }

.how-num {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  flex-shrink: 0;
  width: 22px;
  padding-top: 1px;
}

.how-step-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 3px;
}

.how-step-desc {
  font-size: 13px;
  color: var(--sub);
  line-height: 1.55;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */

#toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 76px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1E1E1E;
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 9999;
}
#toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { color: var(--error); }

/* ── Loading ─────────────────────────────────────────────────────────────── */

#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}
#loading.gone { opacity: 0; pointer-events: none; }

.loading-ring {
  width: 34px;
  height: 34px;
  border: 2.5px solid rgba(255,255,255,0.07);
  border-top-color: rgba(255,255,255,0.55);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Access denied ───────────────────────────────────────────────────────── */

#access-denied {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 32px;
  z-index: 9998;
}
#access-denied.show { display: flex; }

.denied-title { font-size: 20px; font-weight: 800; }
.denied-sub   { font-size: 14px; color: var(--sub); max-width: 220px; line-height: 1.55; }
