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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* Native-app shell tweaks: applied only inside the Capacitor iOS WebView
   (entry.ts tags <html> + <body> with .capacitor-native on bootstrap).
   Web visitors see normal scrollbars + the OS-default tap highlight. */
html.capacitor-native,
body.capacitor-native,
.capacitor-native * {
  -webkit-tap-highlight-color: transparent;
  scrollbar-width: none;       /* Firefox; harmless in WebKit */
  -ms-overflow-style: none;    /* legacy Edge */
}
.capacitor-native ::-webkit-scrollbar,
.capacitor-native::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* Smooth cross-fade between hx-boost page swaps via the View Transitions
   API. Safari 18+ supports it; older WebKits fall back to no transition
   (no error, just a less polished swap). */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 180ms;
  animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* Pull-to-refresh indicator — created from entry.ts on native bootstrap,
   so the styles only matter when we're inside Capacitor. Slides down as
   the user pulls; brand-accent ring when armed; spins during the swap. */
#comomity-ptr {
  position: fixed;
  top: max(env(safe-area-inset-top), 12px);
  left: 50%;
  margin-left: -22px;
  width: 44px; height: 44px;
  display: flex;
  align-items: center; justify-content: center;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(28, 27, 26, 0.12);
  opacity: 0;
  z-index: 50;
  pointer-events: none;
  transform: translateY(-72px);
  transition: opacity 160ms ease-out;
}
#comomity-ptr.armed svg { stroke: var(--color-accent-text); }
#comomity-ptr.spinning svg { animation: comomity-ptr-spin 0.7s linear infinite; }
@keyframes comomity-ptr-spin { to { transform: rotate(360deg); } }

/* htmx top-of-screen progress bar. base.html toggles body.htmx-loading
   on htmx:beforeRequest / htmx:afterRequest. Brand-accent indeterminate
   slide so any wait — dyno warm-up, slow CSS, big template — feels
   acknowledged instead of frozen. */
#comomity-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--color-accent);
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 160ms ease-out;
}
body.htmx-loading #comomity-progress {
  opacity: 1;
  animation: comomity-progress-slide 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}
@keyframes comomity-progress-slide {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(20%); }
  100% { transform: translateX(120%); }
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* `overflow-x: clip` (not `hidden`) so .page-hero's negative-margin
     bleed doesn't create a horizontal scrollbar on narrow viewports,
     while still allowing position: sticky on descendants. */
  overflow-x: clip;
}

img, svg, video { max-width: 100%; height: auto; display: block; }

h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-3);
  line-height: 1.2;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }

/* ── Brand wordmark ──────────────────────────────────────────────────────
   The Comomity logotype: "co" + "mom" + "ity", with the middle
   "mom" carried in cherry-blossom pink (matching the primary logo). Used in
   the app chrome — login, nav, admin topbar — instead of plain text. */
.wordmark {
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
  color: var(--color-accent);
  text-transform: lowercase;
  line-height: 1;
  white-space: nowrap;
}
.wordmark__mom { color: var(--color-pink); }
/* On burgundy backgrounds, the wordmark inverts: cream + pink. */
.wordmark--invert { color: var(--color-bg); }

/* ── Emblem watermark ────────────────────────────────────────────────────
   The co-mom-ity mark blown up and bled off a corner as an ambient graphic,
   the way the brand boards use it. Drop `.has-emblem` on a positioned,
   overflow-hidden panel. Inherits currentColor at low opacity. */
.has-emblem { position: relative; overflow: hidden; }
.has-emblem > * { position: relative; z-index: 1; }
.has-emblem::after {
  content: "";
  position: absolute;
  right: -8%;
  bottom: -28%;
  width: 62%;
  aspect-ratio: 867 / 543;
  background: currentColor;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
  -webkit-mask: url("/static/icons/emblem.9bd03d15ba31.svg") right bottom / contain no-repeat;
          mask: url("/static/icons/emblem.9bd03d15ba31.svg") right bottom / contain no-repeat;
}

p { margin: 0 0 var(--space-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--color-accent-text);
  text-decoration: none;
}
a:hover, a:focus-visible { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.app-header {
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.app-header__brand {
  display: inline-flex;
  align-items: center;
}
/* SVG wordmark in the logged-out header: height-constrained so the bar
   keeps its size at mobile widths; width follows the aspect ratio. */
.app-header__brand img {
  display: block;
  height: 22px;
  width: auto;
}
.app-header__brand:hover { text-decoration: none; }

.app-header__nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}
.app-header__nav a, .app-header__nav button {
  font-size: var(--fs-sm);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-5) var(--space-7);
}

.app-footer {
  padding: var(--space-5);
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

/* Elevated card — opt-in for surfaces that should feel touchable: session
   cards, library resource cards, group/member cards. Lifts on hover. The
   transition is short enough to feel responsive on a phone tap. */
.card-elevated {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.card-elevated:hover,
a.card-elevated:hover,
a.card-elevated:focus-visible {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--color-border-strong);
  text-decoration: none;
}

/* Page hero — warm gradient panel that holds the page title + lede on
   every user-facing screen. Replaces the bare H1-on-cream open with a
   soft horizon line so the page feels framed.

   Usage: wrap the title block in `<header class="page-hero">…</header>`
   at the top of the page content. Optional `.page-hero--soft` for screens
   that already have a strong visual (live session player). */
.page-hero {
  position: relative;
  padding: var(--space-3) var(--space-5) var(--space-5);
  margin-block: 0 var(--space-3);
  /* Auto-bleed: clamp the negative margin to whatever the parent's
     horizontal padding actually is. Pages whose <main> uses .app-main
     (24px padding) get -24px bleed; pages whose <main> has no padding
     (Library, Settings, Group, Sessions — they override main_class to
     use their own wider container) get 0px bleed. Either way the hero's
     text sits 24px from the viewport edge because the internal padding
     is constant. */
  margin-inline: max(calc(50% - 50vw), calc(-1 * var(--space-5)));
  background: var(--gradient-hero);
  overflow: hidden;
}
@media (min-width: 768px) {
  .page-hero {
    padding: var(--space-5) var(--space-5) var(--space-6);
    margin-bottom: var(--space-4);
  }
}
.page-hero--soft {
  background: var(--gradient-hero-soft);
}
.page-hero__eyebrow {
  display: inline-block;
  font-size: var(--fs-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-accent-text);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.page-hero h1 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-2xl);
  line-height: 1.15;
}
@media (min-width: 768px) {
  .page-hero h1 { font-size: var(--fs-3xl); }
}
.page-hero p {
  color: var(--color-text-muted);
  margin: 0;
  max-width: 32rem;
  font-size: var(--fs-sm);
}
@media (min-width: 768px) {
  .page-hero p { font-size: var(--fs-base); }
}
.page-hero__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
}
.page-hero__back {
  display: inline-block;
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

/* Friendly empty-state block — used wherever a list could be empty. The
   centered card with a tinted icon feels intentional vs. the previous
   left-aligned "Nothing yet" line. */
.empty-state {
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-5);
  text-align: center;
  max-width: 36rem;
  margin: 0 auto;
}
.empty-state__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-accent-tint);
  color: var(--color-accent-text);
  margin: 0 auto var(--space-4);
  font-size: 1.5rem;
}
.empty-state h2,
.empty-state h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--fs-xl);
}
.empty-state p {
  color: var(--color-text-muted);
  margin: 0 auto var(--space-4);
  max-width: 28rem;
}
.empty-state p:last-child { margin-bottom: 0; }

/* Avatar circle — 32px default. Initials get the deterministic palette
   index via inline style coming from the templatetag. */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--color-accent-fg);
  flex-shrink: 0;
  user-select: none;
}
.avatar--photo { overflow: hidden; }
.avatar--photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.avatar--lg { width: 48px; height: 48px; font-size: var(--fs-base); }
.avatar--xl { width: 72px; height: 72px; font-size: var(--fs-xl); }
.avatar--p1 { background: var(--avatar-1); }
.avatar--p2 { background: var(--avatar-2); }
.avatar--p3 { background: var(--avatar-3); }
.avatar--p4 { background: var(--avatar-4); }
.avatar--p5 { background: var(--avatar-5); }
.avatar-row {
  display: inline-flex;
  align-items: center;
  gap: calc(-1 * var(--space-2));
}
.avatar-row .avatar {
  margin-left: -8px;
  border: 2px solid var(--color-bg);
}
.avatar-row .avatar:first-child { margin-left: 0; }

.lede {
  color: var(--color-text-muted);
  font-size: var(--fs-lg);
  margin-bottom: var(--space-5);
}

.muted { color: var(--color-text-muted); }

.stack > * + * { margin-top: var(--space-4); }
.stack-tight > * + * { margin-top: var(--space-2); }
.stack-loose > * + * { margin-top: var(--space-6); }

.progress {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.progress__step {
  flex: 1;
  height: 3px;
  background: var(--color-border);
  border-radius: 0;
}
.progress__step--active { background: var(--color-accent); }
.progress__step--complete { background: var(--color-text); }

.cta-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
@media (min-width: 480px) {
  .cta-row { flex-direction: row; }
  .cta-row > * { flex: 1; }
}

.alert {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  font-size: var(--fs-sm);
  border: 1px solid var(--color-border);
}
.alert--error {
  background: #fbecec;
  border-color: #f3cfcf;
  color: #7a2222;
}
.alert--info {
  background: #f3eee5;
  border-color: var(--color-border);
  color: var(--color-text);
}

.legal-doc {
  font-size: var(--fs-base);
  line-height: 1.65;
}
.legal-doc h2 { font-size: var(--fs-xl); margin-top: var(--space-5); }
.legal-doc h3 { font-size: var(--fs-lg); margin-top: var(--space-4); }

.invite-code-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.invite-code-row__code,
.invite-code-row__url {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
  font-size: var(--fs-sm);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-code-row__code {
  letter-spacing: 0.08em;
  font-weight: 600;
}
.invite-code-row__btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.scroll-box {
  max-height: 14rem;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  padding: var(--space-4);
  font-size: var(--fs-sm);
  line-height: 1.55;
  white-space: pre-wrap;
}
