/*
 * Shared typography for course lesson content, dictionary definitions,
 * and word-list meanings.
 *
 * UPDATE-068 applied this to the course lesson modal.
 * UPDATE-080 generalizes it as .ld-tinos-body (course keeps #lessonModalBody
 * selectors as aliases so the modal stays visually unchanged).
 * UPDATE-081 makes the size the same on every phone:
 *   - The size is locked in px through --ld-base (15px everywhere).
 *   - zoom: 0.94 is removed (zoom behaves differently across Chrome,
 *     Samsung Internet, in-app WebViews and Firefox).
 *   - Database content uses keyword sizes (font-size:medium / x-large).
 *     A keyword follows the browser's default font size, not the parent,
 *     so it differed per phone and browser setting. Inside the
 *     typography area every keyword is mapped to var(--ld-base) x the
 *     CSS keyword ratio (x-large = --ld-xl: 1.5 desktop, 1.3 mobile).
 *     Inline !important keywords (set by ld-definition-format.js on
 *     headwords) are rewritten by assets/js/ld-tinos-size.js.
 *
 * Loaded after tinos.css (and, on course.php, after course_dashboard.css).
 * All viewports: force Tinos (Tinos first, so a device or OS
 * "Times New Roman" cannot replace the self-hosted face).
 * Line-height 1.7; mobile (max-width: 768px, same breakpoint as
 * course_dashboard.css) line-height 1.45, headings 1.3.
 *
 * DictBats, icon fonts, and form controls are left alone. tinos.css is not
 * edited; this file does not use .font-tinos (that class still puts
 * Times New Roman first). Inline px/pt sizes are left as they are
 * (they are already the same on every phone).
 *
 * text-size-adjust: 100% stops Chrome Android font boosting. Newer Chrome
 * OS text scaling acts as page zoom and cannot be blocked from the web
 * (it scales the whole page evenly, so proportions stay the same).
 */

/* Stabilize size when these pages are opened in an Android browser. */
html,
body,
#lessonModal,
#lessonModal #lessonModalBody,
.ld-tinos-body {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#lessonModal #lessonModalBody,
.ld-tinos-body {
  --ld-base: 15px;
  --ld-xl: 1.5;
  --ld-xxl: 2;
  font-family: Tinos, 'Times New Roman', 'Liberation Serif', serif !important;
  font-size: var(--ld-base);
  line-height: 1.7;
}

#lessonModalBody *:not(button):not(input):not(select):not(textarea):not(.material-icons):not(.material-icons-outlined):not(.material-symbols-outlined):not(.material-symbols-rounded):not([class*="material-symbols"]):not([class*="icon"]):not(.fa):not([class*="fa-"]):not(.ds-font-dictbats):not([style*="DictBats" i]),
.ld-tinos-body *:not(button):not(input):not(select):not(textarea):not(.material-icons):not(.material-icons-outlined):not(.material-symbols-outlined):not(.material-symbols-rounded):not([class*="material-symbols"]):not([class*="icon"]):not(.fa):not([class*="fa-"]):not(.ds-font-dictbats):not([style*="DictBats" i]) {
  font-family: inherit !important;
}

#lessonModalBody [style*="DictBats" i],
#lessonModalBody [style*="DictBats" i] *,
#lessonModalBody .ds-font-dictbats,
#lessonModalBody .ds-font-dictbats *,
.ld-tinos-body [style*="DictBats" i],
.ld-tinos-body [style*="DictBats" i] *,
.ld-tinos-body .ds-font-dictbats,
.ld-tinos-body .ds-font-dictbats * {
  font-family: 'DictBats' !important;
}

/*
 * Keyword sizes from database content (font-size:medium, x-large, ...)
 * and legacy <font size="n">. Absolute calc() values, so nested
 * headword spans do not compound. Beats non-!important inline styles;
 * inline !important is handled by ld-tinos-size.js.
 */
#lessonModalBody [style*="font-size:xx-small" i],
#lessonModalBody [style*="font-size: xx-small" i],
.ld-tinos-body [style*="font-size:xx-small" i],
.ld-tinos-body [style*="font-size: xx-small" i] {
  font-size: calc(var(--ld-base) * 0.6) !important;
}

#lessonModalBody [style*="font-size:x-small" i],
#lessonModalBody [style*="font-size: x-small" i],
.ld-tinos-body [style*="font-size:x-small" i],
.ld-tinos-body [style*="font-size: x-small" i] {
  font-size: calc(var(--ld-base) * 0.75) !important;
}

#lessonModalBody [style*="font-size:small" i],
#lessonModalBody [style*="font-size: small" i],
.ld-tinos-body [style*="font-size:small" i],
.ld-tinos-body [style*="font-size: small" i] {
  font-size: calc(var(--ld-base) * 0.889) !important;
}

#lessonModalBody [style*="font-size:medium" i],
#lessonModalBody [style*="font-size: medium" i],
.ld-tinos-body [style*="font-size:medium" i],
.ld-tinos-body [style*="font-size: medium" i] {
  font-size: calc(var(--ld-base) * 1) !important;
}

#lessonModalBody [style*="font-size:large" i],
#lessonModalBody [style*="font-size: large" i],
.ld-tinos-body [style*="font-size:large" i],
.ld-tinos-body [style*="font-size: large" i] {
  font-size: calc(var(--ld-base) * 1.2) !important;
}

#lessonModalBody [style*="font-size:x-large" i],
#lessonModalBody [style*="font-size: x-large" i],
.ld-tinos-body [style*="font-size:x-large" i],
.ld-tinos-body [style*="font-size: x-large" i] {
  font-size: calc(var(--ld-base) * var(--ld-xl)) !important;
}

#lessonModalBody [style*="font-size:xx-large" i],
#lessonModalBody [style*="font-size: xx-large" i],
.ld-tinos-body [style*="font-size:xx-large" i],
.ld-tinos-body [style*="font-size: xx-large" i] {
  font-size: calc(var(--ld-base) * var(--ld-xxl)) !important;
}

#lessonModalBody [style*="font-size:xxx-large" i],
#lessonModalBody [style*="font-size: xxx-large" i],
.ld-tinos-body [style*="font-size:xxx-large" i],
.ld-tinos-body [style*="font-size: xxx-large" i] {
  font-size: calc(var(--ld-base) * 3) !important;
}

#lessonModalBody font[size="1"],
.ld-tinos-body font[size="1"] {
  font-size: calc(var(--ld-base) * 0.75);
}

#lessonModalBody font[size="2"],
.ld-tinos-body font[size="2"] {
  font-size: calc(var(--ld-base) * 0.889);
}

#lessonModalBody font[size="3"],
.ld-tinos-body font[size="3"] {
  font-size: calc(var(--ld-base) * 1);
}

#lessonModalBody font[size="4"],
.ld-tinos-body font[size="4"] {
  font-size: calc(var(--ld-base) * 1.2);
}

#lessonModalBody font[size="5"],
.ld-tinos-body font[size="5"] {
  font-size: calc(var(--ld-base) * var(--ld-xl));
}

#lessonModalBody font[size="6"],
.ld-tinos-body font[size="6"] {
  font-size: calc(var(--ld-base) * var(--ld-xxl));
}

#lessonModalBody font[size="7"],
.ld-tinos-body font[size="7"] {
  font-size: calc(var(--ld-base) * 3);
}

#lessonModalBody .dict-headword-large,
#lessonModalBody .dict-headword-large *,
.ld-tinos-body .dict-headword-large,
.ld-tinos-body .dict-headword-large * {
  font-size: calc(var(--ld-base) * var(--ld-xl)) !important;
}

/*
 * Beat desktop-style.css (.reading-content line-height 1 / 1.05) and
 * ld-definition.css (Times, p 120% / .9, panel-body 16px / 1.15) without
 * editing those shared files. These selectors do not match the course modal.
 */
.reading-page .ld-tinos-body.reading-content,
.reading-page .ld-tinos-body.reading-content p,
.reading-page .ld-tinos-body.reading-content p span,
.ld-tinos-body.definition,
.ld-tinos-body.definition p,
.ld-tinos-body.definition p span,
.ld-tinos-body.ld-definition,
.ld-tinos-body.ld-definition p,
.ld-tinos-body .ld-definition p,
.ld-tinos-body.ld-definition .panel-body p,
.ld-tinos-body .panel-body p {
  line-height: 1.7 !important;
  font-size: var(--ld-base);
}

.ld-tinos-body.ld-definition .panel-body p,
.ld-tinos-body .panel-body p {
  font-size: var(--ld-base) !important;
}

@media (max-width: 768px) {
  /*
   * UPDATE-081: no zoom. Size is locked in px (--ld-base) so it is the
   * same on every phone and browser. Headword (x-large) is 1.3x on mobile.
   */
  #lessonModal #lessonModalBody,
  .ld-tinos-body {
    --ld-base: 15px;
    --ld-xl: 1.3;
    --ld-xxl: 1.6;
    line-height: 1.45 !important;
  }

  #lessonModalBody :is(p, div, span, font, td, th, li, dd, dt, blockquote, strong, b, em, i, u, a, sup, sub, label, .box, .ld-definition, .ld-definition p, .panel-body p)
    :not(.material-icons):not(.material-symbols-outlined):not(button):not([style*="line-height:0"]):not([style*="line-height: 0"]),
  .ld-tinos-body :is(p, div, span, font, td, th, li, dd, dt, blockquote, strong, b, em, i, u, a, sup, sub, label, .box, .ld-definition, .ld-definition p, .panel-body p)
    :not(.material-icons):not(.material-symbols-outlined):not(button):not([style*="line-height:0"]):not([style*="line-height: 0"]) {
    line-height: 1.45 !important;
  }

  #lessonModalBody :is(h1, h2, h3, h4, h5, h6),
  .ld-tinos-body :is(h1, h2, h3, h4, h5, h6) {
    line-height: 1.3 !important;
  }

  #lessonModalBody p,
  .ld-tinos-body p {
    margin-top: 0 !important;
    margin-bottom: 0.45em !important;
  }

  #lessonModalBody p:last-child,
  #lessonModalBody td > p:last-child,
  #lessonModalBody li > p:last-child,
  .ld-tinos-body p:last-child,
  .ld-tinos-body td > p:last-child,
  .ld-tinos-body li > p:last-child {
    margin-bottom: 0 !important;
  }

  #lessonModalBody table td,
  #lessonModalBody table th,
  .ld-tinos-body table td,
  .ld-tinos-body table th {
    vertical-align: top;
  }

  #lessonModalBody table.middle-align td,
  #lessonModalBody table.middle-align th,
  #lessonModalBody td[valign="middle"],
  .ld-tinos-body table.middle-align td,
  .ld-tinos-body table.middle-align th,
  .ld-tinos-body td[valign="middle"] {
    vertical-align: middle;
  }

  #lessonModalBody td > p:first-child,
  .ld-tinos-body td > p:first-child {
    margin-top: 0;
  }

  #lessonModalBody img,
  #lessonModalBody video,
  #lessonModalBody audio,
  #lessonModalBody iframe,
  #lessonModalBody table,
  .ld-tinos-body img,
  .ld-tinos-body video,
  .ld-tinos-body audio,
  .ld-tinos-body iframe,
  .ld-tinos-body table {
    max-width: 100%;
  }

  .reading-page .ld-tinos-body.reading-content,
  .reading-page .ld-tinos-body.reading-content p,
  .reading-page .ld-tinos-body.reading-content p span,
  .ld-tinos-body.definition,
  .ld-tinos-body.definition p,
  .ld-tinos-body.definition p span,
  .ld-tinos-body.ld-definition,
  .ld-tinos-body.ld-definition p,
  .ld-tinos-body .ld-definition p,
  .ld-tinos-body.ld-definition .panel-body p,
  .ld-tinos-body .panel-body p {
    line-height: 1.45 !important;
    font-size: var(--ld-base);
  }

  .ld-tinos-body.ld-definition .panel-body p,
  .ld-tinos-body .panel-body p {
    font-size: var(--ld-base) !important;
    margin-top: 0 !important;
    margin-bottom: 0.45em !important;
  }
}
