/* ─────────────────────────────────────────────────────────────────
   YouEnglish — mobile layer
   Activates on viewports ≤ 768px. Borrows tokens from styles.css.
   ─────────────────────────────────────────────────────────────── */

/* Hide mobile chrome by default (desktop) */
.mobile-header,
.mobile-tabbar { display: none; }
.mh-title,
.mh-actions .mh-action { display: none; }

@media (max-width: 768px) {
  /* ─── shell ─── */
  .app-shell { display: block; min-height: 100vh; }
  .sidebar { display: none; }
  .main { padding-top: 56px; padding-bottom: 76px; }
  .page-wrap { padding: 16px 16px 16px; max-width: 100%; }

  /* ─── top header ─── */
  .mobile-header {
    display: flex; align-items: center; gap: 8px;
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 12px;
    background: rgba(255, 254, 251, 0.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
    z-index: 50;
  }
  .mh-btn {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; border: 0;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    flex-shrink: 0;
  }
  .mh-btn:active { background: var(--bg-subtle); }
  .mh-brand {
    padding: 0 4px;
    font-family: 'Fraunces', Georgia, serif; font-weight: 700;
    font-size: 20px; line-height: 1;
    color: var(--text-primary); text-decoration: none;
    flex: 1;
  }
  .mh-brand .e { color: var(--accent); }
  .mh-title {
    flex: 1;
    font-family: 'Manrope', sans-serif; font-weight: 600; font-size: 16px;
    color: var(--text-primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .mh-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
  .mh-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FB923C 0%, #DB2777 100%);
    color: white; font-weight: 700; font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center;
  }

  /* When on a child page (lesson, etc.), back button replaces brand */
  body[data-route="lesson"] .mh-brand,
  body[data-route="lesson-generating"] .mh-brand { display: none; }
  body[data-route="lesson"] .mh-title,
  body[data-route="lesson-generating"] .mh-title { display: block; }
  body[data-route="lesson"] #mh-back,
  body[data-route="lesson-generating"] #mh-back { display: inline-flex; }

  /* ─── bottom tab bar ─── */
  .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0;
    height: 64px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0);
    z-index: 50;
  }
  .mt-item {
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px; font-weight: 600;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--dur-fast) var(--ease-out);
  }
  .mt-item:active .mt-ico { transform: scale(0.92); }
  .mt-ico { transition: transform 150ms var(--ease-out); }
  .mt-item.active { color: var(--accent); }
  .mt-item.active::before {
    content: ""; position: absolute; top: 0; left: 50%;
    transform: translateX(-50%);
    width: 28px; height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
  }
  /* Hide bottom bar on the lesson screens to give content full real-estate */
  body[data-route="lesson-generating"] .mobile-tabbar { display: none; }
  body[data-route="lesson-generating"] .main { padding-bottom: 24px; }

  /* ─────────────────────────── HOME ─────────────────────────── */
  #page-home .stagger { padding: 0; }
  #page-home h1.text-display-xl {
    font-size: 34px;
    line-height: 1.15;
    margin: 0 0 16px;
  }
  #page-home .text-body-lg { font-size: 15px; line-height: 1.5; }
  #page-home > .stagger > div:first-child { padding: 16px 0 16px !important; }

  .card-hero {
    padding: 20px;
    border-radius: var(--radius-xl);
  }
  .card-hero .input-tall { height: 52px; font-size: 16px; }
  .card-hero textarea.srt-input { min-height: 120px; }
  .source-toggle { display: flex; width: 100%; }
  .src-tab {
    flex: 1; justify-content: center;
    padding: 10px 12px;
  }
  /* Stack level + generate */
  .card-hero > .row.between {
    flex-direction: column;
    align-items: stretch !important;
    gap: 12px !important;
  }
  .card-hero .select {
    width: 100%;
    height: 48px;
  }
  .card-hero .btn.btn-primary.btn-lg {
    width: 100%;
    height: 52px;
    font-size: 16px;
  }

  #page-home .grid-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  #page-home .card-stat { padding: 14px 12px; }
  #page-home .card-stat .num { font-size: 22px; }
  #page-home .card-stat .lbl { font-size: 10px; margin-top: 4px; }

  #page-home h2.text-heading-lg { font-size: 20px; }
  #home-continue {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  /* Horizontal scroll alternative — comment in if preferred:
  #home-continue { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
  #home-continue > .lcard { flex: 0 0 78%; scroll-snap-align: start; }
  */
  .lcard .body h3 { font-size: 15px; min-height: auto; }

  /* ─────────────────────────── LESSON ─────────────────────────── */
  /* On mobile the back link is replaced by the header back button */
  #page-lesson > .row.between.center { display: none; }

  .lesson-hero { max-width: 100%; }
  .lesson-player {
    border-radius: var(--radius-md);
    margin: 0 -16px;       /* full bleed */
    width: calc(100% + 32px);
  }
  .lesson-player .play-big {
    width: 60px; height: 60px;
  }
  .lesson-player .play-big::after {
    border-left: 14px solid white;
    border-top: 9px solid transparent;
    border-bottom: 9px solid transparent;
    margin-left: 4px;
  }
  .lesson-meta {
    flex-wrap: wrap; gap: 8px;
    font-size: 12px;
    margin-top: 16px;
  }
  .lesson-meta .sep { display: none; }
  .lesson-meta > span { padding: 2px 0; }
  .lesson-title { font-size: 28px; line-height: 1.15; }
  .lesson-actions-row { gap: 8px; margin-top: 12px; }
  .lesson-actions-row .who { font-size: 12px; flex: 1 1 100%; }
  .lesson-actions { gap: 0; }

  .lesson-tabs-wrap { margin-top: 24px; }
  /* Sticky tabs under the fixed header */
  .lesson-tabs-wrap .tabs {
    margin: 0 -16px;
    padding: 0 16px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: rgba(255, 254, 251, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky; top: 56px;   /* below mobile header */
    z-index: 4;
    gap: 20px;
  }
  .lesson-tabs-wrap .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { font-size: 14px; padding: 12px 0; white-space: nowrap; }
  .tab-btn .tab-count { font-size: 10px; padding: 1px 6px; }

  .tab-content { padding: 20px 0 24px; }

  /* Vocab grid → 1 col */
  .vocab-grid { grid-template-columns: 1fr; gap: 12px; }
  .vcard { padding: 18px 18px 16px; border-radius: var(--radius-lg); }
  .vcard .phrase { font-size: 17px; padding-right: 36px; }

  /* Grammar */
  .grammar-card { padding: 18px 18px 20px 22px; border-radius: var(--radius-lg); }
  .grammar-card h3.pattern { font-size: 16px; }
  .grammar-card h3.pattern .text-body-sm { display: block; margin: 4px 0 0; font-size: 13px; }

  /* Exercises */
  .exer-section + .exer-section { margin-top: 32px; }
  .exer-top { flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
  .exer-top h2 { font-size: 18px; }
  .exer-card { padding: 16px 16px; border-radius: var(--radius-lg); }
  .exer-options { grid-template-columns: 1fr; }
  .exer-card .row { flex-direction: column; align-items: stretch; }
  .exer-card .row .btn { width: 100%; }

  /* Transcript */
  .transcript { font-size: 16px; line-height: 1.65; }

  /* ─────────────────────────── LESSON · GENERATING ─────────────────────────── */
  .generating-wrap {
    padding: 20px 4px;
    min-height: calc(100vh - 80px);
  }
  .gen-thumb-glow { box-shadow: 0 0 60px rgba(251, 146, 60, 0.22); }
  .gen-thumb { border-radius: var(--radius-lg); }
  .gen-stage { font-size: 14px; }

  /* ─────────────────────────── VOCABULARY ─────────────────────────── */
  #page-vocab .page-header h1 { font-size: 28px; }
  #page-vocab .desc { font-size: 13px; }

  /* Collapse filter bar into a single horizontal-scroll row */
  #page-vocab .filter-bar {
    position: sticky; top: 56px;
    padding: 12px 0 12px;
    background: rgba(255, 254, 251, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    gap: 10px;
    flex-direction: column;
    align-items: stretch;
  }
  #page-vocab .filter-bar .search { flex: 1 1 100%; }
  #page-vocab .filter-bar .input { height: 44px; font-size: 15px; }
  /* Chip rows scroll horizontally */
  #page-vocab .filter-bar .chip-group {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px 6px;
    width: max-content;
    max-width: 100%;
  }
  #page-vocab .filter-bar .chip-group::-webkit-scrollbar { display: none; }
  #page-vocab .filter-bar .chip { padding: 8px 14px; font-size: 13px; }
  /* Move sort dropdown into its own row */
  #page-vocab .filter-bar > div[style*="margin-left: auto"] { margin-left: 0 !important; }
  #page-vocab .filter-bar .select {
    width: 100%;
    height: 40px !important;
  }

  /* Vocab rows → card layout */
  .vocab-list { gap: 8px; }
  .vocab-row {
    display: block;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 14px 14px;
  }
  .vocab-row:active { background: var(--surface-hover); }
  .vocab-row .col-text .phrase { font-size: 16px; }
  .vocab-row .col-text .ex { white-space: normal; -webkit-line-clamp: 2; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
  .vocab-row .col-meta {
    margin-top: 12px;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
  }
  .vocab-row .col-meta .source {
    flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 12px;
  }
  .vocab-row .icon-btn.sm { width: 36px; height: 36px; flex-shrink: 0; }

  /* ─────────────────────────── HISTORY ─────────────────────────── */
  #page-history .history-shell { grid-template-columns: 1fr; gap: 20px; }
  #page-history .history-preview { position: static; }

  .hl-item { grid-template-columns: 80px 1fr; padding: 10px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-md); }
  .hl-item.active { border-color: var(--accent); background: var(--accent-soft); }
  .hl-info h3 { font-size: 13px; }

  .preview-card { border-radius: var(--radius-xl); }
  .preview-card .player { border-radius: 0; }
  .preview-body { padding: 18px 20px 22px; }
  .preview-body h2 { font-size: 20px; line-height: 1.25; }
  .preview-body .meta-row { font-size: 13px; flex-wrap: wrap; gap: 6px; }
  .preview-stats { gap: 6px; }
  .preview-stats .card-stat { padding: 12px 10px; }
  .preview-stats .num { font-size: 18px; }
  .preview-stats .lbl { font-size: 9px; }
  .phrase-list-item { flex-wrap: wrap; padding: 8px 10px; gap: 8px; }
  .phrase-list-item .tr { margin-left: 0; text-align: left; flex: 1 1 100%; padding-left: 22px; }
  .preview-actions { flex-direction: column; gap: 8px; }
  .preview-actions .btn { width: 100%; }
  .preview-actions .btn.btn-icon,
  .preview-actions .btn-secondary[title] {
    width: 100%;
    flex-direction: row;
    gap: 8px;
  }

  /* ─────────────────────────── SETTINGS ─────────────────────────── */
  #page-settings { max-width: 100%; }
  #page-settings > div { max-width: 100% !important; }
  #page-settings .page-header h1 { font-size: 28px; }
  #page-settings h2.text-heading-lg { font-size: 19px; }
  .set-divider { margin: 28px 0; }
  .api-row {
    flex-direction: column;
    gap: 10px;
  }
  .api-row .btn { width: 100%; }
  .input-wrap .input-suffix.icon-btn { right: 6px; }
  .seg-control { width: 100%; display: flex; }
  .seg-tab { flex: 1; }
  .set-actions { flex-direction: column; gap: 8px; }
  .set-actions .btn { width: 100%; }

  /* ─────────────────────────── Misc ─────────────────────────── */
  /* Page header tighter */
  .page-header { margin-bottom: 20px; }
  .page-header .desc { font-size: 14px; }

  /* Lesson card thumb play always visible on touch */
  .lcard .thumb .play { opacity: 1; width: 40px; height: 40px; }
  .lcard .thumb .play::after { border-left: 10px solid var(--text-primary); border-top-width: 7px; border-bottom-width: 7px; }

  /* Buttons inherently touch-friendly */
  .btn-sm { height: 40px; padding: 0 14px; }
  .btn-md { height: 48px; padding: 0 18px; }
  .btn-lg { height: 52px; padding: 0 22px; }

  /* Inputs */
  .input { height: 48px; font-size: 16px; }   /* 16px prevents iOS zoom on focus */
  .input-tall { height: 52px; }

  /* Focus rings are still visible (helpful for users with external keyboards) */
}

/* ─────────────────────────────────────────────
   Tiny phones (<360px)
   ───────────────────────────────────────────── */
@media (max-width: 360px) {
  #page-home h1.text-display-xl { font-size: 28px; }
  #page-home .grid-3 { grid-template-columns: 1fr 1fr; }
  #page-home .grid-3 > .card-stat:nth-child(3) { grid-column: 1 / -1; }
  .mt-label { font-size: 10px; }
  .tab-btn { font-size: 13px; }
}

/* ─────────────────────────────────────────────
   Tablet bridge (769–1024px)
   ───────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 200px; padding: 24px 8px 16px; }
  .page-wrap { padding: 32px 28px 64px; }
  .vocab-grid { grid-template-columns: 1fr 1fr; }
  .history-shell { grid-template-columns: 280px 1fr; gap: 20px; }
  #page-home h1.text-display-xl { font-size: 48px; }
}
