/* ═══════════════════════════════════════════════════════════════════════════
   app.css — application-only positioning + layout glue.
   This file MUST NOT define new visual styles. It exists solely to:
     · place cf-modal inside a real fullscreen overlay,
     · pin app shell elements (FAB, route panel, notify toast, etc.),
     · provide hide/show toggles for elements behaviorally controlled by JS.
   All visual tokens come from component-library.css (locked).
   ═══════════════════════════════════════════════════════════════════════════ */

/* Reset body backdrop to the page surface so map fills the viewport */
html, body { height: 100%; }
body { background: var(--surface-page); }

/* Stop mobile WebViews (iOS Safari / Android Chrome) from auto-inflating the
   font of text blocks they heuristically treat as "main content". Long point
   descriptions (.cf-card-stop-text) were getting boosted well past their 18px
   token while short ones stayed put — the "sometimes the description font gets
   really big" report. Pinning to 100% keeps our token sizes; pinch-zoom (a
   separate mechanism) still works for accessibility. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* text-size-adjust alone did NOT fully stop it (#282 recurred): the Android
   System WebView's text-autosizing pass ignores text-size-adjust and boosts
   long paragraphs anyway. That pass SKIPS any element carrying an explicit
   max-height, so we opt the point description + question out of it with an
   effectively-unbounded max-height (never clips). Descendants inherit the size
   so any stray inline markup in the LLM-authored context can't scale either —
   the font is now static regardless of length or content. */
.cf-card-stop-text, .cf-card-stop-question { max-height: 1000000px; }
.cf-card-stop-text *, .cf-card-stop-question * { font-size: inherit; line-height: inherit; }

/* ── Modal overlay (fullscreen backdrop wrapper for cf-modal) ────────────── */
.cf-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--surface-modal);        /* alpha-black-40 */
  display: none;
  align-items: center;
  justify-content: center;
  /* Safe-area-aware gutters so a tall modal — and its absolutely-positioned
     top-right close X — never land under the status bar or the Android nav bar
     (Trello #252/#256: the X sat against the status bar and the modal footer
     hid behind the nav bar). --safe-top is the notch inset on iOS and 0 on
     Android (the shell already offsets the WebView top); env() adds the bottom
     nav-bar / home-indicator gap. Falls back to the plain 24px on web. */
  padding: calc(var(--scale-600) + var(--safe-top)) var(--scale-600) calc(var(--scale-600) + var(--safe-bottom));
  z-index: 9100;                            /* above route-panel (1100) and legacy modal-overlay (2000) */
}
.cf-modal-overlay.open { display: flex; }

/* The guest / pre-register popup outranks the auth overlay (#auth-overlay is
   z 9999 in style_v2.css). The tutorial handoff opens it while a failed guest
   boot may have the login forms up underneath, and the in-app wall is always
   the top-most prompt when it fires — so it must never sit behind the forms.
   (Terms/Privacy modal is 10001, still above this.) */
#guest-caveat-overlay { z-index: 10000; }

/* Confirm buttons carrying a full-sentence label (e.g. the delete-account
   confirmation) need to wrap — the base .cf-btn is nowrap + fixed height. */
.cf-btn.cf-btn-multiline {
  white-space: normal;
  height: auto;
  min-height: var(--scale-1100);
  padding-top: var(--scale-300);
  padding-bottom: var(--scale-300);
}

/* Allow the modal card to scroll if its content exceeds the viewport.
   position:relative anchors the absolute .cf-modal-close to the card — the
   canonical library's base .cf-modal is unpositioned, so without this the X
   escapes to the fixed overlay's top-right corner (near the profile icon).
   Applied once here so every overlay-hosted modal is covered, not per-variant. */
.cf-modal-overlay .cf-modal {
  position: relative;
  /* Cap matches the overlay's safe-area gutters above so the card scrolls
     internally instead of pushing its footer (and the close X's reference box)
     under a system bar (Trello #252/#256). */
  max-height: calc(100vh - var(--scale-1200) - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
}

/* Native <select> inside cf-field: strip the OS chevron — cf-field already
   renders a Phosphor caret in the .caret slot. */
.cf-field select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: 0;
  outline: none;
  font: inherit;
  color: inherit;
  width: 100%;
  cursor: pointer;
}

/* Q/A row inside the submit-node modal — JS-generated. Two cf-fields side
   by side + a ghost remove button. */
.qa-pair {
  display: flex;
  gap: var(--scale-200);
  align-items: flex-start;
  margin-bottom: var(--scale-200);
}
.qa-pair > .cf-field { flex: 1; min-width: 0; }

/* ── Shop / Wallet (#gemStoreModal) ──────────────────────────────────────────
   Layout glue for the Wallet screen (Figma "Shop" 3980:19548). Every component
   inside it is a library one (cf-modal, cf-separator, cf-tag, cf-tag-gems,
   cf-btn) and is NOT restyled here — these rules only place them and build the
   three containers the library has no component for: the balances card, the
   IAP pack row, and the gem→coin exchange card. Tokens only, no raw values. */
/* The Wallet uses the library's Full screen modal (`.cf-modal.full-screen`),
   so this overlay must not letterbox it the way the standard 386-px card is:
   drop the scrim gutter and hand the modal the whole viewport. The generic
   `.cf-modal-overlay .cf-modal` scroll cap above is undone here too — a
   full-screen modal scrolls in its own `.cf-fs-modal-content` slot instead. */
#gemStoreModal { padding: 0; }
#gemStoreModal .cf-modal.full-screen {
  max-height: none;
  height: 100%;
  overflow: hidden;
}
/* Keep the close X off the heading. The full-screen header starts at
   padding-top Scale/400, so top: Scale/200 lands the 40-px button's centre on
   the H6 centre (8 + 20 = 28 = header pt 16 + h6 line-height / 2). */
.shop-modal .cf-modal-close { top: var(--scale-200); right: var(--scale-400); }
.shop-modal .cf-fs-modal-title { padding-right: var(--scale-1200); }   /* 48 — close button footprint */

/* The pinned wallet card sits between the heading and the scroll slot. It is
   flex-shrink:0 so it keeps its height while `.cf-fs-modal-content` (flex:1)
   absorbs the rest and does the scrolling. The heading's bottom padding is
   trimmed to Scale/400 here so the gap above the card is the design's 16, not
   the full-screen header's default 24. */
.shop-modal .cf-fs-modal-header { padding-bottom: var(--scale-400); }
.shop-balances-slot {
  flex-shrink: 0;
  padding: 0 var(--scale-600) var(--scale-400);   /* 24 gutters, 16 below */
}

.shop-content {
  display: flex;
  flex-direction: column;
  gap: var(--scale-400);                       /* 16 */
  padding: 0 var(--scale-600) var(--scale-600);   /* 24 gutters, matching the fs header */
}
.shop-section {
  display: flex;
  flex-direction: column;
  gap: var(--scale-50);                        /* 2 — separator hugs its list */
}

/* Balances — two columns split by a hairline, on a purple→peach wash. */
.shop-balances {
  display: flex;
  align-items: stretch;
  gap: var(--scale-400);                       /* 16 */
  padding: var(--scale-400);
  border-radius: var(--radius-xlg);            /* 16 */
  background: linear-gradient(104deg, var(--surface-information) 0%, var(--surface-orange-background) 100%);
}
.shop-balance {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--scale-300);                       /* 12 */
}
.shop-balances-divider {
  width: var(--border-w-sm);
  align-self: stretch;
  background: var(--border-default);
  flex-shrink: 0;
}
/* One line: icon, amount, currency word. The amount (H6, Lexend) and the word
   (Body md, Work Sans) are different sizes, so they're aligned on the text
   BASELINE — centring them would leave the word floating off the number's
   line. The icon opts out of baseline alignment and centres on the row. */
.shop-balance-amount {
  display: flex;
  align-items: baseline;
  gap: var(--scale-200);                       /* 8 */
  margin: 0;
  font-family: var(--font-family-headings);
  font-weight: var(--font-weight-bold);
  font-size: var(--text-h6-size);
  line-height: var(--text-h6-line-height);
  color: var(--text-headings);
}
.shop-balance-icon {
  width: var(--scale-700); height: var(--scale-700);   /* 28 */
  flex-shrink: 0;
  align-self: center;                          /* a replaced element has no useful baseline */
}
.shop-balance-unit {
  font-family: var(--font-family-text);
  font-weight: var(--font-weight-regular);
  font-size: var(--text-body-sm-size);            /* Body sm — buys the width the
                                                     360-px Android layout needs */
  line-height: var(--text-body-sm-line-height);
  color: var(--text-label);
}
.shop-balance-note { color: var(--text-body); margin: 0; }

/* IAP pack rows */
.shop-packs {
  display: flex;
  flex-direction: column;
  gap: var(--scale-400);                       /* 16 — leaves room for the overhanging badge */
  padding-top: var(--scale-100);
}
.shop-pack {
  position: relative;                          /* anchors the overhanging .cf-tag badge */
  display: flex;
  align-items: center;
  gap: var(--scale-400);                       /* 16 */
  padding: var(--scale-400) var(--scale-400) var(--scale-400) var(--scale-300);
  border: var(--border-w-sm) solid transparent;
  border-radius: var(--radius-lg);             /* 8 */
  background: var(--surface-background);
}
.shop-pack.featured {                          /* Best value — peach fill + orange outline */
  background: var(--surface-orange-background);
  border-color: var(--border-action);
}
.shop-pack-meta {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--scale-100);                       /* 4 */
}
.shop-pack-title {
  margin: 0;
  font-family: var(--font-family-headings);
  font-weight: var(--font-weight-bold);
  font-size: var(--text-h7-size);
  line-height: var(--text-h7-line-height);
  color: var(--text-headings);
}
.shop-pack-sub { color: var(--text-label); margin: 0; }
.shop-pack-badge {                             /* library .cf-tag, pulled onto the row's top edge */
  position: absolute;
  top: calc(var(--scale-500) * -0.5);          /* -10 — half the xsm tag height */
  left: var(--scale-400);
}
.shop-pack .cf-btn { flex-shrink: 0; min-width: var(--scale-2000); }   /* 80 */

/* Exchange card — stepper → result, then the confirm button. */
.shop-rate { color: var(--text-information); gap: var(--scale-100); }
.shop-rate-part { display: inline-flex; align-items: center; gap: var(--scale-100); }
.shop-rate-icon { width: var(--scale-400); height: var(--scale-400); }   /* 16 */

.shop-exchange {
  display: flex;
  flex-direction: column;
  gap: var(--scale-300);                       /* 12 */
  padding: var(--scale-400);
  border-radius: var(--radius-lg);
  background: var(--surface-information);
  margin-top: var(--scale-100);
}
.shop-exchange-row {
  display: flex;
  align-items: center;
  gap: var(--scale-400);                       /* 16 */
}
.shop-stepper {                                /* outlined-button shell holding three controls */
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--scale-300);
  height: var(--scale-1000);                   /* 40 — cf-btn default height */
  padding: 0 var(--scale-300);
  border: var(--border-w-sm) solid var(--border-default);
  border-radius: var(--radius-lg);
  background: var(--surface-page);
}
.shop-stepper-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--scale-400); height: var(--scale-400);
  padding: 0; border: 0; background: transparent;
  color: var(--icon-default);
  cursor: pointer;
  flex-shrink: 0;
}
.shop-stepper-btn .ph { font-size: var(--scale-400); }
.shop-stepper-btn[disabled] { color: var(--icon-disabled); cursor: default; }
.shop-stepper-value {
  flex: 1 1 0;
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--scale-200);
  font-family: var(--font-family-text);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-body-md-size);
  line-height: var(--text-body-md-line-height);
  color: var(--text-body);
}
.shop-exchange-arrow { color: var(--icon-label); flex-shrink: 0; }
.shop-exchange-arrow .ph { font-size: var(--scale-600); }   /* 24 */
.shop-exchange-out {
  flex: 1 1 0;
  display: flex; align-items: center;
  gap: var(--scale-200);
  font-family: var(--font-family-headings);
  font-weight: var(--font-weight-bold);
  font-size: var(--text-h6-size);
  line-height: var(--text-h6-line-height);
  color: var(--text-headings);
}
.shop-exchange-icon { width: var(--scale-400); height: var(--scale-400); }   /* 16 */
.shop-exchange .cf-btn { width: 100%; }

/* Very narrow phones only. The cutoff sits BELOW 360: that is the commonest
   Android CSS width, and stacking there cost the two-column wallet on a large
   share of real devices. At 340 and under the columns genuinely stop working —
   the notes wrap to five lines — so there they stack. */
@media (max-width: 340px) {
  .shop-balances { flex-direction: column; }
  .shop-balances-divider { width: auto; height: var(--border-w-sm); }
  .shop-pack { gap: var(--scale-300); }
  .shop-pack .cf-btn { min-width: 0; padding: 0 var(--scale-200); }
}

/* Service note / empty state inside either list */
.shop-note { color: var(--text-label); margin: 0; padding: var(--scale-300) 0; }

/* Featured route card — vertical layout with hero image, used inside the
   featured-routes cf-modal. Uses library tokens. */
.route-card {
  background: var(--surface-page);
  border: var(--border-w-sm) solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--scale-300) var(--scale-400);
  margin-bottom: var(--scale-300);
  display: flex;
  flex-direction: column;
  gap: var(--scale-100);
}
.route-card-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--surface-darker-background);
  margin-bottom: var(--scale-100);
}
.route-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--scale-200);
  margin-top: var(--scale-100);
}
.route-card-price {
  color: var(--text-warning);
}

/* ── Tap targets in places that need them ────────────────────────────────── */
.cf-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--scale-1000);
  height: var(--scale-1000);
  border-radius: var(--radius-lg);
  background: transparent;
  border: 0;
  cursor: pointer;
  color: var(--icon-default);
}
.cf-icon-btn:hover { background: var(--surface-darker-background); }

/* Point popover (USER_RIDDLES §2-3): tap a map dot → place name + author + Route here. */
.node-popover { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.node-popover-title { font-weight: 600; font-size: 14px; }
.node-popover-sub { font-size: 12px; color: #6b6b73; }
.node-popover-cms { font-size: 12px; }

/* Create-a-riddle popup (USER_RIDDLES §2.5) */
.riddle-overlay { position: fixed; inset: 0; z-index: 4000; background: rgba(10,12,18,.72); display: flex; align-items: center; justify-content: center; padding: 20px; }
.riddle-panel { width: 100%; max-width: 440px; background: #fff; border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 90vh; overflow-y: auto; }
.riddle-panel-title { margin: 0; font-size: 16px; }
.riddle-q { width: 100%; min-height: 70px; resize: vertical; border: 1px solid #d7d7dd; border-radius: 10px; padding: 8px; font: inherit; }
.riddle-opts { display: flex; flex-direction: column; gap: 6px; }
.riddle-opt-row { display: flex; align-items: center; gap: 8px; }
.riddle-opt { flex: 1; border: 1px solid #d7d7dd; border-radius: 8px; padding: 7px 8px; font: inherit; }
.riddle-actions { display: flex; gap: 8px; justify-content: flex-end; }
.riddle-msg { font-size: 13px; color: #6b6b73; min-height: 18px; }
.create-riddle-link { align-self: flex-start; margin-top: 6px; }

/* Artifact avatar (USER_CARD §4): an artifact image cropped to the avatar circle. */
.cf-avatar.has-image { overflow: hidden; padding: 0; }
.cf-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Friends page (FRIENDS §3). Rows and the add-a-friend form are composed from
   the library List family (.cf-list-item*, component-library.css); the invite
   code block reuses the profile referral styles (.cf-profile-referral*). Only
   the code-input text treatment below is friends-specific. */
.fr-code-input { text-transform: uppercase; }
/* Invite-code QR (FRIENDS §3a): centered, with a quiet zone + hairline so the
   dark modules always sit on a scannable light card. */
.fr-qr { display: flex; justify-content: center; }
.fr-qr img, .fr-qr canvas {
  padding: var(--scale-300);
  background: var(--surface-card);
  border: var(--border-w-sm) solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
/* In-app scanner: square camera viewport inside the standard modal card. */
.fr-scan-modal { display: flex; flex-direction: column; gap: var(--scale-300); width: min(90vw, 360px); }
.fr-scan-video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-lg); }
.fr-code-input::placeholder { text-transform: none; letter-spacing: normal; color: var(--text-label-light); }
.fr-add-msg:empty { display: none; }
.cf-separator .cf-sep-badge { margin-left: 6px; background: #4285f4; color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; }
