/* ============================================================
   Cartoon French — MOBILE-FIRST responsive system
   Loads LAST. Progressive enhancement via min-width breakpoints:
   481 · 768 · 1024 · 1440 · 1920
   Goals: no horizontal scroll, no layout jump/shake, 44px taps
   ============================================================ */

/* ---------- Base (mobile 320–480) ---------- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: clip;
  font-size: var(--cf-fs-body);
}

/* Comfortable side gutters on phones — cards must not kiss the viewport */
@media (max-width: 767.98px) {
  :root {
    --cf-gutter: max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  }
}

.container,
.container-wide {
  padding-inline: var(--cf-gutter);
  box-sizing: border-box;
}

/* Defensive: shared-node helpers that once used padding shorthand and wiped gutters */
.container.a0-wrap,
.container.bmc-main,
.bmc-main.container,
.legal-body.container,
.container.a0-hero-inner {
  padding-inline: var(--cf-gutter) !important;
}

/* Prevent width blowouts */
img, video, svg, canvas, iframe, table, pre {
  max-width: 100%;
}

.dash-main,
.nav-inner,
.pay-wrap,
.pay-shell,
.container,
.container-wide,
.section-inner,
.auth-card,
.gh-profile,
.auth-shell,
.hero-grid,
.translator-box,
.pay-stage {
  max-width: 100%;
  min-width: 0;
}

.dash-main,
.pay-wrap,
main,
.hero,
.auth-panel {
  overflow-x: clip;
}

/* Reserve nav space so content never jumps under fixed navbar */
body:not(.auth-body) > .hero,
body:not(.auth-body) > main,
body:not(.auth-body) > .section:first-of-type,
.landing .hero {
  scroll-margin-top: var(--nav-h);
}

/* Touch targets — exclude compact header controls (fixed 2.5rem) */
button:not(.theme-toggle):not(.hamburger):not(.sidebar-toggle),
.btn:not(.btn-sm),
.filter-chip,
.sidebar-nav a,
.nav-links a,
.btn-google {
  min-height: var(--cf-tap);
  min-width: var(--cf-tap);
}

.sidebar-toggle {
  min-height: var(--cf-tap);
  min-width: var(--cf-tap);
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-table-wrap,
.table-responsive,
.panel .admin-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* --- Public HEADER --- */
:root {
  --nav-h: 3.75rem;
}

/* Mobile drawer styles live in style.css (.nav-drawer) — outside header */

/* --- Hero --- */
.hero {
  padding-top: calc(var(--nav-h) + 0.75rem);
  padding-bottom: 2rem;
}

.hero-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  text-align: center;
}

.hero-visual {
  order: -1;
}

.hero-stage,
.hero-logo-stage {
  width: min(15rem, 70vw) !important;
  margin-inline: auto;
  aspect-ratio: 1;
}

.hero-brand {
  font-size: var(--cf-fs-h1) !important;
  line-height: 1.1;
}

.hero-tagline {
  font-size: clamp(1rem, 0.95rem + 0.4vw, 1.2rem) !important;
}

.hero-desc {
  font-size: clamp(0.9rem, 0.85rem + 0.3vw, 1.05rem);
  max-width: 36rem;
  margin-inline: auto;
}

.hero-ctas {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.65rem;
}

.hero-ctas .btn {
  width: 100%;
  justify-content: center;
}

.hero-pills {
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.hero-pills .pill {
  font-size: 0.72rem;
  padding: 0.4rem 0.65rem;
}

.float-chip {
  display: none; /* avoid overflow shake on small screens */
}

/* --- Sections / grids --- */
.section,
.path-section {
  padding-block: clamp(2rem, 4vw, 4rem);
}

.section-head {
  text-align: center;
}

.section-head h2,
h1, h2 {
  font-size: var(--cf-fs-h2);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

h3 {
  font-size: var(--cf-fs-h3);
}

.levels-grid,
.features-grid,
.feature-grid,
.testimonials-grid,
.steps,
.how-grid,
.panel-grid,
.stats-grid,
.preview-grid,
.vocab-grid,
.flip-grid,
.reading-grid,
.gh-pin-grid {
  grid-template-columns: 1fr !important;
  gap: 0.75rem;
}

/* Footer: brand full-width, then 2-col link groups on phones */
.site-footer .footer-grid,
.footer .footer-grid,
footer .footer-grid {
  grid-template-columns: 1fr 1fr !important;
  gap: 1.25rem 1rem;
}
.site-footer .footer-brand,
.footer .footer-brand {
  grid-column: 1 / -1;
}
.site-footer-cta {
  flex-direction: column;
  align-items: flex-start;
  padding: 1.15rem 1.1rem;
}
.site-footer-cta-actions {
  width: 100%;
}
.site-footer-cta-actions .btn {
  flex: 1 1 auto;
  justify-content: center;
}

.path-nodes {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 0.75rem;
}

.path-line {
  display: none !important;
}

/* --- Auth --- */
.auth-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100dvh;
  padding-top: var(--nav-h);
}

.auth-showcase {
  display: none !important;
}

.auth-panel {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1.25rem var(--cf-gutter) 2.5rem;
  width: 100%;
}

.auth-card {
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem 1.15rem;
  margin: 0;
}

.auth-card.wide {
  max-width: 30rem;
}

.form-row {
  grid-template-columns: 1fr !important;
}

.btn-google,
.auth-card .btn-block,
.auth-card .btn-lg {
  width: 100%;
  justify-content: center;
}

/* --- Dashboard --- */
.dash-layout {
  display: grid;
  grid-template-columns: 1fr !important;
}

.sidebar {
  position: fixed !important;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(17.5rem, 86vw);
  z-index: 60;
  transform: translateX(-105%);
  transition: transform 0.25s ease;
  box-shadow: none;
}

.sidebar.open {
  transform: translateX(0);
  box-shadow: var(--cf-shadow-lg);
}

.sidebar-toggle {
  display: grid !important;
  place-items: center;
  width: var(--cf-tap);
  height: var(--cf-tap);
  min-width: var(--cf-tap);
}

body.sidebar-open {
  overflow: hidden;
}

body.sidebar-open::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 51, 0.45);
  z-index: 55;
  animation: cfNavIn 0.2s ease both;
}

.dash-main {
  padding: 0.9rem var(--cf-gutter) 5rem !important;
  width: 100%;
  min-width: 0;
}

.dash-topbar {
  flex-wrap: wrap;
  gap: 0.65rem;
}

.dash-topbar h1 {
  font-size: clamp(1.15rem, 1rem + 1.2vw, 1.5rem);
}

.dash-page-intro {
  padding: 1rem !important;
}

.stats-grid {
  grid-template-columns: 1fr !important;
}

.stat-card {
  padding: 0.9rem !important;
}

.content-list .content-item,
.exercise-list .exercise-card {
  flex-direction: column;
  align-items: stretch;
}

.tr-grid,
.pay-stage,
.pay-grid,
.enroll-grid,
.gh-profile,
.profile-layout-upgraded,
.profile-hero-grid {
  grid-template-columns: 1fr !important;
}

/* Legacy translator-box only — new page uses .cf-tr-board (flex) */
.translator-box {
  grid-template-columns: 1fr !important;
}

.membership-banner {
  flex-direction: column;
  align-items: flex-start;
}

.gh-heatmap-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.pay-wrap {
  width: min(100%, calc(100% - (var(--cf-gutter) * 2)));
  padding: 1rem 0 2rem;
}

.pay-hero-line h1 {
  font-size: clamp(1.35rem, 1.1rem + 2vw, 1.85rem);
}

.pay-price-hero {
  font-size: clamp(2rem, 1.5rem + 3vw, 2.8rem) !important;
}

.pay-coupon-row {
  flex-direction: column;
}

.pay-coupon-btn,
.pay-method {
  width: 100%;
  min-height: var(--cf-tap);
}

/* Forms / buttons — stretch only in content contexts */
.cta-banner .btn,
.hero-ctas .btn,
form .btn-block {
  width: 100%;
  justify-content: center;
}

.dash-top-actions .btn,
.dash-top-actions .theme-toggle,
.filter-chip,
.btn-audio,
.tr-listen-btn,
.vocab-icon-btn,
.bookmark-btn {
  width: auto;
  min-width: var(--cf-tap);
}

/* Tables → scroll cue */
.admin-table-wrap::after {
  content: '';
  display: block;
}

/* Safe areas — navbar already pads; don't double-pad .nav-inner */
@supports (padding: max(0px)) {
  .dash-main,
  .auth-panel {
    padding-bottom: max(4rem, calc(2rem + env(safe-area-inset-bottom))) !important;
  }
}

/* ============================================================
   min-width: 481px — large phones
   ============================================================ */
@media (min-width: 481px) {
  :root { --nav-h: 4rem; }

  .logo-icon { width: 2.35rem; height: 2.35rem; flex-basis: 2.35rem; }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .path-nodes {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .hero-stage,
  .hero-logo-stage {
    width: min(17rem, 62vw) !important;
  }
}

/* ============================================================
   min-width: 768px — tablet
   ============================================================ */
@media (min-width: 768px) {
  :root {
    --nav-h: 4.35rem;
  }

  .site-footer .footer-grid,
  .footer .footer-grid,
  footer .footer-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 1.5rem;
  }
  .site-footer .footer-brand,
  .footer .footer-brand {
    grid-column: 1 / -1;
  }
  .site-footer-cta {
    flex-direction: row;
    align-items: center;
  }
  .site-footer-cta-actions {
    width: auto;
  }

  .logo-text {
    display: flex;
  }

  .logo-icon {
    width: 2.55rem;
    height: 2.55rem;
    flex-basis: 2.55rem;
  }

  /* Keep auth in hamburger drawer until desktop (≥1024) */
  .nav-actions .btn-sm,
  .nav-desktop-only {
    display: none !important;
  }

  .hero-grid {
    text-align: left;
    gap: 1.75rem;
  }

  .hero-ctas {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .hero-ctas .btn {
    width: auto;
  }

  .hero-desc,
  .hero-pills {
    margin-inline: 0;
    justify-content: flex-start;
  }

  .levels-grid,
  .features-grid,
  .feature-grid,
  .testimonials-grid,
  .steps,
  .panel-grid,
  .vocab-grid,
  .flip-grid,
  .reading-grid,
  .gh-pin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .auth-card {
    padding: 2rem 1.75rem;
  }

  .form-row {
    grid-template-columns: 1fr 1fr !important;
  }

  .dash-main {
    padding: 1.25rem 1.25rem 4rem !important;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .pay-coupon-row {
    flex-direction: row;
  }

  .pay-coupon-btn {
    width: auto;
  }
}

/* ============================================================
   min-width: 1024px — laptop / small desktop
   ============================================================ */
@media (min-width: 1024px) {
  :root { --nav-h: 4.5rem; }

  .hamburger {
    display: none !important;
  }

  .nav-inner {
    column-gap: 1rem;
  }

  .nav-links--desktop {
    display: flex !important;
    position: static !important;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.15rem 0.35rem;
    background: transparent !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
  }

  .nav-links--desktop > a {
    min-height: auto;
    min-width: 0;
    padding: 0.35rem 0.45rem !important;
    font-size: 0.82rem !important;
    white-space: nowrap;
  }

  .nav-actions .btn-sm,
  .nav-desktop-only {
    display: inline-flex !important;
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    min-width: 0;
  }

  .nav-drawer {
    display: none !important;
  }

  .lang-switch-select {
    width: 3.5rem;
    min-width: 3.5rem;
    max-width: 3.5rem;
  }

  body.nav-open {
    overflow: auto;
  }

  .hero-grid {
    grid-template-columns: 1.05fr 0.95fr;
    align-items: center;
    text-align: left;
  }

  .hero-visual {
    order: 0;
  }

  .float-chip {
    display: inline-flex;
  }

  .hero-stage,
  .hero-logo-stage {
    width: min(22rem, 100%) !important;
  }

  .levels-grid,
  .features-grid,
  .feature-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .path-nodes {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }

  .auth-shell {
    grid-template-columns: 1fr 1fr;
  }

  .auth-showcase {
    display: flex !important;
  }

  .auth-panel {
    align-items: center;
    min-height: calc(100dvh - var(--nav-h));
  }

  /* Dashboard sidebar permanent */
  .dash-layout {
    grid-template-columns: 16.5rem minmax(0, 1fr) !important;
  }

  .sidebar {
    position: sticky !important;
    top: 0;
    height: 100dvh;
    transform: none !important;
    width: auto;
    box-shadow: none;
  }

  .sidebar-toggle {
    display: none !important;
  }

  body.sidebar-open {
    overflow: auto;
  }

  body.sidebar-open::before {
    display: none !important;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .pay-stage,
  .gh-profile {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) !important;
  }

  /* Legacy 3-col only if an old translator-box page remains */
  .translator-box {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
  }

  .gh-profile {
    grid-template-columns: minmax(15rem, 17.5rem) minmax(0, 1fr) !important;
  }

  .vocab-grid,
  .flip-grid,
  .reading-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .site-footer .footer-grid,
  .footer .footer-grid,
  footer .footer-grid {
    grid-template-columns: minmax(0, 1.55fr) repeat(3, minmax(0, 1fr)) !important;
    gap: 2rem 2.25rem;
  }
  .site-footer .footer-brand,
  .footer .footer-brand {
    grid-column: auto;
  }
  .site-footer-cta {
    flex-direction: row;
    align-items: center;
    padding: 1.35rem 1.5rem;
  }
  .site-footer-cta-actions {
    width: auto;
  }
  .site-footer-cta-actions .btn {
    flex: 0 0 auto;
  }
}

/* ============================================================
   min-width: 1440px — desktop
   ============================================================ */
@media (min-width: 1440px) {
  :root {
    --cf-max: 90rem;
    --nav-h: 4.75rem;
  }

  .hero-stage,
  .hero-logo-stage {
    width: min(26rem, 100%) !important;
  }

  .levels-grid,
  .features-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .vocab-grid,
  .flip-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .dash-layout {
    grid-template-columns: 17.5rem minmax(0, 1fr) !important;
  }

  .dash-main {
    padding: 1.5rem 1.75rem 3.5rem !important;
  }
}

/* ============================================================
   min-width: 1920px — ultra-wide
   ============================================================ */
@media (min-width: 1920px) {
  :root {
    --cf-max: 100rem; /* ~1600px content, centered */
  }

  .container-wide {
    width: min(110rem, calc(100% - 4rem));
  }
}

/* Landscape phones: keep nav usable */
@media (max-height: 480px) and (orientation: landscape) {
  .nav-drawer.open {
    bottom: 0;
  }

  .hero-stage,
  .hero-logo-stage {
    width: min(10rem, 40vh) !important;
  }

  .auth-showcase {
    display: none !important;
  }
}

/* Reduce motion — no jump animations */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .sidebar {
    transition: none !important;
  }
}

/* Neutralize older desktop-first max-width rules that fight this file */
@media (max-width: 1023.98px) {
  .sidebar {
    left: auto; /* transform-based off-canvas instead of left:-280px conflicts */
  }
}

/* Dashboard topbar lang also compact */
.dash-top-actions .lang-switch-select {
  width: 3.5rem;
  min-width: 3.5rem;
  max-width: 3.5rem;
  height: 2.5rem;
}

.dash-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.dash-top-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  flex: 0 0 auto;
}

/* ============================================================
   LAYOUT LOCK — stop mobile layout-viewport expansion
   (blur/aurora/fixed widgets must never widen the page)
   ============================================================ */
html, body {
  width: 100% !important;
  max-width: 100% !important;
  overflow-x: clip !important;
}

header.navbar {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: auto !important;
  max-width: none !important;
  height: var(--nav-h) !important;
  box-sizing: border-box !important;
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px)) !important;
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px)) !important;
  z-index: 1000 !important;
}

header.navbar .nav-inner {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: space-between !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  height: 100% !important;
  gap: 0.5rem !important;
  box-sizing: border-box !important;
}

header.navbar .logo {
  flex: 0 1 auto !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

header.navbar .nav-actions {
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 0.35rem !important;
  flex: 0 0 auto !important;
  margin-left: auto !important;
}

header.navbar .lang-switch {
  display: inline-flex !important;
  flex: 0 0 auto !important;
  margin: 0 !important;
}

header.navbar .lang-switch-select {
  width: 3.5rem !important;
  min-width: 3.5rem !important;
  max-width: 3.5rem !important;
  height: 2.5rem !important;
  min-height: 2.5rem !important;
  padding: 0 1.35rem 0 0.55rem !important;
  box-sizing: border-box !important;
}

header.navbar .theme-toggle,
header.navbar .hamburger {
  width: 2.5rem !important;
  height: 2.5rem !important;
  min-width: 2.5rem !important;
  min-height: 2.5rem !important;
  flex: 0 0 2.5rem !important;
}

.hero,
.hero-aurora {
  overflow: hidden !important;
  max-width: 100% !important;
}

.bmc-float {
  right: max(0.75rem, env(safe-area-inset-right, 0px)) !important;
  left: auto !important;
  max-width: calc(100% - 1.5rem) !important;
}

@media (max-width: 1023.98px) {
  header.navbar .nav-desktop-only,
  header.navbar .nav-actions > .btn {
    display: none !important;
  }

  header.navbar .hamburger {
    display: grid !important;
  }

  header.navbar .nav-links--desktop {
    display: none !important;
  }

  .nav-drawer.open {
    display: flex !important;
  }
}

@media (min-width: 1024px) {
  header.navbar .nav-links--desktop {
    display: flex !important;
    flex: 1 1 auto !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .nav-drawer,
  .nav-drawer.open {
    display: none !important;
  }

  header.navbar .hamburger {
    display: none !important;
  }
}

@media (max-width: 767.98px) {
  header.navbar .logo-text {
    display: none !important;
  }
}

/* ============================================================
   Translator lock (loads last) — flex board immune to grid wars
   ============================================================ */
.cf-tr-board {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: stretch !important;
  grid-template-columns: unset !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

.cf-tr-pane {
  flex: 1 1 0 !important;
  min-width: 0 !important;
}

.cf-tr-mid {
  flex: 0 0 auto !important;
  align-self: center !important;
}

@media (max-width: 860px) {
  .cf-tr-board {
    flex-direction: column !important;
  }
}
