/* ──────────────────────────────────────────────────────
   MODAL — editorial casino
   - Глубокий aubergine, тонкий золотой hairline
   - Display-серif с italic для всех числовых акцентов
   ────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% 30%, rgba(212,169,92,0.06), transparent 50%),
    var(--overlay-shadow);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  animation: backdrop-fade 240ms ease both;
  /* backdrop-filter removed — iOS WebKit downsamples underlying canvas
     compositing layer; once promoted, canvas stays blurry until reload. */
}
@keyframes backdrop-fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(540px, 100%);
  max-height: 88vh;
  background: linear-gradient(180deg, var(--bg-modal), #170A2D 70%);
  border: 1px solid rgba(212, 169, 92, 0.22);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-luxe);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  isolation: isolate;
  animation: modal-rise 360ms cubic-bezier(.22,.61,.36,1) both;
}
.modal::before {
  content: '';
  position: absolute; inset: 0;
  background-image: var(--grain);
  opacity: 0.5;
  mix-blend-mode: overlay;
  pointer-events: none;
  z-index: 0;
}
.modal::after {
  content: '';
  position: absolute; top: 0; left: 12%; right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  pointer-events: none;
}
@keyframes modal-rise {
  from { opacity: 0; transform: translateY(16px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 22px 26px 14px;
  border-bottom: 1px solid rgba(212, 169, 92, 0.14);
  position: relative;
  z-index: 1;
}
.modal__title {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--gold-bright);
  font-size: 26px;
  letter-spacing: 0.02em;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
  text-shadow: 0 3px 0 rgba(0,0,0,0.35), 0 0 18px rgba(244,213,141,0.25);
}
.modal__close {
  background: transparent;
  border: 1px solid rgba(212, 169, 92, 0.22);
  color: var(--ink-muted);
  width: 30px; height: 30px;
  cursor: pointer;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: color 200ms ease, border-color 200ms ease, background 200ms ease;
}
.modal__close:hover {
  color: var(--gold-bright);
  border-color: var(--gold);
  background: rgba(244, 213, 141, 0.08);
}

.modal__body {
  padding: 22px 26px 26px;
  overflow-y: auto;
  flex: 1;
  position: relative;
  z-index: 1;
}

/* ───── Tabs ───── */
.modal__tabs {
  display: flex;
  gap: 0;
  padding: 0 26px;
  background: transparent;
  border-bottom: 1px solid rgba(212, 169, 92, 0.14);
  position: relative;
  z-index: 1;
}
.modal__tab {
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--ink-faded);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  position: relative;
  transition: color 220ms ease;
}
.modal__tab:hover { color: var(--ink-muted); }
.modal__tab--active { color: var(--gold-bright); }
.modal__tab--active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 14px;
  right: 14px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-bright), transparent);
}

/* ───── Balance card ───── */
.balance-card {
  position: relative;
  padding: 38px 20px 28px;
  text-align: center;
  margin-bottom: 24px;
  border-top: 1px solid rgba(212, 169, 92, 0.18);
  border-bottom: 1px solid rgba(212, 169, 92, 0.18);
}
.balance-card::before {
  content: attr(data-label);
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-modal);
  padding: 0 14px;
  color: var(--ink-faded);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.balance-card__amount {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 52px;
  color: var(--gold-bright);
  letter-spacing: 0;
  line-height: 1;
  margin: 0;
  text-shadow:
    0 4px 0 rgba(0,0,0,0.45),
    0 8px 24px rgba(0,0,0,0.5),
    0 0 32px rgba(244, 213, 141, 0.30);
}
.balance-card__unit {
  display: block;
  margin-top: 8px;
  color: var(--ink-faded);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}

/* ───── Quick chips ───── */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip {
  flex: 1 1 auto;
  padding: 9px 14px;
  background: transparent;
  border: 1px solid rgba(212, 169, 92, 0.22);
  color: var(--ink-muted);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  transition: all 200ms ease;
}
.chip:hover { border-color: var(--gold); color: var(--gold-bright); }

/* ───── Buttons ───── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 24px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold) 45%, var(--gold-deep));
  color: #0A0518;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border-radius: var(--radius-soft);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: transform 180ms ease, box-shadow 220ms ease, filter 220ms ease;
  width: 100%;
}
.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow:
    0 12px 28px -8px rgba(0,0,0,0.7),
    0 0 28px -6px rgba(244,213,141,0.30),
    inset 0 1px 0 rgba(244,213,141,0.30);
}
.btn:active { transform: translateY(0); }
.btn--secondary {
  background: transparent;
  color: var(--gold-bright);
  border: 1px solid rgba(212, 169, 92, 0.45);
  box-shadow: none;
}
.btn--secondary:hover {
  background: rgba(244, 213, 141, 0.06);
  border-color: var(--gold-bright);
  filter: none;
}
/* `.btn` uses display:inline-flex which beats native [hidden]. Force it. */
.btn[hidden] { display: none !important; }
/* Spacing between stacked visible buttons (e.g. Connect + Disconnect). */
.modal__body .btn:not([hidden]) + .btn:not([hidden]) { margin-top: 12px; }

/* ───── Input ───── */
.input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(8, 4, 18, 0.6);
  border: 1px solid rgba(212, 169, 92, 0.20);
  border-radius: var(--radius-soft);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 14px;
  transition: border-color 200ms ease, background 200ms ease;
}
.input:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(8, 4, 18, 0.8);
}
.input::placeholder { color: var(--ink-faded); font-weight: 500; }

.field-label {
  display: block;
  color: var(--ink-faded);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.field-hint {
  color: var(--ink-faded);
  font-size: 12px;
  line-height: 1.55;
  margin: 0 0 16px;
}

.flow-status {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(8, 4, 18, 0.5);
  border-left: 1px solid var(--gold);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.55;
  min-height: 18px;
}

.kvs {
  font-size: 13px;
  color: var(--ink-muted);
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 12px;
  margin-top: 8px;
}
.kvs strong {
  color: var(--ink);
  word-break: break-all;
  font-weight: 500;
  font-family: var(--font-body);
}

/* ──────── Leaderboard ──────── */
.lb-period {
  color: var(--ink-faded);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.lb-period::before, .lb-period::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(212,169,92,0.32), transparent);
}

.lb-myrank {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 16px;
  margin-bottom: 10px;
  background: linear-gradient(180deg, rgba(212,169,92,0.10), rgba(212,169,92,0.02));
  border: 1px solid rgba(212, 169, 92, 0.45);
  border-radius: var(--radius-soft);
  font-family: var(--font-body);
}
.lb-myrank__label {
  color: var(--gold-bright);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}
.lb-myrank__rank {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--gold-bright);
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
}
.lb-myrank__amount {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
}

.lb-list { display: flex; flex-direction: column; }
.lb-row {
  display: grid;
  grid-template-columns: 32px 30px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 7px 4px;
  border-bottom: 1px dashed rgba(212, 169, 92, 0.10);
  font-family: var(--font-body);
}
.lb-row:last-child { border-bottom: none; }
.lb-row--top {
  background: linear-gradient(90deg, rgba(212,169,92,0.06), transparent 70%);
  margin: 0 -12px;
  padding: 7px 12px;
}
.lb-rank {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink-faded);
  line-height: 1;
}
.lb-row--top .lb-rank { color: var(--gold-bright); }
.lb-medal {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--gold-bright);
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
}
.lb-medal--1 { font-size: 22px; }
.lb-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: #0A0518;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 13px;
  overflow: hidden;
  object-fit: cover;
  border: 1px solid rgba(212, 169, 92, 0.32);
}
.lb-name {
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.lb-amount {
  font-family: var(--font-display);
  color: var(--gold-bright);
  font-size: 16px;
  line-height: 1;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,0.4);
}

@media (max-width: 480px) {
  .modal__title { font-size: 24px; }
  .modal__header { padding: 18px 20px 12px; }
  .modal__tabs { padding: 0 16px; }
  .modal__tab { padding: 12px 12px; font-size: 10px; }
  .modal__body { padding: 18px 20px 22px; }
  .balance-card__amount { font-size: 44px; }
  .lb-row { grid-template-columns: 32px 32px 1fr auto; gap: 10px; }
}

/* All form elements inside modal must include padding/border in width */
.modal__body, .modal__body * { box-sizing: border-box; }

/* Hide flow-status when it has no message (avoid empty bordered box) */
.flow-status:empty {
  display: none;
  padding: 0;
  border: 0;
  margin: 0;
  min-height: 0;
}

/* Linked wallet address chip in Link tab */
.linked-wallet {
  margin-top: 14px;
  padding: 12px 14px;
  background: rgba(8, 4, 18, 0.5);
  border-left: 1px solid var(--gold);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-muted);
  word-break: break-all;
}
.linked-wallet__addr {
  display: block;
  color: var(--gold-bright);
  font-weight: 600;
  margin-top: 4px;
}

/* Temporarily hide our modal so only TonConnect popup is visible */
.modal-backdrop--hidden {
  visibility: hidden;
  pointer-events: none;
}

/* ───── Referral modal ───── */
.ref-link-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.ref-link-row .input { width: 100%; min-width: 0; font-size: 12px; }
.ref-link-row .btn { width: 100%; }

.ref-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}
.ref-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: rgba(212, 169, 92, 0.05);
  border: 1px solid rgba(212, 169, 92, 0.18);
  border-radius: var(--radius-soft);
  text-align: center;
}
.ref-stat__num {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--gold-bright);
  letter-spacing: 0.01em;
}
.ref-stat__lbl {
  font-size: 11px;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ref-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ref-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(212, 169, 92, 0.04);
  border: 1px solid rgba(212, 169, 92, 0.14);
  border-radius: var(--radius-soft);
  font-size: 13px;
}
.ref-name { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-meta { color: var(--ink-muted); font-size: 11px; }
.ref-amount { color: var(--gold-bright); font-family: var(--font-display); font-size: 13px; }
