:root {
  --bg: #f7f5f0; --paper: #fffdf8; --fg: #1c1b19; --muted: #6b6962; --line: #e3dfd5;
  --accent: #2e6b4f; --onaccent: #fff; --sel: #3949ab; --card: #ffffff; --shadow: 0 6px 24px rgba(0,0,0,.12);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #141413; --paper: #1a1a18; --fg: #ebe9e2; --muted: #a19f97; --line: #2f2e2a;
          --accent: #8fd3b0; --onaccent: #0f1a14; --card: #222220; --shadow: 0 6px 24px rgba(0,0,0,.5); }
}
/* The page chosen in Settings sets the whole app's scheme: a dark page, a dark app. */
:root[data-theme="dark"] { --bg: #141413; --paper: #1a1a18; --fg: #ebe9e2; --muted: #a19f97; --line: #2f2e2a;
        --accent: #8fd3b0; --onaccent: #0f1a14; --card: #222220; --shadow: 0 6px 24px rgba(0,0,0,.5); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
       display: flex; flex-direction: column; }
button, select, input { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 13px; }

/* The book's name on the top line; below it the page counter (chapters and pages) and the buttons. */
.bar { padding: 0 10px; padding-top: env(safe-area-inset-top); background: var(--paper); }
.bar .book { margin-top: 6px; }
.book { font-size: 16px; font-weight: 600; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Reading: the book's name and the buttons fade and fold away over 5 s; the text gets its room. */
.bar .fold { max-height: 80px; overflow: hidden; transition: max-height 1.2s, opacity 1.2s; }
.bar.gone .fold { max-height: 0; opacity: 0; transition: max-height 5s, opacity 5s; }
.tools { display: flex; align-items: center; gap: 6px; height: 40px; }
.tools .grow { flex: 1; }
.toclist { max-height: 50vh; overflow-y: auto; margin: 6px 0 12px; border-bottom: 1px solid var(--line); }
.tocitem { display: block; width: 100%; text-align: left; border: 0; background: transparent; color: inherit; font: inherit;
           font-size: 16px; padding: 8px 0; cursor: pointer; }
.tocitem.on { font-weight: 700; }
.gorow { display: flex; gap: 8px; align-items: center; }
.gorow input { width: 140px; font-size: 16px; padding: 6px 8px; }
.icon { border: 0; background: transparent; color: inherit; text-decoration: none; font-size: 22px; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
.icon.small { font-size: 16px; }
.icon:hover, .btn:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
       background: transparent; padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--onaccent); border-color: var(--accent); font-weight: 600; }
.btn.on { background: var(--accent); color: var(--onaccent); border-color: var(--accent); }

.status { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 14px; font-size: 16px;
          border-bottom: 1px solid var(--line); background: var(--paper); }
#statusText { font-weight: 600; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#statusText.lost { color: #c62828; }
#statusText.plain { font-weight: 500; }
.status #micBtn { margin-left: -8px; }
.status[hidden] { display: none; }
.status.off .meter, .status.off #micBtn { display: none; }
.status.off { cursor: pointer; }
.icon.pages { font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; padding: 4px 6px; }
.icon.pages[hidden] { display: none; }
.meter { flex: .5; height: 6px; background: var(--line); border-radius: 2px; overflow: hidden; min-width: 40px; }
.meter.wide { display: block; width: 100%; }
.meter.wide span { display: block; height: 100%; background: var(--accent); }
#level { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s; }

.tips { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: color-mix(in srgb, var(--accent) 12%, var(--paper));
        border-bottom: 1px solid var(--line); font-size: 14px; }
.tips[hidden] { display: none; }
.tips ol { margin: 0; padding-left: 20px; flex: 1; }
.tips li { margin: 2px 0; }
#layout { flex: 1; display: flex; min-height: 0; }
.text { flex: 1; overflow-y: auto; padding: 16px 20px 40vh; font: 20px/1.6 Georgia, "Iowan Old Style", serif;
        max-width: 760px; margin: 0 auto; width: 100%; position: relative; }
/* The page as chosen in Settings (background, font, size); Auto follows the system's light or dark. */
#layout { background: var(--page-img, none) center / cover no-repeat, var(--page-bg, transparent); }
.text { color: var(--page-fg, inherit); }
.sizerow { display: flex; align-items: center; gap: 10px; margin: 6px 0 4px; }
.sizerow input { flex: 1; }
.text p { margin: 0 0 14px; }
.text h2.chapter { font: 600 22px/1.3 system-ui, sans-serif; margin: 8px 0 18px; }
.w { cursor: pointer; }
.w.last { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.w.skip { text-decoration: line-through; }
.w.scored { color: var(--page-mark, inherit); }
.w.na { opacity: .82; } /* not scored: the app doesn't know how to say it; a shade lighter, still easy to read */
/* The tapped word: a moving dashed frame around it (its score colour stays visible). */
.w.sel { padding: 1px 2px; margin: 0 -2px; border-radius: 2px;
         background-image: linear-gradient(90deg, var(--sel) 50%, transparent 0), linear-gradient(90deg, var(--sel) 50%, transparent 0),
                           linear-gradient(0deg, var(--sel) 50%, transparent 0), linear-gradient(0deg, var(--sel) 50%, transparent 0);
         background-repeat: repeat-x, repeat-x, repeat-y, repeat-y; background-size: 8px 2px, 8px 2px, 2px 8px, 2px 8px;
         background-position: 0 0, 0 100%, 0 0, 100% 0; animation: ants .7s linear infinite; }
@keyframes ants { to { background-position: 8px 0, -8px 100%, 0 -8px, 100% 8px; } }
@media (prefers-reduced-motion: reduce) { .w.sel { animation: none; } }
.titlepage { text-align: center; margin: 12px 0 30px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.titlepage .bt { font-size: 28px; line-height: 1.25; font-weight: 600; }
.titlepage .ba { font-size: 18px; color: var(--muted); margin-top: 8px; font-style: italic; }
.chnav { display: flex; justify-content: center; margin: 24px 0; }
.empty { text-align: center; margin-top: 18vh; font-family: system-ui, sans-serif; }
.empty h1 { font-size: 24px; } .empty p { color: var(--muted); }

.card { background: var(--card); box-shadow: var(--shadow); overflow-y: auto; padding: 12px 16px 16px; }
@media (min-width: 900px) {
  .card { width: 380px; border-left: 1px solid var(--line); box-shadow: none; }
}
@media (max-width: 899px) {
  #layout { flex-direction: column; }
  .card { position: fixed; left: 8px; right: 8px; bottom: 8px; max-height: 55vh; border-radius: 16px; z-index: 5;
          padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
.card .head, .wordview .head { display: flex; align-items: flex-start; gap: 8px; }
/* However long the word or its sound, they wrap; the close button keeps its place. */
.card .head .icon, .wordview .head .icon { flex: none; margin-left: auto; }
.card.peek { padding-top: 8px; padding-bottom: 8px; cursor: pointer; }
@media (max-width: 899px) { .card.peek { padding-bottom: max(8px, env(safe-area-inset-bottom)); } }
.peekrow { display: flex; align-items: center; gap: 8px; min-width: 0; }
.peekrow .word { font-size: 18px; font-weight: 700; flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peekrow .tr { flex: 0 1 auto; max-width: 35%; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 15px; }
.peekrow .icon { flex: none; }
.peekrow .pdef { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.peekrow .more { color: var(--muted); font-size: 22px; }
.card .head .wt, .wordview .head .wt { flex: 1; min-width: 0; overflow-wrap: anywhere; padding-top: 4px; }
.card .word, .wordview .word { font-size: 22px; font-weight: 700; }
.card .tr, .wordview .tr { color: var(--muted); font-size: 17px; margin-left: 6px; }
.card .score { font-weight: 700; }
.card .row, .wordview .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.card .row .btn, .wordview .row .btn { padding: 8px 4px; }
.sounds { font-size: 17px; margin: 4px 0; }
/* Label + value lines on the word card: American /…/, Your reading 82%, Should sound /…/. */
.kv { display: flex; align-items: baseline; gap: 10px; margin: 3px 0; flex-wrap: wrap; }
.kv .k { width: 104px; flex: none; font-size: 13px; color: var(--muted); }
.kv .ipa { font-size: 17px; }
.prons { margin: 2px 0 2px; }
.sounds b { font-weight: 700; }
.def { margin: 4px 0 8px; font-size: 15px; }
.def .mainsense { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 16px; }
.def .mainsense > span:first-child { flex: 1; }
.def .mainsense.only { cursor: default; }
.def .mainsense .arrow { color: var(--muted); padding: 0 6px; transition: transform .15s; }
.def .mainsense.open .arrow { transform: rotate(180deg); }
.def .moresenses { border-left: 3px solid var(--line); margin: 6px 0 2px 2px; padding-left: 10px; font-size: 14px; }
.def .pos { color: var(--muted); font-style: italic; }
.def ol { margin: 4px 0; padding-left: 20px; }
.def .ex { color: var(--muted); font-style: italic; }
.tries .try { display: grid; grid-template-columns: 30px 88px 1fr auto; align-items: center; gap: 8px; padding: 4px 0; }
.tries .try.latest .pct { font-size: 24px; }
.tries .pct { font-weight: 700; font-size: 18px; }
.drill { text-align: center; margin: 10px 0 4px; }
.drill .target { font-size: 34px; font-weight: 800; }
.verdict { font-size: 18px; font-weight: 600; text-align: center; margin: 6px 0 2px; min-height: 26px; }
.verdict.good { color: #2e7d32; } .verdict.bad { color: #c62828; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .verdict.good { color: #81c784; } :root:not([data-theme="light"]) .verdict.bad { color: #ef9a9a; } }
:root[data-theme="dark"] .verdict.good { color: #81c784; } :root[data-theme="dark"] .verdict.bad { color: #ef9a9a; }

/* Where the reader stopped: a small pointer in the gap above the word. */
/* Grey, not a colour of the scores; it sits in its caption, the two one tag. */
:root { --pointer: #5e5e5e; --onpointer: #fff; }
:root[data-theme="dark"] { --pointer: #b0b0b0; --onpointer: #000; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --pointer: #b0b0b0; --onpointer: #000; } }
.here { position: absolute; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent;
        border-top: 7px solid var(--pointer); pointer-events: none; opacity: 0; transition: opacity .4s; z-index: 4; }
.here.on { opacity: 1; pointer-events: auto; cursor: pointer; }
.here::after { content: ''; position: absolute; left: -16px; top: -24px; width: 44px; height: 30px; } /* easier to tap */
/* Its caption: small, beside the pointer in the gap between the lines, and see-through,
   so the text above and below shows through it. */
.here-tip { position: absolute; z-index: 3; background: color-mix(in srgb, var(--pointer) 55%, transparent); color: var(--onpointer);
            font: 600 11px/1 system-ui, sans-serif; padding: 2px 7px 2px 19px; border-radius: 8px; white-space: nowrap;
            pointer-events: none; opacity: 0; transition: opacity 2.5s; }
.here-tip.flip { padding: 2px 19px 2px 7px; }
.here-tip.on { opacity: 1; pointer-events: auto; cursor: pointer; transition: opacity .3s; }
.loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
           background: color-mix(in srgb, var(--paper) 70%, transparent); z-index: 8; font-size: 16px; }
.loading[hidden] { display: none; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.autoclose { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg);
         padding: 10px 16px; border-radius: 10px; z-index: 10; font-size: 14px; max-width: 90vw; }

dialog { border: 0; border-radius: 16px; background: var(--card); color: var(--fg); max-width: min(560px, 94vw);
         width: 100%; box-shadow: var(--shadow); padding: 18px 20px; }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog h2 { margin-top: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 16px; padding: 5px 12px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--onaccent); border-color: var(--accent); }
/* The three figures: one strip, divided in three; a tap opens the charts. */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; margin: 14px 0 6px; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.tile { padding: 10px 6px; text-align: center; }
.tile + .tile { border-left: 1px solid var(--line); }
.tile .num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.tile .lbl { font-size: 14px; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 4px; }
dialog h3 { font-size: 15px; margin: 18px 0 4px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; list-style: none; }
details.more summary::before { content: '▸ '; }
details.more[open] summary::before { content: '▾ '; }
.statrow { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.statrow .wd { flex: 1; min-width: 0; color: var(--accent); cursor: pointer; font-size: 16px; }
.statrow .wd.plain { color: inherit; cursor: default; }
.statrow .snd { flex: 1; font-size: 16px; }
.statrow .det { font-size: 13px; color: var(--muted); }
.statrow .pct { width: 44px; text-align: right; font-weight: 600; font-size: 15px; }
.statrow .rm { border: 0; background: transparent; cursor: pointer; font-size: 16px; color: var(--muted); }
.seg { display: flex; gap: 8px; }
.wide { width: 100%; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: transparent; }
input[type=range] { width: 100%; }

/* The library (Open). */
dialog.lib { max-width: min(640px, 96vw); }
.libhead { display: flex; align-items: center; justify-content: space-between; }
.libhead h2 { margin: 0; }
.cover { position: relative; width: 96px; aspect-ratio: 0.68; border-radius: 4px; overflow: hidden; color: #fff;
         display: flex; align-items: center; justify-content: center; text-align: center; font-size: 12px; flex: none; }
.cover span { padding: 6px; display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover.big { width: 110px; }
.nowreading { display: flex; gap: 16px; margin: 14px 0 6px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.nowreading .nr { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.nowreading .t { font-size: 20px; font-weight: 600; line-height: 1.25; }
.nowreading .btn { align-self: flex-start; margin-top: 8px; }
/* As many to a row as fit, the rest on rows below. */
.shelfrow { display: flex; flex-wrap: wrap; gap: 14px 12px; padding-bottom: 6px; }
.shelfbook { position: relative; width: 96px; flex: none; cursor: pointer; }
.shelfbook .st { font-size: 13px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rmbook { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%; width: 22px; height: 22px; background: rgba(0,0,0,.55);
          color: #fff; font-size: 12px; cursor: pointer; }
.opens { display: flex; flex-direction: column; gap: 8px; }
.opentile { justify-content: flex-start; padding: 12px 14px; }
/* ✕ in a dialog's top right corner. */
.dlgx { position: absolute; top: 10px; right: 10px; }
/* Day-by-day charts behind the statistics figures: one series each, recessive grid. */
.charts { margin: 4px 0 8px; }
.ctitle { font-size: 13px; font-weight: 600; margin: 8px 0 2px; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 10px; }
.chart .val { fill: var(--fg); font-size: 11px; font-weight: 600; }
.chart .bar { fill: var(--accent); opacity: .7; }
.chart .bar.last { opacity: 1; }
.chart .hit { fill: transparent; cursor: pointer; }
/* The reading timer in the top bar: its time in tabular figures, so it doesn't jiggle. */
/* Open, the timer, statistics and settings: the same icons in the same buttons. */
.icon.bar { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; padding: 0 8px; }
.icon.bar .ico { width: 24px; height: 24px; flex: none; }
.icon.timer { font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; gap: 3px; }
.verdict.none { color: var(--accent); }
.pmeter { display: block; margin: 6px 0; }
.pmeter #plevel { display: block; height: 100%; width: 0; background: var(--accent); transition: width .1s; }
.def .lemma { font-weight: 600; margin-top: 4px; }
.def .sense { margin-top: 4px; }
.linkbtn { border: 0; background: transparent; color: var(--accent); font: inherit; font-weight: 600; padding: 6px 0; cursor: pointer; }
.def .ex { padding-left: 12px; font-size: 14px; }
.shelfbook { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.statrow.tap { cursor: pointer; }
.statrow .exl { display: block; font-size: 12px; }
.morerows[hidden] { display: none; }
.readout { min-height: 18px; margin-top: 2px; }
/* Practising a word from the statistics: the dialog's own Close goes (Back takes its place). */
#statsDlg.practising > form:last-of-type { display: none; }
.chip .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 1px solid var(--line); }

/* Terminal: an old green-phosphor screen. The whole app green on black, monospace, a faint glow;
   read words marked the terminal way — bright (right), amber (so-so), reverse video (wrong). */
:root[data-term="1"] { --bg: #000; --paper: #000; --fg: #33ff66; --muted: #1f9a3f; --line: #0f3d1c;
  --accent: #66ff88; --onaccent: #000; --card: #020a04; --sel: #9dffb0; --shadow: 0 0 0 1px #0f3d1c; }
:root[data-term="1"] body, :root[data-term="1"] .text, :root[data-term="1"] button, :root[data-term="1"] input,
:root[data-term="1"] dialog { font-family: "IBM Plex Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas, "Courier New", monospace; }
:root[data-term="1"] .text { color: #33ff66; text-shadow: 0 0 3px rgba(51,255,102,.45); }
:root[data-term="1"] .text .w.scored { color: inherit; }
:root[data-term="1"] .text .w.t-good { color: #e2ffe8; text-shadow: 0 0 7px rgba(140,255,170,.95); }
:root[data-term="1"] .text .w.t-mid { color: #ffb000; text-shadow: 0 0 4px rgba(255,176,0,.6); }
:root[data-term="1"] .text .w.t-bad { color: #000; background: #ff5a36; text-shadow: none; }
:root[data-term="1"] .text .w.skip { opacity: .45; }
:root[data-term="1"] .btn, :root[data-term="1"] .chip { border-color: #1f9a3f; }
:root[data-term="1"] #pageInkBox[hidden] { display: none; }
#pageInkBox[hidden] { display: none; }
:root[data-term="1"] .here-tip { font-family: Menlo, Consolas, "Courier New", monospace; }
/* Colour scheme: one line (what it is, ▾); tap to open the choices. */
.scheme summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; padding: 8px 0; font-weight: 600; }
.scheme summary::-webkit-details-marker { display: none; }
.scheme summary #schemeNow { flex: 1; font-weight: 400; }
.scheme .chev { transition: transform .2s; }
.scheme[open] .chev { transform: rotate(180deg); }
/* Settings: parts with a small coloured heading, a rule between them. */
.set { border-top: 1px solid var(--line); padding: 10px 0 6px; }
.set:first-of-type { border-top: 0; padding-top: 0; }
.set h4 { margin: 0 0 6px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.set p { margin: 4px 0; }
.set .strong { font-size: 16px; }
.set input[type=range] { width: 100%; }
.scheme .schemebody { padding: 2px 0 6px 8px; }

/* Long press selects text to copy; the pointer and its caption aren't part of the book. */
.here, .here-tip { user-select: none; -webkit-user-select: none; }

/* The chapter before / after: a link with its name. */
.chnav .chlink { display: block; text-align: center; padding: 12px 8px; color: var(--accent); font: 600 17px/1.35 system-ui, sans-serif; text-decoration: underline; text-underline-offset: 3px; }
/* Contents: the page each entry starts on, on the right. */
.tocitem { display: flex; gap: 12px; align-items: baseline; }
.tocitem .tt { flex: 1; text-align: left; }
.tocitem .pg { color: var(--muted, #888); font-variant-numeric: tabular-nums; }

/* Russian-accent tips on a word's card: it counted, but sounds Russian. */
.ru { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 10px; padding: 8px 10px; margin: 6px 0; font-size: 13px; line-height: 1.4; }
.ru > div { margin-top: 3px; }
/* Taller when the Russian-accent tips show, so the tries below them stay in view. */
@media (max-width: 899px) { .card.tall { max-height: 78vh; } }
#statusTime { white-space: nowrap; font-variant-numeric: tabular-nums; }
#aloudBtn { padding: 3px 12px; font-size: 13px; min-height: 0; margin-left: 4px; white-space: nowrap; }
#aloudBtn[hidden] { display: none; }
#peekClose { margin-right: -8px; }
