/* Shared design system for all Mini App pages. Source of truth: docs/project/DESIGN.md,
   registry of classes: docs/project/COMPONENTS.md. Surfaces follow the user's Telegram theme
   (--tg-theme-* set by telegram-web-app.js), brand colours are fixed. */

@layer reset, tokens, base, components, utilities;

/* ---------- Font: Onest (OFL, self-hosted variable, see fonts/OFL.txt) ---------- */
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-cyrillic-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Onest";
  src: url("fonts/onest-latin-ext-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Metric-matched fallback keeps the swap from shifting layout (CLS). */
@font-face {
  font-family: "Onest Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Roboto");
  size-adjust: 103%;
  ascent-override: 96%;
  descent-override: 25%;
  line-gap-override: 0%;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  button, input, select, textarea { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: 0; padding: 0; }
  img, svg { display: block; max-width: 100%; }
  h1, h2, h3, p, ul, ol { margin: 0; }
  ul, ol { padding: 0; }
  dialog { padding: 0; border: 0; color: inherit; }
  /* closed sheet must stay hidden even where <dialog> is polyfilled to the open attribute */
  dialog.sheet:not([open]) { display: none; }
  dialog.sheet[open] { display: block; }
  /* author display rules (.note, .back-fallback …) must not defeat the hidden attribute */
  [hidden] { display: none !important; }
}

/* ---------- Tokens (DESIGN.md §Colour, §Type, §Shape & space) ---------- */
@layer tokens {
  :root {
    color-scheme: light;
    --canvas: var(--tg-theme-secondary-bg-color, #eefbf8);
    --surface: var(--tg-theme-section-bg-color, #ffffff);
    --ink: var(--tg-theme-text-color, #091f1b);
    --ink-soft: var(--tg-theme-hint-color, #49615b);
    --line: #cadcd7;
    --accent: #ac6310;
    --on-accent: #ffffff;
    --sea: #00806e;
    --sea-fill: #00b49b;
    --deny: #b55549;
    /* Tonal steps derived from tokens (no new hues). */
    --field: color-mix(in oklab, var(--canvas) 55%, var(--surface));
    --sea-tint: color-mix(in oklab, var(--sea-fill) 9%, var(--surface));
    --deny-tint: color-mix(in oklab, var(--deny) 9%, var(--surface));
    --skeleton: color-mix(in oklab, var(--ink) 8%, var(--surface));
    --shadow-card: 0 1px 2px rgb(0 0 0 / .06);
    --active-opt: var(--surface);

    /* Liquid glass (DESIGN.md §Glass): translucent surfaces over the ambient canvas layer.
       Nothing is a photo background — the glass reads through blur, edge light and the tint below. */
    --glass-bg: rgb(255 255 255 / .58);
    --glass-bg-strong: rgb(255 255 255 / .76);
    --glass-border: rgb(255 255 255 / .72);
    --glass-highlight: rgb(255 255 255 / .9);
    --glass-blur: 18px;
    --shadow-glass: 0 1px 1px rgb(9 31 27 / .04), 0 10px 30px -18px rgb(9 31 27 / .3);
    --field-glass: color-mix(in oklab, var(--surface) 62%, transparent);
    --sea-glass: color-mix(in oklab, var(--sea-fill) 14%, transparent);
    --ambient-1: color-mix(in oklab, var(--sea-fill) 20%, transparent);
    --ambient-2: color-mix(in oklab, var(--accent) 12%, transparent);
    --ambient-opacity: .85;

    --font: "Onest", "Onest Fallback", Arial, sans-serif;
    --fs-amount: 2rem;      --lh-amount: 2.375rem;  /* 32/38 · 600 */
    --fs-title: 1.375rem;   --lh-title: 1.75rem;    /* 22/28 · 600 */
    --fs-body: 1rem;        --lh-body: 1.375rem;    /* 16/22 · 400 */
    --fs-label: .8125rem;   --lh-label: 1.125rem;   /* 13/18 · 500/400 */

    --r-field: 14px;
    --r-card: 20px;
    --r-pill: 999px;
    --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px;

    --safe-top: max(var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top, 0px));
    --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
    --main-button-h: 0px; /* set to 56px+ by tg.js when the in-page fallback button is visible */

    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --z-sticky: 10;
    --z-modal: 40;
  }
  :root.theme-dark {
    color-scheme: dark;
    --canvas: var(--tg-theme-secondary-bg-color, #0a1412);
    --surface: var(--tg-theme-section-bg-color, #131d1b);
    --ink: var(--tg-theme-text-color, #d7f2eb);
    --ink-soft: var(--tg-theme-hint-color, #98b1ab);
    --line: #26302e;
    --accent: #d5945b;
    --on-accent: #0a1412;
    --sea: #3db19b;
    --sea-fill: #3db19b;
    --deny: #e08a7d;
    --sea-tint: color-mix(in oklab, var(--sea-fill) 12%, var(--surface));
    --deny-tint: color-mix(in oklab, var(--deny) 12%, var(--surface));
    --skeleton: color-mix(in oklab, var(--ink) 10%, var(--surface));
    --shadow-card: none;
    --active-opt: color-mix(in oklab, var(--ink) 14%, var(--surface));
    --glass-bg: rgb(30 44 41 / .52);
    --glass-bg-strong: rgb(26 39 36 / .68);
    --glass-border: rgb(255 255 255 / .1);
    --glass-highlight: rgb(255 255 255 / .07);
    --shadow-glass: 0 1px 1px rgb(0 0 0 / .28), 0 12px 32px -20px rgb(0 0 0 / .8);
    --field-glass: color-mix(in oklab, var(--canvas) 55%, transparent);
    --sea-glass: color-mix(in oklab, var(--sea-fill) 16%, transparent);
    --ambient-1: color-mix(in oklab, var(--sea-fill) 26%, transparent);
    --ambient-2: color-mix(in oklab, var(--accent) 18%, transparent);
    --ambient-opacity: .5;
  }
}

/* ---------- Base ---------- */
@layer base {
  html {
    background: var(--canvas);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }
  body {
    position: relative;
    isolation: isolate;
    min-height: 100svh;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--font);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
  }
  /* Ambient brand light behind the glass. Fixed, decorative, never a photo; the content stays on --canvas. */
  body::before {
    content: "";
    position: fixed;
    inset: -15% -10%;
    z-index: -1;
    pointer-events: none;
    opacity: var(--ambient-opacity);
    background:
      radial-gradient(58% 42% at 12% 0%, var(--ambient-1), transparent 70%),
      radial-gradient(52% 38% at 96% 8%, var(--ambient-2), transparent 72%),
      radial-gradient(72% 52% at 50% 104%, var(--ambient-1), transparent 76%);
  }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  /* headings receive programmatic focus for screen readers (dialogs, route changes); they are not controls */
  h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .icon { width: 20px; height: 20px; flex: none; }
}

/* ---------- Components (registry: docs/project/COMPONENTS.md) ---------- */
@layer components {
  /* page shell */
  .page {
    max-width: 480px;
    margin: 0 auto;
    padding: calc(var(--s-4) + var(--safe-top)) var(--s-4)
      calc(var(--s-6) + var(--main-button-h) + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    gap: var(--s-4);
  }
  /* title and toggle share row 1; the subtitle gets the full width of row 2 */
  .page-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: var(--s-3); row-gap: 2px; }
  .page-head__text { display: contents; }
  .page-head__text > :not(.title) { grid-column: 1 / -1; }
  .page-head > :not(.page-head__text) { grid-row: 1; grid-column: 2; }
  .title { font-size: var(--fs-title); line-height: var(--lh-title); font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
  .label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; color: var(--ink-soft); }
  .meta { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 400; color: var(--ink-soft); }
  .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

  /* glass surface (DESIGN.md §Glass): one translucent material for every panel, card and bar.
     Specific components below override radius, padding and background strength only. */
  .calc, .tile, .sheet, .card, .main-button-bar, .glass {
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-glass), inset 0 1px 0 var(--glass-highlight);
  }

  /* lang-toggle: two-option pill, active = ink on surface (never accent) */
  .lang-toggle {
    display: inline-flex; flex: none; padding: 2px; border-radius: var(--r-pill);
    background: color-mix(in oklab, var(--ink) 7%, var(--canvas));
  }
  .lang-toggle__opt {
    min-width: 44px; min-height: 44px; padding: 0 var(--s-2); border-radius: var(--r-pill);
    font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 600; color: var(--ink-soft);
  }
  .lang-toggle__opt[aria-pressed="true"] { background: var(--active-opt); color: var(--ink); box-shadow: var(--shadow-card); }

  /* calculator card: the one card on canvas */
  .calc {
    container-type: inline-size;
    background: var(--glass-bg-strong);
    border-radius: var(--r-card);
    padding: var(--s-2) var(--s-2) var(--s-4);
    display: flex; flex-direction: column;
  }

  /* segmented */
  .segmented {
    display: grid; grid-auto-columns: 1fr; grid-auto-flow: column;
    padding: 3px; border-radius: var(--r-field);
    background: color-mix(in oklab, var(--ink) 6%, transparent);
  }
  .segmented__opt {
    min-height: 44px; border-radius: 11px; display: inline-flex; align-items: center; justify-content: center;
    font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 600; color: var(--ink-soft);
    text-decoration: none;
  }
  .segmented__opt[aria-current="page"], .segmented__opt[aria-pressed="true"] {
    background: var(--active-opt); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08);
  }
  .theme-dark .segmented__opt[aria-current="page"], .theme-dark .segmented__opt[aria-pressed="true"] {
    background: color-mix(in oklab, var(--ink) 16%, transparent);
  }

  /* amount-field: label + big number + currency chip */
  .amount-field {
    position: relative;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto;
    column-gap: var(--s-3); row-gap: 2px; align-items: center;
    padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
    border-radius: var(--r-field);
  }
  .amount-field__label { grid-column: 1 / -1; }
  .amount-field__input, .amount-field__value {
    min-width: 0; width: 100%;
    font-size: var(--fs-amount); line-height: var(--lh-amount); font-weight: 600; letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1;
    white-space: nowrap; overflow: hidden; text-overflow: clip;
  }
  .amount-field__input {
    height: 44px; border: 0; padding: 0; margin: 0; background: transparent; color: var(--ink); outline: none;
    caret-color: var(--accent);
  }
  .amount-field__input::placeholder { color: var(--ink); opacity: 1; }
  .amount-field:has(.amount-field__input:focus) { box-shadow: inset 0 0 0 2px var(--accent); }
  /* long numbers step the size down instead of clipping (data-len set by the page) */
  .amount-field [data-len="l"] { font-size: 1.75rem; }
  .amount-field [data-len="xl"] { font-size: 1.5rem; letter-spacing: -0.03em; }
  .amount-field [data-len="xxl"] { font-size: 1.25rem; letter-spacing: -0.03em; }
  .amount-field--give { background: var(--field-glass); }
  .amount-field--get { background: var(--sea-glass); }
  .amount-field--get .amount-field__value { color: var(--sea); }
  .amount-field--get .amount-field__label { color: color-mix(in oklab, var(--sea) 70%, var(--ink)); }
  .amount-field--muted .amount-field__value { color: var(--ink-soft); }

  /* currency-chip */
  .currency-chip {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 44px; padding: 0 var(--s-3) 0 var(--s-2);
    border-radius: var(--r-pill);
    background: color-mix(in oklab, var(--surface) 78%, transparent);
    box-shadow: inset 0 0 0 1px var(--line), inset 0 1px 0 var(--glass-highlight);
    font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 600; color: var(--ink);
    white-space: nowrap;
  }
  .currency-chip__sym {
    width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center;
    font-size: var(--fs-label); font-weight: 700; color: var(--ink);
    background: color-mix(in oklab, var(--ink) 7%, transparent);
  }
  .currency-chip .icon { width: 16px; height: 16px; color: var(--ink-soft); }
  /* local asset/bank logos inside a chip (fixed box keeps the chip height stable) */
  .currency-chip__logo { width: 24px; height: 24px; border-radius: 50%; object-fit: contain; flex: none; background: color-mix(in oklab, var(--surface) 80%, transparent); }

  /* swap-button sits on the seam between the two amount fields */
  .swap-row { position: relative; z-index: 1; height: 4px; }
  .swap-button {
    position: absolute; left: 50%; top: 50%; translate: -50% -50%;
    width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
    background: color-mix(in oklab, var(--surface) 90%, transparent); color: var(--ink);
    box-shadow: 0 0 0 4px color-mix(in oklab, var(--surface) 45%, transparent), inset 0 0 0 1px var(--line);
    transition: rotate .24s var(--ease-out);
  }
  .swap-button[aria-disabled="true"] { color: var(--ink-soft); opacity: .55; cursor: not-allowed; }
  .swap-button.is-turned { rotate: 180deg; }

  /* rate-line */
  .rate-line {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px var(--s-3);
    padding: var(--s-3) var(--s-4) 0;
    font-size: var(--fs-label); line-height: var(--lh-label);
  }
  .rate-line__rate { font-weight: 600; color: var(--ink); }
  .rate-line__time { color: var(--ink-soft); }

  /* note: info / deny, always text (colour never alone) */
  .note {
    display: flex; gap: var(--s-2); align-items: flex-start;
    margin: var(--s-3) var(--s-2) 0; padding: var(--s-2) var(--s-3);
    border-radius: 12px;
    font-size: var(--fs-label); line-height: var(--lh-label); color: var(--ink-soft);
  }
  .note .icon { width: 16px; height: 16px; margin-top: 1px; }
  .note--deny { background: var(--deny-tint); color: var(--deny); font-weight: 500; }
  .note__action {
    margin: -13px 0 -13px auto; flex: none; min-height: 44px; padding: 0 var(--s-2);
    font-weight: 600; color: var(--ink); text-decoration: underline; text-underline-offset: 3px;
  }

  /* skeleton (loading): same box as the content it replaces */
  .skeleton {
    display: inline-block; border-radius: 8px; background: var(--skeleton);
    color: transparent !important; user-select: none;
    animation: skeleton-pulse 1.2s var(--ease-out) infinite alternate;
  }
  @keyframes skeleton-pulse { from { opacity: 1; } to { opacity: .55; } }

  /* facts line under the calculator (owner claims only) */
  .facts { display: grid; gap: var(--s-2); padding: 0 var(--s-2); }
  .facts__item { display: flex; gap: var(--s-2); align-items: center; font-size: var(--fs-label); line-height: var(--lh-label); color: var(--ink-soft); }
  .facts__item .icon { width: 16px; height: 16px; color: var(--sea); }

  /* tile-grid: home secondary destinations, glass tiles with a plain icon */
  .tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
  .tile {
    width: 100%; min-height: 56px; display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-2) var(--s-3) var(--s-2) var(--s-4); border-radius: var(--r-field);
    background: var(--glass-bg); color: var(--ink); text-align: left; text-decoration: none;
    font-size: var(--fs-body); line-height: 1.25; font-weight: 500;
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    backdrop-filter: blur(var(--glass-blur)) saturate(140%);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-glass), inset 0 1px 0 var(--glass-highlight);
    transition: background-color .16s var(--ease-out), transform .16s var(--ease-out);
  }
  .tile .icon { color: var(--ink-soft); }
  .tile__label { min-width: 0; overflow-wrap: anywhere; }
  .tile__pair { display: block; font-weight: 600; }
  .tile .meta { display: block; margin-top: 2px; }
  .tile:active {
    background: color-mix(in oklab, var(--ink) 8%, var(--glass-bg));
    transform: scale(.985);
  }
  .tile--wide { grid-column: 1 / -1; }
  @media (hover: hover) and (pointer: fine) {
    .tile:hover { background: color-mix(in oklab, var(--ink) 4%, var(--glass-bg)); }
  }

  /* list-row (icon + title + hint + chevron) — used by sheets and sub-pages */
  .list { margin: 0; padding: 0; list-style: none; }
  .list-row {
    width: 100%; min-height: 56px; display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-2) var(--s-4); text-align: left; color: var(--ink);
  }
  .list > li + li .list-row { box-shadow: inset 0 1px 0 var(--line); }
  .list-row__main { min-width: 0; flex: 1; display: grid; }
  .list-row__title { font-weight: 500; }
  .list-row__hint { font-size: var(--fs-label); line-height: var(--lh-label); color: var(--ink-soft); }
  .list-row__end { color: var(--ink-soft); }
  .list-row[aria-checked="true"] .list-row__end { color: var(--ink); }
  .list-row__value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

  /* card: generic glass panel for sub-pages (rate list, order summary, steps) */
  .card { border-radius: var(--r-card); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
  .card--flush { padding: var(--s-2) 0; }
  .card__title { font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 600; }
  .card__text { font-size: var(--fs-label); line-height: var(--lh-label); color: var(--ink-soft); }

  /* field: labelled input / textarea on glass */
  .field { display: grid; gap: var(--s-2); }
  .field__label { font-size: var(--fs-label); line-height: var(--lh-label); font-weight: 500; color: var(--ink-soft); }
  .field__input, .field__area {
    width: 100%; min-height: 48px; padding: var(--s-3) var(--s-4); border-radius: var(--r-field);
    background: var(--field-glass); border: 1px solid var(--line); color: var(--ink); outline: none;
    font-size: var(--fs-body); line-height: var(--lh-body);
  }
  .field__area { min-height: 88px; resize: vertical; font-family: inherit; }
  .field__input:focus, .field__area:focus { box-shadow: inset 0 0 0 2px var(--accent); }
  .field__input::placeholder, .field__area::placeholder { color: color-mix(in oklab, var(--ink-soft) 75%, transparent); }

  /* step: numbered row (process page, order summary) */
  .step-list { display: grid; gap: var(--s-4); margin: 0; padding: 0; list-style: none; }
  .step { display: flex; gap: var(--s-3); align-items: flex-start; }
  .step__num {
    width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
    background: var(--sea-glass); color: var(--sea);
    font-size: var(--fs-label); line-height: 1; font-weight: 700;
  }
  .step__body { min-width: 0; display: grid; gap: 2px; }
  .step__title { font-weight: 600; }
  .step__text { font-size: var(--fs-label); line-height: var(--lh-label); color: var(--ink-soft); }

  /* chip-grid: compact single-choice options (districts, banks, assets) */
  .chip-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); margin: 0; padding: 0; list-style: none; }
  .chip-option {
    width: 100%; min-height: 44px; padding: var(--s-2) var(--s-3); border-radius: var(--r-field);
    background: var(--field-glass); border: 1px solid var(--line); color: var(--ink);
    font-size: var(--fs-body); line-height: 1.25; font-weight: 500; text-align: center; text-decoration: none;
  }
  .chip-option[aria-checked="true"], .chip-option[aria-pressed="true"] {
    background: var(--sea-glass); border-color: var(--sea); color: var(--sea);
  }

  /* sheet: bottom sheet on native <dialog> */
  .sheet {
    position: fixed; inset: auto 0 0 0; margin: 0 auto; width: 100%; max-width: 480px; max-height: 85dvh;
    z-index: var(--z-modal);
    background: var(--glass-bg-strong);
    color: var(--ink);
    border-radius: var(--r-card) var(--r-card) 0 0;
    border-bottom: 0;
    padding: var(--s-2) 0 calc(var(--s-4) + var(--safe-bottom));
    overflow: auto;
  }
  .sheet::backdrop { background: rgb(0 0 0 / .4); }
  .sheet[open] { animation: sheet-in .24s var(--ease-out); }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
  .sheet__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-2) var(--s-4); }
  .sheet__title { font-size: 1.0625rem; line-height: 1.5rem; font-weight: 600; }
  .sheet__body { padding: 0 var(--s-4) var(--s-2); display: grid; gap: var(--s-3); }
  .icon-button { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-soft); }

  /* buttons: primary CTA = Telegram MainButton; .main-button is its in-page fallback */
  .button {
    min-height: 48px; padding: 0 var(--s-4); border-radius: var(--r-field);
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    font-weight: 600; text-decoration: none;
  }
  .button--primary { background: var(--accent); color: var(--on-accent); }
  .button--quiet { background: var(--field); color: var(--ink); }
  .main-button-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
    padding: var(--s-2) var(--s-4) calc(var(--s-2) + var(--safe-bottom));
    background: var(--glass-bg);
    border: 0;
    box-shadow: 0 -1px 0 var(--glass-border);
  }
  .main-button {
    width: 100%; max-width: 448px; margin: 0 auto; min-height: 52px; display: flex;
    align-items: center; justify-content: center; gap: var(--s-2);
    border-radius: var(--r-field); background: var(--accent); color: var(--on-accent);
    font-size: var(--fs-body); font-weight: 600; font-variant-numeric: tabular-nums;
  }
  .main-button[aria-disabled="true"] {
    background: color-mix(in oklab, var(--ink) 10%, var(--canvas)); color: var(--ink-soft); cursor: not-allowed;
  }
  .main-button__spinner {
    width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
    animation: spin .8s linear infinite;
  }
  @keyframes spin { to { rotate: 360deg; } }

  /* back-button fallback (outside Telegram only; tg.js hides it inside Telegram) */
  .back-fallback {
    display: inline-flex; align-items: center; gap: var(--s-1); min-height: 44px; padding: 0 var(--s-2) 0 0;
    color: var(--ink); font-weight: 500;
  }
  :root.in-telegram .back-fallback { display: none; }
}

@layer utilities {
  /* Glass needs a translucent backdrop to read. Where it cannot blur, fall back to the solid surface. */
  @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .calc, .tile, .sheet, .card, .main-button-bar, .glass {
      background: var(--surface);
    }
  }
  @media (prefers-reduced-transparency: reduce) {
    .calc, .tile, .sheet, .card, .main-button-bar, .glass {
      background: var(--surface);
      -webkit-backdrop-filter: none;
      backdrop-filter: none;
    }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  }
  @media (forced-colors: active) {
    .calc, .tile, .currency-chip, .swap-button, .main-button, .card { border: 1px solid CanvasText; }
  }
}
