/* ═══════════════════════════════════════════════════
   Mobile-first polish — Français Maître
   Loaded after styles.css · phones + small tablets
   ═══════════════════════════════════════════════════ */

/* Base mobile safety */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

/* Avoid iOS zoom on focus — 16px minimum on form controls */
input,
select,
textarea,
.typed-input,
.dictation-input,
#maestroInput,
#unlockCodeInput {
  font-size: 16px !important;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

/* Header more menu */
.header-actions {
  position: relative;
}

.header-more-btn {
  display: none;
}

.header-more-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 80;
  min-width: 200px;
  padding: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.header-more-menu[hidden] {
  display: none !important;
}

.header-more-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
}

.header-more-item:hover,
.header-more-item:active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ─── Phones & narrow tablets ─── */
@media (max-width: 720px) {
  .screen {
    padding:
      max(0.75rem, env(safe-area-inset-top))
      max(0.85rem, env(safe-area-inset-right))
      max(1.75rem, env(safe-area-inset-bottom))
      max(0.85rem, env(safe-area-inset-left));
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Header: logo row + full-width actions */
  .app-header {
    flex-wrap: wrap;
    gap: 0.55rem 0.65rem;
    margin-bottom: 0.85rem;
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(245, 240, 232, 0.94);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 0.35rem 0 0.5rem;
    margin-left: -0.15rem;
    margin-right: -0.15rem;
    padding-left: 0.15rem;
    padding-right: 0.15rem;
  }

  .logo-btn,
  .logo {
    min-width: 0;
    flex: 1 1 auto;
  }

  .logo h1 {
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logo-flag {
    width: 26px;
    height: 18px;
    flex-shrink: 0;
  }

  .header-actions {
    display: flex;
    flex: 1 1 100%;
    width: 100%;
    justify-content: space-between;
    gap: 0.35rem;
    order: 3;
  }

  .header-actions .icon-btn {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: 46px;
    font-size: 1.15rem;
    border-radius: 12px;
  }

  /* Collapse support/cortex into ⋯ menu on mobile */
  .header-more-btn {
    display: flex !important;
  }

  /* When those buttons live in the more menu, hide duplicates if any still in bar */
  .header-actions > #btnSupport,
  .header-actions > #btnCortex {
    display: none;
  }

  .page-title {
    font-size: 1.05rem;
    max-width: none;
    flex: 1;
    text-align: center;
  }

  /* Landing */
  .landing-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(245, 240, 232, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 0.5rem 0;
    margin-bottom: 1.25rem;
  }

  .hero-badge {
    font-size: 0.72rem;
    padding: 0.35rem 0.65rem;
    line-height: 1.35;
    white-space: normal;
    text-align: center;
  }

  .hero-title {
    font-size: clamp(1.55rem, 7vw, 1.9rem);
    line-height: 1.15;
  }

  .hero-cta .btn {
    min-height: 50px;
    font-size: 0.95rem;
  }

  .hero-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero-stat {
    padding: 0.65rem 0.5rem;
  }

  .hero-stat strong {
    font-size: 1.15rem;
  }

  .hero-stat span {
    font-size: 0.72rem;
  }

  /* Dashboard strips / banners */
  .dashboard-strips {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
  }

  .free-coach-strip,
  .support-strip {
    width: 100%;
    justify-content: center;
    min-height: 44px;
    font-size: 0.85rem;
  }

  .freemium-banner {
    padding: 0.75rem 0.85rem;
    gap: 0.55rem;
  }

  .fb-text span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .fb-cta {
    font-size: 0.75rem;
  }

  .maestro-home-banner {
    padding: 0.85rem;
  }

  .maestro-home-text span {
    display: none;
  }

  /* Grids → single column where cramped */
  .mode-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .mode-card {
    padding: 0.85rem 0.65rem;
    min-height: 108px;
  }

  .mode-icon {
    font-size: 1.35rem;
  }

  .mode-name {
    font-size: 0.82rem;
  }

  .mode-desc {
    font-size: 0.7rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .landing-features,
  .hub-grid,
  .practice-areas-wrap,
  .exam-sections-grid {
    grid-template-columns: 1fr !important;
  }

  .feature-card {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .stat-card {
    padding: 0.75rem 0.55rem;
  }

  .stat-card strong {
    font-size: 1.15rem;
  }

  /* Game / practice */
  .game-header {
    position: sticky;
    top: 0;
    z-index: 35;
    background: rgba(245, 240, 232, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding-bottom: 0.35rem;
  }

  .progress-wrap {
    position: sticky;
    top: 3.25rem;
    z-index: 34;
    background: rgba(245, 240, 232, 0.97);
    padding: 0.25rem 0 0.4rem;
  }

  .question-card {
    padding: 0.9rem 0.85rem;
    border-radius: 16px;
  }

  .question-prompt {
    font-size: clamp(1.15rem, 5.2vw, 1.4rem);
    line-height: 1.35;
  }

  .options-grid {
    gap: 0.5rem;
  }

  .option-btn {
    min-height: 52px;
    padding: 0.9rem 0.95rem;
    font-size: 0.95rem;
    border-radius: 14px;
    word-break: break-word;
  }

  /* Listening monologues */
  .listen-monologue-card,
  .listen-mono-panel {
    overflow: hidden;
  }

  .listen-mono-fr,
  .mono-phrase {
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .listen-audio-bar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .listen-play-btn {
    flex: 1 1 100%;
    min-height: 50px;
  }

  .speed-controls {
    width: 100%;
    justify-content: space-between;
  }

  .pronunciation-panel,
  .speaker-delivery-panel {
    padding: 0.75rem;
  }

  .speaker-delivery-grid {
    grid-template-columns: 1fr;
  }

  .sentence-phon-row {
    grid-template-columns: 26px 1fr;
  }

  .sp-fr,
  .sp-ph {
    word-break: break-word;
  }

  /* Maestro full-height chat on phones */
  .screen-maestro.active {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }

  .screen-maestro .app-header {
    flex-wrap: nowrap;
  }

  .screen-maestro .header-actions,
  .screen-maestro .app-header .header-more-btn {
    display: none !important;
  }

  .maestro-layout {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }

  .maestro-toolbar {
    padding: 0.65rem;
    gap: 0.5rem;
  }

  .maestro-messages {
    flex: 1 1 auto;
    min-height: 38dvh;
    max-height: none;
    height: auto;
  }

  .maestro-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.15rem;
    gap: 0.4rem;
  }

  .maestro-chips::-webkit-scrollbar {
    display: none;
  }

  .maestro-chip {
    flex: 0 0 auto;
    white-space: nowrap;
    max-width: 78vw;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 40px;
  }

  .maestro-compose {
    position: sticky;
    bottom: 0;
    z-index: 30;
    background: var(--bg-card);
    padding-bottom: max(0.55rem, env(safe-area-inset-bottom));
  }

  .maestro-compose textarea {
    min-height: 48px;
    max-height: 120px;
  }

  .maestro-send {
    width: 100%;
    min-height: 48px;
  }

  .maestro-footnote {
    font-size: 0.68rem;
    padding: 0 0.25rem;
  }

  /* Psychology */
  .psy-grid {
    grid-template-columns: 1fr !important;
  }

  .psy-lesson,
  .psy-hero {
    padding: 1rem;
  }

  .psy-lesson-actions {
    flex-direction: column;
  }

  .psy-lesson-actions .btn {
    width: 100%;
  }

  /* Paywall / onboarding — bottom sheet style */
  .onboarding-overlay,
  .paywall-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
    background: rgba(28, 42, 58, 0.45);
  }

  .onboarding-card,
  .paywall-card {
    width: 100%;
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: min(92dvh, 720px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.25rem 1.15rem max(1.25rem, env(safe-area-inset-bottom));
    margin: 0;
  }

  .paywall-perks {
    font-size: 0.86rem;
  }

  /* Settings */
  .settings-card {
    padding: 1rem;
  }

  .setting-row select,
  .setting-row input[type="checkbox"] {
    min-height: 44px;
  }

  .setting-row select {
    width: 100%;
    font-size: 16px;
  }

  /* Curriculum filters horizontal scroll */
  .curriculum-filters,
  .phase-pills {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.4rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.2rem;
  }

  .curriculum-filters::-webkit-scrollbar,
  .phase-pills::-webkit-scrollbar {
    display: none;
  }

  .curriculum-filter-btn,
  .phase-pill {
    flex: 0 0 auto;
  }

  /* Comics reader */
  .comic-cover {
    min-height: 96px;
  }

  /* Feedback toast */
  .feedback {
    left: 0.75rem !important;
    right: 0.75rem !important;
    width: auto !important;
    max-width: none !important;
    bottom: max(1rem, env(safe-area-inset-bottom)) !important;
  }

  /* Pricing */
  .pricing-cards {
    grid-template-columns: 1fr !important;
  }

  .plan-card {
    padding: 1.1rem;
  }

  /* Prevent accidental horizontal scroll from long French */
  .listen-mono-fr,
  .passage-text,
  .fr-line,
  .maestro-msg-bubble,
  .question-prompt {
    overflow-wrap: anywhere;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }

  .logo h1 {
    font-size: 0.95rem;
  }

  .header-actions .icon-btn {
    height: 44px;
    font-size: 1.05rem;
  }

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

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

/* Landscape phones — keep content usable */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .screen {
    padding-top: 0.5rem;
    padding-bottom: 0.75rem;
  }

  .app-header {
    position: relative;
    margin-bottom: 0.5rem;
  }

  .maestro-messages {
    min-height: 28dvh;
    max-height: 42dvh;
  }

  .landing-hero {
    padding-top: 0.5rem;
  }

  .hero-title {
    font-size: 1.45rem;
  }
}

/* Prefer reduced motion */
@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;
  }
}

/* Touch devices: kill hover stickiness */
@media (hover: none) and (pointer: coarse) {
  .icon-btn:hover,
  .mode-card:hover,
  .hub-card:hover {
    transform: none;
  }

  .icon-btn:active,
  .mode-card:active,
  .hub-card:active,
  .option-btn:active,
  .btn:active {
    transform: scale(0.97);
    opacity: 0.94;
  }
}
