/*
 * app.css: the Mini App's look (spec-v2 E). The arrangement is the owner's mock-up;
 * the visual language is Telegram's own, so the page feels native: its theme
 * variables (--tg-theme-*, set by telegram-web-app.js or, without it, by app.js from
 * the launch parameters) drive every base colour in light and dark themes; the --fb-*
 * values are only the fallbacks outside Telegram (prefers-color-scheme).
 * Soft cards on the secondary background, subtle separators, an 8px spacing grid,
 * one large number per screen, tabular figures where digits tick. Accent colours are tints over the
 * section colour, so they stay readable on any theme. The fonts are served from here
 * (fonts/, cached for a year): B Yekan for the app, B Mitra for the answers of the
 * questions sheet. Both are used for Persian only: Latin text (TON, links, addresses)
 * is in the system font that follows them in the stack.
 */

/* ---- Fonts ------------------------------------------------------------------ */

/* One weight each of Yekan (bold is synthesised, as Iranian sites do with it) and two of
   Mitra. "swap": the text shows at once in the system font if a font is still on its way.
   unicode-range: the Arabic script, its marks and the space, nothing else. These fonts draw
   Latin digits as Persian ones, which would turn an invite link's "r_k7m2" or an address
   into something else; Latin letters, digits and signs come from the next font. */
@font-face {
  font-family: Yekan;
  src: url("fonts/yekan-1.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0020, U+00A0, U+00AB, U+00BB, U+0600-06FF, U+0750-077F, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: Mitra;
  src: url("fonts/mitra-1.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0020, U+00A0, U+00AB, U+00BB, U+0600-06FF, U+0750-077F, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: Mitra;
  src: url("fonts/mitra-bold-1.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0020, U+00A0, U+00AB, U+00BB, U+0600-06FF, U+0750-077F, U+200C-200F, U+FB50-FDFF, U+FE70-FEFF;
}

/* ---- Tokens ----------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --fb-bg: #f1f2f6;
  --fb-section: #ffffff;
  --fb-text: #10151b;
  --fb-hint: #707a86;
  --fb-link: #2481cc;
  --fb-button: #2177bd;
  --fb-button-text: #ffffff;
  --fb-separator: rgba(60, 70, 85, 0.13);
  --fb-destructive: #d13c3c;

  --bg: var(--tg-theme-secondary-bg-color, var(--fb-bg));
  --section: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-section)));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --button: var(--tg-theme-button-color, var(--fb-button));
  --button-text: var(--tg-theme-button-text-color, var(--fb-button-text));
  --separator: var(--tg-theme-section-separator-color, var(--fb-separator));
  --destructive: var(--tg-theme-destructive-text-color, var(--fb-destructive));

  /* WCAG AA (4.5:1) for text. Telegram's hint colour is too faint for small text, so
     secondary text pulls it towards the text colour; link and destructive text on a
     tint likewise. The filled button uses --button-fill, a readable variant of the
     theme's button colour that app.js computes (readableFill). Browsers without
     color-mix keep the plain theme colours. */
  --subtle: var(--hint);
  --subtle: color-mix(in srgb, var(--hint) 50%, var(--text));
  --link-ink: var(--link);
  --link-ink: color-mix(in srgb, var(--link) 75%, var(--text));
  --destructive-ink: var(--destructive);
  --destructive-ink: color-mix(in srgb, var(--destructive) 70%, var(--text));
  --button-bg: var(--button-fill, var(--button));
  --tonal: rgba(36, 129, 204, 0.12);
  --tonal: color-mix(in srgb, var(--button) 13%, transparent);
  --press: rgba(127, 127, 127, 0.12);

  /* Tints (light theme) */
  --warm-tint: rgba(255, 149, 0, 0.12);
  --warm-chip: rgba(255, 149, 0, 0.2);
  --warm-ink: #8f4a00;
  --warm-ring: rgba(230, 140, 20, 0.2);
  --warm-bar: #d27a00;
  --green-tint: rgba(40, 180, 90, 0.11);
  --green-chip: rgba(40, 180, 90, 0.18);
  --green-ring: rgba(40, 160, 80, 0.22);
  --green-ink: #13703a;
  --green-solid: #157f3f;
  --blue-chip: rgba(36, 129, 204, 0.14);
  --blue-ink: #1f6fb2;
  --ok: #13703d;
  --ok-soft: rgba(29, 154, 91, 0.13);
  --wait: #845000;
  --wait-soft: rgba(214, 140, 20, 0.15);
  --bad: #b02e2e;
  --bad-soft: rgba(214, 69, 69, 0.12);
  --muted-soft: rgba(110, 120, 130, 0.13);
  --skeleton: rgba(120, 130, 140, 0.14);
  --skeleton-hi: rgba(255, 255, 255, 0.5);
  --shadow: 0 1px 2px rgba(16, 21, 27, 0.05);
  --sheet-shadow: 0 -10px 40px rgba(16, 21, 27, 0.16);
  --scrim: rgba(10, 14, 20, 0.42);

  --radius: 16px;
  --radius-sm: 12px;
  --font: Yekan, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
  --font-answer: Mitra, var(--font);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Roboto Mono", "Liberation Mono", monospace;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
}

/* The dark tints. Outside Telegram they follow the system; inside, Telegram's scheme
   (data-scheme, set by app.js from Telegram.WebApp.colorScheme) decides. */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --fb-bg: #0f1419;
    --fb-section: #1a2129;
    --fb-text: #e8ecf0;
    --fb-hint: #8b96a2;
    --fb-link: #62b4f5;
    --fb-button: #317ab8;
    --fb-separator: rgba(200, 210, 220, 0.1);
    --fb-destructive: #f07272;
  }
}

:root[data-scheme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --warm-tint: rgba(255, 176, 64, 0.085);
    --warm-chip: rgba(255, 176, 64, 0.17);
    --warm-ink: #ffc06a;
    --warm-ring: rgba(255, 176, 64, 0.16);
    --warm-bar: #ffb54a;
    --green-tint: rgba(70, 210, 120, 0.1);
    --green-chip: rgba(70, 210, 120, 0.18);
    --green-ring: rgba(70, 210, 120, 0.2);
    --green-ink: #6edc96;
    --blue-chip: rgba(100, 180, 245, 0.16);
    --blue-ink: #7cc0f6;
    --ok: #4cc38a;
    --ok-soft: rgba(76, 195, 138, 0.16);
    --wait: #e7ad48;
    --wait-soft: rgba(231, 173, 72, 0.16);
    --bad: #ff9a9a;
    --bad-soft: rgba(240, 114, 114, 0.13);
    --muted-soft: rgba(160, 170, 180, 0.13);
    --skeleton: rgba(160, 170, 180, 0.12);
    --skeleton-hi: rgba(255, 255, 255, 0.07);
    --shadow: none;
    --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
    --scrim: rgba(0, 0, 0, 0.55);
    --press: rgba(255, 255, 255, 0.08);
  }
}

:root[data-scheme="dark"] {
  color-scheme: dark;
  --warm-tint: rgba(255, 176, 64, 0.085);
  --warm-chip: rgba(255, 176, 64, 0.17);
  --warm-ink: #ffc06a;
  --warm-ring: rgba(255, 176, 64, 0.16);
  --warm-bar: #ffb54a;
  --green-tint: rgba(70, 210, 120, 0.1);
  --green-chip: rgba(70, 210, 120, 0.18);
  --green-ring: rgba(70, 210, 120, 0.2);
  --green-ink: #6edc96;
  --blue-chip: rgba(100, 180, 245, 0.16);
  --blue-ink: #7cc0f6;
  --ok: #4cc38a;
  --ok-soft: rgba(76, 195, 138, 0.16);
  --wait: #e7ad48;
  --wait-soft: rgba(231, 173, 72, 0.16);
  --bad: #ff9a9a;
  --bad-soft: rgba(240, 114, 114, 0.13);
  --muted-soft: rgba(160, 170, 180, 0.13);
  --skeleton: rgba(160, 170, 180, 0.12);
  --skeleton-hi: rgba(255, 255, 255, 0.07);
  --shadow: none;
  --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
  --press: rgba(255, 255, 255, 0.08);
}

/* ---- Base ------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.6 var(--font);
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}

/* No page scrolling behind an open sheet. */
html.has-sheet, html.has-sheet body { overflow: hidden; }

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }
strong { font-weight: 700; }
bdi { unicode-bidi: isolate; }

:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
[tabindex="-1"]:focus { outline: none; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Directional icons (the paper plane) point the reading way. */
.icon-flip { transform: scaleX(-1); }

.num { unicode-bidi: isolate; }
/* Tabular figures only where digits change in place (the countdown). */
#timer-value { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 0.92em; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(16px + var(--tg-content-safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(16px + var(--safe-bottom))
    calc(16px + env(safe-area-inset-left, 0px));
}

.view { animation: view-in 0.2s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Text ------------------------------------------------------------------- */

.hint { color: var(--subtle); font-size: 14px; }
.small { font-size: 13px; }
.pad { padding: 0 4px 12px; }
.fine { color: var(--subtle); font-size: 12px; line-height: 1.7; text-align: center; margin: 16px 8px 0; }
.note { color: var(--subtle); font-size: 13px; text-align: center; margin-top: 8px; }

/* Latin values (addresses, codes): their own LTR line. */
.ltr-line {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  overflow-wrap: anywhere;
}
/* Addresses and codes break anywhere, so the lines fill evenly instead of at a "-". */
.ltr-line.mono, .row-extra .ltr-line { word-break: break-all; }

/* ---- Buttons ----------------------------------------------------------------- */

.btn {
  appearance: none;
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 48px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, opacity 0.12s ease, background-color 0.12s ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--button-bg); color: var(--button-text); }
.btn-tonal { background: var(--tonal); color: var(--link-ink); }
.btn-plain { background: var(--section); color: var(--link-ink); box-shadow: var(--shadow); }
.btn-block { display: flex; width: 100%; margin-top: 12px; }
.btn .icon { width: 19px; height: 19px; }

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--link-ink);
  font-weight: 600;
  font-size: 14px;
  min-height: 44px;
  padding: 0 4px;
  margin: -12px -4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.link-btn .icon { width: 16px; height: 16px; }

/* ---- Cards and groups ---------------------------------------------------------- */

.card {
  background: var(--section);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 12px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-title { font-size: 15px; font-weight: 700; line-height: 1.5; }
.chip {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--tonal);
  color: var(--accent);
}
.chip .icon { width: 18px; height: 18px; }

.group {
  background: var(--section);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.group-header { font-size: 17px; font-weight: 700; margin: 32px 4px 4px; }
.sub-header { font-size: 13px; color: var(--subtle); margin: 12px 16px 8px; }

/* Telegram-style separators: a hairline that starts after the leading icon. */
.stat-row, .kv-row, .row { position: relative; }
.stat-row + .stat-row::before, .kv-row + .kv-row::before, .row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  inset-inline-start: 16px;
  inset-inline-end: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
  transform-origin: top;
}
.stat-row + .stat-row::before { inset-inline-start: 60px; }

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--muted-soft);
  color: var(--subtle);
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-wait { background: var(--wait-soft); color: var(--wait); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }

.alert {
  background: var(--bad-soft);
  color: var(--destructive-ink);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 12px 0 0;
  font-size: 14px;
}
.alert-warn { background: var(--wait-soft); color: var(--wait); }

/* ---- Loading skeleton ------------------------------------------------------ */

.sk { background: var(--skeleton); border-radius: var(--radius); position: relative; overflow: hidden; }
.sk::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--skeleton-hi), transparent);
  transform: translateX(100%);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { transform: translateX(-100%); } }
.sk-tile { height: 112px; }
.sk-banner { height: 76px; margin-bottom: 12px; }
.sk-free { height: 104px; margin-bottom: 12px; }
.sk-invite { height: 172px; margin-bottom: 12px; }
.sk-stats { height: 156px; }
.sk-list { height: 132px; margin-bottom: 12px; }
.sk-list-short { height: 64px; }

/* ---- Notice ----------------------------------------------------------------- */

.notice { text-align: center; padding: 16vh 12px 0; }
.notice-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--tonal);
  color: var(--accent);
}
.notice-icon .icon { width: 34px; height: 34px; stroke-width: 1.6; }
.notice-title { font-size: 20px; font-weight: 700; line-height: 1.5; margin: 20px 0 8px; }
.notice-text { color: var(--subtle); margin-bottom: 24px; }
.notice .btn { min-width: 180px; }

/* ---- Main screen ---------------------------------------------------------------- */

/* The rules button sits at the bottom of the screen when the content is shorter. */
.main {
  display: flex;
  flex-direction: column;
  min-height: calc(var(--tg-viewport-stable-height, 100vh) - 32px - var(--safe-bottom)
    - var(--tg-content-safe-area-inset-top, 0px));
}

/* 1. Tiles: one row of three, never wrapping; the text shrinks on narrow screens. */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.tile {
  position: relative;
  appearance: none;
  border: 0;
  margin: 0;
  min-width: 0;
  min-height: 112px;
  padding: 16px 6px 14px;
  border-radius: var(--radius);
  background: var(--section);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  text-align: center;
  font: inherit;
  color: var(--text);
}
.tile-action { cursor: pointer; touch-action: manipulation; transition: transform 0.12s ease, background-color 0.12s; }
.tile-action:active { transform: scale(0.97); background: linear-gradient(var(--press), var(--press)), var(--section); }
.tile-icon {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--tonal);
  color: var(--accent);
  margin-bottom: 4px;
}
.tile-icon .icon { width: 18px; height: 18px; }
.tile-label { font-size: 12px; line-height: 1.5; color: var(--subtle); white-space: nowrap; }
.tile-value {
  font-size: clamp(14px, 4.3vw, 18px);
  font-weight: 700;
  line-height: 1.35;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-value .unit { font-size: 0.78em; font-weight: 600; color: var(--subtle); }
.tile-address { font-family: var(--mono); font-size: clamp(12px, 3.5vw, 14px); font-weight: 600; }
.ton-mark { font-weight: 700; }
/* The tiles' "tap me" chevron: --subtle, not the theme's faint hint (3:1 for a control). */
.tile-go {
  position: absolute;
  top: 10px;
  inset-inline-end: 8px;
  width: 14px;
  height: 14px;
  color: var(--subtle);
  stroke-width: 2.2;
}
.tile-connected .tile-icon { background: var(--green-chip); color: var(--green-ink); }
/* Not connected yet: the label is the action (link colour), not a caption. */
#tile-wallet:not(.tile-connected) .tile-label { color: var(--link-ink); font-weight: 600; }
/* A withdrawal waits only for the address. */
.tile-dot {
  position: absolute;
  top: 12px;
  inset-inline-start: 12px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--destructive);
  box-shadow: 0 0 0 2px var(--section);
}
.tile-ended .tile-value { color: var(--subtle); }

/* 2. Reward banner: a warm tint over the section colour. */
.banner {
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--warm-chip), var(--warm-tint) 60%), var(--section);
  box-shadow: inset 0 0 0 1px var(--warm-ring);
  padding: 16px;
  margin-bottom: 12px;
}
.banner-row { display: flex; align-items: center; gap: 12px; }
.banner-icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--warm-chip);
  color: var(--warm-ink);
}
.banner-icon .icon { width: 22px; height: 22px; }
.banner-text { font-size: 15px; font-weight: 500; line-height: 1.75; text-wrap: balance; }
.banner-text strong { color: var(--warm-ink); font-weight: 800; white-space: nowrap; }
.banner-progress { margin-top: 12px; padding-inline-start: 52px; }
.bar { height: 6px; border-radius: 999px; background: var(--warm-chip); overflow: hidden; }
.bar-fill {
  height: 100%;
  inline-size: calc(var(--fill, 0) * 100%);
  border-radius: inherit;
  background: var(--warm-bar);
  transition: inline-size 0.6s ease;
}
.banner-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--subtle);
}
#banner-progress-count { flex: none; white-space: nowrap; font-weight: 600; }

/* 3. Free reward: green tint, the strongest call to action on the screen. */
.free {
  appearance: none;
  border: 0;
  width: 100%;
  margin: 0 0 12px;
  padding: 20px 16px;
  border-radius: var(--radius);
  background: linear-gradient(var(--green-tint), var(--green-tint)), var(--section);
  box-shadow: inset 0 0 0 1px var(--green-ring);
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: start;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease;
}
.free:active:not(:disabled) { transform: scale(0.985); }
.free:disabled { cursor: default; }
.free-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.free-title { font-size: 15px; font-weight: 700; color: var(--green-ink); }
.free-hero {
  font-size: clamp(22px, 7vw, 28px);
  font-weight: 800;
  line-height: 1.3;
}
.free-hero .pre, .free-hero .unit { font-size: 0.6em; font-weight: 700; color: var(--subtle); }
.free-note { font-size: 13px; color: var(--subtle); margin-top: 2px; }
.free-cta {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  padding: 0 14px 0 10px;
  border-radius: 999px;
  background: var(--green-solid);
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
}
.free-cta .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.free-badge {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--green-chip);
  color: var(--green-ink);
}
.free-badge .icon { width: 22px; height: 22px; }
.free-off { background: var(--section); box-shadow: var(--shadow); }
.free-off .free-title { color: var(--subtle); }
/* Unlocked (done), or nothing to claim while the campaign takes no invites (idle): a
   quiet row, not the screen's headline. */
.free-done, .free-idle {
  padding: 12px 16px;
  min-height: 56px;
  background: var(--section);
  box-shadow: var(--shadow);
}
.free-done .free-title, .free-idle .free-title { font-weight: 500; color: var(--text); }
.free-done .free-note, .free-idle .free-note { margin-top: 0; }
.free-done .free-badge { width: 32px; height: 32px; }
.free-done .free-badge .icon { width: 18px; height: 18px; }

/* 4. Invite card */
.link-field {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}
.link-field bdi {
  display: block;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: left;
  font-size: clamp(13px, 3.8vw, 15px);
  font-weight: 500;
  -webkit-user-select: all;
  user-select: all;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn-copied { background: var(--ok-soft); color: var(--ok); }
.inline-notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bad-soft);
  color: var(--destructive-ink);
  font-size: 14px;
  font-weight: 500;
}
.inline-notice .icon { width: 18px; height: 18px; margin-top: 2px; }

/* 5. Stats */
.stat-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; }
.stat-icon {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
}
.stat-icon .icon { width: 18px; height: 18px; }
.stat-green { background: var(--green-chip); color: var(--green-ink); }
.stat-blue { background: var(--blue-chip); color: var(--blue-ink); }
.stat-warm { background: var(--warm-chip); color: var(--warm-ink); }
.stat-label { flex: 1; min-width: 0; font-size: 15px; }
.stat-value {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
}
.tag {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--muted-soft);
  color: var(--subtle);
}

/* 6. Rules button, 7. questions button */
.rules-button { margin-top: auto; }
.rules-button .icon, .faq-button .icon { color: var(--accent); }

/* ---- Sheets ------------------------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.sheet:not(.sheet-open) { pointer-events: none; }
.sheet-scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  opacity: 0;
  transition: opacity 0.28s ease;
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  max-height: calc(100vh - 24px);
  max-height: calc(var(--tg-viewport-stable-height, 100vh) - 24px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--sheet-shadow);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-open .sheet-scrim { opacity: 1; }
.sheet-open .sheet-panel { transform: none; }

.sheet-head {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
  padding: 12px 16px 4px;
}
.sheet-grabber {
  position: absolute;
  top: 6px;
  left: 50%;
  width: 36px;
  height: 4px;
  margin-left: -18px;
  border-radius: 2px;
  background: var(--hint);
  opacity: 0.35;
}
.sheet-title { flex: 1; font-size: 17px; font-weight: 700; line-height: 1.4; }
.sheet-close {
  appearance: none;
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  margin-inline-end: -8px;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  color: var(--subtle);
  cursor: pointer;
}
/* The 30px circle in the middle of the 44px button, placed explicitly: left to its static
   position (an absolute child of a grid), older WebViews put it in a corner, off the cross. */
.sheet-close::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--muted-soft);
}
.sheet-close .icon { position: relative; width: 18px; height: 18px; stroke-width: 2.2; }
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(24px + var(--safe-bottom));
}

.intro { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; padding: 0 4px; color: var(--subtle); }
.intro p { font-size: 14px; line-height: 1.7; }
.intro-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: var(--tonal);
  color: var(--accent);
}
.intro-green { background: var(--green-chip); color: var(--green-ink); }
.intro-icon .icon { width: 24px; height: 24px; }

/* ---- Verify sheet ------------------------------------------------------------ */

.steps { list-style: none; padding: 0; margin: 0; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.step-head .card-title { margin: 0; }
.step-num {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-text);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}
.step.attention { box-shadow: inset 0 0 0 1.5px var(--wait); }

/* Never display:none while empty: app.js measures its width to pick the widget size. */
.turnstile { margin-top: 12px; display: flex; justify-content: center; min-height: 0; }
.status { font-size: 14px; margin-top: 8px; }
.status:empty { display: none; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-error { color: var(--destructive-ink); }
.status-muted { color: var(--subtle); }
.ltr-line.small { color: var(--subtle); font-size: 12px; margin-top: 4px; }

/* ---- Wallet sheet -------------------------------------------------------------- */

.saved-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.saved .ltr-line { font-size: 14px; line-height: 1.7; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.input {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--separator);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 16px; /* 16px: iOS does not zoom into the field */
  text-align: left;
}
.input:focus { border-color: var(--button-bg); outline: none; box-shadow: 0 0 0 3px var(--tonal); }
.input:disabled { opacity: 0.5; }
#ton-help { margin-top: 8px; }
.field-error { color: var(--destructive-ink); font-size: 13px; margin-top: 6px; }

/* ---- Withdraw sheet ------------------------------------------------------------ */

.hero { text-align: center; padding: 8px 0 20px; }
.hero-label { font-size: 13px; color: var(--subtle); }
.hero-value {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.3;
  margin-top: 4px;
}
.hero-value .unit { font-size: 20px; font-weight: 700; color: var(--subtle); }
.hero-sub { font-size: 14px; color: var(--subtle); margin-top: 2px; }

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px 16px;
}
.kv-label { color: var(--subtle); font-size: 14px; flex: none; }
.kv-value {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 600;
  font-size: 14px;
  text-align: end;
}
.kv-value .mono { font-size: 13.5px; }
.kv-stack { flex-direction: column; align-items: stretch; gap: 4px; }
.kv-stack .ltr-line { font-size: 13.5px; line-height: 1.7; font-weight: 500; }

.open-request { padding: 16px; }
.open-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.open-amount { font-size: 18px; font-weight: 700; margin: 4px 0 2px; }
.open-amount .unit { font-size: 13px; color: var(--subtle); font-weight: 600; }

.stage-title { font-size: 17px; font-weight: 700; margin: 4px 4px 12px; }
.bullets { margin: 0 4px 0; padding-inline-start: 18px; color: var(--subtle); font-size: 13px; }
.bullets li + li { margin-top: 4px; }

.result { text-align: center; padding: 16px 8px 8px; }
.result-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ok-soft);
  color: var(--ok);
}
.result-icon .icon { width: 36px; height: 36px; stroke-width: 2; }
.result-wait { background: var(--wait-soft); color: var(--wait); }
.result-title { font-size: 20px; font-weight: 700; line-height: 1.5; margin: 16px 0 4px; }
.result-amount { font-size: 15px; font-weight: 600; }
.result-text { color: var(--subtle); margin-top: 8px; font-size: 14px; }

/* History rows */
.list { list-style: none; }
.row { padding: 12px 16px; }
.row-head, .row-sub { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-title { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amount { flex: none; font-weight: 700; white-space: nowrap; }
.row-amount .unit { font-weight: 500; font-size: 12px; color: var(--subtle); }
.amount-in { color: var(--ok); }
.row-sub { margin-top: 2px; font-size: 12px; color: var(--subtle); }
.row-extra { margin-top: 6px; font-size: 12px; color: var(--subtle); }
.row-extra .ltr-line { font-family: var(--mono); font-size: 11.5px; color: var(--subtle); }
.empty { color: var(--subtle); font-size: 13px; text-align: center; padding: 4px 0 8px; }
.list:empty { display: none; }

/* ---- Rules sheet ------------------------------------------------------------------ */

.rules-list {
  margin: 0;
  padding: 16px 16px 16px 16px;
  padding-inline-start: 36px;
  font-size: 14px;
  line-height: 1.8;
  list-style-type: persian; /* ۱. ۲. ۳. */
}
.rules-list li + li { margin-top: 12px; }
.rules-list li::marker { color: var(--link-ink); font-weight: 700; }

/* ---- Questions sheet ------------------------------------------------------------- */

/* The three sections stand out; each is a group of questions, Telegram-style. */
.faq-section { font-size: 16px; font-weight: 700; margin: 24px 4px 10px; }
.faq-section:first-child { margin-top: 4px; }
.faq-item { position: relative; }
.faq-item + .faq-item::before {
  content: "";
  position: absolute;
  top: 0;
  inset-inline-start: 16px;
  inset-inline-end: 0;
  height: 1px;
  background: var(--separator);
  transform: scaleY(0.5);
  transform-origin: top;
}
.faq-q {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.7;
  list-style: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.faq-q::-webkit-details-marker { display: none; }
.faq-q:active { background: var(--press); }
.faq-num { flex: none; align-self: flex-start; color: var(--link-ink); }
.faq-text { flex: 1; min-width: 0; }
/* "+" closed, "−" open: two bars, the upright one turns flat. */
.faq-sign {
  flex: none;
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--tonal);
}
.faq-sign::before, .faq-sign::after {
  content: "";
  position: absolute;
  top: 12px;
  left: 7px;
  width: 12px;
  height: 2px;
  border-radius: 1px;
  background: var(--link-ink);
  transition: transform 0.2s ease;
}
.faq-sign::after { transform: rotate(90deg); }
.faq-item[open] .faq-sign::after { transform: none; }
/* Mitra is drawn smaller than Yekan: a larger size reads alike. */
.faq-a {
  padding: 0 16px 16px;
  font-family: var(--font-answer);
  font-size: 18px;
  line-height: 1.9;
}
.faq-a p + p { margin-top: 10px; }
.faq-a bdi { font-family: var(--font); font-size: 0.84em; }

/* ---- Toast ------------------------------------------------------------------ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 100;
  width: max-content;
  max-width: min(92vw, 440px);
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: rgba(24, 28, 34, 0.94);
  color: #ffffff;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  animation: toast-in 0.2s ease-out;
  pointer-events: none; /* it may lie over the rules button: taps go through */
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- Narrow phones ------------------------------------------------------------- */

@media (max-width: 359px) {
  .app { padding-left: 12px; padding-right: 12px; }
  .banner-progress { padding-inline-start: 0; }
  .tiles { gap: 6px; }
  .tile { padding: 14px 4px 12px; }
  .tile-label { font-size: 11px; }
  .free { padding: 16px 12px; }
  .free-cta { padding: 0 10px 0 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .view, .toast { animation: none; }
  .sk::after { animation: none; display: none; }
  .btn, .tile-action, .free, .bar-fill, .sheet-panel, .sheet-scrim, .faq-sign::after { transition: none; }
}
