/* =====================================================================
   من فیزیکی — app shell
   Fluid layout: no fixed 360px anywhere. Works from iPhone SE (375)
   to iPhone 17 Pro Max and beyond; content column capped for readability.
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }

/* .iconbtn and .banner set display, which beats the hidden attribute's
   default UA rule. Make `hidden` win everywhere. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  /* 100dvh tracks Safari's collapsing toolbar; -webkit-fill-available is the
     fallback for older iOS where 100vh overflows behind the bottom bar. */
  height: -webkit-fill-available;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  background: var(--color-surface-board);
  color: var(--color-text-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;     /* kills the rubber-band bounce of the shell */
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

/* Chrome is not selectable; article text is. Otherwise every tap in a
   drill-down list starts a text selection on iOS. */
button, .topbar, .orb-grid, .banner { user-select: none; -webkit-user-select: none; }
.reader { user-select: text; -webkit-user-select: text; }

.app {
  position: relative;
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
  margin-inline: auto;
  /* Phones and tablets only — desktop is redirected to the WordPress site
     in app.js, so there is no wide layout to design for. The cap exists
     for iPad and for the `?desktop=1` development escape hatch. */
  max-width: 820px;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.screen.is-on { display: flex; }

/* ---------- board background ----------
   Replace this block with the site's own artwork:
   background: url("assets/board.webp") center/cover no-repeat, var(--color-surface-board);  */
.board {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(90% 48% at 50% 10%, var(--color-board-glow) 0%, rgba(35,48,107,0) 70%),
    linear-gradient(175deg, var(--color-board-top) 0%, var(--color-surface-board) 62%, var(--color-board-bottom) 100%);
}
.board-formulas {
  position: absolute;
  inset: 0;
  font-family: var(--font-family-formula);
  font-style: italic;
  color: rgba(232, 236, 247, .085);
  pointer-events: none;
}
.board-formulas span { position: absolute; white-space: nowrap; font-size: clamp(11px, 3.4vw, 15px); }

/* ---------- top bar ---------- */
.topbar {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--topbar-height);
  /* the bar itself absorbs the notch, so nothing sits under the status bar */
  padding: var(--safe-top) var(--space-4) 0;
  padding-block-start: calc(var(--safe-top) + var(--space-1));
  padding-block-end: var(--space-1);
}
.topbar--dark  { color: var(--color-text-on-board); }
.topbar--light {
  background: var(--color-surface-card);
  border-bottom: 1px solid var(--color-border-default);
  color: var(--color-text-title);
}
.topbar-titles { flex: 1; min-width: 0; }
.screen-title {
  font-size: var(--font-body-size);
  font-weight: 600;
  line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumb {
  flex: 1; min-width: 0;
  font-size: var(--font-label-size);
  line-height: var(--font-label-lh);
  opacity: .72;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar--light .crumb { opacity: 1; color: var(--color-text-muted); }

.iconbtn {
  flex: 0 0 auto;
  width: 40px; height: 40px;           /* 40 ≥ the 44pt touch target once padding counts */
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-md);
  background: rgba(255,255,255,.09);
  color: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.topbar--light .iconbtn { background: var(--color-primary-subtle); color: var(--color-primary-default); }
.iconbtn:active { transform: scale(.93); }
.iconbtn svg { width: 20px; height: 20px; }
.iconbtn--ai {
  background: linear-gradient(140deg, var(--color-primary-light), var(--color-primary-default));
  color: var(--color-text-on-primary);
  box-shadow: 0 4px 14px -4px rgba(108,99,255,.9);
}
.topbar--light .iconbtn--ai { background: linear-gradient(140deg, var(--color-primary-light), var(--color-primary-default)); color: var(--color-text-on-primary); }

/* ---------- copyright banner ---------- */
.banner {
  position: relative; z-index: 2;
  display: flex; gap: var(--space-2); align-items: flex-start;
  margin: var(--space-1) var(--space-4) 0;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: rgba(242,177,85,.12);
  border: 1px solid rgba(242,177,85,.32);
  color: var(--color-banner-fg);
  font-size: var(--font-label-size);
  line-height: 1.95;
}
.banner svg { width: 16px; height: 16px; flex: 0 0 auto; margin-top: 2px; color: var(--color-accent-warning); }
/* On the circle screen the banner floats under the topbar; in a list it is
   the first item and needs to clear the rows below it. */
.scroll > .banner { margin: var(--space-3) var(--space-4); }

/* ---------- circle grid ---------- */
.orb-stage {
  position: relative; z-index: 2;
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  padding: 0 var(--space-6) calc(var(--safe-bottom) + var(--space-8));
  overflow-y: auto;
}
.orb-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-8) var(--space-4);
  justify-items: center;
  margin-inline: auto;
  width: 100%;
  max-width: 420px;
}
.orb-grid[data-cols="1"] { grid-template-columns: minmax(0, 1fr); max-width: 260px; }

.orb {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  width: 100%;
  padding: 0; border: 0; background: none;
  font-family: inherit; color: inherit; cursor: pointer;
  opacity: 0; transform: translateY(16px) scale(.86);
  transition: opacity var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.orb.is-in  { opacity: 1; transform: none; }
.orb.is-out { opacity: 0; transform: translateY(-18px) scale(.8); }

.orb-disc {
  position: relative;
  width: clamp(88px, 27vw, 116px);
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 32% 22%, rgba(255,255,255,.2) 0%, rgba(255,255,255,.05) 45%, rgba(255,255,255,.02) 100%);
  border: 1px solid rgba(232,236,247,.22);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22), 0 16px 34px -20px rgba(0,0,0,.95);
  transition: transform var(--dur-base) var(--ease);
}
.orb-disc::after {
  content: ""; position: absolute; inset: -7px;
  border-radius: 50%; border: 1px dashed rgba(232,236,247,.16);
}
.orb:active .orb-disc { transform: scale(.95); }
.orb-disc svg { width: 46%; height: 46%; color: var(--color-text-on-board); }

.orb--accent .orb-disc {
  background: radial-gradient(120% 120% at 32% 22%, var(--color-primary-glow) 0%, var(--color-primary-light) 42%, var(--color-primary-default) 100%);
  border-color: rgba(255,255,255,.4);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.4), 0 18px 40px -18px rgba(108,99,255,.85);
}
.orb--accent .orb-disc::after { border-color: rgba(255,255,255,.3); animation: orbit 26s linear infinite; }
@keyframes orbit { to { transform: rotate(360deg); } }

.orb-cap {
  font-size: var(--font-small-size);
  font-weight: 500;
  line-height: 1.6;
  text-align: center;
  color: var(--color-text-on-board);
  text-wrap: balance;
}

/* ---------- scrolling bodies ---------- */
.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--color-surface-background);
  padding-bottom: calc(var(--safe-bottom) + var(--space-6));
}

/* ---------- list rows ---------- */
.row {
  width: 100%;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface-card);
  border: 0; border-bottom: 1px solid var(--color-border-default);
  text-align: start;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) ease;
}
.row:active { background: var(--color-primary-subtle); }
.row-thumb {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--color-primary-subtle), var(--color-primary-hover));
  color: var(--color-primary-default);
  font-weight: 600; font-size: var(--font-small-size);
}
.row--band .row-thumb { background: linear-gradient(140deg, var(--color-band-from), var(--color-band-to)); color: var(--color-band-fg); }
.row-text { flex: 1; min-width: 0; }
.row-t1 { display: block; font-size: var(--font-small-size); font-weight: 500; color: var(--color-text-title); line-height: 1.6; }
.row-t2 { display: block; font-size: var(--font-label-size); color: var(--color-text-muted); line-height: 1.7; }
.row-chev { flex: 0 0 auto; color: var(--color-text-faint); }
.row-chev svg { width: 16px; height: 16px; display: block; }

/* Arrows are drawn RTL-first. transform has no logical-property equivalent,
   so every glyph that means "forward" or "back" is mirrored by hand in LTR. */
:root[data-dir="ltr"] .row-chev svg,
:root[data-dir="ltr"] .prow-chev svg,
:root[data-dir="ltr"] #orb-back svg,
:root[data-dir="ltr"] [data-back] svg,
:root[data-dir="ltr"] [data-page-back] svg { transform: scaleX(-1); }

.group-label {
  padding: var(--space-4) var(--space-4) var(--space-2);
  font-size: var(--font-label-size);
  font-weight: 600;
  letter-spacing: .06em;
  color: var(--color-text-muted);
}

/* ---------- reader ---------- */
.reader {
  background: var(--color-surface-card);
  padding: var(--space-4) var(--space-4) calc(var(--safe-bottom) + var(--space-8));
}
.reader-inner { max-width: var(--content-max); margin-inline: auto; }
.reader h2 { margin: 0 0 var(--space-1); font-size: var(--font-h2-size); font-weight: 600; color: var(--color-text-title); line-height: 1.6; }
.reader .reader-meta { margin: 0 0 var(--space-4); font-size: var(--font-label-size); color: var(--color-text-muted); }

/* save-for-offline — quiet until it is on, because the article is the point */
.savebtn {
  display: block; margin: 0 0 var(--space-5);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-pill);
  background: none; color: var(--color-text-muted);
  font-family: inherit; font-size: var(--font-label-size); line-height: 1.9;
  cursor: pointer;
}
.savebtn.is-on {
  border-color: var(--color-primary-default);
  color: var(--color-primary-default);
  background: var(--color-primary-subtle);
}
.savebtn:disabled { opacity: .55; cursor: default; }

/* Persian text is right-aligned, so the ragged — and therefore free —
   margin is the one at the end of the line. The affordance lives there. */
.para { position: relative; padding-inline-end: 34px; margin-bottom: var(--space-4); }
.para p {
  margin: 0;
  font-size: var(--font-body-size);
  line-height: var(--font-body-lh);
  color: var(--color-text-body);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  margin-inline-end: -4px;
  transition: background var(--dur-fast) ease;
}
.para.is-asked p { background: var(--color-primary-subtle); }

/* Headings, lists, quotes and code come from the site as rendered HTML.
   Only the things that would break the column are constrained here; the
   rest inherits the reader's type so it does not read as a foreign body. */
.reader-html { margin-bottom: var(--space-4); color: var(--color-text-body); font-size: var(--font-body-size); line-height: var(--font-body-lh); }
.reader-html h2, .reader-html h3, .reader-html h4 { color: var(--color-text-title); line-height: 1.7; margin: var(--space-5) 0 var(--space-2); }
.reader-html h2 { font-size: var(--font-h2-size); }
.reader-html h3 { font-size: calc(var(--font-h2-size) - 2px); }
.reader-html img { max-width: 100%; height: auto; border-radius: var(--radius-md); }
.reader-html ul, .reader-html ol { padding-inline-start: var(--space-5); margin: 0 0 var(--space-3); }
.reader-html li { margin-bottom: var(--space-2); }
.reader-html blockquote {
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-inline-start: 3px solid var(--color-primary-default);
  background: var(--color-primary-subtle);
  border-radius: var(--radius-sm);
}
.reader-html blockquote p:last-child { margin-bottom: 0; }
/* Code is the one place that must not wrap or reflow to RTL. */
.reader-html pre {
  direction: ltr; text-align: left;
  overflow-x: auto;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-code, #11151f);
  color: #E6E8EF;
  font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.7;
}
.reader-html code { font-family: 'JetBrains Mono', monospace; font-size: .92em; }
.reader-html table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.reader-html td, .reader-html th { border: 1px solid var(--color-border-default); padding: var(--space-2); }
.reader-html hr { border: 0; border-top: 1px solid var(--color-border-default); margin: var(--space-5) 0; }
.reader-html a { color: var(--color-primary-default); }

.loadfail { padding: var(--space-8) var(--space-4); text-align: center; color: var(--color-text-muted); }
.loadfail p { margin: 0 0 var(--space-4); font-size: var(--font-body-size); }

/* The membership gate. Deliberately calm rather than alarming — nothing
   has gone wrong and the way out is one free tap away. */
.locked { padding: var(--space-8) var(--space-2); text-align: center; }
.locked-ico {
  display: inline-flex;
  width: 56px; height: 56px;
  align-items: center; justify-content: center;
  margin-bottom: var(--space-4);
  border-radius: 50%;
  background: var(--color-surface-card);
  color: var(--color-text-muted);
}
.locked-ico svg { width: 28px; height: 28px; }
.locked h3 { margin: 0 0 var(--space-2); font-size: var(--font-h2-size); font-weight: var(--font-h2-weight); }
.locked p { margin: 0 0 var(--space-4); color: var(--color-text-muted); line-height: var(--font-body-lh); }
.locked .btn { margin-bottom: var(--space-3); }
.locked p:last-child { margin-bottom: 0; }

/* Sits clear of the text, so it never collides with the browser's own
   text-selection handles the way a long-press would. */
.ask {
  position: absolute;
  inset-inline-end: 0;
  top: 3px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-surface-card);
  color: var(--color-text-faint);
  font-family: inherit; font-size: 13px; font-weight: 600; line-height: 1;
  cursor: pointer;
}
.ask:active { transform: scale(.9); color: var(--color-primary-default); }

.formula {
  display: block;
  direction: ltr;
  text-align: center;
  font-family: var(--font-family-formula);
  font-style: italic;
  font-size: 17px;
  color: var(--color-text-title);
  background: var(--color-surface-background);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin: var(--space-4) 0;
}

/* ---------- bottom sheet ---------- */
.scrim {
  position: absolute; inset: 0; z-index: 8;
  background: var(--color-scrim);
  opacity: 0;
  /* a transparent scrim must not swallow taps meant for the screen under it */
  pointer-events: none;
  transition: opacity var(--dur-base) ease;
}
.scrim.is-on, .scrim.on { opacity: 1; pointer-events: auto; }

.sheet {
  position: absolute; inset-inline: 0; bottom: 0; z-index: 9;
  background: var(--color-surface-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-2) var(--space-4) calc(var(--safe-bottom) + var(--space-6));
  transform: translateY(102%);
  transition: transform var(--dur-base) var(--ease);
}
.sheet.is-on { transform: none; }
.sheet-handle { width: 38px; height: 4px; border-radius: var(--radius-pill); background: var(--color-border-default); margin: 0 auto var(--space-3); }
.sheet h3 { margin: 0 0 var(--space-1); color: var(--color-text-title); }
.sheet-sub { margin: 0 0 var(--space-4); color: var(--color-text-muted); }

.opt {
  width: 100%;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  background: var(--color-surface-card);
  text-align: start; font-family: inherit; cursor: pointer;
  transition: border-color var(--dur-fast) ease, background var(--dur-fast) ease;
}
.opt:active { border-color: var(--color-border-focus); background: var(--color-primary-subtle); }
.opt-ico { flex: 0 0 auto; width: 38px; height: 38px; border-radius: var(--radius-md); display: grid; place-items: center; }
.opt-ico svg { width: 18px; height: 18px; }
.opt--ai .opt-ico    { background: linear-gradient(140deg, var(--color-primary-light), var(--color-primary-default)); color: var(--color-text-on-primary); }
.opt--tutor .opt-ico { background: linear-gradient(140deg, var(--color-band-from), var(--color-band-to)); color: var(--color-band-fg); }
.opt-text { display: block; }
.opt-t1 { display: block; font-size: var(--font-small-size); font-weight: 500; color: var(--color-text-title); line-height: 1.6; }
.opt-t2 { display: block; font-size: var(--font-label-size); color: var(--color-text-muted); line-height: 1.7; }

.quota { margin: var(--space-1) 0 0; text-align: center; color: var(--color-text-muted); }
.quota b { color: var(--color-primary-default); font-weight: 600; }

/* =====================================================================
   Account family — auth · account · usage · settings
   One column, capped at the reading width, same card vocabulary in all
   four so they read as one place rather than four separate features.
   ===================================================================== */
.page {
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-4);
}

.hero { text-align: center; padding: var(--space-6) 0 var(--space-4); }
.hero-ico {
  width: 64px; height: 64px;
  margin: 0 auto var(--space-4);
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--color-primary-light), var(--color-primary-default));
  color: var(--color-text-on-primary);
}
.hero-ico svg { width: 30px; height: 30px; }
.hero h2 { margin: 0 0 var(--space-2); font-size: var(--font-h2-size); font-weight: 600; color: var(--color-text-title); }
.hero p { margin: 0; font-size: var(--font-small-size); line-height: var(--font-small-lh); color: var(--color-text-muted); }

.card {
  background: var(--color-surface-card);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.card h4 {
  margin: 0 0 var(--space-3);
  font-size: var(--font-label-size);
  font-weight: 600;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}
.card > p { margin: 0 0 var(--space-3); font-size: var(--font-small-size); line-height: var(--font-small-lh); color: var(--color-text-muted); }
.card > p:last-child { margin-bottom: 0; }

.btn {
  width: 100%;
  padding: var(--space-3);
  border: 0; border-radius: var(--radius-md);
  background: var(--color-primary-default);
  color: var(--color-text-on-primary);
  font-family: inherit; font-size: var(--font-small-size); font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(.985); }
.btn--ghost { background: none; border: 1px solid var(--color-border-default); color: var(--color-text-body); }
.btn--danger { background: var(--color-danger); }
.btn + .btn { margin-top: var(--space-2); }

/* profile head */
.who { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.avatar {
  flex: 0 0 auto;
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(140deg, var(--color-primary-subtle), var(--color-primary-hover));
  color: var(--color-primary-default);
  font-size: var(--font-h2-size); font-weight: 600;
}
.who-text { min-width: 0; }
.who-t1 { display: block; font-size: var(--font-body-size); font-weight: 600; color: var(--color-text-title); }
.who-t2 { display: block; font-size: var(--font-label-size); color: var(--color-text-muted); direction: ltr; }
:root[data-dir="rtl"] .who-t2 { text-align: right; }

.field { display: block; margin-bottom: var(--space-3); }
.field span { display: block; margin-bottom: var(--space-1); font-size: var(--font-label-size); color: var(--color-text-muted); }
.field input {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-surface-background);
  color: var(--color-text-title);
  font-family: inherit; font-size: var(--font-small-size);
}
.field input:focus { outline: none; border-color: var(--color-border-focus); background: var(--color-surface-card); }

/* a settings/navigation row inside a card */
.prow {
  width: 100%;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) 0;
  border: 0; border-bottom: 1px solid var(--color-border-default);
  background: none; text-align: start; font-family: inherit; cursor: pointer;
}
.prow:last-child { border-bottom: 0; padding-bottom: 0; }
.prow:first-child { padding-top: 0; }
.prow-text { flex: 1; min-width: 0; }
.prow-t1 { display: block; font-size: var(--font-small-size); font-weight: 500; color: var(--color-text-title); line-height: 1.6; }
.prow-t2 { display: block; font-size: var(--font-label-size); color: var(--color-text-muted); line-height: 1.7; }
.prow-chev { flex: 0 0 auto; color: var(--color-text-faint); }
.prow-chev svg { width: 16px; height: 16px; display: block; }
.prow--danger .prow-t1 { color: var(--color-danger); }
.app-version { text-align: center; color: var(--color-text-faint); margin-top: 12px; }

/* a saved article: the title opens it, the ✕ removes it */
.srow { display: flex; align-items: center; gap: var(--space-2); border-bottom: 1px solid var(--color-border-default); }
.srow-open {
  flex: 1; min-width: 0; padding: var(--space-3) 0;
  border: 0; background: none; text-align: start; cursor: pointer;
  font-family: inherit; font-size: var(--font-small-size); line-height: 1.7;
  color: var(--color-text-title);
}
.srow-del {
  flex: 0 0 auto; width: 32px; height: 32px;
  border: 0; border-radius: var(--radius-sm); background: none;
  color: var(--color-text-faint); font-size: 15px; cursor: pointer;
}
.srow-del:hover { color: var(--color-danger); }

/* ask a teacher — the compose box and the answers */
.field textarea {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-surface-background);
  color: var(--color-text-title);
  font-family: inherit; font-size: var(--font-small-size); line-height: 1.9;
  resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--color-border-focus); background: var(--color-surface-card); }

.qquote {
  margin: 0;
  padding-inline-start: var(--space-3);
  border-inline-start: 3px solid var(--color-border-default);
  font-size: var(--font-label-size); line-height: 1.9;
  color: var(--color-text-muted);
}
/* A paragraph can be most of a screen. On the compose page it must not push
   the box you came here to type in below the fold. */
#ask-body .qquote { max-height: 8.5em; overflow-y: auto; }

.qcard.is-new { border-color: var(--color-primary-hover); }
.qnew {
  display: inline-block;
  padding: 1px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--color-primary-subtle);
  color: var(--color-primary-default);
  font-size: var(--font-label-size); font-weight: 600; letter-spacing: 0;
}
.qq {
  margin: 0 0 var(--space-3);
  font-size: var(--font-small-size); line-height: var(--font-small-lh);
  color: var(--color-text-title);
}
.qa {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-primary-subtle);
}
.qa-h {
  display: flex; justify-content: space-between; gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--font-label-size); font-weight: 600;
  color: var(--color-primary-default);
}
.qa-when { font-weight: 400; color: var(--color-text-muted); }

/* Waiting is the normal state here, so the card says how long it has been. */
.qwhen {
  margin: calc(-1 * var(--space-2)) 0 var(--space-3);
  font-size: var(--font-label-size); color: var(--color-text-muted);
}
.qa p { margin: 0; font-size: var(--font-small-size); line-height: var(--font-small-lh); color: var(--color-text-body); white-space: pre-wrap; }
.qcard .qopen { margin-top: var(--space-3); }

/* segmented control — language and theme */
.seg {
  display: flex;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.seg button {
  flex: 1;
  padding: var(--space-2) var(--space-1);
  border: 0;
  background: var(--color-surface-background);
  color: var(--color-text-muted);
  font-family: inherit; font-size: var(--font-label-size);
  cursor: pointer;
}
.seg button + button { border-inline-start: 1px solid var(--color-border-default); }
.seg button.on { background: var(--color-primary-default); color: var(--color-text-on-primary); font-weight: 600; }

/* usage figures */
.stats { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); }
.stat {
  flex: 1;
  padding: var(--space-3) var(--space-2);
  border-radius: var(--radius-md);
  background: var(--color-surface-background);
  text-align: center;
}
.stat b { display: block; font-size: var(--font-h2-size); font-weight: 600; color: var(--color-text-title); line-height: 1.4; }
.stat span { display: block; font-size: var(--font-label-size); color: var(--color-text-muted); }
.stat--debt b { color: var(--color-danger); }

/* seven bars, no charting library — the data is one number per day */
.bars { display: flex; align-items: flex-end; gap: var(--space-2); height: 108px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: var(--space-1); height: 100%; }
.bar i {
  display: block; width: 100%;
  min-height: 3px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(180deg, var(--color-primary-light), var(--color-primary-default));
}
.bar.over i { background: linear-gradient(180deg, var(--color-danger), var(--color-danger-strong)); }
.bar u { font-size: 10px; font-style: normal; color: var(--color-text-muted); }

.note { margin: 0; font-size: var(--font-label-size); line-height: 1.9; color: var(--color-warn-fg); }

/* inline confirm — same pattern as deleting a conversation: no system dialog */
.confirm {
  border: 1px solid var(--color-danger-br);
  background: var(--color-danger-bg);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}
.confirm h5 { margin: 0 0 var(--space-1); font-size: var(--font-small-size); font-weight: 600; color: var(--color-danger-deep); }
.confirm p { margin: 0 0 var(--space-3); font-size: var(--font-label-size); line-height: 1.85; color: var(--color-danger-strong); }
.confirm .row2 { display: flex; gap: var(--space-2); }
.confirm .row2 button { flex: 1; padding: var(--space-2); border-radius: var(--radius-sm); font-family: inherit; font-size: var(--font-label-size); font-weight: 600; cursor: pointer; }
.confirm .yes { border: 0; background: var(--color-danger); color: var(--color-text-on-primary); }
.confirm .no  { border: 1px solid var(--color-border-default); background: var(--color-surface-card); color: var(--color-text-body); }

/* waiting for Telegram */
.waiting { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.waiting i {
  flex: 0 0 auto;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--color-primary-subtle);
  border-top-color: var(--color-primary-default);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.code { font-family: var(--font-family-mono); font-size: var(--font-h2-size); letter-spacing: .28em; text-align: center; color: var(--color-text-title); direction: ltr; }

/* sign-up: the three steps, and the code the user carries to the bot */
.steps { list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.steps li { display: flex; gap: var(--space-3); margin-bottom: var(--space-4); }
.steps li > div { flex: 1 1 auto; min-width: 0; }
.steps-n {
  flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-primary-subtle); color: var(--color-primary-default);
  font-size: var(--font-label-size);
}
.steps .waiting { margin-bottom: 0; }
.codebox {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  margin-top: var(--space-2); padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-default); border-radius: var(--radius-md);
  background: var(--color-surface-card);
}
/* The code is the one thing on this screen the user has to read character by
   character, so it gets the mono face and room between the letters. */
.codebox code {
  font-family: var(--font-family-mono); font-size: var(--font-h2-size);
  letter-spacing: .22em; color: var(--color-text-title); direction: ltr;
  user-select: all; -webkit-user-select: all;
}
.btn--sm { padding: var(--space-1) var(--space-3); font-size: var(--font-label-size); width: auto; }

/* =====================================================================
   Onboarding — three pages, skippable, first run only
   ===================================================================== */
.onboard {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--color-surface-board);
  padding-block-start: var(--safe-top);
  padding-block-end: calc(var(--safe-bottom) + var(--space-4));
}
.onb-track { flex: 1; display: flex; overflow: hidden; }
.onb-page {
  flex: 0 0 100%;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-on-board);
  transition: opacity var(--dur-base) var(--ease);
}
.onb-page[hidden] { display: none; }
.onb-page .glyph {
  width: 96px; height: 96px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(120% 120% at 32% 22%, rgba(255,255,255,.2) 0%, rgba(255,255,255,.04) 100%);
  border: 1px solid rgba(232,236,247,.22);
}
.onb-page .glyph svg { width: 42px; height: 42px; }
.onb-page h2 { margin: 0; font-size: var(--font-h1-size); font-weight: 600; text-wrap: balance; }
.onb-page p { margin: 0; max-width: 34ch; font-size: var(--font-small-size); line-height: 2; opacity: .8; }

.onb-foot { flex: 0 0 auto; display: flex; align-items: center; gap: var(--space-3); padding: 0 var(--space-4); }
.onb-dots { flex: 1; display: flex; justify-content: center; gap: var(--space-2); }
.onb-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(232,236,247,.28); transition: background var(--dur-fast) ease, width var(--dur-fast) ease; }
.onb-dots i.on { width: 20px; border-radius: var(--radius-pill); background: var(--color-primary-light); }
.onb-skip { border: 0; background: none; color: var(--color-text-on-board); opacity: .6; font-family: inherit; font-size: var(--font-label-size); cursor: pointer; padding: var(--space-2); }
.onb-next {
  border: 0; border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-6);
  background: var(--color-primary-default);
  color: var(--color-text-on-primary);
  font-family: inherit; font-size: var(--font-small-size); font-weight: 600;
  cursor: pointer;
}

/* ---------- iOS install tip ---------- */
.ios-tip {
  /* Under the scrim (8) and the sheet (9): a tip that floats over an open
     dialog swallows the taps meant for its buttons. */
  position: absolute; z-index: 7;
  inset-inline: var(--space-4);
  /* clears the composer, which is the one control a tip must never cover */
  bottom: calc(var(--safe-bottom) + 86px);
  display: flex; align-items: flex-start; gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-tooltip-bg);
  color: var(--color-text-on-board);
  font-size: var(--font-label-size);
  line-height: 1.9;
  backdrop-filter: blur(8px);
}
.ios-tip p { margin: 0; flex: 1; }
.ios-tip-close { border: 0; background: none; color: inherit; opacity: .6; font-size: 15px; cursor: pointer; padding: 0 2px; }

/* ---------- update tip ---------- */
/* Lower than the install tip so the two can coexist if both ever qualify. */
.update-tip { bottom: calc(var(--safe-bottom) + 22px); }
.update-tip-link {
  color: var(--color-accent-warning);
  font-weight: 700; text-decoration: underline;
  margin-inline-start: var(--space-2);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
