/* Cokoon native UI layer (NOTES #9; rules in docs/NATIVE-PLAYBOOK.md). Loaded after app-shell.css.
   One place that kills the web tells for the whole app, plus the chrome the sheet and navigation
   physics in design/native-ui.js need. Overrides only. */

/* ---- Focus: no rings after a touch. design/native-ui.js sets html.kbd-nav only when a hardware
   keyboard navigates (Tab / arrows); WebKit matches :focus-visible on script focus (C.modal focuses
   the sheet heading), so :not(:focus-visible) guards cannot be trusted on iOS. ---- */
html:not(.kbd-nav) :focus, html:not(.kbd-nav) :focus-visible { outline: none !important; }
html:not(.kbd-nav) :is(label, [class*="option"], [class*="choice"], [class*="enabled"]):has(:focus-visible) { outline: none !important; }
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none !important; }

/* ---- Touch: no grey tap flash, no callout / drag / text selection on chrome (NOTES #5 keeps prose
   and fields selectable in app-shell.css), no text inflation. ---- */
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; color-scheme: light; }
body.cokoon-app a, body.cokoon-app img, body.cokoon-app button { -webkit-touch-callout: none; }
body.cokoon-app img { -webkit-user-drag: none; user-select: none; }

/* ---- Scrolling: the document never rubber-bands; real scroll areas keep momentum and bounce,
   contained (no chaining to the page), and never show a web scrollbar. ---- */
html, body.cokoon-app { overscroll-behavior: none; }
body.cokoon-app :is(.app-scroll, .modal-card, .filter-row) { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
body.cokoon-app .filter-row { overscroll-behavior-x: contain; }
body.cokoon-app *::-webkit-scrollbar { display: none; width: 0; height: 0; }
body.cokoon-app * { scrollbar-width: none; }

/* ---- Fields: never below 16px (iOS zooms into smaller fields), no autofill yellow. ---- */
body.cokoon-app :is(#app-screen, #modal-root) :is(input:not([type="range"]):not([type="checkbox"]):not([type="radio"]), textarea, select) { font-size: max(16px, 1em); }
body.cokoon-app input:-webkit-autofill, body.cokoon-app input:-webkit-autofill:focus { -webkit-box-shadow: 0 0 0 1000px var(--input-background) inset; -webkit-text-fill-color: var(--text-primary); transition: background-color 9999s; }

/* ---- Press states: instant on touch-down, eased release (UIKit highlight). Buttons keep the
   runtime's .975 press scale; rows highlight like table cells; text and icon buttons dim. ---- */
body.cokoon-app button { transition: transform .26s cubic-bezier(.2,.8,.2,1), opacity .26s ease-out, background-color .26s ease-out, filter .26s ease-out; }
body.cokoon-app button:active:not(:disabled) { transition-duration: 0s; }
body.cokoon-app :is(.text-button, .icon-button, .section-heading button, .modal-close):active:not(:disabled) { opacity: .45; }
body.cokoon-app .setting-row:active:not(:disabled) { background-color: color-mix(in srgb, var(--text-secondary) 5.1%, transparent); }
body.cokoon-app :is(.primary, .secondary):active:not(:disabled) { filter: brightness(.92); }
body.cokoon-app #tabbar button:active { transform: none; opacity: .55; }
body.cokoon-app button:disabled:active { transform: none; }

/* ---- Bottom sheets: anchored to the bottom edge, grabber, dimmed backdrop behind (its own layer so
   the swipe can fade it), corners only on top, home-indicator inset inside the card. ---- */
body.cokoon-app .modal-root {
  align-items: flex-end;
  padding: calc(10px + env(safe-area-inset-top)) 0 var(--keyboard-height, 0px);
  background: none; backdrop-filter: none; -webkit-backdrop-filter: none;
}
.sheet-scrim { position: absolute; inset: 0; z-index: 0; background: var(--scrim); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
body.cokoon-app .modal-card {
  position: relative; z-index: 1;
  max-width: 440px; margin: 0 auto;
  border-radius: 24px 24px 0 0;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
  /* second shadow = the sheet's own paper continuing below it, so a pull-up never opens a gap */
  box-shadow: 0 -10px 40px color-mix(in srgb, var(--shadow-color) 12.16%, transparent), 0 320px 0 0 var(--modal-background);
  will-change: transform;
}
body.keyboard-open .modal-card { padding-bottom: 22px; }
/* With the keyboard up the home indicator is covered, so the sheet's action bar drops its inset too, in step
   with the card (native-feel #3): the Send button sits whole on the keyboard's top edge, never clipped. */
body.cokoon-app.keyboard-open #modal-root .sheet-actions { bottom: -22px; margin-bottom: -22px; padding-bottom: 8px; }
/* The grabber sits on its own strip of sheet paper, so content scrolled up passes under it, never through it. */
.sheet-grabber { position: sticky; top: 0; z-index: 3; height: 0; margin: -22px auto 22px; pointer-events: none; }
body.cokoon-app .modal-card > .sheet-grabber { top: -25px; height: 25px; margin: -25px -20px 0; background: var(--modal-background); border-radius: 24px 24px 0 0; }
.sheet-grabber::before { content: ''; display: block; width: 36px; height: 5px; border-radius: 3px; margin: 6px auto 0; background: var(--sheet-grabber); }
.sheet-ghost { pointer-events: none; z-index: 1001; }
.sheet-ghost .modal-card { box-shadow: none; }

/* ---- Screen push / pop / edge swipe (native-ui.js): the live #phone slides as ONE card (status-bar band,
   header, content, pinned composer, a pushed page's bars); the other screen is a frozen copy of the whole
   phone on a fixed stage at the phone's rect, under it (z 1) or over it (z 3). ---- */
.nav-ghost { position: fixed; z-index: 1; overflow: hidden; pointer-events: none; will-change: transform; }
body.cokoon-app .nav-ghost > .phone { width: 100%; max-width: none; box-shadow: none; }
.nav-ghost.above { z-index: 3; }
.nav-ghost.above, #phone.nav-top { box-shadow: -10px 0 28px color-mix(in srgb, var(--shadow-color) 18%, transparent); }
#phone.nav-anim { position: relative; z-index: 2; will-change: transform; }
/* The screen underneath dims like UIKit's: an overlay that lifts as the top screen leaves. */
.nav-dim { position: absolute; inset: 0; z-index: 50; pointer-events: none; background: color-mix(in srgb, var(--shadow-color) 14%, transparent); }
/* Tab bar shown on both screens: it stays still above the dimming (each layer's copy is offset back). */
:is(#phone.nav-keep-bar, .nav-ghost.keep-bar .phone) > #tabbar { z-index: 60; transition: none; }

/* ---- Tool screens as sheets (native-ui.js "route sheets"): the live #app-scroll becomes the sheet, over a
   frozen copy of the tab it rose from (.sheet-presenter) and its own dimming; the leaving copy is a ghost. ---- */
#phone > .sheet-presenter { position: absolute !important; inset: 0 !important; z-index: 30; width: auto !important; height: auto !important; max-width: none !important; margin: 0 !important; border-radius: 0 !important; box-shadow: none !important; overflow: hidden; pointer-events: none; }
#phone > .route-sheet-scrim { z-index: 35; }
#phone.route-sheet > #app-scroll, #phone > .route-sheet-ghost {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 40; flex: none;
  max-height: calc(100% - env(safe-area-inset-top) - 10px);
  background: var(--modal-background); border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px color-mix(in srgb, var(--shadow-color) 12.16%, transparent), 0 320px 0 0 var(--modal-background);
  will-change: transform;
}
#phone > .route-sheet-ghost { bottom: auto; max-height: none; overflow: hidden; pointer-events: none; }
#phone.route-sheet #app-screen { position: relative; padding-bottom: calc(26px + max(var(--keyboard-height, 0px), env(safe-area-inset-bottom))); }
:is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen > .sheet-grabber { margin: -14px auto 14px; }
:is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen { position: relative; }
:is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-header .header-nav { position: absolute; top: 16px; right: 16px; margin: 0; z-index: 4; }
:is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-header .header-nav .wordmark { display: none; }
:is(#phone.route-sheet, #phone > .route-sheet-ghost) #app-screen .page-header h1 { padding-right: 52px; }

/* ---- Tab bar (NOTES #12, Vincent: "too high, too big"): the stock compact UITabBar. 49pt of bar above the
   home-indicator inset, items stacked as a 25pt glyph over a 10pt medium label, selection shown by tint
   only (no pill), no extra padding. Outranks the runtime's studio-era .tabbar rules (style.css). ---- */
body.cokoon-app #tabbar { box-sizing: border-box; height: calc(49px + env(safe-area-inset-bottom)); padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); align-items: stretch; justify-content: space-around; }
body.cokoon-app #tabbar button { flex: 1 1 0; height: 49px; min-height: 0; min-width: 44px; margin: 0; padding: 6px 2px 0; gap: 2px; justify-content: flex-start; font-size: 10px; font-weight: 500; line-height: 12px; letter-spacing: .01em; }
body.cokoon-app #tabbar .nav-icon, body.cokoon-app #tabbar button.active .nav-icon { display: block; height: 25px; padding: 0; margin: 0; background: none; border-radius: 0; }
body.cokoon-app #tabbar .nav-icon svg { width: 25px; height: 25px; }
body.cokoon-app #tabbar .nav-label { font-size: 10px; line-height: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* Play badge (audit F20): the stock UITabBar empty-string badge — a small systemRed dot at the glyph's
   top-trailing corner — while a partner turn, an unseen reveal or a new drawing waits. No count, no card. */
body.cokoon-app #tabbar .nav-icon, #tabbar .nav-icon { position: relative; }
#tabbar .tab-badge { position: absolute; top: -1px; right: -5px; width: 10px; height: 10px; border-radius: 50%; background: var(--notification); box-shadow: 0 0 0 1.5px var(--navigation-background); pointer-events: none; }

/* ---- With the keyboard up, a screen's own main action rides on top of it (native-feel sweep): the mood
   editor's "Save and share", onboarding's "Continue". A field is revealed above the bar (C.keyboard). ---- */
body.cokoon-app.keyboard-open #app-screen .bottom-action:not(.flow-actions) {
  position: sticky; bottom: 0; z-index: 6; margin-top: 14px; padding: 12px 0 10px; background: var(--page-background);
}
body.cokoon-app.keyboard-open :is(#app-screen, #obf-layer) .obf .bottom-actions {
  position: sticky; bottom: 0; z-index: 5; padding-bottom: 12px; background: var(--cream, var(--page-background));
}
/* The onboarding page frame clips its art (overflow hidden), which would also trap the sticky bar inside it;
   clip paints the same but leaves the app scroller in charge, so "Continue" can ride on the keyboard. */
body.cokoon-app.keyboard-open :is(#app-screen, #obf-layer) .obf .ob-phone { overflow: clip; }
/* A game's pinned "Back to Play" footer steps aside while a word is typed, so the field's own button (Perfect
   pair "Add this step") comes up with it; footers holding the screen's action (missions) stay. */
body.cokoon-app.keyboard-open #app-screen .game-foot:not(:has(.primary)) { display: none; }
@media (max-width: 360px) { body.cokoon-app .modal-card > .sheet-grabber { margin-inline: -15px; } }
/* A soft edge under the grabber strip: content scrolling up meets a deliberate boundary, not a hard cut. */
body.cokoon-app .modal-card > .sheet-grabber::after { content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 12px; pointer-events: none; background: linear-gradient(var(--modal-background), color-mix(in srgb, var(--modal-background) 0%, transparent)); }
/* Text areas never show the desktop resize grip. */
body.cokoon-app :is(#app-screen, #modal-root) textarea { resize: none; }
/* Tool screens presented as sheets (mood, note, pet, decorate) ride the keyboard like any sheet: the sheet's bottom
   edge sits on the keyboard's top and its own content padding drops the keyboard term (it is no longer under it). */
body.cokoon-app.keyboard-open #phone.route-sheet > #app-scroll { bottom: var(--keyboard-height, 0px); max-height: calc(100% - env(safe-area-inset-top) - 10px - var(--keyboard-height, 0px)); }
body.cokoon-app.keyboard-open #phone.route-sheet #app-screen { padding-bottom: 26px; }
