/* Literata (SIL Open Font License, fonts/OFL.txt): variable weight and optical size, Latin only. */
@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/literata.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Literata";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/literata-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --text-scale: 1;
  --serif: "Literata", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --reading-font: var(--serif);
}
[data-font="sans"] { --reading-font: var(--sans); }

/* Themes. app.js sets data-theme on <html>; the swatches in the theme picker use the same attribute. */

:root, [data-theme="paper"] {
  color-scheme: light;
  --bg: #fbf8f3; --surface: #ffffff; --fg: #23201b; --muted: #81786c; --line: #ebe4d8;
  --accent: #c0612f; --accent-fg: #ffffff; --sentence: #f8ecd2; --word: #f2cd7a;
  --saved: #2f8a57;
}
[data-theme="sepia"] {
  color-scheme: light;
  --bg: #f4ead3; --surface: #faf2df; --fg: #4a3a28; --muted: #8b765c; --line: #e3d3b0;
  --accent: #9c4f22; --accent-fg: #ffffff; --sentence: #ead9b0; --word: #dcbb6c;
  --saved: #3d7a48;
}
[data-theme="white"] {
  color-scheme: light;
  --bg: #ffffff; --surface: #f5f6f8; --fg: #1c1d21; --muted: #6b7280; --line: #e4e6ea;
  --accent: #2f6fde; --accent-fg: #ffffff; --sentence: #e9f0fd; --word: #b8cff8;
  --saved: #15934a;
}
[data-theme="night"] {
  color-scheme: dark;
  --bg: #141210; --surface: #1d1a17; --fg: #ebe5db; --muted: #998f82; --line: #2c2823;
  --accent: #e58a57; --accent-fg: #1a1410; --sentence: #2f281d; --word: #6b5220;
  --saved: #6fcf97;
}
[data-theme="slate"] {
  color-scheme: dark;
  --bg: #191e26; --surface: #212732; --fg: #dde3ec; --muted: #8b96a8; --line: #2d3542;
  --accent: #7ea6f6; --accent-fg: #101622; --sentence: #243045; --word: #34508a;
  --saved: #62d39a;
}
[data-theme="black"] {
  color-scheme: dark;
  --bg: #000000; --surface: #111111; --fg: #cfcac2; --muted: #85807a; --line: #232323;
  --accent: #d99a4e; --accent-fg: #000000; --sentence: #1d1912; --word: #5c4419;
  --saved: #5fbf86;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { display: block; width: 24px; height: 24px; fill: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
@media (display-mode: standalone) {
  html { overscroll-behavior-y: none; }
}

/* Shared pieces */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(0.5rem, env(safe-area-inset-right)) 0 max(0.5rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0 0.75rem; font-size: 1.25rem; }
.top-title { display: flex; flex-direction: column; min-width: 0; font-weight: 600; line-height: 1.25; }
.top-title small { color: var(--muted); font-size: 0.75rem; font-weight: 500; }
.top-title span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.remaining { flex: none; margin-left: auto; padding: 0 0.75rem; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; }
.chip { min-width: 52px; height: 44px; padding: 0 0.5rem; border-radius: 999px; font-size: 0.95rem; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (hover: hover) {
  .icon:hover, .chip:hover { background: var(--line); }
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.2rem 0.7rem 1rem;
  border-radius: 999px;
  font-weight: 600;
}
.button svg { width: 20px; height: 20px; }
.primary { background: var(--accent); color: var(--accent-fg); }

.meter { height: 4px; margin-top: 0.6rem; overflow: hidden; border-radius: 2px; background: var(--line); }
.meter i { display: block; height: 100%; background: var(--accent); }

.page {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-right)) calc(3rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.app-actions { margin-top: 1.5rem; text-align: center; }
.app-actions:has(button[hidden]) { display: none; }
.app-actions button { border: 1px solid var(--line); }
dialog {
  width: min(24rem, calc(100% - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg);
  color: var(--fg);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0; font-size: 1.2rem; }
dialog form { text-align: right; }
.playback-error { margin: 1rem; color: var(--muted); text-align: center; }

/* Library */

.books { display: grid; gap: 0.75rem; margin: 0; padding: 0; list-style: none; }
.book-card {
  display: flex;
  gap: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.book-card img { flex: none; width: 84px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 8px; }
.book-card > div { flex: 1; min-width: 0; }
.book-card h2 { margin: 0.1rem 0 0.25rem; font-family: var(--serif); font-size: 1.15rem; line-height: 1.25; }
.book-card p { margin: 0; font-size: 0.9rem; }

/* Book */

.hero { display: flex; gap: 1.25rem; align-items: flex-end; }
.hero img { flex: none; width: 132px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.18); }
.hero h1 { margin: 0 0 0.4rem; font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; }
.hero p { margin: 0; }
.hero .button { margin-top: 1rem; }
@media (max-width: 480px) {
  .hero { flex-direction: column; align-items: flex-start; }
}

.chapters { margin: 1.75rem 0 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.chapters a {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.9rem 0.25rem;
  border-bottom: 1px solid var(--line);
}
.chapters .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.chapters .status { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.chapters .done { color: var(--accent); }

/* Saved words */

.words-link { margin: 0 0.25rem 0 auto; padding: 0.5rem 0.9rem 0.5rem 0.7rem; font-size: 0.9rem; }
.words-link svg { width: 18px; height: 18px; color: var(--accent); }
@media (hover: hover) {
  .words-link:hover { background: var(--line); }
}
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.filters a { padding: 0.4rem 0.9rem; border: 1px solid var(--line); border-radius: 999px; font-size: 0.9rem; font-weight: 600; }
.filters a[aria-current="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-fg); }
.word-list { display: grid; gap: 0.75rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.word-list li { position: relative; }
.word-list a {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.85rem 3rem 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}
.word-en { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; line-height: 1.3; }
.word-base { font-size: 0.9rem; }
.word-base b { font-family: var(--serif); font-weight: 600; }
.word-es { font-family: var(--serif); font-size: 1.1rem; line-height: 1.3; }
.word-note { padding: 0.45rem 0.65rem; border-radius: 8px; background: color-mix(in srgb, var(--accent) 10%, var(--surface)); font-size: 0.92rem; }
.word-sentence { color: var(--muted); font-family: var(--serif); font-size: 0.95rem; line-height: 1.5; }
.word-sentence mark { background: none; color: var(--fg); font-weight: 600; text-decoration: underline 2px var(--accent); text-underline-offset: 0.2em; }
.word-where { color: var(--muted); font-size: 0.8rem; }
.word-list .remove { position: absolute; top: 0.35rem; right: 0.35rem; color: var(--muted); }
.empty { margin: 1.5rem 0.25rem; }
.empty svg { display: inline; width: 1.1em; height: 1.1em; vertical-align: -0.2em; color: var(--accent); }
.backup { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.backup p, .backup output { flex-basis: 100%; margin: 0; font-size: 0.9rem; }
.backup .button { border: 1px solid var(--line); }

/* Reader */

.text {
  max-width: 36rem;
  margin: 0 auto;
  padding: 1.5rem max(1.25rem, env(safe-area-inset-right)) calc(12rem + env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
  font-family: var(--reading-font);
  font-size: calc(1.2rem * var(--text-scale));
  line-height: 1.75;
}
.text h2 { margin: 1.25em 0 1em; font-size: 1.3em; font-weight: 600; line-height: 1.3; text-align: center; }
.text p { margin: 0 0 0.9em; }
.text hr { margin: 1.5em 0; border: 0; color: var(--muted); text-align: center; }
.text hr::after { content: "* * *"; }
.text { position: relative; }
/* A ring around a saved unit; app.js places it over the words. */
.marks i {
  position: absolute;
  margin: calc(-0.04em - 2px) calc(-0.05em - 2px);
  padding: 0.04em 0.05em;
  box-sizing: content-box;
  border: 2px solid var(--saved);
  border-radius: 0.5em;
  background: color-mix(in srgb, var(--saved) 12%, transparent);
  pointer-events: none;
}
.bubble {
  position: absolute;
  left: calc(100% + 1.25rem);
  display: none;
  width: 13rem;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  border-left: 3px solid var(--saved);
  background: color-mix(in srgb, var(--saved) 16%, var(--surface));
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: left;
  overflow-wrap: anywhere;
}
/* The pointer to the line */
.bubble::before { content: ""; position: absolute; top: 0.7rem; left: -9px; border: 6px solid transparent; border-left: 0; border-right-color: var(--saved); }
@media (min-width: 66rem) {
  .bubble { display: block; }
}
.w { border-radius: 0.2em; cursor: pointer; transition: background-color 0.15s; }
.s.on { border-radius: 0.2em; background: var(--sentence); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.w.on { background: var(--word); }
/* Translation between the lines: each sentence starts a line, and each unit (.u) is a column with the English
   over the Spanish (.g). app.js makes the columns. */
.g { display: none; }
[data-gloss] .text { line-height: 1.5; }
[data-gloss] .text .s { display: block; margin-bottom: 0.45em; }
[data-gloss] .u { display: inline-block; vertical-align: top; }
[data-gloss] .g {
  display: block;
  margin-bottom: 0.35em;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.6em;
  line-height: 1.3;
  cursor: pointer;
}
/* The sentence of the word in the popup */
.s.look { border-radius: 0.2em; background: color-mix(in srgb, var(--accent) 9%, transparent); -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.w.picked { background: color-mix(in srgb, var(--accent) 22%, transparent); text-decoration: underline 2px var(--accent); text-underline-offset: 0.22em; }
@media (hover: hover) {
  .w:hover { text-decoration: underline dotted var(--muted); text-underline-offset: 0.2em; }
}

.pop {
  position: absolute;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(22rem, calc(100vw - 16px));
  padding: 1rem 1rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 12px 36px rgb(0 0 0 / 0.22);
}
/* English: what the reader tapped */
.pop-head { position: relative; padding: 0 5.25rem 0.6rem 0; border-bottom: 1px solid var(--line); }
.pop-save, .pop-close { position: absolute; top: -0.6rem; color: var(--muted); }
.pop-save { right: 2.15rem; }
.pop-close { right: -0.6rem; }
.pop-save[aria-pressed="true"] { color: var(--saved); }
.pop-word { font-family: var(--serif); font-size: 1.2rem; line-height: 1.3; }
.pop-base { margin-top: 0.2rem; font-size: 0.9rem; }
.pop-base span, .word-base span { margin-right: 0.15rem; color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.pop-base b { font-family: var(--serif); font-weight: 600; }
/* Spanish: the meaning, then the note */
.pop-gloss { font-family: var(--serif); font-size: 1.45rem; font-weight: 700; line-height: 1.25; }
.pop-note {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  font-size: 0.95rem;
  line-height: 1.45;
}
.pop-note i { font-family: var(--serif); font-size: 1.05em; }
.pop-gloss:empty, .pop-note:empty { display: none; }
.pop-more { display: flex; align-items: center; gap: 0.25rem; align-self: flex-start; margin: -0.1rem 0 -0.1rem -0.2rem; padding: 0.3rem 0.4rem 0.3rem 0.1rem; border-radius: 8px; color: var(--accent); font-size: 0.95rem; font-weight: 600; }
.pop-more svg { width: 22px; height: 22px; fill: currentColor; transition: transform 0.15s; }
.pop-more[aria-expanded="true"] svg { transform: rotate(180deg); }
.pop-sentence { margin: 0; padding-left: 0.75rem; border-left: 3px solid var(--line); font-family: var(--serif); font-size: 1.02rem; line-height: 1.5; }
.pop-sentence mark { background: var(--word); color: var(--fg); border-radius: 0.15em; }
.pop-play { width: 100%; margin-top: 0.15rem; }
/* Narrow screens: a panel on top of the player, from the bottom of the sentence. app.js sets its place and its
   height. The play button of the player rises over its last part. */
@media (max-width: 40rem) {
  .pop {
    position: fixed;
    right: 0;
    left: 0;
    z-index: 9;
    width: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem max(1rem, env(safe-area-inset-right)) 3rem max(1rem, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 20px rgb(0 0 0 / 0.12);
  }
  .pop > * { flex: none; }
  /* Room to scroll the last sentence up above the panel */
  #view:has(> .pop:not([hidden])) .text { padding-bottom: 100svh; }
  .pop:not([hidden]) ~ .player .pill { display: none; }
}
/* The reader's own note: the saved colour, as the rings and the bubbles. The box is the field. */
.pop-mine {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.5rem 0.75rem 0.45rem;
  border-left: 3px solid var(--saved);
  border-radius: 10px;
  background: color-mix(in srgb, var(--saved) 10%, var(--surface));
  cursor: text;
}
.pop-mine:focus-within { background: color-mix(in srgb, var(--saved) 17%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--saved) 45%, transparent); }
.pop-mine span { color: var(--saved); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.pop-mine textarea {
  width: 100%;
  min-height: 2lh;
  max-height: 8lh;
  padding: 0;
  border: 0;
  outline: none;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 16px; /* smaller text makes iOS zoom in */
  line-height: 1.4;
  resize: none;
  field-sizing: content;
}
.pop-mine textarea::placeholder { color: var(--muted); }
.search {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 16px; /* smaller text makes iOS zoom in */
}
@media (hover: hover) {
  .pop-more:hover { background: var(--line); }
}

/* The reading position beside the scrollbar, when the user has scrolled away from it */
.mark {
  position: fixed;
  right: 0;
  z-index: 11;
  display: flex;
  justify-content: flex-end;
  width: 20px;
  height: 32px;
  padding-right: 3px;
  transform: translateY(-50%);
  transition: top 0.2s;
}
.mark::before { content: ""; width: 5px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 0 2px var(--bg); }

.player {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  padding: 0.4rem max(1rem, env(safe-area-inset-right)) calc(0.4rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.pill {
  position: absolute;
  bottom: calc(100% + 2.75rem);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.2);
}
.player:has(.panel:not([hidden])) .pill { display: none; }

.controls { position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; max-width: 36rem; margin: 0 auto; }
.controls .rate { justify-self: start; }
.controls .end { display: flex; gap: 0.25rem; justify-self: end; }
.controls .look { font-family: var(--serif); }
.chip.gloss[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.chip[aria-expanded="true"] { background: var(--line); }

/* The play button rises out of the top of the player. The surface-coloured ring makes the bar bulge around it. */
.controls .play {
  width: 64px;
  height: 64px;
  margin-top: -2.4rem;
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: 0 0 0 5px var(--surface), 0 6px 18px rgb(0 0 0 / 0.25);
  transition: transform 0.1s;
}
.controls .play:active { transform: scale(0.95); }
.controls .play svg { width: 34px; height: 34px; }
@media (hover: hover) {
  .controls .play:hover { background: color-mix(in srgb, var(--accent) 88%, var(--fg)); }
}

/* Speed menu and text and theme panel */

.panel {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  z-index: 1;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.2);
}
.rates { left: 0; display: flex; flex-direction: column; min-width: 8.5rem; }
.rates button { display: flex; justify-content: space-between; padding: 0.55rem 0.8rem; border-radius: 10px; font-variant-numeric: tabular-nums; }
.rates [aria-checked="true"] { color: var(--accent); font-weight: 700; }
.rates [aria-checked="true"]::after { content: "✓"; }

.looks { right: 0; display: grid; gap: 1rem; width: min(21rem, calc(100vw - 2rem)); padding: 1rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.seg { display: flex; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: 999px; }
.seg button { min-height: 36px; padding: 0 0.9rem; border-radius: 999px; }
.seg [aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.seg [data-font="serif"] { font-family: var(--serif); }
.stepper button { width: 44px; padding: 0; font-family: var(--serif); font-weight: 600; }
.stepper [data-step="-1"] { font-size: 0.8rem; }
.stepper [data-step="1"] { font-size: 1.2rem; }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.stepper output { min-width: 3.2em; font-size: 0.9rem; text-align: center; font-variant-numeric: tabular-nums; }
@media (hover: hover) {
  .rates button:hover, .seg button:not([aria-pressed="true"], :disabled):hover { background: var(--line); }
}

.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.75rem 0.25rem; }
/* --ring is read here, in the current theme, before the swatch switches to its own theme. */
.themes button { --ring: var(--accent); --gap: var(--surface); display: flex; flex-direction: column; align-items: center; gap: 0.3rem; color: var(--muted); font-size: 0.75rem; }
.swatch {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
}
.swatch[data-theme="auto"] { background: linear-gradient(135deg, #fbf8f3 50%, #141210 50%); color: transparent; }
.themes [aria-pressed="true"] { color: var(--fg); font-weight: 600; }
.themes [aria-pressed="true"] .swatch { box-shadow: 0 0 0 2px var(--gap), 0 0 0 4px var(--ring); }
