/*!
 * BardoBlaze design system — v1.0 (2026-11-13)
 * Plain CSS, no framework. One stylesheet for RTL (fa) and LTR (en), dark (default) and light.
 * Rules: logical properties only (no left/right), tokens only (no raw colors outside @layer tokens),
 * every text/background pair passes WCAG 2.2 AA, motion respects prefers-reduced-motion.
 * Fonts are declared in fonts.css (self-hosted); this file only names the families.
 */

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

/* ------------------------------------------------------------------ reset */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
  ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
  img, svg, video { display: block; max-inline-size: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  button { cursor: pointer; }
  table { border-collapse: collapse; }
  [hidden] { display: none !important; }
}

/* ----------------------------------------------------------------- tokens */
@layer tokens {
  :root,
  [data-theme="dark"] {
    color-scheme: dark;

    /* surfaces: canvas < s1 (cards) < s2 (inputs, hover) < s3 (selected) */
    --bg: #171A1A;
    --s1: #202424;
    --s2: #282D2D;
    --s3: #323838;
    --border: #353C3C;          /* decorative dividers */
    --border-strong: #6E7979;   /* control boundaries: >= 3:1 on s1 and s2 */

    --text-1: #F1F4F4;          /* 14.2:1 on s1 */
    --text-2: #C3CCCB;          /*  9.6:1 on s1 */
    --text-3: #97A2A1;          /*  6.0:1 on s1, 5.3:1 on s2 */

    --accent: #22C3A6;          /* brand teal (interactive) */
    --accent-hover: #3FD3B8;
    --on-accent: #04211C;       /* 7.6:1 on accent */
    --accent-text: #34D3B6;     /* teal used as text: 8.3:1 on s1 */
    --accent-soft: rgb(34 195 166 / 0.14);
    --accent-line: rgb(34 195 166 / 0.45);

    --profit: #5BD98B;          /* outcome colors are separate from the brand accent */
    --profit-soft: rgb(91 217 139 / 0.14);
    --loss: #FF7A7A;
    --loss-soft: rgb(255 122 122 / 0.14);
    --ember: #FF9B42;           /* brand signature: logo core, insights */
    --ember-soft: rgb(255 155 66 / 0.14);
    --warn: #F2C94C;
    --warn-soft: rgb(242 201 76 / 0.14);

    --focus: #7FE6D2;
    --logo-flame: #22C3A6;
    --logo-ember: #FF9B42;
    --scrim: rgb(5 8 8 / 0.62);
    --shadow-1: 0 1px 0 rgb(255 255 255 / 0.03) inset, 0 1px 2px rgb(0 0 0 / 0.35);
    --shadow-2: 0 1px 0 rgb(255 255 255 / 0.04) inset, 0 12px 32px -12px rgb(0 0 0 / 0.6);
    --chart-grid: rgb(255 255 255 / 0.06);
  }

  [data-theme="light"] {
    color-scheme: light;
    --bg: #F3F6F6;
    --s1: #FFFFFF;
    --s2: #EDF2F1;
    --s3: #E1E8E7;
    --border: #DCE3E2;
    --border-strong: #7F8C8B;

    --text-1: #101616;
    --text-2: #384443;
    --text-3: #5A6766;

    --accent: #007D6C;
    --accent-hover: #00695B;
    --on-accent: #FFFFFF;
    --accent-text: #006E5F;
    --accent-soft: rgb(0 125 108 / 0.10);
    --accent-line: rgb(0 125 108 / 0.40);

    --profit: #0E7443;
    --profit-soft: rgb(14 116 67 / 0.10);
    --loss: #B3343B;
    --loss-soft: rgb(179 52 59 / 0.09);
    --ember: #A9480A;
    --ember-soft: rgb(169 72 10 / 0.09);
    --warn: #8A6200;
    --warn-soft: rgb(138 98 0 / 0.10);

    --focus: #00695B;
    --logo-flame: #008C79;
    --logo-ember: #FF9B42;
    --scrim: rgb(16 22 22 / 0.42);
    --shadow-1: 0 1px 2px rgb(16 22 22 / 0.06), 0 0 0 1px rgb(16 22 22 / 0.02);
    --shadow-2: 0 16px 40px -18px rgb(16 22 22 / 0.25);
    --chart-grid: rgb(16 22 22 / 0.07);
  }

  :root {
    /* type */
    --font-fa: "Vazirmatn", "Inter", Tahoma, system-ui, sans-serif;
    --font-en: "Inter", "InterVariable", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-num: "Inter", "InterVariable", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --fs-2xs: 0.6875rem;
    --fs-xs: 0.75rem;
    --fs-s: 0.875rem;
    --fs-m: 1rem;
    --fs-l: clamp(1.0625rem, 1rem + 0.25vw, 1.1875rem);
    --fs-xl: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
    --fs-2xl: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);
    --fs-3xl: clamp(1.875rem, 1.4rem + 2vw, 2.75rem);
    --lh-tight: 1.25;
    --lh: 1.6;

    /* space (4px grid) */
    --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem;
    --sp-5: 1.25rem; --sp-6: 1.5rem; --sp-7: 2rem; --sp-8: 2.5rem; --sp-9: 3rem;
    --gutter: clamp(1rem, 0.6rem + 1.6vw, 2rem);

    /* shape */
    --r-s: 8px; --r-m: 12px; --r-l: 16px; --r-xl: 22px; --r-pill: 999px;
    --hit: 44px;                       /* minimum touch target */
    --sidebar-w: 248px;
    --content-max: 1320px;

    /* motion */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --t-fast: 120ms;
    --t: 200ms;
    --t-slow: 420ms;

    /* safe areas (notch, home indicator) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-start: env(safe-area-inset-left, 0px);
    --safe-end: env(safe-area-inset-right, 0px);
  }

  @media (prefers-color-scheme: light) {
    [data-theme="system"] {
      color-scheme: light;
      --bg: #F3F6F6; --s1: #FFFFFF; --s2: #EDF2F1; --s3: #E1E8E7;
      --border: #DCE3E2; --border-strong: #7F8C8B;
      --text-1: #101616; --text-2: #384443; --text-3: #5A6766;
      --accent: #007D6C; --accent-hover: #00695B; --on-accent: #FFFFFF; --accent-text: #006E5F;
      --accent-soft: rgb(0 125 108 / 0.10); --accent-line: rgb(0 125 108 / 0.40);
      --profit: #0E7443; --profit-soft: rgb(14 116 67 / 0.10);
      --loss: #B3343B; --loss-soft: rgb(179 52 59 / 0.09);
      --ember: #A9480A; --ember-soft: rgb(169 72 10 / 0.09);
      --warn: #8A6200; --warn-soft: rgb(138 98 0 / 0.10);
      --focus: #00695B; --scrim: rgb(16 22 22 / 0.42);
      --logo-flame: #008C79; --logo-ember: #FF9B42;
      --shadow-1: 0 1px 2px rgb(16 22 22 / 0.06), 0 0 0 1px rgb(16 22 22 / 0.02);
      --shadow-2: 0 16px 40px -18px rgb(16 22 22 / 0.25);
      --chart-grid: rgb(16 22 22 / 0.07);
    }
  }
}

/* ------------------------------------------------------------------- base */
@layer base {
  html {
    background: var(--bg);
    color: var(--text-1);
    font-family: var(--font-en);
    font-size: 100%;
    line-height: var(--lh);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scrollbar-color: var(--s3) transparent;
  }
  html:lang(fa) { font-family: var(--font-fa); }
  body {
    min-block-size: 100dvh;
    background: var(--bg);
    color: var(--text-1);
    font-size: var(--fs-m);
  }
  h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: 700; letter-spacing: -0.01em; }
  :lang(fa) h1, :lang(fa) h2, :lang(fa) h3, :lang(fa) h4 { letter-spacing: 0; }
  h1 { font-size: var(--fs-2xl); }
  h2 { font-size: var(--fs-xl); }
  h3 { font-size: var(--fs-l); }
  p { text-wrap: pretty; }
  a { color: var(--accent-text); text-decoration-thickness: 1px; text-underline-offset: 3px; }
  a:hover { color: var(--accent-hover); }
  ::selection { background: var(--accent-soft); color: var(--text-1); }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
  /* user-written text: direction follows its own first strong character */
  .user-text { unicode-bidi: plaintext; text-align: start; white-space: pre-line; }
}

/* ----------------------------------------------------------------- layout */
@layer layout {
  .skip-link {
    position: absolute; inset-inline-start: var(--sp-4); inset-block-start: -100px;
    padding: var(--sp-2) var(--sp-4); background: var(--accent); color: var(--on-accent);
    border-radius: var(--r-s); font-weight: 600; z-index: 100;
  }
  .skip-link:focus { inset-block-start: var(--sp-4); }

  /* desktop: sidebar + main; phone: top bar + bottom tab bar */
  .app {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-block-size: 100dvh;
  }
  .app__sidebar {
    position: sticky; inset-block-start: 0; block-size: 100dvh;
    display: flex; flex-direction: column; gap: var(--sp-6);
    padding: var(--sp-6) var(--sp-4);
    padding-block-start: calc(var(--sp-6) + var(--safe-top));
    background: var(--s1);
    border-inline-end: 1px solid var(--border);
    overflow-y: auto;
  }
  .app__main { min-inline-size: 0; display: flex; flex-direction: column; }
  .app__content {
    inline-size: 100%; max-inline-size: var(--content-max); margin-inline: auto;
    padding: var(--sp-6) var(--gutter) var(--sp-9);
    display: flex; flex-direction: column; gap: var(--sp-6);
    container: content / inline-size;
  }
  .topbar {
    position: sticky; inset-block-start: 0; z-index: 20;
    display: flex; align-items: center; gap: var(--sp-4); flex-wrap: wrap;
    padding: var(--sp-4) var(--gutter);
    padding-block-start: calc(var(--sp-4) + var(--safe-top));
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
    backdrop-filter: saturate(140%) blur(14px);
    border-block-end: 1px solid var(--border);
  }
  .topbar__title { font-size: var(--fs-xl); font-weight: 750; margin-inline-end: auto; }
  .tabbar { display: none; }

  .grid { display: grid; gap: var(--sp-4); }
  /* six KPIs never leave an orphan card: 2 columns on phones, 3 from 620px of content width */
  .grid--kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  @container content (min-width: 620px) { .grid--kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); } }
  .grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
  .grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
  .split { display: grid; gap: var(--sp-6); grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
  .split__aside { position: sticky; inset-block-start: 96px; display: flex; flex-direction: column; gap: var(--sp-4); }
  .stack { display: flex; flex-direction: column; gap: var(--sp-4); }
  .stack--s { gap: var(--sp-2); }
  .cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
  .section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }

  @media (max-width: 1100px) {
    .split { grid-template-columns: minmax(0, 1fr); }
    .split__aside { position: static; }
  }
  @media (max-width: 860px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .app__sidebar { display: none; }
    .app__content { padding-block-end: calc(96px + var(--safe-bottom)); gap: var(--sp-5); }
    .topbar__title { font-size: var(--fs-l); }
    .tabbar {
      position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 30;
      display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
      padding: var(--sp-2) var(--sp-2) calc(var(--sp-2) + var(--safe-bottom));
      background: color-mix(in srgb, var(--s1) 90%, transparent);
      -webkit-backdrop-filter: saturate(140%) blur(16px);
      backdrop-filter: saturate(140%) blur(16px);
      border-block-start: 1px solid var(--border);
    }
  }
}

/* ------------------------------------------------------------- components */
@layer components {
  /* brand */
  .brand { display: flex; align-items: center; gap: var(--sp-3); text-decoration: none; color: var(--text-1); padding-inline: var(--sp-2); }
  .brand__mark { inline-size: 36px; block-size: 36px; flex: none; }
  .brand__flame { fill: var(--logo-flame); }
  .brand__ember { fill: var(--logo-ember); stroke: var(--logo-ember); }
  .brand__name { font-family: var(--font-en); font-weight: 750; font-size: 1.125rem; letter-spacing: -0.02em; line-height: 1; }
  .brand__name b { color: var(--accent-text); font-weight: 750; }

  /* sidebar navigation */
  .nav { display: flex; flex-direction: column; gap: var(--sp-1); }
  .nav__label { font-size: var(--fs-xs); color: var(--text-3); padding: var(--sp-4) var(--sp-3) var(--sp-2); font-weight: 600; }
  .nav__link {
    display: flex; align-items: center; gap: var(--sp-3);
    min-block-size: var(--hit); padding-inline: var(--sp-3);
    border-radius: var(--r-m); color: var(--text-2); text-decoration: none; font-weight: 550;
    transition: background-color var(--t-fast) ease, color var(--t-fast) ease;
  }
  .nav__link:hover { background: var(--s2); color: var(--text-1); }
  .nav__link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); }
  .nav__link svg { inline-size: 20px; block-size: 20px; flex: none; }
  .nav__foot { margin-block-start: auto; display: flex; flex-direction: column; gap: var(--sp-2); }

  /* icons (stroke, inherit color) */
  .icon { inline-size: 20px; block-size: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
  .icon--s { inline-size: 16px; block-size: 16px; }
  :dir(rtl) .icon--flip { transform: scaleX(-1); }

  /* buttons */
  .btn {
    --_bg: var(--s2); --_fg: var(--text-1); --_bd: var(--border);
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    min-block-size: var(--hit); padding-inline: var(--sp-5);
    border: 1px solid var(--_bd); border-radius: var(--r-m);
    background: var(--_bg); color: var(--_fg);
    font-weight: 650; font-size: var(--fs-s); line-height: 1; text-decoration: none; white-space: nowrap;
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, transform var(--t-fast) ease, box-shadow var(--t) ease;
    -webkit-tap-highlight-color: transparent;
  }
  .btn:hover { --_bg: var(--s3); }
  .btn:active { transform: scale(0.98); }
  .btn--primary { --_bg: var(--accent); --_fg: var(--on-accent); --_bd: transparent; box-shadow: 0 6px 20px -10px var(--accent); }
  .btn--primary:hover { --_bg: var(--accent-hover); }
  .btn--ghost { --_bg: transparent; --_bd: transparent; color: var(--text-2); }
  .btn--ghost:hover { --_bg: var(--s2); color: var(--text-1); }
  .btn--icon { padding: 0; inline-size: var(--hit); }
  .btn--block { inline-size: 100%; }
  .btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }

  /* cards */
  .card {
    background: var(--s1); border: 1px solid var(--border); border-radius: var(--r-l);
    padding: var(--sp-5); box-shadow: var(--shadow-1);
    display: flex; flex-direction: column; gap: var(--sp-4); min-inline-size: 0;
  }
  .card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
  .card__title { font-size: var(--fs-m); font-weight: 700; }
  .card__sub { font-size: var(--fs-xs); color: var(--text-3); }
  .card--flush { padding: 0; overflow: hidden; }
  .card--flush > .card__head { padding: var(--sp-5) var(--sp-5) 0; }
  @media (max-width: 860px) {
    .card { padding: var(--sp-4); border-radius: var(--r-m); }
    .card--flush { padding: 0; }
    .card--flush > .card__head { padding: var(--sp-4) var(--sp-4) 0; }
  }

  /* numbers: Latin digits, tabular, isolated from RTL text */
  .num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "cv11" 1; direction: ltr; unicode-bidi: isolate; letter-spacing: -0.01em; }
  .pos { color: var(--profit); }
  .neg { color: var(--loss); }

  /* KPI */
  .kpi { gap: var(--sp-2); container-type: inline-size; }
  .kpi__label { font-size: var(--fs-xs); color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: var(--sp-1); }
  /* the value scales with its own card, so long numbers never wrap or overflow */
  .kpi__value { font-size: clamp(1.25rem, 14.5cqi, 2rem); font-weight: 700; line-height: 1.1; white-space: nowrap; }

  /* small stat strip (under charts) */
  .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: var(--sp-3); padding-block-start: var(--sp-4); border-block-start: 1px solid var(--border); }
  .stat { display: flex; flex-direction: column; gap: 2px; }
  .stat__label { font-size: var(--fs-xs); color: var(--text-3); }
  .stat__value { font-weight: 700; }
  .kpi__foot { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--text-3); }

  /* delta vs previous period; .delta--inverse for "lower is better" metrics */
  .delta {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 2px var(--sp-2); border-radius: var(--r-pill);
    font-family: var(--font-num); font-size: var(--fs-xs); font-weight: 650; font-variant-numeric: tabular-nums;
    direction: ltr; unicode-bidi: isolate;
  }
  .delta--up { color: var(--profit); background: var(--profit-soft); }
  .delta--down { color: var(--loss); background: var(--loss-soft); }
  .delta--flat { color: var(--text-3); background: var(--s2); }

  /* segmented control (period selector, intent) */
  .seg {
    display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-m);
    background: var(--s2); border: 1px solid var(--border);
    overflow-x: auto; scrollbar-width: none; max-inline-size: 100%;
  }
  .seg::-webkit-scrollbar { display: none; }
  .seg__item {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    min-block-size: 36px; padding-inline: var(--sp-3); border-radius: 9px;
    color: var(--text-2); font-size: var(--fs-s); font-weight: 600; text-decoration: none; white-space: nowrap;
    border: 0; background: transparent;
    transition: color var(--t-fast) ease, background-color var(--t) var(--ease-out);
  }
  .seg__item:hover { color: var(--text-1); }
  .seg__item[aria-current="true"], .seg__item[aria-pressed="true"], .seg input:checked + .seg__item {
    background: var(--s1); color: var(--text-1); box-shadow: 0 1px 2px rgb(0 0 0 / 0.25), 0 0 0 1px var(--border);
  }
  .seg label { position: relative; display: inline-flex; }
  /* inside a form field the control fills the row: bigger, easier targets */
  .field > .seg { display: flex; }
  .field > .seg label { flex: 1 1 0; }
  .field > .seg .seg__item { inline-size: 100%; min-block-size: 40px; }
  .seg input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
  .seg input:focus-visible + .seg__item { outline: 2px solid var(--focus); outline-offset: 1px; }

  /* badges */
  .badge {
    display: inline-flex; align-items: center; gap: var(--sp-1);
    min-block-size: 24px; padding-inline: var(--sp-2); border-radius: var(--r-pill);
    font-size: var(--fs-xs); font-weight: 650; white-space: nowrap;
    background: var(--s2); color: var(--text-2); border: 1px solid var(--border);
  }
  .badge--accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
  .badge--ember { background: var(--ember-soft); color: var(--ember); border-color: transparent; }
  .badge--profit { background: var(--profit-soft); color: var(--profit); border-color: transparent; }
  .badge--loss { background: var(--loss-soft); color: var(--loss); border-color: transparent; }
  .badge--warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

  /* coin avatar */
  .coin {
    display: inline-grid; place-items: center; inline-size: 32px; block-size: 32px; flex: none;
    border-radius: 50%; background: var(--s3); color: var(--text-1);
    font-family: var(--font-num); font-size: 0.625rem; font-weight: 750; letter-spacing: 0.02em;
  }
  .symbol { display: flex; align-items: center; gap: var(--sp-3); min-inline-size: 0; }
  .symbol__name { font-family: var(--font-num); font-weight: 700; direction: ltr; unicode-bidi: isolate; }
  .symbol__meta { font-size: var(--fs-xs); color: var(--text-3); }

  /* tables */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { inline-size: 100%; font-size: var(--fs-s); }
  .table th {
    text-align: start; font-size: var(--fs-xs); font-weight: 600; color: var(--text-3);
    padding: var(--sp-3) var(--sp-4); border-block-end: 1px solid var(--border); white-space: nowrap;
  }
  .table td { padding: var(--sp-3) var(--sp-4); border-block-end: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
  .table tbody tr { transition: background-color var(--t-fast) ease; }
  .table tbody tr:hover { background: var(--s2); }
  .table tbody tr:last-child td { border-block-end: 0; }
  .table .t-num { text-align: end; }
  .row-link { color: inherit; text-decoration: none; }

  /* forms */
  .form-section { display: flex; flex-direction: column; gap: var(--sp-4); }
  .form-section__head { display: flex; align-items: center; gap: var(--sp-3); }
  .form-section__step {
    display: inline-grid; place-items: center; inline-size: 28px; block-size: 28px; border-radius: 50%;
    background: var(--accent-soft); color: var(--accent-text); font-family: var(--font-num); font-weight: 750; font-size: var(--fs-xs);
  }
  .fields { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
  .field { display: flex; flex-direction: column; gap: var(--sp-2); min-inline-size: 0; }
  .field--wide { grid-column: 1 / -1; }
  .label { font-size: var(--fs-s); font-weight: 600; color: var(--text-2); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
  .label__hint { font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); }
  .input, .select, .textarea {
    inline-size: 100%; min-block-size: var(--hit);
    padding: 0 var(--sp-4);
    font-size: max(16px, 1rem);            /* >= 16px: no iOS zoom */
    color: var(--text-1); background: var(--s2);
    border: 1px solid var(--border-strong); border-radius: var(--r-m);
    transition: border-color var(--t-fast) ease, box-shadow var(--t-fast) ease, background-color var(--t-fast) ease;
  }
  .textarea { padding-block: var(--sp-3); min-block-size: 96px; resize: vertical; line-height: var(--lh); }
  .input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
  .input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .input[aria-invalid="true"] { border-color: var(--loss); }
  .input--num { font-family: var(--font-num); font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }
  :dir(ltr) .input--num { text-align: start; }
  .input-group { position: relative; display: flex; align-items: center; }
  .input-group .input { padding-inline-end: 64px; }
  /* RTL page + LTR number: number hugs the right edge, unit sits on the left */
  .input-group:dir(rtl) > .input--num { padding-inline: 64px var(--sp-4); text-align: end; }
  .input-group__addon {
    position: absolute; inset-inline-end: var(--sp-3);
    font-family: var(--font-num); font-size: var(--fs-xs); font-weight: 650; color: var(--text-3);
    pointer-events: none;
  }
  .select {
    appearance: none; -webkit-appearance: none; padding-inline-end: var(--sp-8);
    background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
    background-size: 5px 5px; background-repeat: no-repeat;
    background-position: calc(100% - 22px) 50%, calc(100% - 17px) 50%;
  }
  :dir(rtl) .select { background-position: 17px 50%, 22px 50%; }
  .error { font-size: var(--fs-xs); color: var(--loss); }

  /* choice chips (emotions, mistakes) and toggle chips (confirmations) */
  .chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .chip { position: relative; }
  .chip input { position: absolute; opacity: 0; pointer-events: none; }
  .chip span {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    min-block-size: var(--hit); padding-inline: var(--sp-4);
    border-radius: var(--r-pill); border: 1px solid var(--border-strong);
    background: var(--s2); color: var(--text-2); font-size: var(--fs-s); font-weight: 600;
    cursor: pointer; user-select: none;
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease, transform var(--t-fast) ease;
  }
  .chip span:hover { color: var(--text-1); border-color: var(--text-3); }
  .chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }
  .chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
  .chip span:active { transform: scale(0.97); }

  .toggles { display: grid; gap: var(--sp-2); grid-template-columns: repeat(auto-fill, minmax(min(100%, 168px), 1fr)); }
  .toggle { position: relative; }
  .toggle input { position: absolute; opacity: 0; pointer-events: none; }
  .toggle label {
    display: flex; align-items: center; gap: var(--sp-3);
    min-block-size: 52px; padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-m); border: 1px solid var(--border-strong); background: var(--s2);
    font-weight: 650; font-size: var(--fs-s); color: var(--text-2); cursor: pointer; user-select: none;
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
  }
  .toggle__box {
    display: inline-grid; place-items: center; inline-size: 22px; block-size: 22px; flex: none;
    border-radius: 7px; border: 1.5px solid var(--border-strong); background: var(--s1);
    transition: background-color var(--t-fast) ease, border-color var(--t-fast) ease;
  }
  .toggle__box svg { inline-size: 14px; block-size: 14px; stroke: var(--on-accent); stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset var(--t) var(--ease-out); }
  .toggle input:checked + label { background: var(--accent-soft); border-color: var(--accent); color: var(--text-1); }
  .toggle input:checked + label .toggle__box { background: var(--accent); border-color: var(--accent); }
  .toggle input:checked + label .toggle__box svg { stroke-dashoffset: 0; }
  .toggle input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }
  .toggle__sub { display: block; font-size: var(--fs-2xs); font-weight: 500; color: var(--text-3); }
  .toggle--alt label { border-style: dashed; }

  /* slider 1–10 (stress, confidence) */
  .scale { display: flex; flex-direction: column; gap: var(--sp-2); }
  .range { inline-size: 100%; accent-color: var(--accent); block-size: var(--hit); background: transparent; }
  .scale__ends { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-3); }
  .scale__value { font-family: var(--font-num); font-weight: 750; color: var(--accent-text); }

  /* intent cards (radio) */
  .options { display: grid; gap: var(--sp-2); grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
  .option { position: relative; }
  .option input { position: absolute; opacity: 0; pointer-events: none; }
  .option label {
    display: flex; flex-direction: column; gap: var(--sp-1); block-size: 100%;
    padding: var(--sp-4); border-radius: var(--r-m); border: 1px solid var(--border-strong); background: var(--s2);
    cursor: pointer; transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
  }
  .option__title { font-weight: 700; font-size: var(--fs-s); color: var(--text-1); }
  .option__desc { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.55; }
  .option input:checked + label { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
  .option input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 2px; }

  /* conditional fields without JS: shown when the matching market is selected */
  .when-futures { display: none; }
  form:has(input[name="market"][value="futures"]:checked) .when-futures { display: contents; }

  /* summary (live calculation) */
  .summary { gap: var(--sp-3); }
  .summary__row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); font-size: var(--fs-s); }
  .summary__row dt { color: var(--text-3); }
  .summary__row dd { margin: 0; font-weight: 700; }
  .summary__big { font-size: var(--fs-3xl); font-weight: 750; line-height: 1; }
  .meter { block-size: 8px; border-radius: var(--r-pill); background: var(--s3); overflow: hidden; }
  .meter > span { display: block; block-size: 100%; border-radius: inherit; background: var(--accent); inline-size: var(--v, 0%); transition: inline-size var(--t-slow) var(--ease-out); }

  /* insights */
  .insight { flex-direction: row; align-items: flex-start; gap: var(--sp-4); }
  .insight__icon {
    display: inline-grid; place-items: center; inline-size: 40px; block-size: 40px; flex: none;
    border-radius: var(--r-m); background: var(--ember-soft); color: var(--ember);
  }
  .insight__text { font-size: var(--fs-s); line-height: 1.75; color: var(--text-1); }
  .insight__text strong { color: var(--ember); font-weight: 750; }
  .insight__basis { font-size: var(--fs-xs); color: var(--text-3); margin-block-start: var(--sp-1); }

  /* charts (server-rendered SVG + CSS bars) */
  .chart { position: relative; inline-size: 100%; }
  .chart svg { inline-size: 100%; block-size: auto; overflow: visible; }
  .chart__grid line { stroke: var(--chart-grid); stroke-width: 1; }
  .chart__axis text { fill: var(--text-3); font-family: var(--font-num); font-size: 11px; }
  /* y labels are HTML, positioned in % of the chart height, so they keep their real size when the SVG scales */
  .chart__y {
    position: absolute; inset-inline-start: 0; inset-block-start: var(--y);
    transform: translateY(-120%);
    font-family: var(--font-num); font-size: 11px; font-weight: 600; color: var(--text-3);
    font-variant-numeric: tabular-nums; pointer-events: none;
  }
  .chart__line { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
  .chart__area { fill: var(--accent); opacity: 0.12; }
  .chart__zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 4 4; }
  .chart__dot { fill: var(--accent); stroke: var(--s1); stroke-width: 3; }

  .bars { display: flex; flex-direction: column; gap: var(--sp-3); }
  .bar { display: grid; grid-template-columns: minmax(84px, 7.5rem) minmax(0, 1fr) 6.5rem; align-items: center; gap: var(--sp-3); font-size: var(--fs-s); }
  .bar__label { color: var(--text-2); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar__track { block-size: 10px; border-radius: var(--r-pill); background: var(--s3); overflow: hidden; }
  .bar__fill { display: block; block-size: 100%; inline-size: var(--v, 0%); border-radius: inherit; background: var(--accent); transform-origin: var(--origin, left); }
  :dir(rtl) .bar__fill { --origin: right; }
  .bar__fill--profit { background: var(--profit); }
  .bar__fill--loss { background: var(--loss); }
  .bar__fill--ember { background: var(--ember); }
  .bar__value { text-align: end; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; direction: ltr; unicode-bidi: isolate; }
  .bar__n { font-weight: 500; color: var(--text-3); font-size: var(--fs-xs); }

  .heat { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; }
  /* --h = intensity 0–50% (server clamps); text-1 stays >= 4.5:1 on every cell in both themes */
  .heat__cell {
    aspect-ratio: 1; border-radius: 6px; display: grid; place-items: center;
    font-family: var(--font-num); font-size: 11px; font-weight: 650; color: var(--text-1);
    background: color-mix(in srgb, var(--accent) min(var(--h, 0%), 50%), var(--s2));
  }
  .heat__legend { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); }

  /* empty / not-enough-data state */
  .empty {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3);
    padding: var(--sp-8) var(--sp-5); color: var(--text-3); border: 1px dashed var(--border-strong); border-radius: var(--r-l);
  }
  .empty__title { color: var(--text-1); font-weight: 700; }

  /* phone tab bar */
  .tabbar__item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    min-block-size: 52px; justify-content: center;
    color: var(--text-3); text-decoration: none; font-size: var(--fs-2xs); font-weight: 600;
  }
  .tabbar__item[aria-current="page"] { color: var(--accent-text); }
  .tabbar__item svg { inline-size: 22px; block-size: 22px; }
  .tabbar__fab {
    justify-self: center; display: grid; place-items: center;
    inline-size: 56px; block-size: 56px; margin-block-start: -22px;
    border-radius: 18px; background: var(--accent); color: var(--on-accent);
    box-shadow: 0 10px 24px -8px var(--accent), 0 0 0 4px var(--bg);
    text-decoration: none;
  }
  .tabbar__fab svg { inline-size: 26px; block-size: 26px; stroke-width: 2.25; }

  /* phone save bar (forms): replaces the tab bar on form pages */
  .savebar { display: none; }
  @media (max-width: 860px) {
    .savebar {
      position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 30;
      display: flex; align-items: center; gap: var(--sp-3);
      padding: var(--sp-3) var(--gutter) calc(var(--sp-3) + var(--safe-bottom));
      background: color-mix(in srgb, var(--s1) 92%, transparent);
      -webkit-backdrop-filter: saturate(140%) blur(16px);
      backdrop-filter: saturate(140%) blur(16px);
      border-block-start: 1px solid var(--border);
    }
    .savebar .btn { flex: none; }
    .has-savebar .tabbar { display: none; }
  }

  /* file drop zone */
  .dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
    min-block-size: 120px; padding: var(--sp-5); text-align: center;
    border: 1.5px dashed var(--border-strong); border-radius: var(--r-l); background: var(--s2);
    color: var(--text-3); font-size: var(--fs-s); cursor: pointer;
    transition: border-color var(--t-fast) ease, background-color var(--t-fast) ease;
  }
  .dropzone:hover { border-color: var(--accent); color: var(--text-1); }
  .dropzone strong { color: var(--accent-text); }

  /* toast / messages */
  .toast {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4); border-radius: var(--r-m);
    background: var(--s1); border: 1px solid var(--border); box-shadow: var(--shadow-2); font-size: var(--fs-s);
  }

  /* offline page */
  .offline { min-block-size: 100dvh; display: grid; place-items: center; padding: var(--gutter); text-align: center; }
}

/* -------------------------------------------------------------- utilities */
@layer utilities {
  .muted { color: var(--text-3); }
  .text-2 { color: var(--text-2); }
  .small { font-size: var(--fs-s); }
  .xsmall { font-size: var(--fs-xs); }
  .bold { font-weight: 700; }
  .end { text-align: end; }
  .ltr { direction: ltr; unicode-bidi: isolate; }
  .nowrap { white-space: nowrap; }
  .grow { flex: 1 1 auto; min-inline-size: 0; }
  .visually-hidden {
    position: absolute !important; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  @media (max-width: 860px) { .hide-phone { display: none !important; } }
  @media (max-width: 560px) { .hide-narrow { display: none !important; } }
  @media (min-width: 861px) { .show-phone { display: none !important; } }
}

/* ----------------------------------------------------------------- motion */
@layer motion {
  /* smooth page changes between server-rendered pages (Chrome, Edge, Safari 18.2+); others navigate normally */
  @view-transition { navigation: auto; }
  .topbar { view-transition-name: topbar; }
  .app__sidebar { view-transition-name: sidebar; }
  ::view-transition-old(root) { animation: vt-out 160ms var(--ease-in-out) both; }
  ::view-transition-new(root) { animation: vt-in 260ms var(--ease-out) both; }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-4px); } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(6px); } }

  /* staggered reveal on first paint: add .reveal to a container; children use --i for order */
  .reveal > * { animation: rise var(--t-slow) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 45ms); }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } }

  /* the equity line draws itself once */
  .chart__line--draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1100ms var(--ease-out) 150ms forwards; }
  .chart__area--fade { animation: fade 700ms ease 500ms both; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  @keyframes fade { from { opacity: 0; } }

  /* bars grow from the inline-start edge */
  .bar__fill { animation: grow 700ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 50ms + 120ms); }
  @keyframes grow { from { transform: scaleX(0); } }

  /* the brand ember breathes slowly (logo only) */
  .brand__ember { animation: ember 3.2s ease-in-out infinite; transform-origin: 50% 70%; transform-box: fill-box; }
  @keyframes ember { 50% { opacity: 0.82; transform: scale(0.94); } }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) {
      animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
      transition-duration: 1ms !important; scroll-behavior: auto !important;
    }
    .chart__line--draw { stroke-dashoffset: 0; }
  }
}

/* ======================================================================
 * App additions (build, 2026-11-14)
 * New rules needed by the Django templates. Tokens only, logical properties only.
 * Same layers as above; the layer order is fixed by the @layer statement at the top.
 * ====================================================================== */
@layer layout {
  /* login and other shell-less pages */
  .auth { min-block-size: 100dvh; display: grid; place-items: center; padding: calc(var(--sp-6) + var(--safe-top)) var(--gutter) calc(var(--sp-6) + var(--safe-bottom)); }
  .auth__card { inline-size: min(100%, 420px); }
  .auth__brand { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); }
  .auth__brand .brand__name { font-size: 1.5rem; }
  .auth__switches { justify-content: center; }
  .narrow { max-inline-size: 640px; }
  .stack--l { gap: var(--sp-5); }
}

@layer components {
  .brand__mark--s { inline-size: 30px; block-size: 30px; }
  .brand__mark--l { inline-size: 48px; block-size: 48px; }

  /* logout lives in a form: a button that looks like a nav link */
  .nav__link--button { inline-size: 100%; border: 0; background: transparent; text-align: start; font: inherit; font-weight: 550; }

  /* theme button shows the theme it switches to */
  .theme-icon { display: inline-flex; }
  [data-theme="dark"] .theme-icon--moon, [data-theme="light"] .theme-icon--sun { display: none; }
  [data-theme="system"] .theme-icon--moon { display: none; }
  @media (prefers-color-scheme: light) {
    [data-theme="system"] .theme-icon--moon { display: inline-flex; }
    [data-theme="system"] .theme-icon--sun { display: none; }
  }

  /* icon inside a segmented item (calendar on "custom") */
  .seg__item > .icon { margin-inline-end: 6px; }

  /* messages */
  .toasts { display: flex; flex-direction: column; gap: var(--sp-2); }
  .toasts:empty { display: none; }
  .toast > .icon { color: var(--accent-text); }
  .toast--error > .icon, .toast--warning > .icon { color: var(--loss); }
  .toast { animation: rise var(--t-slow) var(--ease-out) both; }

  /* error summary at the top of a form */
  .error-summary {
    display: flex; align-items: flex-start; gap: var(--sp-3);
    padding: var(--sp-4); border-radius: var(--r-m);
    background: var(--loss-soft); border: 1px solid var(--loss); color: var(--text-1); font-size: var(--fs-s);
  }
  .error-summary > .icon { color: var(--loss); }
  .error-summary__list { margin: 0; padding-inline-start: var(--sp-5); }
  .error-summary a { color: var(--text-1); }
  .error p + p { margin-block-start: 2px; }

  /* plain fieldsets inside forms */
  fieldset.field, fieldset.form-fieldset { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
  fieldset > legend.label { margin-block-end: var(--sp-2); padding: 0; }

  /* "now" button inside the date input */
  .input-group__btn { position: absolute; inset-inline-end: 2px; min-block-size: 40px; padding-inline: var(--sp-3); }
  .input-group:has(.input-group__btn) .input { padding-inline-end: 84px; }
  .input-group:dir(rtl):has(.input-group__btn) > .input--num { padding-inline: 84px var(--sp-4); }

  /* Django's RadioSelect / CheckboxSelectMultiple rendered as chips */
  .chips > div { display: contents; }
  .chips label { position: relative; }

  /* key/value grid on detail pages */
  .kv { display: grid; gap: var(--sp-3) var(--sp-5); grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); margin: 0; }
  .kv > div { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
  .kv dt { font-size: var(--fs-xs); color: var(--text-3); }
  .kv dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }

  /* image thumbnails */
  .thumbs { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
  .thumb { position: relative; display: block; border-radius: var(--r-m); overflow: hidden; border: 1px solid var(--border); background: var(--s2); aspect-ratio: 16 / 10; }
  .thumb img { inline-size: 100%; block-size: 100%; object-fit: cover; }
  .thumb__remove { position: absolute; inset-block-start: var(--sp-1); inset-inline-end: var(--sp-1); }

  /* filters bar above lists */
  .filters { display: flex; flex-wrap: wrap; align-items: end; gap: var(--sp-3); }
  .filters .field { flex: 1 1 150px; }
  .filters .btn { flex: none; }

  /* pagination */
  .pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-block-start: 1px solid var(--border); font-size: var(--fs-s); }

  /* disclosure (optional closing notes) */
  details > summary { display: flex; align-items: center; min-block-size: var(--hit); cursor: pointer; color: var(--text-2); }
  details > summary:hover { color: var(--text-1); }
  .details-body { margin-block-start: var(--sp-3); }

  .divider { border: 0; border-block-start: 1px solid var(--border); margin: 0; inline-size: 100%; }

  /* footnote inside a flush card */
  .card__note { padding: 0 var(--sp-5) var(--sp-5); }

  /* compact select next to a heading (account filter) */
  .select--inline { inline-size: auto; min-inline-size: 11rem; min-block-size: 36px; }

  /* custom period form */
  .period-form { display: flex; flex-wrap: wrap; align-items: end; gap: var(--sp-3); }
  .period-form .field { flex: 1 1 160px; }

  /* list rows in settings (accounts, confirmations) */
  .rows { display: flex; flex-direction: column; }
  .row { display: flex; align-items: center; gap: var(--sp-3); padding-block: var(--sp-3); border-block-end: 1px solid var(--border); flex-wrap: wrap; }
  .row:last-child { border-block-end: 0; }
  .row__main { flex: 1 1 200px; min-inline-size: 0; }
  .row__actions { display: flex; gap: var(--sp-1); flex-wrap: wrap; }
  .row form { display: inline-flex; }

  /* "more" page on phones */
  .menu { display: flex; flex-direction: column; gap: var(--sp-1); }

  /* small button variant for table/row actions */
  .btn--s { min-block-size: 36px; padding-inline: var(--sp-3); font-size: var(--fs-xs); }
  .btn--danger { --_fg: var(--loss); }
  .btn--danger:hover { --_bg: var(--loss-soft); }

  /* error pages */
  .error-page { min-block-size: 100dvh; display: grid; place-items: center; padding: var(--gutter); text-align: center; }
  .error-page__code { font-family: var(--font-num); font-size: var(--fs-3xl); font-weight: 750; color: var(--accent-text); }

  /* trade rows: whole row clickable on desktop via the symbol link */
  .table td a.row-link:hover .symbol__name { color: var(--accent-text); }
}
/* ======================================================================
 * Phase 2 additions (2026-11-21): error codes on error pages.
 * Tokens only, logical properties only.
 * ====================================================================== */
@layer components {
  .error-code { padding: var(--sp-4); border-radius: var(--r-m); background: var(--s2); border: 1px solid var(--border); }
  .error-code__row { display: flex; align-items: center; justify-content: center; gap: var(--sp-3); flex-wrap: wrap; }
  .error-code__value { font-size: var(--fs-l); font-weight: 700; letter-spacing: 0.08em; color: var(--text-1); user-select: all; }
}

/* Admin two-factor pages: the QR code needs dark modules on a light ground in both themes. */
@layer tokens {
  :root { --qr-bg: #FFFFFF; --qr-fg: #000000; }
}
@layer components {
  .qr { align-self: center; inline-size: min(100%, 232px); padding: var(--sp-3); border-radius: var(--r-m); background: var(--qr-bg); color: var(--qr-fg); }
  .qr__svg { display: block; inline-size: 100%; block-size: auto; }
  .qr__svg path { fill: var(--qr-fg); }
  .secret-key { display: block; font-size: var(--fs-m); letter-spacing: 0.06em; overflow-wrap: anywhere; user-select: all; }
  .recovery-codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2) var(--sp-4); margin: 0; padding: var(--sp-4); list-style: none; border-radius: var(--r-m); background: var(--s2); border: 1px solid var(--border); text-align: center; font-size: var(--fs-m); }
}

/* ======================================================================
 * Landing page (public site, Phase 2): same tokens, same components.
 * Dark by default; follows the OS theme (data-theme="system"). RTL-first.
 * ====================================================================== */
@layer layout {
  .site { display: flex; flex-direction: column; overflow-x: clip; }
  .site > main { flex: 1 0 auto; }
  .wrap {
    inline-size: 100%; max-inline-size: 1180px; margin-inline: auto;
    padding-inline: max(var(--gutter), var(--safe-start)) max(var(--gutter), var(--safe-end));
  }
  .site-header {
    position: sticky; inset-block-start: 0; z-index: 20;
    padding-block-start: var(--safe-top);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    -webkit-backdrop-filter: saturate(140%) blur(14px);
    backdrop-filter: saturate(140%) blur(14px);
    border-block-end: 1px solid var(--border);
  }
  .site-header__bar { display: flex; align-items: center; gap: var(--sp-3); min-block-size: 64px; }
  .site-header__nav { margin-inline-start: auto; display: flex; align-items: center; gap: var(--sp-1); }
  .section { padding-block: clamp(3.5rem, 2rem + 6vw, 7rem); scroll-margin-block-start: 72px; }
  .section--alt { background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--s1) 55%, transparent) 18%, color-mix(in srgb, var(--s1) 55%, transparent) 82%, transparent); }
  .site-footer { border-block-start: 1px solid var(--border); padding-block: var(--sp-8) calc(var(--sp-8) + var(--safe-bottom)); }
  .site-footer__inner { display: grid; gap: var(--sp-5); grid-template-columns: minmax(0, 1fr); align-items: start; }
  @media (min-width: 760px) { .site-footer__inner { grid-template-columns: minmax(0, 1fr) auto; } }
  .site-footer__brand { display: flex; flex-direction: column; gap: var(--sp-2); }
  .site-footer__brand .brand { padding-inline: 0; }
  .site-footer__links { display: flex; flex-wrap: wrap; gap: 0 var(--sp-5); }
  .site-footer__links a { display: inline-flex; align-items: center; min-block-size: var(--hit); color: var(--text-2); text-decoration: none; font-size: var(--fs-s); }
  .site-footer__links a:hover { color: var(--text-1); text-decoration: underline; }
  .site-footer__copy { color: var(--text-3); grid-column: 1 / -1; }
}

@layer components {
  .brand__mark--xs { inline-size: 22px; block-size: 22px; }
  .btn--l { min-block-size: 52px; padding-inline: var(--sp-6); font-size: var(--fs-m); border-radius: var(--r-l); }
  .btn--quiet { --_bg: var(--s2); --_bd: var(--border); }
  .site-header .btn { padding-inline: var(--sp-4); }
  .site-header .btn .icon { inline-size: 18px; block-size: 18px; }
  .text-link { font-weight: 650; text-decoration: none; }
  .text-link:hover { text-decoration: underline; }

  /* hero */
  .hero { position: relative; isolation: isolate; padding-block: clamp(2.75rem, 1rem + 6vw, 6.5rem) clamp(3rem, 1.5rem + 5vw, 5.5rem); }
  .hero::before {
    content: ""; position: absolute; z-index: -1; inset: -12rem 0 auto; block-size: 52rem; pointer-events: none;
    background:
      radial-gradient(38rem 26rem at 78% 30%, var(--accent-soft), transparent 70%),
      radial-gradient(28rem 20rem at 14% 8%, var(--ember-soft), transparent 70%);
  }
  .hero:dir(rtl)::before { transform: scaleX(-1); }
  .hero__grid { display: grid; gap: clamp(2.5rem, 1rem + 4vw, 4.5rem); align-items: center; }
  @media (min-width: 980px) { .hero__grid { grid-template-columns: minmax(0, 1.02fr) minmax(0, 1fr); } }
  .hero__copy { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-5); }
  .eyebrow {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    padding-block: 6px; padding-inline: var(--sp-2) var(--sp-3); border-radius: var(--r-pill);
    background: var(--accent-soft); color: var(--accent-text); border: 1px solid var(--accent-line);
    font-size: var(--fs-xs); font-weight: 650;
  }
  .eyebrow .icon { inline-size: 16px; block-size: 16px; color: var(--ember); }
  .hero__title {
    font-size: clamp(2.25rem, 1.2rem + 4.2vw, 4.35rem); line-height: 1.06; font-weight: 800;
    letter-spacing: -0.035em; text-wrap: balance;
  }
  .hero__title:lang(fa) { line-height: 1.32; letter-spacing: 0; font-weight: 850; }
  .hero__title em {
    font-style: normal; color: var(--accent-text);
    background: linear-gradient(transparent 62%, var(--accent-soft) 62%); padding-inline: 0.08em; border-radius: 4px;
  }
  .hero__lead { font-size: var(--fs-l); line-height: 1.8; color: var(--text-2); max-inline-size: 36rem; }
  .hero__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
  .hero__note { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-3); }
  .hero__note .icon { color: var(--profit); }

  /* the live product visual (decorative, sample numbers) */
  .demo {
    position: relative; display: grid; gap: var(--sp-3); padding: var(--sp-4);
    border-radius: var(--r-xl); background: var(--s1); border: 1px solid var(--border);
    box-shadow: var(--shadow-2), 0 40px 90px -50px var(--accent);
    container-type: inline-size;
  }
  .demo::after {
    content: ""; position: absolute; inset: -1px; padding: 1px; border-radius: inherit; pointer-events: none;
    background: linear-gradient(150deg, var(--accent-line), transparent 32%, transparent 70%, var(--ember-soft));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude;
  }
  .demo__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-1) var(--sp-1) 0; }
  .demo__title { display: inline-flex; align-items: center; gap: var(--sp-2); font-weight: 700; font-size: var(--fs-s); }
  .demo .card { background: var(--s2); box-shadow: none; padding: var(--sp-3) var(--sp-4); gap: var(--sp-2); border-radius: var(--r-m); }
  .demo__kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-3); }
  .demo .kpi__value { font-size: clamp(1rem, 11cqi, 1.6rem); }
  @container (max-width: 380px) { .demo__kpis .kpi__foot, .demo__unit { display: none; } }
  .demo .bar { grid-template-columns: minmax(84px, 7rem) minmax(0, 1fr) 3rem; }
  .demo .chart__dot { stroke: var(--s2); }

  /* section heads */
  .section__head { max-inline-size: 46rem; margin-inline: auto; margin-block-end: clamp(2rem, 1rem + 3vw, 3.25rem); text-align: center; display: flex; flex-direction: column; gap: var(--sp-3); }
  .section__title { font-size: clamp(1.75rem, 1.15rem + 2.2vw, 2.65rem); line-height: 1.18; letter-spacing: -0.025em; font-weight: 800; text-wrap: balance; }
  .section__title:lang(fa) { letter-spacing: 0; line-height: 1.4; }
  .section__lead { font-size: var(--fs-l); line-height: 1.8; color: var(--text-2); }
  .section__foot { text-align: center; margin-block-start: var(--sp-5); }

  /* insights */
  .insight-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
  .insight-grid .insight__icon .icon { inline-size: 22px; block-size: 22px; }

  /* features */
  .feature-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
  .feature {
    display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-6);
    border-radius: var(--r-l); background: var(--s1); border: 1px solid var(--border);
    transition: border-color var(--t) ease, transform var(--t) var(--ease-out);
  }
  .feature:hover { border-color: var(--accent-line); transform: translateY(-2px); }
  .feature__icon { display: inline-grid; place-items: center; inline-size: 44px; block-size: 44px; border-radius: var(--r-m); background: var(--accent-soft); color: var(--accent-text); }
  .feature__title { font-size: var(--fs-l); font-weight: 750; }
  .feature__text { color: var(--text-2); font-size: var(--fs-s); line-height: 1.8; }

  /* steps */
  .steps { counter-reset: step; list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
  .step { counter-increment: step; position: relative; display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-6); padding-block-start: calc(var(--sp-6) + 52px); border-radius: var(--r-l); background: var(--s1); border: 1px solid var(--border); }
  .step::before {
    content: counter(step); position: absolute; inset-block-start: var(--sp-6); inset-inline-start: var(--sp-6);
    display: grid; place-items: center; inline-size: 40px; block-size: 40px; border-radius: 50%;
    background: var(--ember-soft); color: var(--ember); font-family: var(--font-num); font-weight: 800;
  }
  .step__title { font-size: var(--fs-l); font-weight: 750; }
  .step__text { color: var(--text-2); font-size: var(--fs-s); line-height: 1.8; }

  /* privacy and security */
  .trust { display: grid; gap: clamp(2rem, 1rem + 3vw, 4rem); align-items: start; }
  @media (min-width: 900px) { .trust { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); } }
  .trust__intro { display: flex; flex-direction: column; gap: var(--sp-4); }
  .trust__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-3); }
  .trust__list li { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-radius: var(--r-m); background: var(--s1); border: 1px solid var(--border); line-height: 1.7; }
  .trust__list .icon { color: var(--profit); margin-block-start: 3px; }

  /* early access */
  .ea {
    position: relative; isolation: isolate; overflow: hidden;
    display: grid; gap: var(--sp-6); align-items: center;
    padding: clamp(1.5rem, 0.5rem + 4vw, 3.5rem); border-radius: var(--r-xl);
    background: var(--s1); border: 1px solid var(--accent-line); box-shadow: var(--shadow-2);
  }
  .ea::before {
    content: ""; position: absolute; z-index: -1; inset: 0; pointer-events: none;
    background: radial-gradient(30rem 18rem at 100% 0%, var(--accent-soft), transparent 70%), radial-gradient(24rem 16rem at 0% 100%, var(--ember-soft), transparent 70%);
  }
  @media (min-width: 900px) { .ea { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
  .ea__copy, .ea__panel, .ea__form { display: flex; flex-direction: column; gap: var(--sp-3); }
  .ea__row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
  .ea__row .input { flex: 1 1 14rem; min-block-size: 52px; }
  .ea__row .btn { flex: 0 0 auto; min-block-size: 52px; padding-inline: var(--sp-6); }
  .ea__result:empty { display: none; }
  .ea__result { padding: var(--sp-4); border-radius: var(--r-m); font-weight: 600; }
  .ea__result--ok { background: var(--profit-soft); color: var(--text-1); border: 1px solid var(--profit); }
  .ea__result--error { background: var(--loss-soft); color: var(--text-1); border: 1px solid var(--loss); }
  .ea .error:empty { display: none; }
  .check { display: flex; align-items: flex-start; gap: var(--sp-3); min-block-size: var(--hit); font-size: var(--fs-s); color: var(--text-2); line-height: 1.7; cursor: pointer; }
  .check input { flex: none; inline-size: 22px; block-size: 22px; margin-block-start: 2px; accent-color: var(--accent); }
  .hp { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

  /* FAQ */
  .faq__list { max-inline-size: 52rem; margin-inline: auto; display: flex; flex-direction: column; gap: var(--sp-3); }
  .faq__item { border-radius: var(--r-m); background: var(--s1); border: 1px solid var(--border); padding-inline: var(--sp-5); }
  .faq__item > summary { justify-content: space-between; gap: var(--sp-3); min-block-size: 60px; color: var(--text-1); font-weight: 650; list-style: none; }
  .faq__item > summary::-webkit-details-marker { display: none; }
  /* (beats the RTL flip of .icon--flip: the chevron points down, and up when open) */
  .faq__item .faq__chev { transform: rotate(90deg); transition: transform var(--t) var(--ease-out); color: var(--text-3); }
  .faq__item[open] .faq__chev { transform: rotate(-90deg); }
  .faq__item > p { padding-block-end: var(--sp-5); color: var(--text-2); line-height: 1.85; }

  /* links to the legal pages inside the app */
  .legal-links { color: var(--text-3); text-align: center; }
  .legal-links a { color: var(--text-3); display: inline-flex; align-items: center; min-block-size: var(--hit); }
  .legal-links a:hover { color: var(--text-1); }

  /* legal pages */
  .prose { max-inline-size: 46rem; display: flex; flex-direction: column; gap: var(--sp-4); line-height: 1.85; }
  .prose h1 { font-size: var(--fs-3xl); }
  .prose h2 { font-size: var(--fs-xl); margin-block-start: var(--sp-5); }
  .prose ul { margin: 0; padding-inline-start: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-2); color: var(--text-2); }
  .prose p { color: var(--text-2); }
  .prose strong { color: var(--text-1); }
}

@layer motion {
  /* sections rise into view as they scroll in (browsers with scroll-driven animations only) */
  @media (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
      .scroll-in { animation: rise linear both; animation-timeline: view(); animation-range: entry 0% entry 55%; }
    }
  }
}
