/* C25: THE shared screen layout (the one place it lives). home/src/layout.css is a byte copy of this file
   (scripts/test/layout-shell.test.js keeps them equal); the burst host (games/, shipped alone) follows the same rule in
   games/src/host/host.css.

   Why: the old shell was body { min-height: 100dvh; padding: safe-area } + #app { min-height: inherit } + .screen
   { flex: 1; padding } with the button pushed down by margin-top: auto. #app inherited the full 100dvh INSIDE a body
   that had already spent the safe-area insets on padding, so the page was always taller than the WebView by those
   insets (phantom scroll on every screen); every screen only had a MINIMUM height, so a long screen grew the whole
   page and its button went below the fold; and h1/p margins stacked on top of the flex gap (odd empty space).

   Now: the page is exactly one viewport tall and never scrolls. Each screen is a flex column that scrolls by
   itself only when its content really is taller, and its action bar (.screen__actions) sticks to the bottom edge
   above the system navigation bar, so the primary button is always on screen. Fonts are never shrunk to fit.

   API (for every screen, onboarding + home):
     <main class="screen">            root of a screen: fills the space under the top inset; the ONLY scroller
       ...header / content...         direct children are spaced by --screen-gap only (their own block margins are 0)
       <div class="screen__actions">  the primary button(s); sticky at the bottom, safe-area aware. JS helper:
                                        actions(...nodes) in onboarding/src/layout.js
     .screen[data-overflow]           set by watchOverflow() (layout.js) while the content is taller than the screen:
                                        the action bar then gets a backdrop so content scrolls under it cleanly.
   Logical properties only (RTL + LTR share one sheet). Chrome 100 floor: no :has(), dvh has a 100% fallback. */
:root {
  /* One spacing scale for screens (built on the 4px --space-* scale in tokens.css). */
  --screen-pad-top: var(--space-6);
  --screen-pad-inline: var(--space-5);
  --screen-pad-bottom: max(var(--space-6), env(safe-area-inset-bottom, 0px));
  --screen-gap: var(--space-4);
  --screen-head-gap: var(--space-4);   /* extra space under a step header row (back + progress bars) */
  --screen-actions-gap: var(--space-3);
  --screen-actions-pad-bottom: max(var(--space-4), env(safe-area-inset-bottom, 0px));
  --screen-max: 36rem;
}

html { block-size: 100%; }

body {
  margin: 0;
  /* Exactly one viewport: 100% of the initial containing block (= the WebView), 100dvh where supported (Chrome 108+).
     border-box (base.css) keeps the inset padding INSIDE this height. */
  block-size: 100%;
  block-size: 100dvh;
  overflow: hidden;
  /* Top / side insets here; the bottom inset belongs to whatever sits at the bottom (action bar, tab bar). */
  padding-block: env(safe-area-inset-top, 0px) 0;
  padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
}

/* W45: the keyboard overlays the page (no resizes-content): the shell is the visible area (layout.js watchKeyboard) */
html[data-kb="overlay"] body { block-size: var(--vvh, 100dvh); }

#app {
  block-size: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* a screen's enter animation (transform) can never make the page scroll */
}

.screen {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--screen-gap);
  inline-size: 100%;
  max-inline-size: var(--screen-max);
  margin-inline: auto;
  padding-block: var(--screen-pad-top) 0;
  padding-inline: var(--screen-pad-inline);
}
/* The bottom space is the last block's own margin (a scroller's end padding plus a sticky bar overcounts the
   scroll range in Chrome); an action bar at the end owns the bottom edge and its inset instead. */
.screen > :last-child { margin-block-end: var(--screen-pad-bottom); }
.screen > .screen__actions:last-child { margin-block-end: 0; }
/* Spacing between blocks comes from the gap alone: no margin stacking on top of it. */
.screen > :is(h1, h2, h3, p) { margin-block: 0; }
.screen:focus { outline: none; }

.screen__actions {
  position: sticky;
  inset-block-end: 0;
  z-index: 2;
  flex: none;
  margin-block-start: auto; /* sits at the bottom when the content is short */
  display: grid;
  gap: var(--screen-actions-gap);
  padding-block: var(--space-3) var(--screen-actions-pad-bottom);
}
.screen__actions > * { margin: 0; }
/* A bar followed by more content (the paywall's terms and restore) does not own the bottom edge. */
.screen__actions:not(:last-child) { padding-block-end: var(--space-3); }
.screen[data-overflow] > .screen__actions {
  background: linear-gradient(to bottom, transparent, var(--background) var(--space-3));
}

/* W17 (webapp fork only; onboarding/ and home/ keep C25 as it is): a FRAMED onboarding screen (layout.js frame(),
   data-framed) is three rows, as the prototype (.hdr / .body / .foot): the step header, one scrolling body, and the
   action bar below the body. The column itself reserves the bar's real height at every text size and locale, so
   content can never sit under the bar (a tap on what you see is a tap on it) and the header never scrolls away. */
.screen[data-framed] { overflow: hidden; gap: 0; }
.screen[data-framed] > .hdr { flex: none; }
.screen[data-framed] > .screen__body:last-child { margin-block-end: 0; padding-block-end: var(--screen-pad-bottom); }
.screen__body {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: var(--screen-gap);
  /* full width scroller (card shadows keep their room), content keeps the screen's side padding */
  margin-inline: calc(-1 * var(--screen-pad-inline));
  padding-inline: var(--screen-pad-inline);
  padding-block: var(--screen-gap) var(--space-4);
}
.screen__body > * { flex-shrink: 0; }
.screen__body > :is(h1, h2, h3, p) { margin-block: 0; }
.screen[data-framed] > .screen__actions {
  position: relative;
  margin-block-start: 0;
  max-block-size: 60%; /* a very short window still shows some of the body; the bar then scrolls by itself */
  overflow-y: auto;
  background: var(--background);
}
/* content continues below the fold: a thin edge on the bar says "more above, scroll" (no fade over the content) */
.screen[data-framed][data-overflow] > .screen__actions { background: var(--background); box-shadow: 0 -1px 0 var(--line, rgba(0, 0, 0, 0.08)); }
