/* The page layout that never changes (WP2; core DESIGN §3.2): header#top, div#stage, main#view, nav#tabs, #layer-sheets.
 * Forked from demo app.css @7aafc93 L41 (.app)
 * Forked from demo app.css @7aafc93 L44-50 and L58-61 (header, brand, flow title, back and its word)
 * Forked from demo app.css @7aafc93 L91-92 and L54-56 (the grown-ups key, its icon-only phone form)
 * Forked from demo app.css @7aafc93 L64-65 (main.view, .no-tabs)
 * Forked from demo app.css @7aafc93 L150-163 (bottom tab bar)
 * Forked from demo app.css @7aafc93 L675-676, L679 and L700-704 (tablet and desktop widths)
 * Forked from demo app.css @7aafc93 L744-746 (reduced motion: the tab press)
 * Changes: the header is header#top with one class per View.chrome (is-tabs, is-flow, is-overlay, is-none); the
 * grown-ups key is a 60 px target on every chrome (the demo's was 48 px); the 'overlay' chrome and every chrome over a
 * shown stage float transparent over #stage, their buttons on --overlay-bg; the tab bar takes the build's tab count
 * (--tabs) and stays at the bottom at every width (no header tabs, no flowbar); the persistent #stage layer is new:
 * fixed under the view, hidden but attached while a route hides it, and while it shows the view passes pointers through
 * to it except on its controls; the kitchen's dev tiles are styled here (html[data-app="kitchen"] only, the kitchen has
 * no stylesheet of its own); a screen without chrome gets its own top padding. */

.app { position: relative; width: 100%; min-height: 100dvh; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }

/* The one 3D layer: under everything, never rebuilt; a hidden route keeps its canvas attached and its rAF stopped. */
#stage { position: fixed; inset: 0; z-index: var(--z-stage); background: var(--sand); overflow: hidden; }
html:not(.stage-on) #stage { visibility: hidden; pointer-events: none; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* Header: brand + grown-ups key; a flow screen swaps the brand for back + title. */
#top { position: relative; width: 100%; z-index: var(--z-top); }
.top-in { display: flex; align-items: center; gap: 12px; padding: 14px var(--gutter) 6px; min-height: var(--head); max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: 0; min-width: 0; }
.brand img { width: 34px; height: 34px; object-fit: contain; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flow-title { margin: 0; min-height: 1px; font-size: 22px; font-weight: 800; letter-spacing: 0; line-height: 1.15; flex: 1; text-align: center; min-width: 0; overflow-wrap: anywhere; }
.top-gap { flex: none; width: var(--tap); }
.btn.back { min-width: var(--tap); min-height: var(--tap); padding: 0 18px 0 12px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow), var(--press);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; flex: none; font-weight: 750; font-size: var(--label); }
/* Back is an icon plus its word in 6-8 (an arrow alone carries no meaning for a non-reader); 9-10 shows the round icon. */
html.older .btn.back { width: var(--tap); padding: 0; }
html.older .back-word { display: none; }
/* The grown-ups key: quiet, top right, 60 px; its word on tab screens, the icon alone on flows and over the stage. */
.btn.grownups { margin-left: auto; min-height: var(--tap); min-width: var(--tap); padding: 0 16px; border-radius: 999px; background: transparent; color: var(--muted);
  font-weight: 650; font-size: var(--muted-size); display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; }
.btn.grownups .ico { width: 24px; height: 24px; }
.btn.grownups.icon-only { width: var(--tap); padding: 0; }
#top.is-flow .btn.grownups, #top.is-overlay .btn.grownups { margin-left: 0; }
/* On a phone the brand keeps its whole name: the key's word stays its label but leaves the bar. */
@media (max-width: 429px) {
  #top .btn.grownups.has-word { width: var(--tap); padding: 0; }
  #top .btn.grownups.has-word span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* Over the live stage: the header floats, transparent; only its controls take pointers. */
#top.is-overlay, html.stage-on #top { position: fixed; inset: 0 0 auto 0; background: transparent; pointer-events: none; padding-top: env(safe-area-inset-top); }
#top.is-overlay :is(button, a), html.stage-on #top :is(button, a) { pointer-events: auto; }
#top.is-overlay .btn.back, #top.is-overlay .btn.grownups, html.stage-on #top .btn.back, html.stage-on #top .btn.grownups {
  background: var(--overlay-bg); color: var(--overlay-ink); box-shadow: var(--shadow), var(--press); }
/* No backdrop blur over the live stage: it would read the 3D canvas back every frame on a phone. */
html.stage-on #top .brand { padding: 6px 14px 6px 8px; border-radius: 999px; background: var(--overlay-bg); color: var(--overlay-ink); }
#top.is-overlay .flow-title { flex: 0 1 auto; margin: 0 auto; padding: 8px 16px; border-radius: 999px; background: var(--overlay-bg); color: var(--overlay-ink); font-size: 20px; }
#top.is-overlay .flow-title:empty { visibility: hidden; }

/* The view: the route's panel. */
main.view { position: relative; z-index: var(--z-view); flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 4px var(--gutter) calc(136px + env(safe-area-inset-bottom)); }
main.view.no-tabs { padding-bottom: calc(36px + env(safe-area-inset-bottom)); --dock: var(--edge); }
/* Over a shown stage the view is the HUD: the stage gets every pointer except on the view's own controls. */
html.stage-on main.view { max-width: none; min-height: 100dvh; padding: calc(var(--head) + 8px) var(--gutter) var(--edge); pointer-events: none; }
html.stage-on main.view :is(button, a, input, select, label, [role="button"], [data-pad], [data-talk], [data-player], [data-hit], .card, .sheet, .still-card) { pointer-events: auto; }

/* Bottom tab bar: the build's tabs, icon + one word, lifted clear of the bottom 24 px where wrists and thumbs rest. */
#tabs.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: var(--edge); width: calc(100vw - 32px); max-width: 520px;
  display: grid; grid-template-columns: repeat(var(--tabs, 4), minmax(0, 1fr)); background: rgba(255, 251, 243, .95); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-radius: 999px; box-shadow: var(--shadow-lift); padding: 5px; z-index: var(--z-top); }
.tab { min-height: 64px; border-radius: 22px; padding: 4px 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 0.9375rem; font-weight: 700; letter-spacing: 0; color: var(--ink); text-decoration: none; min-width: 0; transition: transform var(--t-micro) var(--spring); }
/* A label too long for a narrow tab wraps (at its soft hyphen), never clips. */
.tab span { max-width: 100%; text-align: center; line-height: 1.05; hyphens: manual; }
.tab img { width: 32px; height: 32px; object-fit: contain; }
.tab .tab-ico { width: 30px; height: 30px; }
.tab:active { transform: scale(.96); }
/* Where am I: the one selection pattern (coral field + coral-deep keyline), readable in grayscale. */
.tab[aria-current="page"] { background: var(--coral-field); color: var(--coral-deep); box-shadow: 0 0 0 3px var(--coral-deep); }

/* Sheets, the break and toasts stack over the app (their looks are grownup.css and base.css). */
#layer-sheets { position: relative; z-index: var(--z-sheet); }

/* A route that could not be shown: the still card, centred. */
.route-still { display: grid; place-items: center; min-height: 50dvh; }

/* The kitchen's dev pages (the core's own test app, never a build). */
html[data-app="kitchen"] .kx-home h1 { font-size: 34px; font-weight: 850; margin: 8px 0 16px; }
html[data-app="kitchen"] .kx-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--tap-gap); }
html[data-app="kitchen"] .kx-tile { min-height: 76px; border-radius: 22px; background: var(--card); box-shadow: var(--shadow), var(--press); padding: 10px 14px;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; text-align: left; font-weight: 800; font-size: var(--label); }
html[data-app="kitchen"] .kx-tile small { color: var(--muted); font-weight: 650; font-size: 0.875rem; }
html[data-app="kitchen"] .kx-page .say.card { display: block; width: fit-content; max-width: 100%; margin: 8px 0; padding: 14px 18px; cursor: default; }

/* Tablet and up */
@media (min-width: 640px) {
  :root { --gutter: 28px; }
  #tabs.tabbar { width: min(560px, calc(100vw - 48px)); }
}
/* Desktop: content up to 1200 px; the bar stays at the bottom (a phone-first app). */
@media (min-width: 960px) {
  :root { --gutter: 40px; --head: 80px; }
  .top-in { padding: 10px var(--gutter); }
  main.view, main.view.has-tabs, main.view.no-tabs { padding-top: 12px; }
}

/* A screen without chrome (the grown-up setup) still keeps its card clear of the top edge, at every width. */
main.view.is-none { padding-top: max(24px, var(--gutter)); }

@media (prefers-reduced-motion: reduce) {
  .tab:active { transform: none; filter: brightness(.93); transition: filter var(--t-calm); }
}
