/* ==========================================================================
   Satsang — shared web components (requires tokens.css first)
   Mobile-first, 100dvh app shell, safe-area aware, no framework.
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--color-background);
  color: var(--color-text-primary);
  font: var(--text-body);
  letter-spacing: var(--tracking-tight);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--color-accent); }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell: fills the *visual* viewport so the composer rides the keyboard ---------- */
.app {
  position: fixed; left: 0; right: 0; top: 0;
  height: var(--app-h, 100dvh);            /* --app-h set from visualViewport in JS */
  display: flex; flex-direction: column;
  overflow: hidden; isolation: isolate;
  max-width: 100vw;
}
/* warm ambient light + grain (decorative) */
.app::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 55% at 50% -8%, rgba(var(--color-glow-rgb), var(--glow-strength)) 0%, transparent 62%),
    radial-gradient(90% 40% at 50% 112%, rgba(var(--color-glow-rgb), calc(var(--glow-strength) * .45)) 0%, transparent 70%);
}
.app::after {
  content: ""; position: absolute; inset: 0; z-index: 60; pointer-events: none;
  opacity: var(--grain-opacity); mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

/* ---------- Glass (Liquid-Glass-ish) ---------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(18px) saturate(1.6);
  backdrop-filter: blur(18px) saturate(1.6);
  box-shadow: var(--shadow-floating), inset 0 0 0 0.75px var(--glass-stroke);
}

/* ---------- Top bar ---------- */
.topbar {
  position: relative; z-index: 30; flex: none;
  padding: calc(var(--safe-top) + 6px) calc(var(--screen-margin) + var(--safe-right)) 6px calc(var(--screen-margin) + var(--safe-left));
  min-height: calc(var(--nav-h) + var(--safe-top));
  display: flex; align-items: center; justify-content: space-between;
}
.topbar__title { position: absolute; left: 0; right: 0; bottom: 6px; height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.topbar__name { font: var(--text-nav-title); letter-spacing: .1px; }
.topbar__sub { font: var(--text-caption2); font-size: 12px; color: var(--color-text-tertiary); margin-top: 1px; letter-spacing: 0; }
.icon-btn {
  width: var(--tap-min); height: var(--tap-min); border-radius: 50%;
  display: inline-grid; place-items: center; color: var(--color-text-primary);
  transition: transform var(--dur-fast) var(--ease-calm);
}
.icon-btn:active { transform: scale(.94); }
.ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Scroll area ---------- */
.scroll {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 4px calc(var(--screen-margin) + var(--safe-right)) 12px calc(var(--screen-margin) + var(--safe-left));
  /* soft fade under the top bar */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
          mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}
.scroll > .inner { max-width: var(--content-max); margin: 0 auto; }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  flex: none; position: relative; z-index: 30;
  margin: 8px calc(20px + var(--safe-right)) max(12px, calc(var(--safe-bottom) - 8px)) calc(20px + var(--safe-left));
  height: var(--tabbar-h); border-radius: 31px;
  display: flex; align-items: center; padding: 0 4px;
}
.tabbar a {
  flex: 1; height: 54px; border-radius: 27px; text-decoration: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--color-text-primary); font: var(--text-tab); letter-spacing: 0;
}
.tabbar a .ic { width: 24px; height: 24px; stroke-width: 1.7; }
.tabbar a[aria-current="page"] { color: var(--color-accent); background: var(--color-accent-soft); }
.tabbar a[aria-current="page"] .ic--fillable { fill: currentColor; }
/* hide tab bar while typing so the composer sits right on the keyboard */
.is-typing .tabbar { display: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card), inset 0 0 0 1px var(--card-stroke);
}
.eyebrow { font: var(--text-caption); letter-spacing: var(--tracking-eyebrow); text-transform: uppercase; color: var(--color-text-tertiary); }
.well { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--color-accent-soft); color: var(--color-accent); }
.well .ic { width: 19px; height: 19px; }

/* ---------- Buttons ---------- */
.btn {
  text-decoration: none;
  min-height: var(--tap-min); padding: 0 18px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: var(--text-headline); letter-spacing: -.2px;
  transition: transform var(--dur-fast) var(--ease-calm), opacity var(--dur-fast);
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--color-accent); color: var(--color-on-accent); }
.btn--soft { background: var(--color-accent-soft); color: var(--color-accent); }
.btn--ghost { color: var(--color-text-secondary); }
.btn .ic { width: 19px; height: 19px; }
.chip-btn { height: 40px; min-width: 44px; padding: 0 10px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--color-text-secondary); font: 500 13px/1 var(--font-ui); letter-spacing: 0; }
.chip-btn .ic { width: 18px; height: 18px; }
.chip-btn[aria-pressed="true"] { color: var(--color-accent); background: var(--color-accent-soft); }
.chip-btn[aria-pressed="true"] .ic { fill: currentColor; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 150px); z-index: 80;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: var(--radius-full);
  background: var(--color-text-primary); color: var(--color-background); font: var(--text-footnote); font-weight: 600;
  transition: opacity var(--dur-base) var(--ease-calm), transform var(--dur-base) var(--ease-calm);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Sheets (native <dialog>) ---------- */
dialog.sheet {
  width: min(100%, 560px); max-width: 100%; max-height: 88dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 28px 28px 0 0; background: var(--color-surface-elevated); color: var(--color-text-primary);
  box-shadow: var(--shadow-floating);
}
dialog.sheet::backdrop { background: rgba(20, 14, 8, .38); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.sheet__body { padding: 10px 22px calc(22px + var(--safe-bottom)); }
.sheet__grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--color-divider); margin: 0 auto 14px; }
.sheet h2 { font: var(--text-title2); margin: 4px 0 10px; }
.sheet p { font: var(--text-subheadline); color: var(--color-text-secondary); margin: 0 0 12px; }

/* ---------- Motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(var(--message-rise)); } to { opacity: 1; transform: none; } }
@keyframes breathe { 0%, 100% { transform: scale(.96); opacity: .82; } 50% { transform: scale(1.04); opacity: 1; } }
.breathe { animation: breathe calc(var(--dur-breath) * 2) ease-in-out infinite; transform-origin: 50% 50%; }

/* ---------- Lotus emblem (inline SVG, original abstract mark) ---------- */
.emblem .em-g0 { stop-color: var(--color-glow); stop-opacity: var(--emblem-glow); }
.emblem .em-g1 { stop-color: var(--color-glow); stop-opacity: calc(var(--emblem-glow) * .35); }
.emblem .em-g2 { stop-color: var(--color-glow); stop-opacity: 0; }
.emblem .em-p0 { stop-color: var(--color-glow); stop-opacity: .55; }
.emblem .em-p1 { stop-color: var(--color-glow); stop-opacity: .08; }
.emblem .em-ring { fill: none; stroke: var(--color-accent); stroke-opacity: .14; stroke-width: 1; }
.emblem .em-ring--dots { stroke-opacity: .28; stroke-dasharray: 1.5 5; stroke-linecap: round; }
.emblem .em-lotus path { stroke: var(--color-accent); stroke-width: 1.5; stroke-linejoin: round; }
.emblem .em-water { stroke: var(--color-accent); stroke-opacity: .45; stroke-width: 1.5; stroke-linecap: round; }
.emblem .em-water--2 { stroke-opacity: .25; }
.avatar { width: var(--avatar-size); height: var(--avatar-size); border-radius: 50%; background: var(--color-accent-soft); display: inline-grid; place-items: center; flex: none; }
.avatar svg { width: 14px; height: 14px; fill: none; stroke: var(--color-accent); stroke-width: 5; }

/* The hidden attribute must win over component display rules (e.g. .btn { display:inline-flex }) */
[hidden] { display: none !important; }
