/* ====================================================================
   app-mode.css — schoolclaude PWA/TWA App Mode styles
   Activated only when html[data-app-mode="true"] is set by app-mode.js.
   On the regular website (no attribute), this stylesheet has zero effect.
   ==================================================================== */

/* ── Body baseline in app mode ─────────────────────────────────────── */
html[data-app-mode="true"] body {
  min-height: 100vh;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ── Hide marketing site chrome ────────────────────────────────────── */
/* dashboard-nav has BOTH `dashboard-nav` and `site-nav` classes; the
   :not(.dashboard-nav) keeps its logout/theme controls reachable while
   the marketing nav on other pages stays hidden. */
html[data-app-mode="true"] .site-nav:not(.dashboard-nav),
html[data-app-mode="true"] .footer,
html[data-app-mode="true"] footer.footer,
html[data-app-mode="true"] .site-footer,
html[data-app-mode="true"] .nav-back,
html[data-app-mode="true"] .floating-stats,
html[data-app-mode="true"] .hero,
html[data-app-mode="true"] .hero-editorial,
html[data-app-mode="true"] .hero-canvas {
  display: none !important;
}

/* Index page in app mode: redirects to /login → keep blank during transition */
html[data-app-mode="true"] body.home-page {
  background: #050508;
}
html[data-app-mode="true"] body.home-page > *:not(.app-mode-splash):not(script):not(style) {
  visibility: hidden;
}

/* ── Dashboard nav slimmed in app mode ─────────────────────────────── */
html[data-app-mode="true"] .dashboard-nav .nav-link {
  display: none;
}
html[data-app-mode="true"] .dashboard-nav .nav-link.nav-link-skills {
  display: inline-flex;
}
html[data-app-mode="true"] .dashboard-nav .nav-logo {
  pointer-events: none;
  cursor: default;
}

/* ── Splash overlay (login.html, fade-out after auth check) ────────── */
.app-mode-splash { display: none; }
html[data-app-mode="true"] .app-mode-splash {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(180deg, #050508 0%, #0A0515 100%);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
  font-family: 'Heebo', sans-serif;
  color: #F0F0FF;
  opacity: 1;
  transition: opacity 250ms ease-out;
}
html[data-app-mode="true"] .app-mode-splash[data-fade="out"] {
  opacity: 0;
  pointer-events: none;
}
.app-mode-splash__logo {
  width: 96px; height: 96px; border-radius: 24px;
  box-shadow: 0 8px 32px rgba(232, 160, 32, 0.35);
  animation: appSplashPulse 1.6s ease-in-out infinite;
}
.app-mode-splash__title {
  font-size: 1.5rem; font-weight: 700; margin: 0;
  background: linear-gradient(135deg, #F5C040 0%, #E8A020 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.app-mode-splash__sub {
  font-size: 0.95rem; margin: 0;
  color: rgba(240, 240, 255, 0.65);
}
.app-mode-splash__spinner {
  width: 28px; height: 28px;
  border: 2px solid rgba(232, 160, 32, 0.2);
  border-top-color: #E8A020;
  border-radius: 50%;
  animation: appSplashSpin 0.8s linear infinite;
}
@keyframes appSplashPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.05); opacity: 0.85; }
}
@keyframes appSplashSpin { to { transform: rotate(360deg); } }

/* ── Bottom navigation (mounted by app-mode.js) ────────────────────── */
html[data-app-mode="true"] .app-bottom-nav {
  position: fixed;
  inset-block-end: 0;
  inset-inline: 0;
  z-index: 100;
  display: flex;
  background: rgba(10, 10, 16, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(232, 160, 32, 0.18);
  padding: 0.5rem 0 max(0.5rem, env(safe-area-inset-bottom));
  font-family: 'Heebo', sans-serif;
}
html[data-app-mode="true"] .app-bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.2rem;
  color: rgba(240, 240, 255, 0.6);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 600;
  transition: color 200ms ease, transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
}
html[data-app-mode="true"] .app-bottom-nav a:active {
  transform: scale(0.94);
}
html[data-app-mode="true"] .app-bottom-nav a.is-active {
  color: #F5C040;
}
html[data-app-mode="true"] .app-bottom-nav .abn-icon {
  font-size: 1.4rem;
  line-height: 1;
}
html[data-app-mode="true"] .app-bottom-nav .abn-lbl {
  letter-spacing: 0.02em;
}
/* Reserve room for bottom-nav so content doesn't hide under it */
html[data-app-mode="true"] body:not(.auth-page):not(.home-page) {
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0)) !important;
}
/* Hide bottom-nav on login (entry) screen */
html[data-app-mode="true"] body.auth-page .app-bottom-nav { display: none; }

/* ── Page transition (fade-in on every page load) ──────────────────── */
html[data-app-mode="true"] body {
  animation: appPageEnter 220ms ease-out;
}
@keyframes appPageEnter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Native feel: disable pull-to-refresh, prevent overscroll bounce */
html[data-app-mode="true"] body {
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  /* scroll-behavior:smooth removed — causes jank/lock in Android WebView */
}
/* touch-action:manipulation on html REMOVED — caused scroll blocks in Android WebView.
   Applied only to interactive elements to prevent double-tap zoom without blocking scroll. */
html[data-app-mode="true"] button,
html[data-app-mode="true"] a,
html[data-app-mode="true"] [role="button"],
html[data-app-mode="true"] label {
  touch-action: manipulation;
}

/* No selection / no tap-flash on UI controls (keeps content selectable) */
html[data-app-mode="true"] button,
html[data-app-mode="true"] .btn,
html[data-app-mode="true"] .nav-link,
html[data-app-mode="true"] a[role="button"],
html[data-app-mode="true"] .app-bottom-nav a {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Touch feedback — scale on press (broad, all common button classes) */
html[data-app-mode="true"] button:active,
html[data-app-mode="true"] .btn:active,
html[data-app-mode="true"] a.btn:active,
html[data-app-mode="true"] .btn-submit:active,
html[data-app-mode="true"] .btn-primary:active,
html[data-app-mode="true"] .btn-google:active,
html[data-app-mode="true"] .tab-btn:active,
html[data-app-mode="true"] .dash-next-btn:active,
html[data-app-mode="true"] .dash-logout-btn:active {
  transform: scale(0.97);
  transition: transform 80ms ease;
}

/* ── Lesson page: prevent grid items from overflowing the viewport ── */
/* Grid items default to min-content min-size, which can stretch wider
   than 1fr when they contain wide images/tables/code. min-width:0 forces
   them to shrink to the available column width instead. */
html[data-app-mode="true"] .lesson-layout > * {
  min-width: 0;
}
html[data-app-mode="true"] .lesson-content-wrap,
html[data-app-mode="true"] .lesson-sidebar {
  max-width: 100%;
}
/* Also clamp wide media inside lesson body */
html[data-app-mode="true"] .lesson-content-wrap img,
html[data-app-mode="true"] .lesson-content-wrap video,
html[data-app-mode="true"] .lesson-content-wrap iframe {
  max-width: 100%;
  height: auto;
}
html[data-app-mode="true"] .lesson-content-wrap pre,
html[data-app-mode="true"] .lesson-content-wrap .code-block-wrap {
  max-width: 100%;
  overflow-x: auto;
}
html[data-app-mode="true"] .lesson-content-wrap table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
/* Reduce side padding on small screens to claw back space */
@media (max-width: 480px) {
  html[data-app-mode="true"] .lesson-main {
    padding-inline: 0.75rem !important;
  }
  html[data-app-mode="true"] .lesson-content-wrap {
    padding: 1rem !important;
  }
}

/* ── AI Tutor FAB: lift above bottom-nav in app mode ──────────────── */
html[data-app-mode="true"] .ai-tutor-fab,
html[data-app-mode="true"] .lesson-fab,
html[data-app-mode="true"] .chatbot-fab,
html[data-app-mode="true"] [class*="floating"][class*="btn"] {
  bottom: calc(90px + env(safe-area-inset-bottom, 0)) !important;
}
/* Hide FAB on auth screens — no lesson context yet */
html[data-app-mode="true"] body.auth-page .ai-tutor-fab,
html[data-app-mode="true"] body.home-page .ai-tutor-fab {
  display: none !important;
}

/* ── Kids zone in app mode ────────────────────────────────────── */
/* Hide the kids-topbar's "back to main site" link since app users
   should stay inside the app shell (use bottom-nav to leave) */
html[data-app-mode="true"] .kids-topbar .kids-hex-btn--back {
  display: none !important;
}
/* Reserve room at the bottom for the bottom-nav (80px + safe area) */
html[data-app-mode="true"] body.kids-page {
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0)) !important;
}
/* Kids page CSS forces position:relative on direct body children — restore fixed
   for the bottom-nav with !important to beat the high-specificity :not() chain. */
html[data-app-mode="true"] body.kids-page .app-bottom-nav {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 1000;
}
/* Lift the AI tutor FAB above the bottom-nav on kids pages too */
html[data-app-mode="true"] body.kids-page .ai-tutor-fab,
html[data-app-mode="true"] body.kids-page .lesson-fab {
  bottom: calc(90px + env(safe-area-inset-bottom, 0)) !important;
}
/* Kids hero uses min-height: 100vh - topbar — in app mode we also need to
   subtract the 80px bottom-nav so the hero CTA stays tappable above it. */
html[data-app-mode="true"] body.kids-page .kids-hero {
  min-height: calc(100vh - 144px) !important;
}

/* ── Lesson breadcrumb — hide in app mode (bottom-nav handles nav) ── */
html[data-app-mode="true"] .lesson-breadcrumb {
  display: none;
}

/* ── Dashboard bg-attachment fix — scroll jank on Android/iOS TWA ── */
html[data-app-mode="true"] body.dashboard-page {
  background-attachment: scroll, scroll !important;
}

/* ── Bottom nav polish — larger icons + labels + active glow ─────── */
html[data-app-mode="true"] .app-bottom-nav .abn-icon {
  font-size: 1.55rem;
}
html[data-app-mode="true"] .app-bottom-nav .abn-lbl {
  font-size: 0.74rem;
}
html[data-app-mode="true"] .app-bottom-nav a.is-active .abn-icon {
  filter: drop-shadow(0 0 6px rgba(245, 192, 64, 0.55));
}

/* ── Reduced motion: respect user preference ───────────────────────── */
@media (prefers-reduced-motion: reduce) {
  html[data-app-mode="true"] body { animation: none; }
  .app-mode-splash__logo,
  .app-mode-splash__spinner { animation: none; }
  html[data-app-mode="true"] button:active,
  html[data-app-mode="true"] .btn:active,
  html[data-app-mode="true"] a.btn:active { transform: none; }
}
