/*
 * Klyp shared app stylesheet — on-brand building blocks for funky apps.
 * Self-hosted Plus Jakarta Sans (same face as the feed shell) so apps match the app-store type system AND
 * still load instantly offline (woff2 vendored under /apps/fonts, precached by the SW).
 * Include with: <link rel="stylesheet" href="/apps/klyp-app.css">
 */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/apps/fonts/jakarta.woff2") format("woff2");
}
@font-face { /* latin-ext (accented creator/app names) */
  font-family: "Plus Jakarta Sans";
  font-style: normal; font-weight: 200 800; font-display: swap;
  src: url("/apps/fonts/jakarta-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  /* SHARED SAFE-TOP: the reserved band the host top chrome floats over — post the
     2026-07 tab-bar redesign that's ONE row: streak chip (left, bottom ≈ inset+46px)
     and coin jar (right, bottom ≈ inset+52px); search/daily/rank live in the bottom
     tab bar now. 64px = jar worst-case + 12px breathing (was 92px for the retired
     two-row pill stack — every app gets ~28px of its screen back). Any app whose
     content sits at the top MUST pad with this — one source of truth. */
  --klyp-safe-top: calc(env(safe-area-inset-top) + 64px);
  /* SHARED SAFE-BOTTOM: the reserved strip the host bottom chrome (the ~58px nav /
     coin-jar / progress bar) floats over. Mirrors --klyp-safe-top. Full-bleed apps
     pad their play-zone with this (via .klyp-stage) so nothing tappable hides under
     the bottom strip. Additive: existing apps ignore it. */
  --klyp-safe-bottom: calc(58px + env(safe-area-inset-bottom));
  --cream: #FEFAF6;
  --cream-2: #F5EDE4;
  --coral: #E07A5F;
  --coral-dark: #C4593F;
  --teal: #7BA7BC;
  --purple: #9B72CF;
  --gold: #F2CC8F;
  --green: #81B29A;
  --ink: #1A1816; /* warm-black — aligned to the feed's canonical --text-primary (was #2D2A26, the deprecated ink) */
  --ink-2: #6B6560;
  --ink-3: #9B948D;
  --line: #E8DFD5;
  /* serif is RESERVED for the result-card score reveal only (.df-score) — the one editorial flourish; every
     other heading/number/body is Plus Jakarta Sans, matching the feed shell (founder call 2026-07-15). */
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
/* FRAMED-BY-THE-FEED (L15): the feed insets the app iframe below the top band and above the identity strip
   (globals.css --top-h/--strip-h), so the host ALREADY clears the chrome. Re-applying the full safe bands
   INSIDE the frame double-counts them → a big empty void above (and below) every app (the 64px shoved
   margin:auto content down so the top void dwarfed the bottom). klyp.js tags <html> .klyp-framed only for
   the feed's <iframe class="klyp-app-frame"> (NOT standalone /a/<slug> or previews), so here we collapse the
   bands to a small SYMMETRIC breathing gap. The notch is the host band's job now, so no env().
   We deliberately KEEP the shared .k-wrap { margin:auto }: in a scrolling flex column that is the correct
   "centre-if-it-fits, top-anchor-and-scroll-if-it-doesn't" behaviour (auto-margins split free space when
   content fits → centred; collapse to 0 when it overflows → top-aligned + scrollable, never top-clipped
   unlike justify-content:center). With the padding fixed, that reads exactly right. */
html.klyp-framed {
  --klyp-safe-top: 12px;
  --klyp-safe-bottom: 12px;
}
/* #5 — when a framed app OVERFLOWS (a utility taller than the middle), show a slim right scrollbar so
   "there's more" is discoverable. Only renders when actually scrollable (overflow-y:auto). Reliable on
   Chromium/Android; iOS keeps its overlay bar (best-effort). Non-scrolling apps show no track. */
html.klyp-framed body { scrollbar-width: thin; scrollbar-color: rgba(120,120,130,0.5) transparent; }
html.klyp-framed body::-webkit-scrollbar { width: 4px; }
html.klyp-framed body::-webkit-scrollbar-thumb { background: rgba(120,120,130,0.5); border-radius: 999px; }
/* V1a FIT FLOOR — the floor-below-the-floor: when a locked-layout app would need <0.7 scale to fit
   (unreadable), klyp.js unlocks BODY scroll instead so every control stays reachable. Body only —
   html stays non-scrolling (the L9 single-scroller law; a second scroll container freezes Android). */
html.klyp-fit-scroll body { overflow-y: auto !important; height: auto !important; min-height: 100%; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }

/* ── Attract-mode preview: keep the feed swipeable ──────────────────────────
   While the host is auto-demoing this app (body.klyp-attracting, toggled by the SDK),
   force every element to allow vertical pan so a swipe-up/down still reaches the host
   feed — apps lock their play surface to touch-action:none for gameplay, which
   otherwise eats the swipe during the preview (the "can't scroll while demo plays"
   bug). The SDK's tap-vs-drag detector still starts the game on a clean tap. */
body.klyp-attracting,
body.klyp-attracting * { touch-action: pan-y !important; }

/* During the host auto-demo the HOST renders the name + one-line "what to do"
   (the .klyp-attract-label, positioned correctly BELOW the top chrome). Hide the
   app's own standard header (.k-h1/.k-sub) while attracting so the name isn't
   doubled and never sits tucked under the streak/daily/rank pills. The demo itself
   shows the play + score; the app's header returns the moment real play starts.
   (Apps that self-name via Klyp.attract(...,{named:true}) keep their own header.) */
body.klyp-attracting .k-h1,
body.klyp-attracting .k-sub { visibility: hidden; }

/* ── Attract-demo "scorecard" flash (shared by every auto-demo app) ─────────────
   When the demo finishes a round it flashes the score on a real CARD, not a flat
   wash: an OPAQUE blurred backdrop (so the playfield never bleeds through — was the
   tap-speed "TAP! shows behind the score" bug) + a glassy rounded panel with a big
   serif score in the app's accent. Each app only sets `--df-accent` (its score
   colour) + wraps its emoji/score/sub in `.df-card`. Markup:
     <div class="demo-flash" id="demoFlash"><div class="df-card">
        <div class="df-emoji">🫧</div><div class="df-score">0 popped</div>
        <div class="df-sub">now make a friend beat it 😏</div></div></div> */
.demo-flash {
  position: fixed; inset: 0; z-index: 9;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  pointer-events: none; opacity: 0; transition: opacity .26s ease;
  background: radial-gradient(120% 90% at 50% 40%, rgba(10, 14, 20, .80), rgba(5, 7, 11, .95));
  -webkit-backdrop-filter: blur(7px) saturate(1.1); backdrop-filter: blur(7px) saturate(1.1);
}
.demo-flash.show { opacity: 1; }
.df-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 26px 34px; border-radius: 26px; min-width: min(70vw, 270px);
  background: linear-gradient(168deg, rgba(255, 255, 255, .12), rgba(255, 255, 255, .035));
  border: 1px solid rgba(255, 255, 255, .16);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.demo-flash.show .df-card { animation: dfPop .36s cubic-bezier(.2, .9, .3, 1.25) both; }
@keyframes dfPop { 0% { transform: scale(.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.df-emoji { font-size: 2.4rem; line-height: 1; filter: drop-shadow(0 6px 16px rgba(0, 0, 0, .5)); }
.df-score {
  font-family: var(--serif), Georgia, serif; font-weight: 800; line-height: .98;
  font-size: 3.5rem; letter-spacing: -.02em; color: var(--df-accent, #fff);
  text-shadow: 0 2px 18px rgba(0, 0, 0, .45);
}
.df-sub {
  margin-top: 4px; padding-top: 12px; width: 100%;
  border-top: 1px solid rgba(255, 255, 255, .14);
  font-size: .9rem; font-weight: 600; color: rgba(255, 255, 255, .74);
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  display: flex;
  flex-direction: column;
  min-height: 100%;
  /* Top pad clears the HOST chrome (streak chip · daily/standings pill · search · coin jar), which
     floats over the top of every app iframe. We declare --klyp-safe-top for exactly this but the body
     was only padding ~20px — so flow-layout apps (word-guess, quizzes, tools) rendered their header
     UNDER the chrome. Use the var. Full-bleed canvas games position fixed/absolute → unaffected. */
  padding: var(--klyp-safe-top) 20px max(20px, env(safe-area-inset-bottom));
  overflow-x: hidden;
  /* tall apps stay fully reachable on small screens */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Android: don't let the app's own body-scroll rubber-band inside the (cross-origin) feed iframe — that
     bounce reads as jank and swallows the residual swipe. iOS momentum is unaffected. */
  overscroll-behavior-y: none;
}
.k-wrap {
  width: 100%;
  max-width: 460px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: center;
}
.k-emoji { font-size: 3rem; line-height: 1; }
/* SWEEP-2 LESS-IS-MORE (2026-07-28): the app's own start screen is where type gets LARGE (the
   "taste") — host chrome stays standard. Title up 1.9→2.2rem, tighter; the hook is visually capped
   at 3 lines on a narrow measure so it reads as a HOOK, not a rules paragraph (full rules belong
   in-game). Category faces via the host's ?kind= tag: game = Jakarta energy (default), toy =
   rounded friendliness (system SF-Rounded on iOS; falls back to Jakarta elsewhere — zero bytes). */
.k-h1 { font-family: var(--sans); font-weight: 800; font-size: 2.2rem; margin: 0; letter-spacing: -0.03em; line-height: 1.05; text-wrap: balance; }
html.k-kind-toy .k-h1 { font-family: ui-rounded, "SF Pro Rounded", var(--sans); letter-spacing: -0.02em; }
.k-sub { color: var(--ink-2); margin: 0 auto; font-size: 1.02rem; line-height: 1.45; max-width: 32ch; text-align: center;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.k-big { font-family: var(--sans); font-weight: 800; font-size: 3.4rem; line-height: 1; letter-spacing: -0.02em; color: var(--coral); margin: 6px 0; }
.k-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ink-3); }

.k-input, .k-textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 14px; padding: 14px; outline: none;
  /* 16px keeps mobile browsers from zooming the page when a field is focused;
     scroll-margin leaves room so the SDK can scroll it clear of the keyboard. */
  font-size: 16px;
  scroll-margin: 90px;
}
.k-input:focus, .k-textarea:focus { border-color: var(--coral); }
.k-textarea { min-height: 130px; resize: none; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px; }

.k-btn {
  font: inherit; font-weight: 800; border: none; cursor: pointer;
  background: var(--coral); color: #fff; padding: 14px 22px; border-radius: 999px;
  font-size: 1.02rem; transition: transform 0.12s cubic-bezier(.34,1.56,.64,1), filter 0.15s;
}
.k-btn:active { transform: scale(0.96); }
.k-btn:hover { filter: brightness(1.04); }
.k-btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.k-btn.wa { background: #25D366; }
.k-btn:disabled { opacity: 0.45; cursor: default; }

.k-row { display: flex; gap: 10px; }
.k-row > * { flex: 1; }

.k-card {
  background: #fff; border: 1px solid var(--line); border-radius: 22px;
  padding: 22px 18px; box-shadow: 0 16px 40px rgba(45,42,38,0.12); text-align: center;
}
.k-watermark { font-size: 0.62rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); margin-top: 14px; }

/* big choice buttons (this-or-that) */
.k-choice {
  font: inherit; font-weight: 800; font-size: 1.25rem; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 22px; padding: 28px 16px; transition: transform 0.1s cubic-bezier(.34,1.56,.64,1), border-color 0.12s;
}
.k-choice:active { transform: scale(0.95); border-color: var(--coral); }

/* FILL-THE-BLANK without the OS keyboard (D22): answer TILES (.k-slots/.k-slot) up top + a compact tappable
   LETTER BANK (.k-bank/.k-chip) below. Tap a chip to fill the next blank; tap a filled tile to clear. Keeps
   the whole game ON SCREEN (no keyboard eating half the viewport, no buried board). A choice pad, NOT a QWERTY. */
.k-slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; }
.k-slot {
  width: 40px; height: 48px; display: grid; place-items: center;
  font: 800 1.4rem/1 var(--sans); color: var(--ink);
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px;
}
.k-slot.on { border-color: var(--coral); box-shadow: 0 0 0 3px color-mix(in srgb, var(--coral) 22%, transparent); } /* active blank */
.k-slot.fixed { background: var(--cream-2); border-style: dashed; color: var(--ink-2); }  /* a pre-revealed letter */
.k-slot.gap { border: none; background: none; width: 14px; }                              /* a space between words */
.k-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.k-chip {
  min-width: 42px; height: 46px; padding: 0 10px; font: inherit; font-weight: 800; font-size: 1.15rem;
  color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
  box-shadow: 0 4px 12px rgba(45,42,38,0.08); transition: transform 0.1s cubic-bezier(.34,1.56,.64,1), opacity 0.12s;
}
.k-chip:active { transform: scale(0.9); }
.k-chip:disabled, .k-chip.used { opacity: 0.32; pointer-events: none; }

.k-fade { animation: kfade 0.4s ease both; }
@keyframes kfade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.k-hidden { display: none !important; }

/* ── Deterministic play-zone contract (opt-in; premium full-bleed apps) ──────────
   A full-screen app puts ALL of its play content inside `.klyp-stage` and its HUD in
   `.klyp-hud`. The stage auto-pads the host's top + bottom chrome bands so nothing is
   ever hidden under or colliding with the host UI — one source of truth instead of each
   app guessing the safe insets. Deliberately CLASS-based (not a bare `#stage` id rule):
   several live apps already use `id="stage"` for other things, so an id rule would
   silently restyle them. Apps opt in with the class; everyone else is untouched. */
.klyp-stage {
  position: absolute; inset: 0;
  padding-top: var(--klyp-safe-top);
  padding-bottom: var(--klyp-safe-bottom);
}
/* Top-centre HUD slot — score/timer/combo live here, clear of the top chrome corners
   (host streak/daily cluster top-left, search/mute top-right). Non-interactive by
   default so taps fall through to the play surface underneath. */
/* STRUCTURAL HUD CLEARANCE (I11 "BrainFill" learning): when an app has a populated, POSITIONED hud, the
   platform reserves the hud band — stage content starts below it automatically. klyp.js adds the html class
   on load. Before this, every generated app had to hand-tune headroom and models kept getting it wrong on
   short screens (the grid crept up into the hearts/score row). Now the layer makes the mistake impossible. */
.klyp-has-hud .klyp-stage { padding-top: calc(var(--klyp-safe-top) + 54px); }

.klyp-hud {
  position: absolute; left: 0; right: 0; top: var(--klyp-safe-top);
  display: flex; justify-content: center; align-items: flex-start; gap: 34px;
  padding: 6px 18px; z-index: 5; pointer-events: none;
  font-variant-numeric: tabular-nums;
}
/* Canonical inner scroller for tall (list/quiz/result) apps that use the
   html,body{overflow:hidden} + inner-scroll pattern. 39 live apps hand-roll this and
   near-universally forget the BOTTOM safe band (audit 2026-07-03: last row hides under
   the 58px bottom chrome). Use this class on the scroller instead of hand-rolling:
   it pads both chrome bands and keeps momentum scrolling. (Prefer plain body-scroll
   for new apps — L9 — this helper is for the existing inner-scroll cohort.) */
.klyp-scroll {
  width: 100%; height: 100%;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none; /* Android: no rubber-band inside the iframe (reads as jank) */
  padding-top: var(--klyp-safe-top);
  padding-bottom: var(--klyp-safe-bottom);
  box-sizing: border-box;
}

/* ── NO blanket body-scroll "rescue" here — it was the regression. ───────────────────────────────────────
   We briefly forced `body{overflow-y:auto !important}` + `body > *{flex-shrink:0}` on EVERY app to rescue the
   handful of CONTENT apps that mistakenly declare `html,body{overflow:hidden}`. But that blanket override was
   worse than the disease: it forced a competing body scroller onto apps that INTENTIONALLY lock the viewport —
   games with `touch-action:none` playfields (orbit, trace-race…) and apps that own their scroll via an inner
   `#scroll`/`#main` element (cosmos, compliment-inbox…). The result on Android was the "can only scroll by
   grabbing the tiny strip at the very bottom" bug (the touch-action:none surface eats the drag everywhere
   else). The base `body{overflow-y:auto}` above is the ONLY shared scroller; apps that need it get it by NOT
   declaring their own overflow:hidden (like every working content app: this-or-that, discount, wrong-answers).
   The few content apps that wrongly locked overflow are fixed AT SOURCE (their own `overflow:hidden` →
   `overflow-x:hidden`), so games and inner-scroller apps are never touched. */

/* Un-shrink direct body children so a tall content wrapper actually overflows the fixed-height flex body and
   the base `body{overflow-y:auto}` can scroll it (without this the flex column shrinks the wrapper to fit →
   nothing overflows → dead scroll). This is HARMLESS to the apps the overflow-rescue broke: a game's
   `#wrap{flex:1}` still grows to fill (no overflow, body stays overflow:hidden → not scrollable), and an
   inner-scroller's `#scroll{height:100%}` stays exactly 100% — neither becomes body-scrollable, so there is
   no "grab from the bottom" surface. It only matters for a real content app whose wrapper is taller than the
   screen. Defers to intentional `flex:1` (non-!important). */
body > * { flex-shrink: 0; }
