/* Reset + phone-first app shell. Lexend (self-hosted — see styles/fonts.css) is
   the UI typeface; the system-ui fallback keeps the layout identical until it
   paints. The font ships from THIS origin, so the showcase still makes no
   external / third-party font request — self-contained + privacy-safe. */

* { box-sizing: border-box; margin: 0; padding: 0; }

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

/* FB2-3 — vertical-swipe / overscroll guard. Pure CSS, active in every context
   (plain-URL preview AND inside Telegram): keep drags from chaining to the page
   so a top/bottom overscroll can't trigger the client's swipe-to-close or the
   browser's pull-to-refresh. Pairs with the feature-detected
   WebApp.disableVerticalSwipes() in theme.js. */
html, body { overscroll-behavior-y: none; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: #ded7c9;                 /* desktop backdrop behind the phone frame */
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] body { background: #0e0d0a; }

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; color: inherit; }

/* iOS input-focus zoom guard: mobile Safari auto-zooms into any focused form
   control whose text is < 16px (and never zooms back out on blur). The design
   uses 15px body text, so on phone-width viewports we bump form controls to 16px
   — the standards-safe fix. We deliberately do NOT set user-scalable=no /
   maximum-scale on the viewport (that stops the zoom too, but breaks pinch-zoom
   accessibility). Scoped to phone widths so the desktop preview keeps the 15px
   type. Pairs with -webkit-text-size-adjust: 100% above. */
@media (max-width: 480px) {
  input, select, textarea { font-size: 16px; }
}
a { color: var(--green); text-decoration: none; }
ul { list-style: none; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 4px; }

/* ---- phone frame ---- */
.app-frame {
  position: relative;
  width: 100%;
  max-width: var(--frame-w);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 440px) {
  body { padding: 24px 0; }
  .app-frame {
    min-height: min(880px, calc(100dvh - 48px));
    height: min(880px, calc(100dvh - 48px));
    border-radius: 28px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
    border: 1px solid var(--border);
    /* Establish a containing block so viewport-fixed shell primitives (bottom
       navigation and shared overlays) stay inside the framed phone rather than
       covering the desktop window. No visual transform: translateZ(0) only
       promotes the frame. */
    transform: translateZ(0);
  }
}

/* ---- a screen: optional top bar, scroll body, optional bottom nav ---- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.screen.dark-screen { background: #23221b; color: #fff; }

.screen-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.screen-scroll.tight { gap: 12px; }
.screen-scroll.flush { padding-left: 0; padding-right: 0; }
.app-frame.overlay-open > .screen .screen-scroll {
  overflow: hidden;
  touch-action: none;
}

/* ---- top bar (pushed screens) ---- */
.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg);
}
.topbar__title { font-size: var(--fs-h); font-weight: 700; flex: 1; }
.topbar__title.center { text-align: center; }
.topbar .iconbtn { flex: 0 0 auto; }
.topbar__spacer { width: 40px; flex: 0 0 auto; }

/* ---- bottom nav ---- */
/* Pinned to the VISIBLE viewport bottom (not laid out in the scroll flow). On
   phone widths the frame IS the viewport, so `fixed` keeps the nav on the true
   bottom fold — it can no longer be pushed below the fold or scrolled away when
   the Telegram WebView reports a viewport taller than the visible area (the
   reported bug). It spans the frame via the centred max-width and reserves the
   iPhone home-indicator inset (env(safe-area-inset-bottom), needs the
   viewport-fit=cover meta, which index.html sets). On desktop (>=440px) the
   framed phone becomes the containing block (see .app-frame) so the nav pins to
   the frame rather than the browser window. */
.bottomnav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--frame-w);
  z-index: 50;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--border);
  background: var(--card);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
/* Reserve room so page content is never hidden behind the fixed nav (only on the
   tab screens that actually have one — pushed screens keep their own padding). */
.screen:has(> .bottomnav) .screen-scroll {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
}
/* Hide persistent navigation while the software keyboard is genuinely occluding
   the viewport; it must never float above the keyboard while someone types. */
#app.keyboard-open .bottomnav {
  transform: translate(-50%, calc(100% + env(safe-area-inset-bottom, 0px)));
  visibility: hidden;
  pointer-events: none;
}
.history-results { display: flex; flex-direction: column; gap: 16px; }
.bottomnav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.bottomnav__item.active { color: var(--green); }
.bottomnav__item svg { width: 22px; height: 22px; }
.bottomnav__fab {
  flex: 0 0 auto;
  width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bottomnav__fab button {
  width: 56px; height: 56px;
  margin-top: -14px;
  border-radius: var(--r-pill);
  background: var(--green-solid);
  color: var(--on-green);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-fab);
}
.bottomnav__fab svg { width: 24px; height: 24px; }

/* ---- generic layout utilities ---- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.gap-8 { gap: 8px; }
.stack.gap-16 { gap: 16px; }
.stack.gap-20 { gap: 20px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.strong { font-weight: 700; }
.green-text { color: var(--green); font-weight: 600; }
.danger-text { color: var(--danger); font-weight: 600; }
.hidden { display: none !important; }

.section-label {
  font-size: var(--fs-label);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.screen-greeting { font-size: var(--fs-display); font-weight: 700; line-height: 1.15; }
.screen-sub { color: var(--muted); font-size: var(--fs-sm); }

.divider { height: 1px; background: var(--border); border: 0; }

/* subtle slide-in between screens (transform-only, so a mid-frame capture is
   never faint) */
@keyframes screen-in { from { transform: translateY(6px); } to { transform: none; } }
.screen { animation: screen-in 0.16s ease; }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }
