/* StarBozor — Telegram iOS look. Colours come from Telegram's themeParams when the app runs
   inside Telegram (set as --sb-* by js/app.js); otherwise the device-theme palettes below. */

:root {
  --d-bg: #efeff4;
  --d-card: #ffffff;
  --d-text: #000000;
  --d-hint: #8a8a8e;
  --d-link: #007aff;
  --d-btn: #007aff;
  --d-btn-text: #ffffff;
  --d-sep: rgba(60, 60, 67, 0.2);
  --d-danger: #ff3b30;
  --seg-bg: rgba(118, 118, 128, 0.12);
  --seg-thumb: #ffffff;
  --seg-thumb-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 1px 1px rgba(0, 0, 0, 0.04);
  --seg-border: transparent;
  --press: rgba(0, 0, 0, 0.06);
  --radio-off: rgba(60, 60, 67, 0.3);

  --bg: var(--sb-bg, var(--d-bg));
  --card: var(--sb-card, var(--d-card));
  --text: var(--sb-text, var(--d-text));
  --hint: var(--sb-hint, var(--d-hint));
  --link: var(--sb-link, var(--d-link));
  --btn: var(--sb-btn, var(--d-btn));
  --btn-text: var(--sb-btn-text, var(--d-btn-text));
  --sep: var(--sb-sep, var(--d-sep));
  --danger: var(--sb-danger, var(--d-danger));

  color-scheme: light;
  --side: 16px;
  --radius: 22px;
  --star: clamp(92px, 29vw, 124px);
  --hero-h: calc(var(--star) + 92px);
  /* in Telegram fullscreen the status bar and Telegram's own close/menu buttons sit on top of the page */
  --safe-top: max(env(safe-area-inset-top, 0px), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --kb: 0px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

:root[data-theme="dark"] {
  /* Telegram iOS "tinted night", as in the reference recording */
  --d-bg: #161e29;
  --d-card: #1d2a39;
  --d-text: #ffffff;
  --d-hint: #7f909f;
  --d-link: #2a9bff;
  --d-btn: #299cff;
  --d-btn-text: #ffffff;
  --d-sep: rgba(255, 255, 255, 0.08);
  --d-danger: #ff5a52;
  --seg-bg: rgba(255, 255, 255, 0.05);
  --seg-thumb: rgba(0, 0, 0, 0.42);
  --seg-thumb-shadow: none;
  --seg-border: rgba(255, 255, 255, 0.09);
  --press: rgba(255, 255, 255, 0.06);
  --radio-off: rgba(255, 255, 255, 0.28);
  color-scheme: dark;
}

/* same palette before any script has run (js/app.js always sets data-theme afterwards) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* Telegram iOS "tinted night", as in the reference recording */
    --d-bg: #161e29;
    --d-card: #1d2a39;
    --d-text: #ffffff;
    --d-hint: #7f909f;
    --d-link: #2a9bff;
    --d-btn: #299cff;
    --d-btn-text: #ffffff;
    --d-sep: rgba(255, 255, 255, 0.08);
    --d-danger: #ff5a52;
    --seg-bg: rgba(255, 255, 255, 0.05);
    --seg-thumb: rgba(0, 0, 0, 0.42);
    --seg-thumb-shadow: none;
    --seg-border: rgba(255, 255, 255, 0.09);
    --press: rgba(255, 255, 255, 0.06);
    --radio-off: rgba(255, 255, 255, 0.28);
    color-scheme: dark;
  }
}

@media (max-height: 600px) {
  :root { --star: clamp(84px, 26vw, 100px); --hero-h: calc(var(--star) + 82px); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.29 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Roboto, "Segoe UI", sans-serif;
  letter-spacing: -0.2px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

button, input { font: inherit; letter-spacing: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; margin: 0; cursor: pointer; -webkit-appearance: none; appearance: none; }
[hidden] { display: none !important; }

.app { position: relative; max-width: 480px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; }

.screen { padding-bottom: calc(96px + var(--safe-bottom) + var(--kb)); }
.screen-shop.leaving, .screen-confirm.leaving { pointer-events: none; }

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

.hero {
  position: relative;
  height: calc(var(--hero-h) + var(--safe-top));
  overflow: hidden;
  /* sparks may be seen under the tabs' top edge; nothing here takes taps except the star */
}
.hero canvas { transition: opacity 0.22s ease; }
.hero.is-gift canvas { opacity: 0; }

.hero-slot {
  position: absolute;
  left: 50%;
  top: calc(18px + var(--safe-top));
  width: var(--star);
  height: var(--star);
  margin-left: calc(var(--star) / -2);
  border-radius: 50%;
  outline: none;
  cursor: pointer;
  transition: opacity 0.22s ease;
}
.hero.is-gift .hero-slot { opacity: 0; pointer-events: none; }

.hero-gift {
  position: absolute;
  left: 50%;
  top: calc(8px + var(--safe-top));
  width: calc(var(--star) + 20px);
  height: calc(var(--star) + 20px);
  margin-left: calc((var(--star) + 20px) / -2);
  opacity: 0;
  transform: scale(0.86);
  transition: opacity 0.22s ease, transform 0.36s var(--ease);
  pointer-events: none;
}
.hero.is-gift .hero-gift { opacity: 1; transform: none; }
.hero-gift > div, .hero-gift svg { width: 100%; height: 100%; display: block; }
.hero-gift .fallback { display: flex; align-items: center; justify-content: center; font-size: 84px; line-height: 1; }

.hero-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  font: 700 28px/34px -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Roboto, "Segoe UI", sans-serif;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 350px) { .hero-title { font-size: 25px; } }

/* storefront name; inside Telegram the client's own header already shows it */
.brand {
  position: absolute;
  z-index: 2;
  top: calc(10px + var(--safe-top));
  left: var(--side);
  height: 28px;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--hint);
}
.in-telegram .brand { display: none; }

.lang {
  position: absolute;
  z-index: 2;
  top: calc(10px + var(--safe-top));
  right: var(--side);
  display: flex;
  padding: 2px;
  border-radius: 14px;
  background: var(--seg-bg);
  box-shadow: inset 0 0 0 0.5px var(--seg-border);
}
.lang button {
  min-width: 34px;
  height: 24px;
  padding: 0 7px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--hint);
}
.lang button[aria-pressed="true"] { background: var(--seg-thumb); box-shadow: var(--seg-thumb-shadow); color: var(--text); }

/* ---------- segmented controls ---------- */

.seg {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 2px;
  border-radius: 18px;
  background: var(--seg-bg);
  box-shadow: inset 0 0 0 0.5px var(--seg-border);
}
.seg button {
  position: relative;
  z-index: 1;
  height: 32px;
  padding: 0 8px;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s ease;
}
.seg button[aria-selected="true"], .seg button[aria-checked="true"] { font-weight: 600; }
.seg-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / var(--n, 3));
  border-radius: 16px;
  background: var(--seg-thumb);
  box-shadow: var(--seg-thumb-shadow);
  transform: translateX(calc(100% * var(--i, 0)));
  transition: transform 0.28s var(--ease);
}
.tabs { margin: 2px var(--side) 14px; }
.seg-small { --n: 2; min-width: 168px; border-radius: 16px; }
.seg-small button { height: 28px; font-size: 14px; border-radius: 14px; }
.seg-small .seg-thumb { border-radius: 14px; }

/* ---------- grouped lists ---------- */

.group {
  margin: 0 var(--side) 12px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  transition: background-color 0.2s ease;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 9px 16px;
  text-align: left;
}
button.row { transition: background-color 0.15s ease; }
button.row:active { background: var(--press); }
/* hairline, inset to the text like on iOS */
.row + .row::before, .collapse .row::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: var(--inset, 16px);
  height: 1px;
  background: var(--sep);
  transform: scaleY(0.5);
  transform-origin: 0 0;
}
#list .row { --inset: 50px; }
#list .row.row-gift { --inset: 108px; min-height: 62px; padding-top: 7px; padding-bottom: 7px; }

.radio {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--radio-off);
  display: grid;
  place-items: center;
  transition: background-color 0.18s ease, box-shadow 0.18s ease;
}
.radio svg { width: 12px; height: 12px; opacity: 0; transform: scale(0.5); transition: opacity 0.15s ease, transform 0.25s var(--ease); }
.row[aria-checked="true"] .radio { background: var(--btn); box-shadow: none; }
.row[aria-checked="true"] .radio svg { opacity: 1; transform: none; }

.row-icon { flex: none; width: 24px; height: 24px; margin-right: -4px; }
.row-icon svg { width: 100%; height: 100%; display: block; }

.row-thumb img { display: block; width: 100%; height: 100%; }
.row-thumb { flex: none; width: 46px; height: 46px; }
.row-thumb > div, .row-thumb svg { width: 100%; height: 100%; display: block; }
.row-thumb .fallback { display: flex; align-items: center; justify-content: center; font-size: 34px; line-height: 1; }

.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { display: block; font-weight: 500; }
#list .row-title { font-weight: 600; }
#list.compact .unit { display: none; }
.row-sub { display: block; margin-top: 1px; font-size: 14px; line-height: 18px; color: var(--hint); letter-spacing: -0.1px; }
.row-price { flex: none; color: var(--hint); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.row[aria-checked="true"] .row-price { color: var(--text); }

.row-more { justify-content: center; color: var(--link); font-weight: 400; gap: 6px; }
.row-more svg { width: 14px; height: 14px; }

.row-recipient { justify-content: space-between; padding-right: 10px; }
.row-recipient .row-title { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* The username row opens without animating layout: the row appears at once (it fades in) and the
   content below slides down with a transform (see revealRecipient in app.js). */
.collapse { display: none; }
.collapse.open { display: block; }
.collapse > .row { min-height: 50px; padding-top: 9px; padding-bottom: 9px; }
.collapse.open > .row { animation: rowIn 0.26s var(--ease) both; }
@keyframes rowIn { from { opacity: 0; transform: translate3d(0, -6px, 0); } to { opacity: 1; transform: none; } }
.slide { transition: transform 0.3s var(--ease); will-change: transform; }

.row-input { gap: 2px; cursor: text; }
.at { color: var(--hint); font-size: 17px; }
.row-input input {
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 17px; /* 16px+ keeps iOS from zooming the page on focus */
  caret-color: var(--link);
  -webkit-user-select: text;
  user-select: text;
}
.row-input input::placeholder { color: var(--hint); opacity: 0.75; }

/* recipient: whose account the username is, and «choose from contacts» */
.row-who { gap: 12px; min-height: 52px; }
.row-who[hidden], .row-contact[hidden] { display: none; }
.who-pic {
  flex: none; width: 34px; height: 34px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 15px;
  background: var(--sep);
}
.who-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who-pic.big { width: 56px; height: 56px; font-size: 24px; }
.who-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-state { font-size: 14px; line-height: 18px; color: var(--hint); }
.row-who.looking .who-pic { animation: whoPulse 1s ease-in-out infinite alternate; }
.row-who.looking .who-name { font-weight: 400; color: var(--hint); }
.row-who.missing .who-pic { display: none; }
.row-who.missing .who-name { font-weight: 400; color: var(--danger); white-space: normal; }
.row-who.found { animation: rowIn 0.22s var(--ease) both; }
@keyframes whoPulse { from { opacity: 0.45; } to { opacity: 1; } }
.row-contact { gap: 10px; color: var(--link); font-weight: 400; }
.contact-ic { flex: none; width: 34px; height: 34px; display: grid; place-items: center; }
.row-contact:disabled { opacity: 0.5; }

.note { margin: -4px calc(var(--side) + 16px) 14px; font-size: 13px; line-height: 17px; color: var(--hint); letter-spacing: -0.05px; }
.note-error { color: var(--danger); }

/* ---------- bottom bar ---------- */

.bar {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px var(--side) calc(12px + var(--safe-bottom));
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--bg) 16px);
  transform: translate3d(0, calc(-1 * var(--kb)), 0);
  transition: transform 0.22s var(--ease);
  will-change: transform;
}
.bar.kb { padding-bottom: 10px; }
.cta {
  pointer-events: auto;
  display: block;
  width: 100%;
  max-width: 448px;
  margin: 0 auto;
  height: 50px;
  padding: 0 16px;
  border-radius: 25px;
  background: var(--btn);
  color: var(--btn-text);
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
  transition: transform 0.12s ease, filter 0.12s ease, background-color 0.2s ease;
}
.cta:active { transform: scale(0.985); filter: brightness(0.92); }
.cta.shake { animation: shake 0.36s ease; }
@keyframes shake { 20% { transform: translateX(-6px); } 45% { transform: translateX(5px); } 70% { transform: translateX(-3px); } 100% { transform: none; } }

/* ---------- confirmation ---------- */

.screen-confirm { padding-top: calc(8px + var(--safe-top)); }
.back { display: flex; align-items: center; gap: 3px; height: 44px; padding: 0 var(--side) 0 10px; color: var(--link); font-size: 17px; }
.back svg { width: 12px; height: 20px; }
.back.in-telegram { visibility: hidden; height: 12px; }
.confirm-art { width: 96px; height: 96px; margin: 2px auto 10px; }
.confirm-art > div, .confirm-art svg { width: 100%; height: 100%; display: block; }
.confirm-art .fallback { display: flex; align-items: center; justify-content: center; font-size: 68px; line-height: 1; height: 100%; }
.confirm-title { margin: 0 24px 20px; text-align: center; font: 700 22px/28px -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Roboto, "Segoe UI", sans-serif; letter-spacing: 0.2px; }
#summary .row { align-items: baseline; }
#summary .k { flex: none; color: var(--hint); }
#summary .v { flex: 1 1 auto; min-width: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
#summary .row.total .k { color: var(--text); font-weight: 600; }
#summary .row.total .v { font-weight: 700; }
.notice { margin: 0 var(--side) 12px; padding: 12px 16px; border-radius: 16px; background: var(--seg-bg); box-shadow: inset 0 0 0 0.5px var(--seg-border); font-size: 15px; line-height: 20px; }

/* ---------- payment ---------- */

.screen-pay { padding-top: calc(24px + var(--safe-top)); }
.screen-shop.leaving, .screen-confirm.leaving, .screen-pay.leaving { pointer-events: none; }
.pay-line { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; }
.pay-line + .pay-line::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; height: 1px; background: var(--sep); transform: scaleY(0.5); transform-origin: 0 0; }
.pay-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pay-k { font-size: 13px; line-height: 17px; color: var(--hint); }
.pay-v { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pay-amount { font: 700 26px/32px -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Roboto, "Segoe UI", sans-serif; letter-spacing: 0.2px; }
.pay-num { font-size: 18px; line-height: 24px; font-weight: 600; letter-spacing: 0.2px; white-space: nowrap; }
.pay-holder { font-size: 14px; line-height: 18px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.4px; }
.copy { flex: none; height: 34px; padding: 0 13px; border-radius: 17px; background: var(--seg-bg); color: var(--link); font-size: 15px; font-weight: 600; transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease; }
.copy:active { transform: scale(0.96); }
.copy.copied { background: var(--btn); color: var(--btn-text); }
.pay-exact { font-size: 14px; line-height: 19px; }
.pay-status { margin: 4px calc(var(--side) + 4px) 4px; font-size: 17px; line-height: 23px; font-weight: 600; text-align: center; }
.pay-status.waiting, .pay-status.checking { color: var(--text); }
.pay-status.paid, .pay-status.done { color: #31b545; }
.pay-status.review, .pay-status.expiredPaid { color: var(--hint); font-weight: 500; }
.pay-status.expired { color: var(--danger, #e53935); }
.pay-timer { margin: 0 var(--side) 8px; text-align: center; font-size: 15px; color: var(--hint); font-variant-numeric: tabular-nums; }
.pay-steps { margin: 14px calc(var(--side) + 4px) 8px; padding-left: 20px; font-size: 15px; line-height: 21px; color: var(--hint); }
.pay-steps li + li { margin-top: 4px; }
.screen-pay.settled .pay-steps, .screen-pay.settled .pay-exact, .screen-pay.settled .copy { display: none; }
.pay-links { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 8px var(--side) 0; }
.link { padding: 10px 12px; color: var(--link); font-size: 15px; }
.cta:disabled { opacity: 0.55; transform: none; filter: none; }
.cta.loading { opacity: 0.7; pointer-events: none; }

/* ---------- screen change (iOS push) ---------- */

.screen { transition: transform 0.34s var(--ease), opacity 0.24s ease; }
.screen.enter-right { transform: translate3d(36px, 0, 0); opacity: 0; }
.screen.enter-left { transform: translate3d(-36px, 0, 0); opacity: 0; }

.debug {
  position: fixed;
  z-index: 20;
  left: 8px;
  right: 8px;
  bottom: calc(84px + var(--safe-bottom));
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font: 11px/15px ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0;
  pointer-events: none;
  word-break: break-word;
}

/* ---------- narrow phones (kept last so they win over the base rules) ---------- */

@media (max-width: 380px) {
  body { font-size: 16px; }
  .row { gap: 10px; }
}
@media (max-width: 350px) {
  :root { --side: 12px; }
  body { font-size: 15px; }
  .row { gap: 8px; padding-left: 12px; padding-right: 12px; }
  #list .row { --inset: 42px; }
  #list .row.row-gift { --inset: 96px; }
  .seg-small { min-width: 150px; }
  .seg-small button { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- receipt: «Stars sent» ---------- */
.receipt[hidden] { display: none; }
.receipt { display: flex; flex-direction: column; align-items: center; padding-top: 8px; }
.rc-badge { margin: 6px 0 10px; }
.rc-badge svg { display: block; }
.rc-ring { fill: #31b545; transform-origin: 50% 50%; animation: rcPop 0.45s cubic-bezier(.2,1.4,.4,1) both; }
.rc-tick { fill: none; stroke: #fff; stroke-width: 4.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 34; stroke-dashoffset: 34; animation: rcTick 0.35s 0.3s ease-out forwards; }
@keyframes rcPop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes rcTick { to { stroke-dashoffset: 0; } }
.rc-title { margin: 0 var(--side) 14px; font: 700 24px/30px -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Roboto, "Segoe UI", sans-serif; text-align: center; }
.rc-who { display: flex; align-items: center; gap: 12px; margin: 0 var(--side) 16px; max-width: calc(100% - 2 * var(--side)); }
.rc-who-text { display: flex; flex-direction: column; min-width: 0; }
.rc-name { font-size: 18px; line-height: 23px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-user { font-size: 15px; line-height: 20px; color: var(--hint); }
.rc-rows { align-self: stretch; }
.rc-row { justify-content: space-between; gap: 12px; }
.rc-k { color: var(--hint); }
.rc-v { font-weight: 500; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.rc-note { align-self: stretch; margin-top: 2px; text-align: center; }
.screen-pay.delivered .pay-links #payCancel { display: none; }
@media (prefers-reduced-motion: reduce) { .rc-ring, .rc-tick, .row-who.found { animation: none; } .rc-tick { stroke-dashoffset: 0; } }
