/* reading.css - reading, listening and the word look-up (U track: js/screens/read.js, listen.js, js/study/lookup.js).
   Only what the design system (app.css) does not already have; colours, sizes and space only through its tokens, so
   light and dark follow by themselves. Rules it keeps: 44 px targets; 14 px text at the least; nothing wider than the
   page at 320 px; Japanese in .ja / .ja-lg keeps its fixed ruby line height, so a tapped word, a lit sentence or the
   furigana switch never moves a line; the bar at the foot and the look-up sheet sit above the tab bar and Tomo
   (--tutor-room), and on a wide screen Tomo has her own lane, so nothing here is ever under her. Phone first
   (docs/mobile-plan.md J12 to J15): lists are rows, the player is docked at the foot of a phone's screen, and a
   tapped word opens a bottom sheet of about half the screen (its pitch, kanji and Keep under More). */

/* ---- tappable words (lookup.js): lines break between phrases only (lookup.js marks them with <wbr>) ---- */
/* (the word spans are lang=ja too, so app.css's :lang(ja) auto-phrase is overridden on them as well) */
.lk-phrased, .lk-phrased :lang(ja) { word-break: keep-all; overflow-wrap: anywhere; }
.tw { border-radius: var(--r-1); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background .12s, box-shadow .12s; }
@media (hover: hover) { .tw:hover { background: var(--accent-soft); } }
.tw.on { background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent-text); }
.tw:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---- the look-up sheet: at the foot on a phone or tablet, a side panel on a wide screen ---- */
.lk-sheet { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-3); min-width: 0; }
.lk-float { position: fixed; z-index: 34; left: 0; right: 0; margin-inline: auto; width: calc(100% - 2 * var(--gutter)); max-width: 720px;
  bottom: calc(max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) + var(--s-2));
  max-height: min(70vh, calc(var(--vvh, 100vh) - var(--bar-h) - max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) - var(--s-6)));
  overflow: auto; overscroll-behavior: contain; padding: var(--s-3) var(--s-5) var(--s-5); box-shadow: var(--shadow-lg); }
/* On a phone it is a bottom sheet, the full width, docked on the tab bar; its first look is about half the screen
   (the word, its meaning, Add to my words), the rest under More. */
@media (max-width: 720px) {
  .lk-float { width: 100%; max-width: none; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: var(--r-3) var(--r-3) 0 0;
    padding: var(--s-2) max(var(--s-4), env(safe-area-inset-right)) var(--s-4) max(var(--s-4), env(safe-area-inset-left)); }
}
.lk-float::before { content: ""; display: block; width: 40px; height: 4px; margin: 0 auto var(--s-3); border-radius: var(--r-pill); background: var(--line-strong); }
@media (min-width: 1100px) {
  .lk-float { left: auto; right: calc(var(--tutor-w) + var(--s-6)); bottom: auto; top: calc(var(--bar-h) + var(--s-4)); width: min(400px, 34vw); margin: 0;
    max-height: calc(100vh - var(--bar-h) - var(--s-7) - var(--tutor-room, 0px)); padding-top: var(--s-5); }
  .lk-float::before { display: none; }
}
/* the page can always scroll its last line above an open sheet */
@media (max-width: 1099px) {
  html.lk-open .page { padding-bottom: calc(var(--lk-h, 0px) + max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) + var(--s-6)); }
}
.lk-dock { display: none; }
@media (min-width: 1100px) {
  .lk-dock { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-2); padding: var(--s-5); min-width: 0; }
}
.lk-idle p { margin: 0; }
.lk-head { display: flex; align-items: flex-start; gap: var(--s-3); }
.lk-word { flex: 1; min-width: 0; }
.lk-ja { margin: 0; font-size: var(--fs-30); line-height: var(--lh-ruby-big); font-weight: 700; overflow-wrap: anywhere; }
.lk-kana { margin: 0; font-size: var(--fs-18); color: var(--ink-2); }
.lk-x { margin: calc(-1 * var(--s-2)) calc(-1 * var(--s-2)) 0 0; }
.lk-asis { margin: var(--s-2) 0 0; color: var(--ink-2); }
.lk-mean { margin: var(--s-2) 0 0; font-size: var(--fs-20); font-weight: 700; line-height: 1.35; }
.lk-senses { margin: var(--s-1) 0 0; color: var(--ink-3); }
.lk-wait { margin: var(--s-3) 0 0; }
.lk-chips { margin-top: var(--s-3); }
.lk-pitch { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); margin-top: var(--s-3); }
.lk-pitch svg { max-width: 100%; height: auto; }
.lk-kanji { list-style: none; margin: var(--s-4) 0 0; padding: 0; display: grid; gap: var(--s-2); }
.lk-kanji li { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.lk-kmean { min-width: 0; overflow-wrap: anywhere; color: var(--ink-2); }
.lk-kmean b { color: var(--ink); }
.lk-acts { margin-top: var(--s-4); }
.lk-acts .chip { min-height: var(--tap); padding-inline: var(--s-4); }
/* what is already done (in your reviews, sentence kept): quiet words with the done mark, never a coloured chip */
.lk-done { display: inline-flex; align-items: center; gap: var(--s-2); min-height: var(--tap); color: var(--ink-2); font-weight: 700; }
.lk-more { margin-top: var(--s-4); }
.lk-more[open] > summary { margin-bottom: var(--s-1); }
.lk-more .lk-senses, .lk-more .lk-pos { margin: 0 0 var(--s-2); }
.lk-more .lk-acts { margin-top: var(--s-3); }
.lk-note { margin: var(--s-2) 0 0; color: var(--ink-2); }
.lk-note:empty { display: none; }
.lk-also { margin-top: var(--s-4); padding-top: var(--s-3); border-top: 1px solid var(--line); }
.lk-also p { margin: 0 0 var(--s-2); }
.lk-other { flex-direction: column; align-items: flex-start; gap: 2px; height: auto; min-height: var(--tap); padding: var(--s-2) var(--s-3); white-space: normal; text-align: left; font-weight: 400; max-width: 100%; }
.lk-other [lang=ja] { font-size: var(--fs-18); font-weight: 700; }
.lk-links { margin: var(--s-3) 0 0; }

/* ---- list pages: the title with its level chip, next up, the Topic select, the rows ---- */
.rd-titlerow { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2) var(--s-3); }
.rd-titlerow h1 { margin: 0; }
.rd-list-page .pagehead p { margin: var(--s-1) 0 0; }
.rd-featured { overflow: hidden; margin-bottom: var(--s-5); }
.rd-featured:has(> .rd-feat-pic:not([hidden])) { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.rd-feat-pic { margin: 0; min-height: 100%; }
.rd-feat-pic img { display: block; width: 100%; height: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.rd-feat-body { padding: var(--s-5); display: grid; gap: var(--s-2); align-content: center; min-width: 0; }
.rd-feat-body p { margin: 0; }
.rd-feat-ja { margin: 0; font-size: var(--fs-26); font-weight: 700; overflow-wrap: anywhere; }
.rd-feat-en { margin: 0; font-size: var(--fs-18); color: var(--ink-2); font-weight: 700; }
.rd-feat-body .row { margin-top: var(--s-2); }
.rd-kindsel { display: inline-flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-2); max-width: 100%; }
.rd-kindlabel { color: var(--ink-3); font-size: var(--fs-14); font-weight: 700; }
.rd-kindsel select { min-height: var(--tap); min-width: 0; max-width: calc(100vw - 2 * var(--gutter) - 64px); font-size: var(--fs-input); }
.rd-list { margin: 0; }
.rd-feat-big { font-size: var(--fs-20); color: var(--ink); }
.rd-list .rd-row-ja { font-size: var(--fs-18); line-height: var(--lh-ruby-big); font-weight: 700; }
.rd-done { display: inline-flex; align-items: center; gap: var(--s-1); }
.rd-done .maru { font-size: var(--fs-16); }
.rd-soon .empty svg { width: 48px; height: 48px; }

/* ---- one reading or one listening piece ---- */
.rd-plan { margin: 0 0 var(--s-3); }
.rd-head { margin-bottom: var(--s-5); min-width: 0; }
.rd-head h1 { margin: var(--s-1) 0 0; overflow-wrap: anywhere; }
.rd-title { font-size: var(--fs-40); }
.rd-topic { margin: var(--s-2) 0 0; max-width: var(--measure); }
.rd-main { display: grid; gap: var(--s-5); align-content: start; min-width: 0; }
.rd-aside { display: grid; gap: var(--s-5); align-content: start; min-width: 0; }
@media (min-width: 1100px) {
  .rd-aside { position: sticky; top: calc(var(--bar-h) + var(--s-4)); max-height: calc(100vh - var(--bar-h) - var(--s-6)); overflow: auto; overscroll-behavior: contain; }
}
.rd-figure { margin: 0; border-radius: var(--r-2); overflow: hidden; background: var(--surface-2); }
.rd-figure img { display: block; width: 100%; max-height: 440px; object-fit: cover; }
.rd-tools { display: grid; gap: var(--s-3); min-width: 0; }
.rd-tools .row { gap: var(--s-3) var(--s-4); }
.rd-hint { margin: 0; }
/* one line of help, and Aa (furigana and English, on a sheet) at its end; on an upright phone Aa is in the bar */
.rd-hintrow { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-width: 0; }
.rd-text { padding: var(--s-3) var(--s-4); }
.rd-sents { list-style: none; margin: 0; padding: 0; }
.rd-sent { display: grid; grid-template-columns: var(--tap) minmax(0, 1fr); gap: var(--s-2) var(--s-3); align-items: start; padding: var(--s-2); border-radius: var(--r-2);
  scroll-margin: calc(var(--bar-h) + var(--s-4)) 0 calc(max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) + 120px); transition: background .2s; }
.rd-sent + .rd-sent { margin-top: var(--s-1); }
/* a sentence's number plays it; the one playing shows a play mark in its place */
.rd-say { width: var(--tap); height: var(--tap); min-height: var(--tap); margin-top: 4px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--ink-3); font-size: var(--fs-14); font-weight: 400; }
@media (hover: hover) { .rd-say:hover { background: var(--accent-soft); color: var(--accent-text); } }
.rd-say svg { display: none; width: 20px; height: 20px; }
.rd-sent.now .rd-say { background: var(--accent-soft); color: var(--accent-text); }
.rd-sent.now .rd-say .rd-num { display: none; }
.rd-sent.now .rd-say svg { display: block; }
.rd-sent.now { background: var(--accent-soft); }
.rd-sent.cur:not(.now) { box-shadow: inset 3px 0 0 var(--accent-text); }
.rd-sbody { min-width: 0; }
.rd-ja { margin: 0; }
.rd-en { margin: 0 0 var(--s-2); color: var(--ink-2); }
.rd-finish { justify-content: flex-start; }
.rd-qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-6); }
.rd-qt { display: flex; gap: var(--s-3); align-items: flex-start; margin: 0; font-size: var(--fs-18); font-weight: 700; line-height: 1.5; }
.rd-qn { flex: none; display: grid; place-items: center; width: 28px; height: 28px; margin-top: 1px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-14); }
.rd-q .choices { margin-top: var(--s-3); }
.rd-why { display: block; margin-top: var(--s-1); font-weight: 400; color: var(--ink-2); line-height: var(--lh-body); }
.rd-end { scroll-margin: calc(var(--bar-h) + var(--s-4)) 0 var(--s-7); }
.rd-end .rd-hanamaru { font-size: var(--fs-40); margin-bottom: var(--s-2); }
.rd-end-go { justify-content: center; margin-top: var(--s-4); }
.rd-saved { margin: var(--s-2) 0 0; }
.rd-words .card-body { padding-bottom: var(--s-4); }
.rd-wlist .main small { white-space: normal; }
.rd-wja { font-size: var(--fs-20); font-weight: 700; }
@media (max-width: 720px) {
  .rd-title { font-size: var(--fs-30); }
  .rd-feat-ja { font-size: var(--fs-22); }
  .rd-featured:has(> .rd-feat-pic:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
  /* Next up's picture: a strip of about 120 px (cut from the 16:9 picture), so the title and Start reading come up
     on the first screen */
  .rd-feat-pic { min-height: 0; }
  .rd-feat-pic img { aspect-ratio: auto; height: 120px; }
  .rd-feat-body { padding: var(--s-4); }
  .rd-text { padding: var(--s-2) var(--s-2); }
  /* a narrow gutter for the sentence numbers, so the lines get the width; each number still takes a 44 px tap, its
     reach running out to the left into the card's padding */
  .rd-sent { grid-template-columns: 20px minmax(0, 1fr); gap: var(--s-1) var(--s-2); padding: var(--s-2) var(--s-1); }
  .rd-say { position: relative; width: 20px; border-radius: var(--r-pill); }
  .rd-say::before { content: ""; position: absolute; top: 0; bottom: 0; left: -24px; right: 0; }
  .rd-sent.now .rd-say { width: 28px; margin-left: -8px; }
  /* the player is docked at the foot (play and Slow are there), so the text starts sooner */
  .rd-tools-play { display: none; }
}

/* ---- the bar at the foot while a piece plays (and on a phone all along): above the tab bar and Tomo; on a wide
   screen at the page's foot ---- */
.rd-bar { position: sticky; z-index: 6; bottom: calc(max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) + var(--s-2));
  display: grid; gap: var(--s-2); margin-top: var(--s-5); padding: var(--s-3) var(--s-4); border-radius: var(--r-3); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg); }
@media (min-width: 1100px) { .rd-bar { bottom: var(--s-4); max-width: 760px; } }
.rd-bar-top { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.rd-bar-pos { flex: none; color: var(--ink-2); }
.rd-bar-line { flex: 1; margin: 0; }
.rd-bar-go { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
/* Slowly: a toggle with its icon, at the end of the progress line (pressed: the accent fill) */
.rd-bar .rd-slow { flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 var(--s-3); }
.rd-bar .rd-slow svg { width: 20px; height: 20px; }
.rd-slow[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); }
.rd-stop { margin-left: auto; }
@media (max-width: 440px) { .rd-stop span { display: none; } .rd-stop { width: var(--tap); padding: 0; } }
/* Docked on a phone: one compact card on the tab bar; play is the big one, in the thumb's reach. */
@media (max-width: 720px) {
  .rd-bar.docked { gap: var(--s-1); margin-top: var(--s-4); padding: var(--s-2) var(--s-3); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + var(--s-2)); }
  /* one button language: ‹, › and ↻ (and Stop while it plays) equal 48 px icon buttons round the 56 px play, centred */
  .rd-bar.docked .rd-bar-go { flex-wrap: nowrap; justify-content: center; }
  .rd-bar.docked .rd-bar-go > :is(.icon, .rd-stop) { width: 48px; height: 48px; min-height: 48px; padding: 0; }
  .rd-bar.docked #bar-toggle { width: 56px; height: 56px; min-height: 56px; border-radius: 50%; }
  .rd-bar.docked .rd-stop { margin-left: 0; }
  .rd-bar.docked .rd-stop span { display: none; }
  html:has(#main .rd-bar.docked) { scroll-padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 120px); }
}
/* An upright phone: the docked player is the screen's one bar at the foot, the full width on the tab bar, as every
   session's dock is (study.css): a hairline over it, no card. */
@media (max-width: 720px) and (min-height: 501px) {
  .rd-bar.docked { bottom: var(--dock-at); margin: var(--s-4) calc(-1 * var(--gut-r)) 0 calc(-1 * var(--gut-l));
    padding: var(--s-2) var(--gut-r) calc(var(--s-2) + var(--dock-pad)) var(--gut-l); border: 0; border-top: 1px solid var(--line); border-radius: 0; box-shadow: none; }
  html:not(.lk-open) #main:has(> .rd .rd-bar.docked:not([hidden])) { padding-bottom: var(--dock-at); }
}
/* A listening piece on an upright phone: while its player is docked the tab bar steps aside, as in a session, so the
   player and the tab bar never take the foot of the screen together; ‹ Listening in the bar is the way back. */
@media (max-width: 720px) and (min-height: 501px) {
  html:not(.lk-open):has(#main .ls-page .rd-bar.docked:not([hidden])) #tabbar { display: none; }
  :root:not(.lk-open):has(#main .ls-page .rd-bar.docked:not([hidden])) { --tab-h: 0px; --dock-at: 0px; --dock-pad: env(safe-area-inset-bottom); }
}

/* ---- listening ---- */
.ls-cast { list-style: none; margin: var(--s-3) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); }
.ls-who { display: inline-flex; align-items: center; gap: var(--s-2); }
.ls-who [lang=ja] { font-weight: 700; }
.ls-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--who, var(--accent-text)); }
.ls-player .card-body { padding-top: var(--s-5); display: grid; gap: var(--s-3); }
.ls-player .eyebrow { margin: 0; }
.ls-now { margin: 0; min-height: 1.6em; }
/* where the piece is: one labelled progress line ("Line 3 of 8"), never a row of grey pills; on a phone the docked
   player says it already, so the card leaves it out */
.ls-progrow { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.ls-proglabel { flex: none; font-size: var(--fs-14); color: var(--ink-2); white-space: nowrap; }
.ls-progline { flex: 1; margin: 0; }
@media (max-width: 720px) { .ls-player .ls-progrow { display: none; } }
.ls-go { gap: var(--s-2); }
.ls-go .big { min-width: 140px; }
.ls-speed-row { gap: var(--s-3); }
.ls-qhint { margin: 0 0 var(--s-3); }
.ls-lines { list-style: none; margin: var(--s-4) 0 0; padding: 0; display: grid; gap: var(--s-3); }
.ls-line { padding: var(--s-2) var(--s-3) var(--s-2) var(--s-4); border-left: 3px solid var(--who, var(--line-strong)); border-radius: 0 var(--r-2) var(--r-2) 0; transition: background .2s;
  scroll-margin: calc(var(--bar-h) + var(--s-4)) 0 calc(max(calc(var(--tab-h) + env(safe-area-inset-bottom)), var(--tutor-room, 0px)) + 120px); }
.ls-line.now { background: var(--accent-soft); }
.ls-line-who { display: flex; align-items: center; gap: var(--s-2); margin: 0; }
.ls-line-who [lang=ja] { font-weight: 700; }
.ls-line-body { display: grid; grid-template-columns: var(--tap) minmax(0, 1fr); gap: var(--s-3); align-items: start; }
.ls-line-body > .btn-play { margin-top: 6px; }
.ls-line-body .ja-lg { margin: 0; }
.ls-shadow { font-size: var(--fs-14); }
/* How to listen 聞き方: the Japanese on the label's line, in quiet ink */
.ls-how-ja { margin-left: var(--s-1); font-size: var(--fs-14); font-weight: 400; color: var(--ink-3); }
.ls-steps { margin: 0; padding-left: 1.2em; display: grid; gap: var(--s-2); color: var(--ink-2); }
.ls-steps b { color: var(--ink); }
@media (max-width: 720px) {
  /* the player's Play, ‹ › and Slow are in the bar docked at the foot (listen.js), in the thumb's reach: the card
     keeps where it is and the line being said */
  .ls-player .ls-go, .ls-player .ls-speed-row { display: none; }
  .ls-line { padding-left: var(--s-3); }
  .ls-line-body { gap: var(--s-2); }
  .ls-go .big { flex: 1; min-width: 0; }
}
