/* Lectura fàcil
   Layout of the reader: an open book. Each sentence is one row across both
   pages, so the original and its translation always sit on the same line. */

:root {
  --bg: #e7ecea;
  --page: #fbfcfa;
  --fold: #d9e0dd;
  --ink: #1d2a31;
  --muted: #5c6c74;
  --line: #d3dbd8;
  --accent: #1f6670;
  --accent-ink: #ffffff;
  --mark: #f3e3a0;
  --mark-soft: #f8efc9;
  --speak: #cfe6e3;
  --auto: #c9d6e8;
  --danger: #a3342b;
  --shadow: 0 1px 2px rgba(25, 40, 45, .06), 0 12px 32px rgba(25, 40, 45, .10);
  --f-body: "Atkinson Hyperlegible", "Verdana", "Segoe UI", sans-serif;
  --f-display: "Literata", "Georgia", serif;
  --f-tr: var(--f-body);
  --fs: 21px;
  --lh: 1.6;
  --lh-tr: 1.6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f171b; --page: #172228; --fold: #0c1316; --ink: #e2eaec; --muted: #9aacb3;
    --line: #2a3a41; --accent: #70c2c7; --accent-ink: #0f171b; --mark: #5a4f22; --mark-soft: #3a3520;
    --speak: #1f4a4c; --auto: #2c3c55; --danger: #ef8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f171b; --page: #172228; --fold: #0c1316; --ink: #e2eaec; --muted: #9aacb3;
  --line: #2a3a41; --accent: #70c2c7; --accent-ink: #0f171b; --mark: #5a4f22; --mark-soft: #3a3520;
  --speak: #1f4a4c; --auto: #2c3c55; --danger: #ef8a80;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); margin: 0; }
body { color: var(--ink); font-family: var(--f-body); font-size: 16px; line-height: 1.5; -webkit-text-size-adjust: 100%; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--bg); }
button { font: inherit; color: inherit; }
a { color: var(--accent); }
code { font-size: .92em; background: var(--mark-soft); padding: 0 4px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--page); padding: 8px 12px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
.noscript { padding: 24px; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--bg);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px; border-bottom: 1px solid var(--line);
}
.bar-in { max-width: 1160px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.brand { display: flex; flex-direction: column; min-width: 0; margin-right: auto; }
.brand b { font-family: var(--f-display); font-weight: 600; font-size: 20px; letter-spacing: -.01em; line-height: 1.2; }
.brand span { font-size: 12.5px; color: var(--muted); }
.controls { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
.ctl { display: flex; flex-direction: column; gap: 3px; }
.ctl > label, .ctl > .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.ctl > label i, .ctl > .lbl i { font-style: normal; text-transform: none; letter-spacing: 0; opacity: .8; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--page); }
.seg button { border: 0; background: transparent; padding: 6px 11px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
select, input, textarea { font: inherit; font-size: 15px; color: var(--ink); background: var(--page); border: 1px solid var(--line); border-radius: 8px; }
select { max-width: 260px; padding: 6px 8px; }
.bar select { max-width: 196px; }
.bar #chap { max-width: 230px; }
input, textarea { padding: 8px 10px; width: 100%; }
textarea { line-height: 1.5; resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--page); border-radius: 8px; padding: 6px 11px; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn[aria-pressed="true"], .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.icon { padding: 6px 8px; }
.btn.icon svg { width: 18px; height: 18px; }
.btn .aa { font-family: var(--f-display); font-size: 15px; }
.ibtn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; display: grid; place-items: center; color: var(--ink); flex: none; }
.ibtn svg { width: 16px; height: 16px; }
.ibtn:hover { border-color: var(--accent); color: var(--accent); }
.ibtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ibtn.sm { width: 28px; height: 28px; }
.linkb { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; }
.badge { display: block; max-width: 1160px; margin: 10px auto 0; width: 100%; border: 1px dashed var(--accent); color: var(--accent); background: var(--mark-soft); border-radius: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer; text-align: left; }

/* dropdown menus */
.dd { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 35; min-width: 260px; max-width: calc(100vw - 32px); background: var(--page); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.menu.right { left: auto; right: 0; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }
.mi { display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left; padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.mi:hover { background: var(--mark-soft); }
.mi:disabled { opacity: .45; cursor: not-allowed; background: none; }
.mi svg { width: 18px; height: 18px; flex: none; color: var(--accent); }
.mi[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.mi[aria-pressed="true"] svg { color: var(--accent-ink); }
#toolsMenu { gap: 2px; min-width: 300px; }

/* ---------- library ---------- */
.lib { max-width: 1160px; margin: 0 auto; padding: 26px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); }
.lib h1 { font-family: var(--f-display); font-weight: 600; font-size: 30px; margin: 0 0 6px; letter-spacing: -.01em; }
.lib h2 { font-family: var(--f-display); font-weight: 600; font-size: 22px; margin: 0 0 12px; }
.lib h2 small { font-family: var(--f-body); font-weight: 400; font-size: 15px; color: var(--muted); }
.lead { color: var(--muted); margin: 0 0 22px; max-width: 70ch; font-size: 17px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 18px; }
.card { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 16px; background: var(--page); border-radius: 10px; box-shadow: var(--shadow); padding: 16px; }
.cover { border: 0; padding: 0; background: var(--fold); border-radius: 6px; overflow: hidden; aspect-ratio: 3 / 4; cursor: pointer; display: block; width: 100%; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { display: flex; flex-direction: column; gap: 8px; align-items: center; justify-content: center; height: 100%; padding: 10px; color: var(--accent); text-align: center; }
.cover .ph svg { width: 30px; height: 30px; }
.cover .ph b { font-family: var(--f-display); font-size: 13px; color: var(--ink); }
.meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.meta h3 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 19px; line-height: 1.25; }
.meta p { margin: 0; font-size: 14px; }
.subt { color: var(--ink); }
.linkish { border: 0; background: none; padding: 0; font: inherit; text-align: left; cursor: pointer; }
.linkish:hover { color: var(--accent); }
.langs { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; color: var(--muted); }
.langs svg { width: 14px; height: 14px; }
.langs span { background: var(--mark-soft); border-radius: 999px; padding: 0 8px; font-size: 13px; color: var(--ink); }
.card-actions { margin-top: auto; padding-top: 8px; display: flex; gap: 8px; align-items: center; }
.add { margin-top: 36px; }
.drop { display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; border: 1.5px dashed var(--line); border-radius: 10px; padding: 16px; background: var(--page); }
.drop.over { border-color: var(--accent); background: var(--mark-soft); }
.drop > div:first-child { flex: 1; min-width: 220px; display: flex; flex-direction: column; }
.drop span { color: var(--muted); font-size: 14px; }
.ai-cta { margin: 10px 2px 0; color: var(--muted); font-size: 13.5px; }
.ai-cta .linkb { font-size: inherit; }
.ai h2 { display: flex; align-items: center; gap: 8px; }
.ai h2 svg { width: 22px; height: 22px; color: var(--accent); }
.ai .step { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 14px; }
.ai .step h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 16px; }
.stepn { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 13px; flex: none; }
.ai .lbl { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 12px 0 6px; }
.ai .lbl small { text-transform: none; letter-spacing: 0; }
.choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.choices.row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dlg label.choice { flex-direction: row; align-items: flex-start; gap: 8px; margin: 0; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--ink); font-size: 14px; }
.dlg label.choice:has(input:checked) { border-color: var(--accent); background: var(--mark-soft); }
.dlg .choice input, .dlg .chk input { width: auto; flex: none; margin: 3px 0 0; accent-color: var(--accent); }
.choice span { display: flex; flex-direction: column; gap: 2px; }
.choice small { color: var(--muted); font-size: 12.5px; }
.chks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.dlg label.chk { flex-direction: row; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: 14px; }
.chk small { color: var(--muted); }
.chk.add select { font-size: 13px; padding: 3px 6px; }
.ai details { margin-top: 10px; }
.ai details summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.ai details.more { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.ai details.more[open] { padding-bottom: 12px; }
.ai details.more > .two, .ai details.more > label { margin-top: 10px; }
.ai textarea { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
.ai .btns { gap: 8px; }
.ai .btns .muted { font-size: 13px; margin-left: 6px; }
.ai-status { margin: 8px 0 0; font-size: 14px; }
.ai-status.ok { color: var(--accent); }
.ai-status.bad { color: var(--danger); }
@media (max-width: 760px) { .choices, .choices.row { grid-template-columns: 1fr; } }
.foot { margin-top: 40px; border-top: 1px solid var(--line); padding-top: 16px; color: var(--muted); font-size: 13.5px; }
.foot p { margin: 0 0 6px; max-width: 80ch; }
.foot-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 8px 24px; margin-top: 14px; }
.foot .author { display: flex; flex-direction: column; margin: 0; }
.foot .author b { color: var(--ink); font-weight: 700; }
.foot .lic { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.foot .lic a { color: var(--muted); }
.foot .lic a:hover { color: var(--accent); }

/* ---------- book ---------- */
#readerMain { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 22px 40px; }
.book { max-width: 1160px; margin: 0 auto; }
.spread {
  position: relative; border-radius: 6px; box-shadow: var(--shadow);
  background:
    linear-gradient(to right, transparent calc(50% - 26px), rgba(0, 0, 0, .035) calc(50% - 1px), var(--fold) 50%, rgba(0, 0, 0, .035) calc(50% + 1px), transparent calc(50% + 26px)),
    var(--page);
  padding-block: 40px 22px; min-height: 62vh; display: flex; flex-direction: column;
}
.no-tr .spread, .tr-below .spread { background: var(--page); }
.rows { flex: 1; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); position: relative; }
.no-tr .row, .tr-below .row { grid-template-columns: minmax(0, 1fr); max-width: 820px; margin-inline: auto; width: 100%; }
.cell { padding: 7px 44px 7px 64px; position: relative; transition: background-color .15s, opacity .15s; min-width: 0; }
.cell.tr { padding: 7px 56px 7px 44px; }
.tr-below .cell.tr { padding: 0 44px 10px 64px; }
.no-tr .cell.tr { display: none; }
.row.pstart { margin-top: calc(var(--fs) * .7); }
.row.pstart:first-child { margin-top: 0; }
.row[data-i]:hover .cell, .row.active .cell { background: var(--mark-soft); }
.row[data-i]:hover .cell.ca, .row.active .cell.ca { box-shadow: inset 3px 0 0 var(--mark); }
.row.speaking .cell { background: var(--speak); }
.focus-mode .rows:hover .row[data-i]:not(:hover):not(.active) .cell,
.focus-mode .rows:has(.active) .row[data-i]:not(.active):not(:hover) .cell { opacity: .3; }
.ca .txt { font-size: var(--fs); line-height: var(--lh); }
.trt { font-family: var(--f-tr); font-size: calc(var(--fs) * .92); line-height: var(--lh-tr); white-space: pre-line; }
.trt[dir="rtl"] { text-align: right; }
/* second language, below the main one */
.trt.sec { font-size: calc(var(--fs) * .78); color: var(--muted); margin-top: 3px; padding-top: 3px; border-top: 1px dotted var(--line); }
.chead .trt.sec { font-size: var(--fs); }
.trswitch { position: absolute; top: 10px; right: 56px; z-index: 2; }
.trswitch button { padding: 4px 10px; font-size: 13px; }
.tr-below .trswitch { right: 16px; }
.tr-below .trt { color: var(--muted); }
.trt.pending { color: var(--muted); }
.trt.fail { font-size: 14px; }
.teacher .trt.auto { box-shadow: inset 3px 0 0 var(--auto); padding-inline-start: 8px; }
.teacher .trt[contenteditable] { cursor: text; border-radius: 4px; }
.teacher .trt[contenteditable]:hover { outline: 1px dashed var(--accent); }
.teacher .trt[contenteditable]:focus { outline: 2px solid var(--accent); background: var(--page); }
.hide-tr .row:not(:hover):not(.active) .trt { filter: blur(7px); opacity: .55; user-select: none; }
.hide-tr .trt { transition: filter .2s, opacity .2s; }

.w { cursor: pointer; border-radius: 3px; padding: 0 1px; margin: 0 -1px; }
.w:hover { background: var(--mark); }
.w.k { text-decoration: underline; text-decoration-color: var(--accent); text-decoration-style: dotted; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.w.on { background: var(--accent); color: var(--accent-ink); }
.w.saved { text-decoration: underline; text-decoration-style: solid; text-decoration-color: var(--accent); text-underline-offset: 4px; text-decoration-thickness: 2px; }

.acts { position: absolute; left: 12px; top: 9px; display: flex; flex-direction: column; gap: 4px; opacity: 0; transition: opacity .15s; }
.row:hover .acts, .row.active .acts, .acts:focus-within { opacity: 1; }
.say, .explain { width: 30px; height: 30px; border-radius: 50%; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.say svg { width: 15px; height: 15px; }
.say:hover, .explain:hover { border-color: var(--line); color: var(--accent); }

.chead { padding-bottom: 18px; }
.chead .cell { padding-top: 0; padding-bottom: 0; }
.chead .num { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.chead h2 { font-family: var(--f-display); font-weight: 600; font-size: calc(var(--fs) * 1.6); line-height: 1.2; margin: 4px 0 0; text-wrap: balance; letter-spacing: -.01em; }
.chead .trt { font-size: calc(var(--fs) * 1.3); margin-top: 4px; }
.tr-below .chead .tr { padding-top: 6px; }
.tr-below .chead .tr .num { display: none; }
.rules { padding-bottom: 18px; }
.rule { height: 1px; background: var(--line); margin: 0 44px 0 64px; }
.rule.r { margin: 0 56px 0 44px; }
.no-tr .rule.r, .tr-below .rule.r { display: none; }
.row.sub { margin-top: calc(var(--fs) * 1.1); }
.row.sub h3 { font-family: var(--f-display); font-weight: 600; font-size: calc(var(--fs) * 1.05); margin: 0; }
.row.sub .trt { font-weight: 600; }
.row.img { margin-block: 14px; }
.fig { margin: 0; text-align: center; }
.tr-below .row.img .cell.tr { display: none; }
.fig img { max-width: min(100%, 520px); max-height: 38vh; border-radius: 6px; mix-blend-mode: multiply; }
:root[data-theme="dark"] .fig img { mix-blend-mode: normal; background: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .fig img { mix-blend-mode: normal; background: #fff; } }

.folio { display: grid; grid-template-columns: 1fr 1fr; margin-top: 24px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.folio span:first-child { padding-left: 64px; }
.folio span:last-child { text-align: right; padding-right: 56px; }

/* vocabulary */
.vocab { padding: 24px 56px 0 64px; }
.vocab h3 { font-family: var(--f-display); font-weight: 600; font-size: calc(var(--fs) * 1.2); margin: 0 0 4px; }
.vocab p.sub { color: var(--muted); margin: 0 0 12px; }
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 28px; }
.vitem { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-content: start; align-items: start; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.vitem:hover .vca { color: var(--accent); }
.vca { font-size: calc(var(--fs) * .95); font-weight: 700; grid-column: 1; }
.vdef { color: var(--muted); font-size: 14.5px; grid-column: 1; }
.vtr { font-family: var(--f-tr); grid-column: 1; font-size: 16px; line-height: var(--lh-tr); }
.vtr.pending { color: var(--muted); }
.vtr.sec { font-size: 14.5px; color: var(--muted); }
.vitem .ibtn { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
.endnav { display: flex; gap: 10px; margin: 26px 56px 0 64px; flex-wrap: wrap; align-items: center; }
.credits { margin: 22px 56px 0 64px; font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
.credits p { margin: 0 0 4px; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.navb { border: 1px solid var(--line); background: var(--page); border-radius: 999px; padding: 9px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; font-size: 15px; }
.navb:disabled { opacity: .4; cursor: default; }
.navb svg { width: 16px; height: 16px; }
.progress { flex: 1; min-width: 120px; display: flex; flex-direction: column; gap: 6px; }
.progress .track { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress.big .track { height: 8px; }
.progress .fill { height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.progress small { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.legend { margin-top: 14px; color: var(--muted); font-size: 13px; display: flex; gap: 6px 18px; flex-wrap: wrap; }
.legend em { font-style: normal; text-decoration: underline dotted var(--accent) 2px; text-underline-offset: 4px; color: var(--ink); }

/* ---------- word popover ---------- */
.pop { position: absolute; z-index: 40; width: min(360px, calc(100vw - 32px)); background: var(--page); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px 12px; }
.pop .head { display: flex; align-items: flex-start; gap: 10px; }
.pop .hw { font-family: var(--f-display); font-weight: 600; font-size: 24px; line-height: 1.2; }
.pop .pos { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pop .form { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pop .tools { margin-left: auto; display: flex; gap: 6px; flex: none; }
.pop dl { margin: 10px 0 0; display: grid; gap: 8px; }
.pop dt { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.pop dd { margin: 1px 0 0; font-size: 16px; line-height: 1.45; }
.pop dd.trd { font-family: var(--f-tr); font-size: 18px; line-height: var(--lh-tr); }
.pop dd[dir="rtl"] { text-align: right; }
.pop dd.pending { color: var(--muted); }
.pop dd.err { color: var(--danger); font-size: 14px; font-family: var(--f-body); }
.pop .alt { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.pop .note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }

/* ---------- drawer ---------- */
.drawer { position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); background: var(--page); border-left: 1px solid var(--line); box-shadow: var(--shadow); padding: calc(18px + env(safe-area-inset-top, 0px)) max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) 18px; overflow-y: auto; }
.drawer h3 { font-family: var(--f-display); font-weight: 600; margin: 0; font-size: 20px; }
.drawer .dh { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.drawer p { margin: 0 0 12px; font-size: 14px; }
.empty { border: 1px dashed var(--line); border-radius: 10px; padding: 16px; color: var(--muted); font-size: 14px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 60; max-width: calc(100vw - 32px); text-align: center; }

/* ---------- dialogs ---------- */
.dlg { border: 0; border-radius: 14px; padding: 22px 24px; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--page); color: var(--ink); box-shadow: var(--shadow); }
.dlg.wide { width: min(760px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(10, 20, 25, .45); }
.dlg h2 { font-family: var(--f-display); font-weight: 600; margin: 0 0 8px; font-size: 22px; }
.dlg h3 { font-size: 15px; margin: 18px 0 4px; }
.dlg p { margin: 0 0 10px; }
.dlg ul { padding-left: 20px; margin: 0 0 8px; }
.dlg li { margin-bottom: 6px; }
.dlg li svg { width: 15px; height: 15px; vertical-align: -2px; }
.dlg label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.dlg label input, .dlg label select, .dlg label textarea { color: var(--ink); max-width: none; }
.dlg fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px 4px; margin: 0 0 12px; }
.dlg legend { font-weight: 700; padding: 0 4px; }
.dlg .two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.dlg-actions.left { justify-content: flex-start; margin-top: 4px; }
.checklist { margin: 8px 0 4px; padding-left: 20px; font-size: 14px; }
.checklist li { margin-bottom: 4px; }
.checklist li.ok::marker { content: "✓  "; color: var(--accent); }
.checklist li.bad::marker { content: "✗  "; color: var(--danger); }
.warn { background: var(--mark-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.copyrow { display: flex; gap: 8px; margin: 6px 0 10px; }
.copyrow input { flex: 1; min-width: 0; }
.review { border: 1px solid var(--line); border-radius: 10px; max-height: 46vh; overflow-y: auto; margin: 6px 0 10px; }
.rv { display: grid; grid-template-columns: auto 64px minmax(0, 1fr); gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.rv:last-child { border-bottom: 0; }
.rvk { font-size: 13px; color: var(--muted); text-align: center; }
.rvt { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.rvt input { padding: 4px 8px; font-weight: 700; }
.rvt small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vlist { max-height: 60vh; overflow-y: auto; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .spread { background: var(--page); padding-block: 22px 14px; min-height: 0; }
  .row { grid-template-columns: minmax(0, 1fr); padding-block: 4px; }
  .row[data-i] + .row[data-i]:not(.pstart) { border-top: 1px solid var(--line); }
  .cell, .cell.tr, .tr-below .cell.tr { padding: 4px 16px 4px 52px; }
  .cell.tr { padding-top: 0; padding-bottom: 8px; }
  .trt { color: var(--muted); }
  .acts { opacity: .85; left: 8px; top: 4px; }
  .row:hover .cell.ca, .row.active .cell.ca { box-shadow: none !important; }
  .chead .cell, .chead .cell.tr { padding-left: 16px; }
  .rules { display: none; }
  .chead .tr { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
  .folio { grid-template-columns: 1fr; padding: 0 16px; }
  .folio span:first-child { padding-left: 0; }
  .folio span:last-child { display: none; }
  .vocab { padding: 16px 16px 0; }
  .endnav, .credits { margin: 20px 16px 0; }
  .fig { padding: 6px 16px; }
  .row.img .cell.tr, .chead .tr .num { display: none; }
  .bar-in > .brand { flex: 1 1 0; }
  .pop.sheet { position: fixed; left: 0 !important; right: 0; bottom: 0; top: auto !important; width: 100%; max-height: 70vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .brand b { font-size: 18px; }
  .bar { position: static; }
  .ctl.spacer > .lbl { display: none; }
  .controls { width: 100%; }
  select, .bar select, .bar #chap { max-width: 100%; }
  .card { grid-template-columns: 84px minmax(0, 1fr); padding: 12px; gap: 12px; }
  .dlg .two { grid-template-columns: 1fr; }
  .menu, .menu.right { position: fixed; left: 12px; right: 12px; top: auto; bottom: 12px; max-height: 75vh; overflow-y: auto; min-width: 0; }
  .legend { display: none; }
  .trswitch { position: static; margin: 0 16px 12px; align-self: flex-start; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ---------- print: the chapter, bilingual, without the app around it ---------- */
@media print {
  :root { --bg: #fff; --page: #fff; --ink: #000; --muted: #333; --line: #bbb; --fs: 14pt; }
  .bar, .pager, .legend, .acts, .pop, .drawer, .toast, .endnav, .folio, .badge, .skip, .trswitch { display: none !important; }
  #readerMain { padding: 0; }
  .spread { box-shadow: none; background: #fff; min-height: 0; padding: 0; }
  .row { break-inside: avoid; }
  .cell { padding: 3pt 12pt 3pt 0; }
  .cell.tr { padding: 3pt 0 3pt 12pt; border-left: 1px solid #ddd; }
  .hide-tr .trt { filter: none !important; opacity: 1 !important; }
  .row:hover .cell { background: none; box-shadow: none; }
  .teacher .trt.auto { box-shadow: none; padding: 0; }
  .fig img { max-height: 8cm; }
}
