/* ---------- KiddReads — shared mobile baseline ---------- */
/* Loaded by every page; provides safe-area handling, comfortable
   tap targets, smoother iOS feel, and a couple of small-screen
   sanity defaults. Per-page styles still own layout decisions. */

:root {
  --kr-safe-top: env(safe-area-inset-top, 0px);
  --kr-safe-right: env(safe-area-inset-right, 0px);
  --kr-safe-bottom: env(safe-area-inset-bottom, 0px);
  --kr-safe-left: env(safe-area-inset-left, 0px);
}

/* No grey flash on tap (iOS/Android default is ugly) */
* { -webkit-tap-highlight-color: transparent; }

/* Don't let the page scroll horizontally — catch overflow early */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Notch / Dynamic Island / home-indicator safe areas on the body itself */
body {
  padding-left: var(--kr-safe-left);
  padding-right: var(--kr-safe-right);
}

/* Page headers should clear the iPhone status bar / Dynamic Island */
header {
  padding-top: max(var(--kr-safe-top), 0px);
}

/* Anything pinned to the bottom should clear the iOS home indicator */
.kr-safe-bottom,
footer[role="contentinfo"],
.bottom-bar,
.mk-band + footer,
.mk-footer {
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* Smoother iOS scroll inside scrollable regions */
.scroll, .scrollable, [data-scroll] {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Skip the iOS 300ms double-tap delay on tappable things — safe at any width */
.tap, button, [role="button"], .toggle-btn, .mk-btn, .btn {
  touch-action: manipulation;
}

/* Stop iOS Safari from auto-zooming when an input is focused with <16px font.
   Scoped strictly to narrow viewports so desktop inputs keep their designed
   font size. Per-page mobile overrides handle tap-target sizing. */
@media (max-width: 600px) {
  input, select, textarea {
    font-size: max(16px, 1rem);
  }
}

/* Make images scale instead of overflowing on phones */
img, video, svg {
  max-width: 100%;
  height: auto;
}

/* When the URL bar hides on mobile, regular 100vh leaks under it.
   100dvh = dynamic viewport height. Pages opting in can use:
   .kr-dvh-min { min-height: 100dvh; } */
@supports (height: 100dvh) {
  .kr-dvh-min { min-height: 100dvh; }
}
@supports not (height: 100dvh) {
  .kr-dvh-min { min-height: 100vh; }
}

/* ---------- PWA install banner ---------- */
.kr-pwa-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--kr-safe-bottom));
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: #fff;
  color: #2d3436;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22);
  font-family: 'Inter', system-ui, sans-serif;
  transform: translateY(140%);
  opacity: 0;
  transition: transform 280ms cubic-bezier(.2,.8,.2,1), opacity 200ms ease;
}
.kr-pwa-banner.kr-pwa-in  { transform: translateY(0);   opacity: 1; }
.kr-pwa-banner.kr-pwa-out { transform: translateY(140%); opacity: 0; }
.kr-pwa-icon  { flex-shrink: 0; width: 44px; height: 44px; border-radius: 10px; }
.kr-pwa-body  { flex: 1; min-width: 0; }
.kr-pwa-title { font-weight: 800; font-size: 0.94rem; line-height: 1.2; }
.kr-pwa-sub   { font-size: 0.78rem; color: #636e72; margin-top: 2px; line-height: 1.3; }
.kr-pwa-action {
  flex-shrink: 0;
  border: none;
  background: linear-gradient(135deg, #4a90e2, #4a00e0);
  color: #fff;
  font-weight: 800;
  font-size: 0.86rem;
  padding: 10px 16px;
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
}
.kr-pwa-x {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #636e72;
  font-size: 1.4rem;
  line-height: 1;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 50%;
  min-width: 32px;
  min-height: 32px;
}
.kr-pwa-x:hover { background: #f0f2f5; color: #2d3436; }
