/* mobile.css - phones and small tablets (loaded last, after theme.css).
   Nothing here changes the site on a computer: every rule is either "hidden by default"
   or inside a max-width block.
     1. Bottom menu (five tabs) in place of the sideways menu strip
     2. Lesson page: step bar under the top bar + the outline as a drawer
     3. Voices: one round speed button for the whole page, bigger play buttons
     4. Tap sizes and text sizes
     5. Tables
     6. Tests: the Next / Submit bar stays at the bottom of the screen
     7. Words, Grammar, Lessons pages
     8. Phone on its side (landscape) */

.mtabs, .voice-fab, .ol-mbar, .ol-shade, .ol-drawer-close { display: none; }

/* ---------- Lesson helpers (static/js/extras.js, outline.js), every screen size ---------- */
.card-header .x-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.x-tool { font: inherit; font-size: .95rem; font-weight: 600; min-height: 40px; padding: 0 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); -webkit-tap-highlight-color: transparent; }
.x-tool:hover { border-color: var(--primary-line); color: var(--primary-text); }
.x-tool.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.x-note { font-size: .95rem; color: var(--muted); }
.dialogue .line.x-now { background: var(--primary-soft); }
.dialogue.x-no-english .line .muted.small { display: none; }
/* "Continue where you stopped" */
.ol-resume { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 16px; padding: 12px 16px; border-radius: 14px;
  background: var(--primary-soft); border: 1px solid var(--primary-line); color: var(--text); font-size: 1rem; }
.ol-resume span { flex: 1 1 200px; }
.ol-resume button { font: inherit; font-weight: 600; min-height: 40px; padding: 0 18px; border-radius: 999px; cursor: pointer; border: 0; }
.ol-resume .ol-resume-go { background: var(--primary); color: #fff; }
.ol-resume .ol-resume-no { background: transparent; color: var(--muted); padding: 0 8px; }
/* The cartoon filling the whole window */
body.scene-full { overflow: hidden; }
body.scene-full #scene { position: fixed; inset: 0; z-index: 200; margin: 0; border: 0; border-radius: 0; overflow-y: auto; background: #10201f; }
body.scene-full #scene .card-header { position: sticky; top: 0; z-index: 2; min-height: 48px; padding: 4px 12px; background: #10201f; border: 0; }
body.scene-full #scene .card-title { color: #fff; font-size: 1rem; }
body.scene-full #scene .card-body { background: #10201f; }
body.scene-full #scene iframe { width: min(100vw, calc((100vh - 56px) * 16 / 9)) !important; margin: 0 auto; }
body.scene-full .x-full { background: #fff; border-color: #fff; color: #10201f; }

@media (max-width: 900px) {
  /* ---------- 1. Bottom menu ---------- */
  body.has-mtabs { padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
  .mtabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: var(--surface);
    border-top: 1px solid var(--border); box-shadow: 0 -6px 18px rgba(20, 60, 60, .07); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .mtabs > a, .mtabs-more > summary { flex: 1 1 0; min-width: 0; min-height: 62px; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; font-size: .8125rem; font-weight: 600; line-height: 1; color: var(--muted); text-decoration: none;
    cursor: pointer; list-style: none; -webkit-tap-highlight-color: transparent; }
  .mtabs-more { flex: 1 1 0; min-width: 0; position: static; }
  .mtabs-more > summary::-webkit-details-marker { display: none; }
  .mtabs svg.i { width: 24px; height: 24px; }
  .mtabs > a.active, .mtabs-more > summary.active, .mtabs-more[open] > summary { color: var(--primary-text); }
  .mtabs > a.active svg.i, .mtabs-more > summary.active svg.i { color: var(--primary); }
  .mtabs-sheet { position: absolute; right: 8px; bottom: calc(100% + 8px); width: min(260px, calc(100vw - 16px)); background: var(--surface);
    border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 12px 34px rgba(20, 60, 60, .2); padding: 8px; display: flex; flex-direction: column; }
  .mtabs-sheet a { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 12px; border-radius: 10px; font-size: 1rem;
    font-weight: 500; color: var(--text); text-decoration: none; }
  .mtabs-sheet a.active { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }
  .mtabs-sheet a svg.i { width: 21px; height: 21px; color: var(--muted); }
  .mtabs-sheet hr { border: 0; border-top: 1px solid var(--border); margin: 6px 4px; }
  /* The menu strip that scrolled sideways is not needed any more. */
  body.has-mtabs .cv-side { display: none; }
  body.has-mtabs .to-top { right: 14px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  body.has-outline .to-top { display: none; }   /* the lesson has its step bar instead */
  /* During a test the menu is put away, so nothing sits under the answer buttons. */
  body.in-test .mtabs { display: none; }
  body.in-test.has-mtabs { padding-bottom: 0; }

  /* ---------- 2. Lesson page ---------- */
  body.has-outline .ol-mbar { display: flex; align-items: center; gap: 6px; position: sticky; top: 62px; z-index: 25; margin: -22px -24px 14px;
    padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: 0 4px 12px rgba(20, 60, 60, .06); }
  .ol-mbar button { font: inherit; border: 0; background: transparent; color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .ol-mbar-open { flex: none; width: 44px; height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border-radius: 10px; }
  .ol-mbar-open span { display: block; width: 20px; height: 2px; border-radius: 2px; background: currentColor; }
  .ol-mbar-now { flex: 1 1 auto; min-width: 0; min-height: 44px; text-align: left; padding: 2px 4px; display: flex; flex-direction: column; justify-content: center; }
  .ol-mbar-now small { font-size: .8125rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
  .ol-mbar-now strong { font-size: 1rem; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ol-mbar-prev, .ol-mbar-next { flex: none; width: 44px; height: 44px; border-radius: 50%; font-size: 1.7rem; line-height: 1; background: var(--primary-soft) !important; color: var(--primary-text) !important; }
  .ol-mbar-prev:disabled, .ol-mbar-next:disabled { opacity: .35; }
  .ol-shade { position: fixed; inset: 0; z-index: 58; background: rgba(15, 40, 40, .45); }
  .ol-shade.is-open { display: block; }
  body.has-outline .ol-side, body.has-outline .ol-side.is-closed { display: flex; position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: min(86vw, 340px); max-height: none; margin: 0; padding: 0; border: 0; transform: translateX(-105%); transition: transform .22s ease; }
  body.has-outline .ol-side.is-open { transform: none; }
  body.has-outline .ol-side .ol-toggle { display: none; }
  body.has-outline .ol-side .ol-panel, body.has-outline .ol-side.is-closed .ol-panel { display: block; flex: 1; max-height: none; height: 100%; overflow-y: auto;
    border-radius: 0 18px 18px 0; border: 0; padding: 18px 14px calc(24px + env(safe-area-inset-bottom, 0px)); }
  .ol-drawer-close { display: block; float: right; width: 44px; height: 44px; margin: -8px -4px 0 0; border: 0; border-radius: 50%; background: transparent;
    font-size: 1.8rem; line-height: 1; color: var(--muted); cursor: pointer; }
  body.has-outline .ol-side .ol-list a { min-height: 46px; }
  /* The print button is of no use on a phone. */
  .print-btn { display: none !important; }

  .card-header .x-tools { margin-left: 0; width: 100%; }
  .card-header:has(.x-tools) { flex-wrap: wrap; row-gap: 8px; }
  body.scene-full #scene .card-header { flex-wrap: nowrap; }
  body.scene-full #scene .card-header .x-tools { width: auto; margin-left: auto; }

  /* ---------- 3. Voices ---------- */
  .play .rates { display: none !important; }
  .play-btn { width: 44px !important; height: 44px !important; }
  .play-btn svg { width: 20px; height: 20px; }
  .voice-fab { display: grid; place-items: center; position: fixed; left: 14px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 44;
    width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--primary); color: #fff; font: inherit; font-size: 1.05rem; font-weight: 700;
    box-shadow: 0 6px 16px rgba(20, 60, 60, .3); cursor: pointer; -webkit-tap-highlight-color: transparent; }
  body.in-test .voice-fab { display: none; }
  .ts-listen { min-height: 44px; padding: 0 16px; }
  /* Dialogue: the play button sits to the right of the sentence, not on a line of its own. */
  .dialogue .say { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: center; }
  .dialogue .say > * { grid-column: 1; }
  .dialogue .say > .play { grid-column: 2; grid-row: 1 / span 2; margin: 0; }

  /* ---------- 4. Tap sizes and text sizes ---------- */
  .btn, .btn-sm { min-height: 44px; }
  .small, .muted.small, .badge-sm, .subtitle small { font-size: .875rem; }
  .dialogue .line { padding: 14px 16px; }
  .dialogue .line .who a.row { min-height: 32px; }
  .user-drop a, .user-drop button { min-height: 46px; }
  .cv-partrow > summary { min-height: 56px; }
  .vx-pills button, .vx-views button, .cv-filters button, .cv-chip { min-height: 40px; }

  /* ---------- 5. Tables ---------- */
  /* A table wider than the screen: a soft shadow on the right says "there is more, swipe". */
  .table-scroll { background: linear-gradient(to right, var(--surface) 30%, rgba(255, 255, 255, 0)) 0 0 / 40px 100% no-repeat local,
      linear-gradient(to left, var(--surface) 30%, rgba(255, 255, 255, 0)) 100% 0 / 40px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(20, 60, 60, .18), rgba(0, 0, 0, 0)) 0 0 / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(20, 60, 60, .18), rgba(0, 0, 0, 0)) 100% 0 / 12px 100% no-repeat scroll;
    -webkit-overflow-scrolling: touch; }
  /* Sentence dissections: each word becomes a small block (word, kind, meaning, job) - no swiping. */
  .dissection .table-scroll { background: none; overflow: visible; }
  .dissection table, .dissection tbody, .dissection tr, .dissection td { display: block; width: auto; }
  .dissection thead { display: none; }
  .dissection tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
  .dissection tr:last-child { border-bottom: 0; }
  .dissection td { padding: 0 !important; border: 0 !important; }
  .dissection td:nth-child(1) { font-size: 1.05rem; }
  .dissection td:nth-child(2) { font-size: .875rem; color: var(--muted); }
  .dissection td:nth-child(3) { margin-top: 2px; }
  .dissection td:nth-child(4) { font-size: .9375rem; color: var(--text-2); }
  .dissection td:empty { display: none; }
  /* The word list of a lesson: the "Type" column is dropped so two columns fit. */
  .vocab-table th:nth-child(3), .vocab-table td:nth-child(3) { display: none; }

  /* ---------- 6. Tests ---------- */
  .practice .ts-foot.ts-foot-live { position: sticky; bottom: 0; z-index: 20; margin: 14px -20px -20px; padding: 10px 20px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -6px 16px rgba(20, 60, 60, .08); gap: 10px; }
  .practice .ts-foot-live .btn { flex: 1 1 auto; min-height: 48px; }
  .practice .ts-foot-live .ts-prevpage { flex: 0 0 auto; }
  .practice .ts-foot-live .ts-saved { display: none; }
  .practice .ts-foot-live .ts-left { flex: 1 0 100%; order: -1; text-align: center; min-height: 0; }
  .practice .ts-foot-live .ts-left:empty { display: none; }
  .ts-opt { min-height: 52px; }
  .ts-tile { min-height: 44px; }
  .ts-dots button { min-width: 14px; min-height: 14px; }

  /* ---------- 7. Words, Grammar, Lessons ---------- */
  .vx-tools { position: sticky; top: 62px; z-index: 15; background: var(--bg, #f1f6f6); margin: 0 -24px; padding: 8px 24px; }
  .g-toc.is-fold ol, .g-toc.is-fold ul { display: none; }
  .g-toc.can-fold .g-toc-title { display: flex; align-items: center; justify-content: space-between; min-height: 44px; margin: 0; cursor: pointer; }
  .g-toc.can-fold .g-toc-title::after { content: "+"; font-size: 1.4rem; font-weight: 500; color: var(--muted); }
  .g-toc.can-fold:not(.is-fold) .g-toc-title::after { content: "\2212"; }
  .g-toc.can-fold { padding: 8px 18px; margin-bottom: 20px; }
}

/* ---------- 8. Phone on its side ---------- */
/* A phone held sideways is wide but very low (about 390 px). The bars get thinner so the lesson keeps its room,
   and the cartoon is sized to fit the height of the screen. */
@media (max-width: 950px) and (max-height: 500px) and (orientation: landscape) {
  .topbar { position: static; }
  body.has-outline .ol-mbar { top: 0; padding: 2px 10px; }
  .ol-mbar-now small { display: none; }
  .vx-tools { top: 0; }
  body.has-mtabs { padding-bottom: calc(46px + env(safe-area-inset-bottom, 0px)); }
  .mtabs > a, .mtabs-more > summary { min-height: 46px; flex-direction: row; gap: 8px; }
  .mtabs svg.i { width: 20px; height: 20px; }
  .voice-fab, body.has-mtabs .to-top { bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .voice-fab { width: 46px; height: 46px; }
  body:not(.scene-full) #scene iframe { width: min(100%, calc((100vh - 105px) * 16 / 9)) !important; margin: 0 auto; }
  #scene .card-body { background: #10201f; }
  .ol-shade, body.has-outline .ol-side { z-index: 60; }
}
