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

html, body {
  /* Must be a real, definite height -- not min-height -- or nothing below
     it in the flex chain has an actual ceiling to size against, and the
     internal-scroll pattern (flex:1 + min-height:0 + overflow-y:auto on
     .screen__body) has nothing to clip to. dvh over % specifically so this
     tracks the real visible viewport on mobile browsers with a dynamic
     address-bar/toolbar too, not just the Capacitor WebView (which has
     none, so 100% and 100dvh happened to agree there -- which is exactly
     why this was missed the first time). */
  height: 100dvh;
  margin: 0;
  padding: 0;
}

html {
  direction: rtl;
}

body {
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, h4, p { margin: 0; }

button {
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: not-allowed; }

::selection { background: var(--color-primary-100); color: var(--color-primary-700); }

/* App shell -------------------------------------------------------- */

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  /* Same reason .screen__body needs it below -- without this, .screen's
     own default min-height:auto lets it grow past what flex:1 allocates
     to fit whatever .screen__body's content wants to be, instead of being
     held to exactly #app's height so .screen__body is the thing that
     clips and scrolls. */
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-app);
}

.screen__body {
  flex: 1;
  /* Without this, a flex item's default min-height:auto stops it shrinking
     below its content size — it grows to fit everything instead of being
     clipped to the space flex:1 gives it, and overflow-y:auto never gets a
     chance to kick in. That silently broke three things at once on real
     Android WebView (invisible in a normal desktop-browser check, since
     desktop happened to still scroll the whole page as a fallback): the
     infinite-scroll listener below never fired because this element never
     actually scrolled, .screen grew to the height of all its content
     instead of the viewport, and every position:fixed child measured
     "bottom" against that oversized box instead of the real viewport. */
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-4) var(--space-4) calc(var(--space-8) + var(--safe-bottom));
}

.screen__body--flush { padding: 0 0 calc(var(--space-8) + var(--safe-bottom)); }

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: calc(var(--space-3) + var(--safe-top)) var(--space-4) var(--space-3);
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.appbar__title {
  flex: 1;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appbar__icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease-standard);
  position: relative;
}
.appbar__icon-btn:hover { background: var(--bg-surface-muted); }
.appbar__icon-btn:active { transform: scale(0.92); }

.center-fill {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  text-align: center;
  padding: var(--space-6);
}

/* Scrollbar ---------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* Focus ---------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}
