/* Hold Miniapp */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #eef2f7);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #0f1419);
  --hint: var(--tg-theme-hint-color, #667380); /* AA on white for 13px+ */
  --link: var(--tg-theme-link-color, #007aff);
  --accent: var(--tg-theme-button-color, #007aff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --sep: color-mix(in srgb, var(--hint) 18%, transparent);
  --soft: #f0f2f5;        /* flat neutral fill */
  --soft-blue: #e7f1fd;   /* flat accent fill */
  --green: #2ea44f;
  --orange: #ff9500;
  --red: #e5484d;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0e1621);
    --card: var(--tg-theme-bg-color, #17212b);
    --text: var(--tg-theme-text-color, #f5f7fa);
    --hint: var(--tg-theme-hint-color, #708499);
    --soft: #212d3b;
    --soft-blue: #1b2b3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}
button, [role="button"], [role="radio"], select, a { cursor: pointer; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 12px calc(96px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---- User chip ---- */
.user-chip { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.user-chip { cursor: pointer; }
.user-chip .avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--accent);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 17px;
  overflow: hidden;
}
.user-chip .avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-chip .who { min-width: 0; }
.user-chip .who .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .who .uname { font-size: 13px; color: var(--hint); }
.lang-switch { margin-left: auto; }
.lang-switch select {
  appearance: none; border: none; background: var(--soft-blue);
  color: var(--link); font-weight: 600; font-size: 13px; padding: 6px 10px; border-radius: 99px;
  font-family: inherit; cursor: pointer;
}

/* ---- Hero ---- */
.hero {
  position: relative;
  padding: 22px 18px;
  display: flex; align-items: center; gap: 16px;
  background: var(--card);
}
.hero .badge-wrap { flex: none; }
.hero .badge-wrap img { width: 64px; height: 64px; display: block; }
.hero h1 { font-size: 21px; letter-spacing: -.02em; }
.hero p { font-size: 13.5px; color: var(--hint); margin-top: 3px; }

/* ---- Inputs ---- */
.input-row { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; }
.input-row .at { color: var(--hint); font-weight: 600; font-size: 17px; }
.input-row input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  color: var(--text); font-size: 16px; padding: 10px 0; font-family: inherit;
}
.input-row input::placeholder { color: var(--hint); }
.btn-mini {
  border: none; background: var(--accent); color: var(--accent-text);
  font-weight: 600; font-size: 14px; padding: 9px 16px; border-radius: 99px;
  cursor: pointer; font-family: inherit;
}
.field-note { font-size: 12.5px; padding: 0 16px 10px; display: none; }
.field-note.ok { color: #2ea44f; display: block; }
.field-note.err { color: #e5484d; display: block; }

/* ---- Section labels ---- */
.section-label {
  font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--hint); padding: 4px 16px 0;
}

/* ---- Products ---- */
.product { display: flex; align-items: center; gap: 12px; padding: 13px 16px; cursor: pointer; position: relative; transition: background .15s ease; }
@media (hover: hover) and (pointer: fine) {
  .product:hover { background: var(--soft); }
}
.product + .product { border-top: 1px solid var(--sep); }
.product .radio {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  border: 2px solid color-mix(in srgb, var(--hint) 55%, transparent);
  display: grid; place-items: center; transition: all .15s ease;
}
.product.selected .radio { border-color: var(--accent); background: var(--accent); }
.product.selected .radio::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-text); }
.product .p-info { min-width: 0; flex: 1; }
.product .p-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.product .p-sub { font-size: 13px; color: var(--hint); margin-top: 1px; }
.product .p-price { text-align: right; font-weight: 700; font-size: 16.5px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.product .p-old { font-size: 13px; color: var(--hint); text-decoration: line-through; font-weight: 500; }
.chip {
  font-size: 11.5px; font-weight: 700; color: #fff; background: var(--accent);
  border-radius: 99px; padding: 2px 8px; letter-spacing: .02em;
}

/* ---- Coins ---- */
.coin-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; user-select: none;
}
.coin-head > img {
  width: 40px; height: 40px; flex: none;
  transition: transform .25s ease;
}
.coin-head:active > img { transform: scale(.92); }
.cs-info { min-width: 0; flex: 1; }
.cs-sym { font-weight: 700; font-size: 16px; }
.cs-net { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.chev {
  color: var(--hint); flex: none;
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
.coin-select.open .chev { transform: rotate(180deg); }

.coin-body {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .32s cubic-bezier(.4, 0, .2, 1);
}
.coin-body > .coin-grid {
  overflow: hidden; min-height: 0;
  padding: 0 12px;
  transition: padding .32s cubic-bezier(.4, 0, .2, 1);
}
.coin-select.open .coin-body { grid-template-rows: 1fr; }
.coin-select.open .coin-body > .coin-grid { padding: 12px; }
.coin-select.open .coin-head { box-shadow: inset 0 -1px 0 var(--sep); }

.coin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.coin {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px 8px; border-radius: 14px; cursor: pointer;
  border: 1.5px solid transparent; background: var(--soft);
  transition: all .15s ease;
}
.coin img { width: 34px; height: 34px; }
.coin .c-sym { font-size: 12.5px; font-weight: 600; }
.coin .c-net { font-size: 10px; color: var(--hint); font-weight: 500; }
.coin.selected {
  border-color: var(--accent);
  background: var(--soft-blue);
}

/* ---- Support card ---- */
.support-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.sp-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 19px;
  overflow: hidden;
}
.sp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sp-info { flex: 1; min-width: 0; }
.sp-name { font-weight: 700; font-size: 15.5px; display: flex; align-items: center; gap: 5px; }
.sp-badge { width: 17px; height: 17px; }
.sp-handle { color: var(--link); font-size: 13px; font-weight: 500; }
.sp-hint { color: var(--hint); font-size: 12.5px; margin-top: 2px; }
.sp-open { flex: none; }

/* ---- Footer / buy ---- */
.terms-row { text-align: center; padding: 2px 0 4px; }
.terms-row a { color: var(--link); font-size: 13.5px; text-decoration: none; }

.buybar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--sep);
}
.buybar .btn-buy {
  width: 100%; max-width: 448px; margin: 0 auto; display: block;
  border: none; border-radius: 16px; padding: 15px;
  background: var(--accent); color: var(--accent-text);
  font-size: 16.5px; font-weight: 700; font-family: inherit; cursor: pointer;
}
.buybar .btn-buy:disabled { opacity: .55; cursor: default; }

/* ---- Button interactions (spring press + hover lift + ripple) ----
   Ported from be-ui-button (React/motion): pressScale .93, hover 1.02,
   spring release ≈ back-out overshoot, EASE_OUT = cubic-bezier(.16,1,.3,1). */
.btn-mini, .btn-buy {
  position: relative; overflow: hidden;
  transform: scale(1);
  transition: transform .38s cubic-bezier(.34, 1.56, .64, 1), opacity .2s, background .2s;
  will-change: transform;
}
.btn-mini:active, .btn-buy:active {
  transform: scale(.93);
  transition-duration: .08s;
  transition-timing-function: ease-out;
}
@media (hover: hover) and (pointer: fine) {
  .btn-mini:hover:not(:active):not(:disabled),
  .btn-buy:hover:not(:active):not(:disabled) { transform: scale(1.02); }
}
.ripple {
  position: absolute; border-radius: 50%;
  background: currentColor; pointer-events: none;
  transform: translate(-50%, -50%) scale(0);
  opacity: .3;
  animation: ripple-out 1.2s cubic-bezier(.16, 1, .3, 1) forwards;
}
@keyframes ripple-out {
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .btn-mini, .btn-buy { transition: opacity .2s, background .2s; }
  .btn-mini:active, .btn-buy:active,
  .btn-mini:hover, .btn-buy:hover { transform: none; }
  .ripple { display: none; }
  .card { animation: none; }
}
body.tg-native .buybar { display: none; } /* Telegram MainButton takes over */

/* ---- Splash ---- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  background: #000;
  opacity: 1;
  transition: opacity .45s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
#splash canvas { display: block; width: 100%; height: 100%; }

/* ---- Overlay states ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  background: var(--bg);
  padding: 48px 24px; text-align: center;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
}
.overlay.show { display: flex; }
.overlay .big-icon { font-size: 58px; line-height: 1; }
.big-icon svg { width: 64px; height: 64px; }
.icon-success { color: #2ea44f; }
.icon-expired { color: #f5a623; }
.pay-expired .big-icon svg { width: 44px; height: 44px; }
.overlay h2 { font-size: 21px; }
.overlay p { color: var(--hint); font-size: 14.5px; max-width: 320px; }
.overlay .btn-mini { margin-top: 8px; padding: 11px 26px; font-size: 15px; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3.5px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- White-label payment sheet ---- */
.pay-overlay { padding: 16px; align-items: stretch; justify-content: flex-start; overflow-y: auto; }
.pay-sheet {
  width: 100%; max-width: 440px; margin: 0 auto;
  background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
  padding: 20px 18px; text-align: left;
  display: flex; flex-direction: column; gap: 16px;
}
.pay-head { display: flex; align-items: center; gap: 14px; }
.pay-head img { width: 46px; height: 46px; flex: none; }
.pay-head h2 { font-size: 19px; }
.pay-hint { font-size: 13px; color: var(--hint); margin-top: 2px; }

.qr-box { display: grid; place-items: center; }
.qr-box img {
  width: 190px; height: 190px; border-radius: 16px;
  background: #fff; padding: 10px; box-shadow: var(--shadow);
}
.qr-box img[src=""] { display: none; }

.pay-rows { border: 1px solid var(--sep); border-radius: 14px; overflow: hidden; }
.pay-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; }
.pay-row + .pay-row { border-top: 1px solid var(--sep); }
.pr-label { font-size: 12px; color: var(--hint); flex: none; width: 72px; }
.pr-value { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; }
.pr-value.addr { word-break: break-all; font-size: 12.5px; line-height: 1.35; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.btn-copy {
  flex: none; border: none; cursor: pointer; font-family: inherit;
  background: var(--soft-blue); color: var(--link);
  font-weight: 600; font-size: 12.5px; padding: 6px 12px; border-radius: 99px;
  transition: background .2s;
}
.btn-copy.copied { background: var(--soft); color: var(--green); }
.memo-warn { font-size: 12.5px; color: #e5484d; font-weight: 600; margin-top: -8px; padding: 0 4px; }

.pay-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--hint);
  background: var(--soft);
  border-radius: 99px; padding: 7px 13px;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #f5a623;
  animation: blink 1.2s ease-in-out infinite;
}
.status-pill.confirming .dot { background: #2ea44f; }
.status-pill.underpaid { color: #e5484d; }
.status-pill.underpaid .dot { background: #e5484d; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
.countdown { font-size: 13px; color: var(--hint); }
.countdown b { color: var(--text); font-variant-numeric: tabular-nums; }

.pay-expired { text-align: center; padding: 8px 0; }
.pay-expired .big-icon { font-size: 44px; }
.pay-expired h2 { font-size: 18px; margin-top: 6px; }
.pay-expired p { color: var(--hint); font-size: 13.5px; margin-top: 4px; }
.btn-cancel { align-self: center; background: var(--soft); color: var(--text); }

/* ---- Profile / account center ---- */
.profile-overlay { padding: 12px; align-items: stretch; justify-content: flex-start; overflow-y: auto; text-align: left; }
.profile-page {
  width: 100%; max-width: 480px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 12px;
}
.profile-top { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.btn-back {
  width: 36px; height: 36px; border-radius: 50%; border: none; flex: none;
  background: var(--soft); color: var(--text); cursor: pointer;
  display: grid; place-items: center;
}
.btn-back svg { width: 18px; height: 18px; }
.profile-title { flex: 1; text-align: center; font-size: 17px; font-weight: 700; margin-right: 46px; }
.profile-user { padding: 14px; }
.profile-user .avatar { width: 48px; height: 48px; font-size: 19px; }
.pnote { font-size: 12.5px; color: var(--hint); padding: 0 8px; }

.menu-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; }
.m-tile {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  display: grid; place-items: center; color: #fff;
}
.m-tile svg { width: 22px; height: 22px; }
.t-blue { background: #007aff; }
.t-green { background: #34c759; }
.t-orange { background: #ff9500; }
.t-sky { background: #32ade6; }
.m-info { flex: 1; min-width: 0; }
.m-name { font-weight: 700; font-size: 15.5px; }
.m-sub { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.count-pill {
  flex: none; background: var(--soft); color: var(--green);
  font-weight: 700; font-size: 13px; padding: 3px 11px; border-radius: 99px;
}
.pill-reward { color: var(--orange); }
.chev-r { width: 18px; height: 18px; color: var(--hint); flex: none; }

.p-list { min-height: 56px; }
.pl-row { display: flex; align-items: center; gap: 12px; padding: 13px 15px; }
.pl-row + .pl-row { border-top: 1px solid var(--sep); }
.pl-info { flex: 1; min-width: 0; }
.pl-title { font-weight: 600; font-size: 14.5px; }
.pl-sub { font-size: 12.5px; color: var(--hint); margin-top: 1px; }
.pl-right { text-align: right; flex: none; }
.pl-amount { font-weight: 700; font-size: 14.5px; font-variant-numeric: tabular-nums; }
.badge-st {
  display: inline-block; background: var(--soft);
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 99px;
}
.st-green { color: var(--green); }
.st-orange { color: var(--orange); }
.st-red { color: var(--red); }
.st-gray { color: var(--hint); }
.empty-note { padding: 18px 16px; text-align: center; color: var(--hint); font-size: 13.5px; }

/* ---- Referral card ---- */
.ref-card { position: relative; padding: 24px 20px; overflow: hidden; }
.ref-img {
  position: absolute; right: 18px; top: 18px;
  width: 76px; height: 76px; opacity: .14; pointer-events: none;
}
.ref-badge {
  display: inline-block; background: var(--soft-blue); color: var(--link);
  font-size: 12.5px; font-weight: 700; padding: 6px 13px; border-radius: 99px;
  margin-bottom: 14px;
}
.ref-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; line-height: 1.15; }
.ref-desc { color: var(--hint); font-size: 14px; margin-top: 4px; }
.ref-how { font-size: 14.5px; font-weight: 700; margin: 22px 0 12px; }
.ref-steps { list-style: none; display: flex; flex-direction: column; gap: 13px; }
.ref-steps li { display: flex; align-items: center; gap: 12px; font-size: 13.5px; color: var(--hint); line-height: 1.35; }
.ref-step-ico {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--soft-blue); color: var(--accent);
}
.ref-step-ico svg { width: 14px; height: 14px; }
.ref-link-row { display: flex; flex-direction: column; gap: 10px; }
.ref-link-box {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--sep); border-radius: 13px; padding: 0 14px;
  background: var(--soft);
}
.ref-link-box svg { width: 16px; height: 16px; color: var(--hint); flex: none; }
.ref-link-box p {
  flex: 1; min-width: 0; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 13px 0;
}
.ref-copy {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 13px; border-radius: 13px; font-size: 14.5px;
}
.ref-copy svg { width: 16px; height: 16px; }
.ref-copy.copied { background: var(--green); }

/* ---- Withdrawal form ---- */
.wd-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.wd-field {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--sep); border-radius: 13px; padding: 0 14px;
  background: var(--soft);
}
.wd-field svg { width: 16px; height: 16px; color: var(--hint); flex: none; }
.wd-dollar { color: var(--hint); font-weight: 600; font-size: 15px; }
.wd-field input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent;
  color: var(--text); font-size: 14.5px; padding: 13px 0; font-family: inherit;
}
.wd-field input::placeholder { color: var(--hint); }
.wd-field:focus-within { border-color: var(--accent); }
.wd-note { padding: 0 4px; margin: -2px 0; }
.field-note.wd-note { display: block; color: var(--hint); }
.field-note.wd-note.ok { color: #2ea44f; }
.field-note.wd-note.err { color: #e5484d; }
.wd-submit { width: 100%; padding: 13px; border-radius: 13px; font-size: 14.5px; }

/* ---- Terms of Service ---- */
.tos-overlay { padding: 12px; align-items: stretch; justify-content: flex-start; overflow-y: auto; text-align: left; }
.tos-body { padding: 20px 18px; font-size: 13.5px; line-height: 1.55; }
.tos-body h2 { font-size: 17px; margin-bottom: 2px; }
.tos-updated { color: var(--hint); font-size: 12px; margin-bottom: 14px; }
.tos-body h3 { font-size: 14.5px; margin: 16px 0 6px; }
.tos-body p { margin: 6px 0; color: var(--text); }
.tos-body ul { margin: 6px 0 6px 18px; color: var(--text); }
.tos-body li { margin: 3px 0; }

.inv-stats { display: flex; padding: 18px 6px; }
.inv-stat { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; padding: 0 6px; }
.inv-stat b { font-size: 19px; font-variant-numeric: tabular-nums; }
.inv-stat span { font-size: 11px; color: var(--hint); line-height: 1.3; }
.inv-stat + .inv-stat { border-left: 1px solid var(--sep); }

/* ---- Micro-entrance ---- */
.card { animation: rise .35s ease both; }
.card:nth-child(2) { animation-delay: .03s; }
.card:nth-child(3) { animation-delay: .06s; }
.card:nth-child(4) { animation-delay: .09s; }
.card:nth-child(5) { animation-delay: .12s; }
.card:nth-child(6) { animation-delay: .15s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
