/* The reading surface: article typography, word highlight, dictionary panel. */

.reader {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  cursor: default;
}

/* iOS Safari only sends `click` for taps on elements it considers clickable; a pointer
   cursor is what makes plain text count. Touch devices only, so a mouse still sees
   an ordinary text cursor. */
@media (hover: none) {
  .reader { cursor: pointer; }
  .panel { cursor: auto; }
}

.hl-layer { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.hl { position: absolute; background: var(--hl); }

.md {
  position: relative;
  z-index: 1;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: calc(28px + var(--safe-top)) calc(var(--gutter) + var(--safe-right)) 45vh calc(var(--gutter) + var(--safe-left));
  font-family: var(--font-read);
  font-size: var(--size);
  line-height: var(--lh);
  /* Kaiti is a light face; keep rendering crisp rather than emboldened. */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-break: strict;
  overflow-wrap: break-word;
}

.md > :first-child { margin-top: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .table-wrap { margin: 0 0 0.75em; }

.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { font-weight: 600; line-height: 1.3; margin: 1.4em 0 0.55em; }
.md h1 { font-size: 1.85em; margin-top: 0.3em; }
.md h2 { font-size: 1.48em; padding-bottom: 0.25em; border-bottom: 1px solid var(--rule); }
.md h3 { font-size: 1.26em; }
.md h4 { font-size: 1.1em; }
.md h5 { font-size: 1em; }
.md h6 { font-size: 0.92em; color: var(--ink-2); }

.md strong { font-weight: 700; }
.md del { color: var(--ink-2); }
.md a { color: var(--indigo); text-underline-offset: 0.18em; }
.md .inert-link { color: var(--ink-2); text-decoration: underline dotted; text-underline-offset: 0.18em; }
.md .missing-image { color: var(--ink-3); font-size: 0.85em; border: 1px dashed var(--rule); padding: 0 0.4em; }
.md img { max-width: 100%; height: auto; }

.md code { font-family: var(--font-mono); font-size: 0.86em; background: var(--wash); padding: 0.1em 0.3em; }
.md pre {
  background: var(--wash);
  border: 1px solid var(--rule);
  padding: 0.7em 0.85em;
  overflow-x: auto;
  line-height: 1.45;
  -webkit-overflow-scrolling: touch;
}
.md pre code { background: none; padding: 0; font-size: 0.82em; white-space: pre; }
.md pre.raw-html { white-space: pre-wrap; font-family: var(--font-mono); font-size: 0.8em; color: var(--ink-2); }

.md blockquote { margin-left: 0; padding-left: 0.9em; border-left: 3px solid var(--rule); color: var(--ink-2); }
.md blockquote > :last-child { margin-bottom: 0; }

.md ul, .md ol { padding-left: 1.5em; }
.md li { margin: 0.2em 0; }
.md li > ul, .md li > ol { margin: 0.2em 0 0; }
.md li > p { margin-bottom: 0.4em; }
.md ul.tasks { list-style: none; padding-left: 0.2em; }
.md li.task { display: flex; align-items: baseline; gap: 0.5em; flex-wrap: wrap; }
.md li.task > ul, .md li.task > ol { flex-basis: 100%; padding-left: 1.5em; }
.md .checkbox {
  flex: none;
  width: 0.78em; height: 0.78em;
  border: 1.5px solid var(--ink-2);
  transform: translateY(0.06em);
}
.md .checkbox.checked { background: var(--ink-2); box-shadow: inset 0 0 0 2px var(--paper); }

.md hr { border: 0; border-top: 1px solid var(--rule); margin: 1.6em 0; }

.md .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; font-size: 0.9em; line-height: 1.5; }
.md th, .md td { border: 1px solid var(--rule); padding: 0.35em 0.65em; text-align: left; vertical-align: top; }
.md th { background: var(--wash); font-weight: 600; }
.md .align-right { text-align: right; }
.md .align-center { text-align: center; }

/* ---- pages ----
   The article becomes screen-high columns that run off to the right, and the reader
   scrolls sideways over them one screen at a time. Sizes come from reader/flow.js. */

html.paged-mode, html.paged-mode body { height: 100%; overflow: hidden; overscroll-behavior: none; }

.reader.paged {
  position: fixed;
  inset: 0;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.reader.paged::-webkit-scrollbar { display: none; }

.reader.paged .md {
  box-sizing: border-box;
  /* Pixels, not percentages: WebKit does not paginate a column box of percentage height. */
  width: var(--page-w, 100vw);
  height: var(--page-h, 100vh);
  max-width: none;
  margin: 0;
  padding: calc(30px + var(--safe-top)) var(--page-side, 22px) calc(30px + var(--safe-bottom));
  /* column-width rather than column-count: WebKit ignores a count of one. */
  column-width: var(--page-col, 300px);
  column-gap: calc(2 * var(--page-side, 22px));
  column-fill: auto;
  orphans: 2;
  widows: 2;
}
.reader.paged .md h1, .reader.paged .md h2, .reader.paged .md h3,
.reader.paged .md h4, .reader.paged .md h5, .reader.paged .md h6 { break-after: avoid; break-inside: avoid; }
.reader.paged .md.chaptered h2 { break-before: column; margin-top: 0; }
/* Where break-before: column is not supported (Firefox), flow.js sizes these instead. */
.page-fill { height: 0; margin: 0; }
.reader:not(.paged) .page-fill { display: none; }
.reader.paged .md li, .reader.paged .md tr { break-inside: avoid; }
.reader.paged .md img { max-height: calc(var(--page-h, 100vh) - 140px); object-fit: contain; }
.reader.paged .md pre { white-space: pre-wrap; overflow-x: visible; }
.reader.paged .md pre code { white-space: pre-wrap; overflow-wrap: anywhere; }

/* One snap point per screen. */
.page-rail { position: absolute; left: 0; top: 0; height: 0; }
.page-rail > i {
  position: absolute;
  top: 0;
  width: var(--page-w, 100vw);
  height: 1px;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* ---- dictionary panel ---- */

.panel {
  z-index: 5;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--edge);
  display: flex;
  flex-direction: column;
  cursor: auto;
}
.panel.popup { position: absolute; }
.panel.dock-bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 44vh;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 0 var(--rule);
}
.panel.dock-top {
  position: fixed;
  left: 0; right: 0; top: 0;
  max-height: 44vh;
  padding-top: var(--safe-top);
  box-shadow: 0 1px 0 var(--rule);
}
.panel.dock-right {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) 0;
  box-shadow: -1px 0 0 var(--rule);
}
.panel-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.panel-close { display: none; position: absolute; top: 0; right: 0; width: 44px; height: 44px; align-items: center; justify-content: center; color: var(--ink-3); z-index: 1; }
.panel.dock-bottom .panel-close, .panel.dock-top .panel-close, .panel.dock-right .panel-close { display: flex; }
.panel.dock-right .panel-close, .panel.dock-top .panel-close { top: var(--safe-top); }

/* Sizes follow the reading size, as in the Mac app, within sane bounds. */
.entry {
  --e: clamp(15px, calc(var(--size) * 0.8), 20px);
  padding: 12px 14px 12px;
  font-family: var(--font-ui-zh);
  font-size: var(--e);
  line-height: 1.4;
}
.panel.dock-bottom .entry, .panel.dock-top .entry, .panel.dock-right .entry { padding-right: 44px; }
.entry p, .entry ol, .entry h3 { margin: 0; }

.entry-sources { display: flex; gap: 2px; margin: -2px 0 10px; border-bottom: 1px solid var(--rule); }
.entry-source { min-height: 36px; padding: 0 12px; font-size: 13px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.entry-source[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

.entry-head { display: flex; align-items: baseline; gap: 0.6em; flex-wrap: wrap; margin-bottom: 2px; }
.entry-headword { font-size: 1.9em; line-height: 1.2; font-weight: 500; }
.entry-variant { font-size: 1.25em; color: var(--ink-2); }

.entry-sense + .entry-sense { margin-top: 10px; }
.entry-reading { color: var(--indigo); font-size: 1.08em; margin-bottom: 2px !important; font-family: var(--font-ui-zh); }
.entry-defs { padding-left: 1.5em; }
.entry-defs li { padding-left: 0.1em; margin: 1px 0; }
.entry-defs li::marker { color: var(--ink-3); font-size: 0.85em; }

.entry-label { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 14px 0 4px !important; padding-top: 8px; border-top: 1px solid var(--rule); font-family: var(--font-ui); }
.entry-example + .entry-example { margin-top: 7px; }
.entry-example-zh { font-size: 1.06em; }
.entry-example-en { font-size: 0.86em; color: var(--ink-2); font-family: var(--font-ui); }

.entry-character { display: flex; align-items: baseline; gap: 0.5em; margin: 3px 0 !important; }
.entry-character-han { font-size: 1.15em; flex: none; }
.entry-character-reading { color: var(--indigo); font-size: 0.86em; flex: none; }
.entry-character-gloss { color: var(--ink-2); font-size: 0.86em; font-family: var(--font-ui); min-width: 0; }

.entry-credit { margin-top: 12px !important; font-size: 11.5px; color: var(--ink-3); font-family: var(--font-ui); }
.entry-empty { color: var(--ink-2); font-family: var(--font-ui); }
