/* ============================================================
   responsive.css — Multi-device layout (Computer / iPad / Phone)
   Enhances styles.css with proper breakpoints + touch support
   ============================================================ */

/* ── iOS safe areas (iPhone notch / Dynamic Island) ───────── */
@supports (padding: env(safe-area-inset-top)) {
  .sidebar       { padding-top: max(20px, env(safe-area-inset-top)); }
  .main-content  { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .mobile-toggle { top: max(14px, env(safe-area-inset-top)); }
  .feedback-fab  {
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
    right:  max(24px, calc(env(safe-area-inset-right) + 16px));
  }
}

/* ── Touch-friendly defaults ──────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  /* Bigger tap targets on touch devices */
  button, .btn, .nav-item button, [role="button"] {
    min-height: 44px;
  }
  .speak-btn { min-width: 36px; min-height: 36px; opacity: 0.9; }
  /* Disable hover transforms on touch (sticky hover) */
  .feature:hover, .pricing-card:hover, .course-card:hover { transform: none; }
}

/* iOS-specific: prevent zoom on input focus */
@media (max-width: 1023px) {
  input, select, textarea { font-size: 16px !important; }
}

/* Smooth scrolling on touch devices */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: rgba(37, 99, 235, .15); -webkit-overflow-scrolling: touch; }

/* ════════════════════════════════════════════════════════════
   BREAKPOINT 1: Large Desktop (≥1280px) — keep current layout
   ════════════════════════════════════════════════════════════ */

/* ════════════════════════════════════════════════════════════
   BREAKPOINT 2: Small Desktop / Landscape iPad (1024-1279px)
   ════════════════════════════════════════════════════════════ */
@media (max-width: 1279px) and (min-width: 1024px) {
  :root { --sidebar-w: 220px; }
  .sidebar-logo .logo-text { font-size: 1.05rem; }
  .main-content { padding: 28px 28px; }
}

/* ════════════════════════════════════════════════════════════
   BREAKPOINT 3: iPad Portrait / Tablet (768-1023px)
   Sidebar becomes a slide-in drawer like mobile
   ════════════════════════════════════════════════════════════ */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 0px; }

  .sidebar {
    transform: translateX(-280px);
    width: 280px;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 80px 32px 32px; }
  .mobile-toggle { display: flex; }

  /* Backdrop when sidebar open */
  body.sidebar-open::before {
    content: ''; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 99;
    backdrop-filter: blur(2px);
  }
  .sidebar { z-index: 100; }

  /* Use ipad screen real estate better */
  .dashboard-grid       { grid-template-columns: repeat(2, 1fr); }
  .quick-actions        { grid-template-columns: repeat(3, 1fr); }
  .course-hub-grid      { grid-template-columns: repeat(2, 1fr); }
  .features-grid        { grid-template-columns: repeat(2, 1fr); }
  .pricing-grid         { grid-template-columns: repeat(2, 1fr); }
}

/* ════════════════════════════════════════════════════════════
   BREAKPOINT 4: Mobile (≤767px)
   Refine the existing mobile layout
   ════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  :root { --sidebar-w: 0px; }

  /* Header bar at top (always visible on mobile) */
  body.has-mobile-header { padding-top: 56px; }
  .mobile-header {
    position: fixed; top: 0; left: 0; right: 0; height: 56px;
    background: var(--surface, #fff); border-bottom: 1px solid var(--border, #E2E8F0);
    display: flex; align-items: center; gap: 10px; padding: 0 14px;
    z-index: 90;
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }

  /* Sidebar = slide-in drawer */
  .sidebar {
    width: min(85vw, 320px);
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.3);
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 70px 14px 24px; }

  /* Mobile hamburger button */
  .mobile-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 44px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #E2E8F0);
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
  }

  /* Backdrop */
  body.sidebar-open::before {
    content: ''; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 99;
    backdrop-filter: blur(2px);
  }

  /* Page headers smaller */
  h1, .page-header h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  h3 { font-size: 1.1rem; }

  /* Single-column grids */
  .options-grid, .q-options { grid-template-columns: 1fr; }
  .progress-top, .dashboard-welcome { grid-template-columns: 1fr; }
  .dashboard-grid, .quick-actions { grid-template-columns: 1fr; }
  .course-hub-grid, .course-hub-grid-locked { grid-template-columns: 1fr; }

  /* Cards & components */
  .flashcard-scene { height: 240px; }
  .flashcard-word { font-size: 1.6rem; }
  .listen-text { font-size: 1.1rem; }
  .category-grid { grid-template-columns: repeat(2, 1fr); }

  /* Tighter padding on cards */
  .card, .lesson-card, .course-card-body { padding: 16px; }

  /* Buttons stack on small screens */
  .btn-group, .quiz-actions, .ai-actions {
    flex-direction: column; align-items: stretch;
  }
  .btn-group .btn, .quiz-actions .btn { width: 100%; justify-content: center; }

  /* Tables become scrollable */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modals fit screen better */
  .auth-modal-card, .feedback-card {
    margin: 12px; max-height: calc(100vh - 24px);
    border-radius: 16px;
  }

  /* Daily plan stacks */
  #daily-plan-grid { grid-template-columns: 1fr !important; }

  /* Speech buttons more visible on mobile */
  .speak-btn { font-size: 1.1rem; opacity: 0.9; padding: 6px 10px; }
}

/* ════════════════════════════════════════════════════════════
   BREAKPOINT 5: Small phones (≤375px) — iPhone SE etc.
   ════════════════════════════════════════════════════════════ */
@media (max-width: 375px) {
  .main-content { padding: 64px 10px 20px; }
  .category-grid { grid-template-columns: 1fr; }
  .nav-items { font-size: .95rem; }
  .quick-actions .btn { font-size: .9rem; padding: 12px 14px; }
}

/* ════════════════════════════════════════════════════════════
   LANDSCAPE PHONE — short height adjustments
   ════════════════════════════════════════════════════════════ */
@media (max-width: 1023px) and (orientation: landscape) and (max-height: 500px) {
  .flashcard-scene { height: 180px; }
  .hero { padding: 40px 0 50px !important; }
  .auth-modal-card, .feedback-card { max-height: 92vh; overflow-y: auto; }
}

/* ════════════════════════════════════════════════════════════
   PRINT — make courses printable
   ════════════════════════════════════════════════════════════ */
@media print {
  .sidebar, .mobile-toggle, .feedback-fab, button:not(.print-keep) { display: none !important; }
  .main-content { margin: 0; padding: 0; }
  body { background: #fff; color: #000; }
}

/* ════════════════════════════════════════════════════════════
   REDUCED MOTION — respect accessibility
   ════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ════════════════════════════════════════════════════════════
   PWA STANDALONE — when installed as app
   ════════════════════════════════════════════════════════════ */
@media (display-mode: standalone) {
  .install-cta { display: none !important; }
  body { user-select: none; -webkit-user-select: none; }
  /* Allow text selection in content areas */
  .lesson-content, .reading-passage, p, h1, h2, h3, .ai-message { user-select: text; -webkit-user-select: text; }
}

/* ════════════════════════════════════════════════════════════
   MOBILE SIDEBAR CLOSE BUTTON
   ════════════════════════════════════════════════════════════ */
.sidebar-close {
  display: none;
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px;
  background: transparent; border: 0; cursor: pointer;
  font-size: 1.4rem; color: var(--text2, #64748B);
  border-radius: 8px;
}
.sidebar-close:hover { background: var(--bg3, rgba(0,0,0,.05)); }

@media (max-width: 1023px) {
  .sidebar-close { display: flex; align-items: center; justify-content: center; }
}

/* ════════════════════════════════════════════════════════════
   PWA INSTALL BANNER
   ════════════════════════════════════════════════════════════ */
.install-banner {
  position: fixed; bottom: 16px; left: 16px; right: 16px;
  max-width: 420px; margin: 0 auto;
  background: linear-gradient(135deg, #312E81, #4338CA);
  color: #fff; padding: 14px 16px;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(49, 46, 129, .4);
  display: flex; align-items: center; gap: 12px;
  z-index: 998;
  animation: slideUp .35s ease-out;
}
.install-banner-icon { font-size: 1.6rem; flex-shrink: 0; }
.install-banner-text { flex: 1; font-size: .9rem; }
.install-banner-text strong { display: block; }
.install-banner-text small { opacity: .8; }
.install-banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
.install-banner-btn {
  background: rgba(255,255,255,.95); color: #312E81;
  border: 0; padding: 8px 14px; border-radius: 8px;
  font-weight: 700; font-size: .85rem; cursor: pointer;
  font-family: inherit;
}
.install-banner-btn:hover { background: #fff; }
.install-banner-close {
  background: transparent; color: rgba(255,255,255,.8);
  border: 0; cursor: pointer; font-size: 1.2rem;
  padding: 4px 8px; border-radius: 6px;
}
.install-banner-close:hover { background: rgba(255,255,255,.15); color: #fff; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
