/* die Deutsche Bibliothek — design system */

:root {
  --bg: #f4ede0;
  --bg-soft: #faf6ec;
  --bg-deep: #ebe1cd;
  --paper: #fefaf2;
  --ink: #2a1f15;
  --ink-soft: #5a4a38;
  --ink-mute: #8a7960;
  --line: #d9cdb3;
  --line-soft: #e6dcc6;

  --brown: #7a3a2a;
  --forest: #1f3a2e;
  --navy: #2a3b66;
  --burgundy: #6e2538;
  --gold: #b0823a;
  --gold-soft: #e8d4a0;

  --a1: #1f3a2e;
  --a1-bg: #d9e3d6;
  --a2: #2a3b66;
  --a2-bg: #d6dde8;
  --b1: #6e2538;
  --b1-bg: #ebd6db;

  --radius: 4px;
  --radius-lg: 8px;
  --shadow-sm: 0 1px 2px rgba(58, 42, 26, 0.06), 0 1px 1px rgba(58, 42, 26, 0.04);
  --shadow: 0 4px 14px rgba(58, 42, 26, 0.08), 0 1px 3px rgba(58, 42, 26, 0.06);
  --shadow-lg: 0 18px 48px rgba(58, 42, 26, 0.16), 0 4px 12px rgba(58, 42, 26, 0.08);

  --nav-bg: rgba(244, 237, 224, 0.92);
  --reader-foot-bg: rgba(254, 250, 242, 0.92);

  --font-sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

/* ---------- DARK THEME ---------- */
:root[data-theme="dark"] {
  --bg: #181310;
  --bg-soft: #1f1814;
  --bg-deep: #2a211b;
  --paper: #221a15;
  --ink: #f0e3cf;
  --ink-soft: #c8b89c;
  --ink-mute: #8a7a64;
  --line: #3a2f25;
  --line-soft: #2c241c;

  --brown: #c97758;
  --forest: #8db09e;
  --navy: #8aa1d8;
  --burgundy: #d68ea2;
  --gold: #d4a661;
  --gold-soft: #6b4f25;

  --a1: #b6d4ad;
  --a1-bg: #2a3a30;
  --a2: #adc1e6;
  --a2-bg: #2a3554;
  --b1: #e0a4b3;
  --b1-bg: #4a2733;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 1px 1px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.65), 0 4px 12px rgba(0, 0, 0, 0.4);

  --nav-bg: rgba(24, 19, 16, 0.92);
  --reader-foot-bg: rgba(34, 26, 21, 0.92);

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ---------- TOP NAV ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--nav-bg);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 28px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 28px;
  align-items: center;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--bg-soft);
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 600;
  font-size: 15px;
  border-radius: 3px;
}
.brand em {
  font-style: italic;
  font-weight: 400;
  color: var(--ink-soft);
}
.nav-links {
  display: flex;
  gap: 4px;
}
.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--ink-soft);
  font-weight: 500;
}
.nav-link:hover { background: var(--bg-deep); color: var(--ink); }
.nav-link.active { color: var(--ink); background: var(--bg-deep); }
.nav-right { display: flex; align-items: center; gap: 10px; }
.lang-switch, .theme-switch {
  display: flex;
  background: var(--bg-deep);
  border-radius: 999px;
  padding: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.lang-switch button, .theme-switch button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 999px;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: inherit;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.lang-switch button.on, .theme-switch button.on {
  background: var(--ink);
  color: var(--bg-soft);
}
.theme-switch button {
  padding: 5px 8px;
  line-height: 0;
}
.theme-switch button svg {
  width: 13px;
  height: 13px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.streak-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink);
}
.streak-pill .dot {
  width: 6px;
  height: 6px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(176, 130, 58, 0.18);
}

/* ---------- LAYOUT ---------- */
.page { max-width: 1280px; margin: 0 auto; padding: 32px 28px 80px; }
.page-narrow { max-width: 980px; margin: 0 auto; padding: 32px 28px 80px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.h-display {
  font-family: var(--font-serif);
  font-size: 64px;
  line-height: 1.02;
  letter-spacing: -0.02em;
  font-weight: 400;
  margin: 0;
  text-wrap: balance;
}
.h-display em { font-style: italic; color: var(--brown); }
.h-section {
  font-family: var(--font-serif);
  font-size: 32px;
  line-height: 1.1;
  letter-spacing: -0.015em;
  font-weight: 500;
  margin: 0;
}
.h-card {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 1.2;
  font-weight: 500;
  margin: 0;
}

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--ink); color: var(--bg-soft); }
.btn-primary:hover { filter: brightness(0.85); }
.btn-outline { border-color: var(--ink); }
.btn-outline:hover { background: var(--ink); color: var(--bg-soft); }
.btn-ghost { color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg-deep); color: var(--ink); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 24px; font-size: 15px; }

/* ---------- LEVEL BADGE ---------- */
.lvl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.lvl-A1 { background: var(--a1-bg); color: var(--a1); }
.lvl-A2 { background: var(--a2-bg); color: var(--a2); }
.lvl-B1 { background: var(--b1-bg); color: var(--b1); }

/* ---------- BOOK COVER ---------- */
.cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  border-radius: 2px 4px 4px 2px;
  box-shadow:
    -1px 0 0 rgba(0,0,0,0.08) inset,
    1px 0 0 rgba(255,255,255,0.1) inset,
    0 6px 18px rgba(58, 42, 26, 0.16),
    0 1px 3px rgba(58, 42, 26, 0.1);
  overflow: hidden;
  background: var(--ink);
  color: #f3ead7;
  padding: 16px 14px 18px;
  font-family: var(--font-serif);
  display: flex;
  flex-direction: column;
}
.cover::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6%;
  bottom: 6%;
  width: 1px;
  background: rgba(255,255,255,0.12);
}
.cover-title {
  font-size: 18px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-weight: 500;
  margin: 0;
  text-wrap: balance;
}
.cover-author {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.7;
}
.cover-lvl {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  padding: 2px 6px;
  border-radius: 2px;
  margin-bottom: 12px;
  opacity: 0.85;
}
.cover-rule {
  width: 28px;
  height: 1px;
  background: currentColor;
  opacity: 0.4;
  margin: 12px 0;
}
.cover-sub {
  font-size: 11px;
  letter-spacing: 0.04em;
  font-style: italic;
  opacity: 0.7;
}

.cover.theme-brown { background: #5a2818; }
.cover.theme-forest { background: #1f3a2e; }
.cover.theme-navy { background: #1f2e52; }
.cover.theme-burgundy { background: #4d1828; }
.cover.theme-gold { background: #b0823a; color: #2a1f15; }
.cover.theme-cream { background: var(--paper); color: var(--ink); }
.cover.theme-ink { background: #2d2a37; }

/* ---------- CARD ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

/* ---------- INPUT ---------- */
.input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
}
.input input {
  border: 0;
  background: transparent;
  outline: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--ink);
  width: 100%;
}
.input input::placeholder { color: var(--ink-mute); }
.input:focus-within { border-color: var(--ink); }

/* ---------- TAP-WORD POPUP ---------- */
.word {
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  transition: background 0.1s;
}
.word:hover { background: rgba(176, 130, 58, 0.2); }
.word.known { color: var(--ink-mute); }
.word.saved {
  background: rgba(176, 130, 58, 0.24);
  border-bottom: 1px dashed var(--gold);
}
.word.hl-yellow { background: rgba(244, 211, 106, 0.45); box-shadow: inset 0 -3px 0 rgba(176, 130, 58, 0.4); }
.word.hl-green  { background: rgba(122, 168, 117, 0.32); box-shadow: inset 0 -3px 0 rgba(31, 90, 58, 0.4); }
.word.hl-pink   { background: rgba(217, 142, 158, 0.38); box-shadow: inset 0 -3px 0 rgba(150, 60, 78, 0.4); }
.word.hl-blue   { background: rgba(140, 168, 210, 0.36); box-shadow: inset 0 -3px 0 rgba(42, 70, 130, 0.4); }
.word.active {
  background: var(--gold) !important;
  color: var(--paper);
  box-shadow: none !important;
}

/* paragraph w/ bookmark */
.para {
  position: relative;
  margin: 0 0 1.1em;
  text-wrap: pretty;
}
.para .bm-btn {
  position: absolute;
  left: -36px;
  top: 4px;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  font-family: var(--font-mono);
  color: var(--ink-mute);
  font-size: 18px;
  line-height: 1;
  border-radius: 3px;
  display: grid;
  place-items: center;
}
.para:hover .bm-btn { opacity: 0.55; }
.para .bm-btn:hover { opacity: 1 !important; background: var(--bg-deep); }
.para.bookmarked .bm-btn { opacity: 1; color: var(--brown); }
.para.bookmarked::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--brown);
  border-radius: 1px;
}

/* color picker swatches in popup */
.wp-colors {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(244, 237, 224, 0.12);
}
.wp-colors .sw {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
}
.wp-colors .sw:hover { transform: scale(1.1); }
.wp-colors .sw.on { border-color: var(--paper); }
.wp-colors .sw.clear {
  background: transparent;
  border: 2px dashed rgba(244, 237, 224, 0.3);
  color: rgba(244, 237, 224, 0.6);
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
}
.wp-colors .sw.yellow { background: #f4d36a; }
.wp-colors .sw.green { background: #7aa875; }
.wp-colors .sw.pink { background: #d98e9e; }
.wp-colors .sw.blue { background: #8ca8d2; }

/* lemma block */
.wp-lemma {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin: 8px 0 4px;
  padding: 8px 10px;
  background: rgba(244, 237, 224, 0.08);
  border-radius: 4px;
  border-left: 2px solid var(--gold);
}
.wp-lemma .l1 {
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(244, 237, 224, 0.55);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.wp-lemma .l2 {
  font-family: var(--font-serif);
  font-size: 17px;
  font-style: italic;
  font-weight: 500;
  color: var(--gold-soft);
}

.word-pop {
  position: absolute;
  z-index: 60;
  background: var(--ink);
  color: var(--bg-soft);
  border-radius: 6px;
  padding: 14px 16px;
  width: 280px;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
}
.word-pop::after {
  content: "";
  position: absolute;
  top: -5px;
  left: 28px;
  width: 10px;
  height: 10px;
  background: var(--ink);
  transform: rotate(45deg);
}
.word-pop .wp-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.word-pop .wp-de {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 500;
}
.word-pop .wp-pos {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(244, 237, 224, 0.55);
}
.word-pop .wp-tr {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin: 4px 0;
}
.word-pop .wp-flag {
  font-family: var(--font-mono);
  font-size: 9px;
  color: rgba(244, 237, 224, 0.5);
  width: 20px;
  letter-spacing: 0.1em;
}
.word-pop .wp-val { font-size: 14px; }
.word-pop .wp-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(244, 237, 224, 0.12);
}
.word-pop .wp-actions button {
  flex: 1;
  background: transparent;
  border: 1px solid rgba(244, 237, 224, 0.2);
  color: var(--bg-soft);
  padding: 6px 8px;
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 0.04em;
  font-family: inherit;
}
.word-pop .wp-actions button:hover { background: rgba(244, 237, 224, 0.08); }
.word-pop .wp-actions button.saved { background: var(--gold); color: var(--ink); border-color: var(--gold); }

/* ---------- MODAL ---------- */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(26, 19, 11, 0.5);
  display: grid; place-items: center;
  z-index: 100;
  padding: 24px;
}
.modal {
  background: var(--bg-soft);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}
.modal h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  margin: 0 0 4px;
  font-weight: 500;
}
.modal p { color: var(--ink-soft); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  resize: vertical;
}
.field textarea { min-height: 110px; font-family: var(--font-serif); }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--ink); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- READER ---------- */
.reader-shell {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  min-height: calc(100vh - 56px);
}
.reader-side {
  border-right: 1px solid var(--line);
  padding: 28px 24px;
  background: var(--bg);
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
.reader-side.right {
  border-right: 0;
  border-left: 1px solid var(--line);
}
.reader-stage {
  background: var(--paper);
  padding: 56px 64px 120px;
  min-height: 100%;
  position: relative;
}
.reader-body {
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 1.7;
  color: var(--ink);
  max-width: 580px;
  margin: 0 auto;
}
.reader-body p { margin: 0 0 1.1em; text-wrap: pretty; }
.reader-body h1 {
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.1;
  margin: 0 0 8px;
}
.reader-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-bottom: 32px;
}
.reader-foot {
  position: sticky;
  bottom: 0;
  background: var(--reader-foot-bg);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

/* ---------- CHAPTER ROW ---------- */
.chap {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
.chap:hover { background: var(--bg-deep); }
.chap.current { background: var(--bg-deep); }
.chap-num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
}
.chap-title { font-size: 14px; font-weight: 500; }
.chap-meta { font-family: var(--font-mono); font-size: 10px; color: var(--ink-mute); letter-spacing: 0.06em; }

/* ---------- PROGRESS ---------- */
.bar {
  height: 3px;
  background: var(--line-soft);
  border-radius: 2px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--ink);
  border-radius: 2px;
}

/* ---------- TABLE OF NUMBERS / STATS ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}
.stat-grid .s {
  padding: 18px 22px;
  border-right: 1px solid var(--line);
}
.stat-grid .s:last-child { border-right: 0; }
.stat-grid .s .n {
  font-family: var(--font-serif);
  font-size: 36px;
  line-height: 1;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.stat-grid .s .l {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  margin-top: 6px;
}

/* ---------- QUIZ ---------- */
.quiz-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 36px;
  max-width: 560px;
  margin: 0 auto;
}
.quiz-prompt {
  font-family: var(--font-serif);
  font-size: 26px;
  line-height: 1.3;
  font-weight: 500;
  margin: 8px 0 24px;
  text-wrap: balance;
}
.quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
  transition: all 0.15s;
}
.quiz-option:hover { border-color: var(--ink); background: var(--paper); }
.quiz-option.correct { background: var(--a1-bg); border-color: var(--a1); }
.quiz-option.wrong { background: var(--b1-bg); border-color: var(--b1); }

/* ---------- FLASHCARD ---------- */
.flash-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  margin: 0 auto 22px;
  padding: 4px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
  max-width: fit-content;
}
.flash-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
  white-space: nowrap;
}
.flash-tab:hover:not(.active):not([disabled]) { color: var(--ink); background: rgba(255,255,255,0.4); }
.flash-tab.active {
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.flash-tab[disabled] { opacity: 0.4; cursor: not-allowed; }
.flash-tab-count {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-mute);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 20px;
  text-align: center;
}
.flash-tab.active .flash-tab-count { background: var(--bg-deep); color: var(--ink); }

.flash-stage {
  max-width: 480px;
  margin: 0 auto;
  perspective: 1600px;
  position: relative;
  min-height: 280px;
}
.flash-card-wrap {
  width: 100%;
  will-change: transform, opacity;
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0.2, 1), opacity 240ms ease;
}
@keyframes flash-in-right {
  from { transform: translateX(36px) rotate(2deg); opacity: 0; }
  to   { transform: translateX(0) rotate(0); opacity: 1; }
}
@keyframes flash-in-left {
  from { transform: translateX(-36px) rotate(-2deg); opacity: 0; }
  to   { transform: translateX(0) rotate(0); opacity: 1; }
}
.flash-enter-right { animation: flash-in-right 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.flash-enter-left  { animation: flash-in-left  280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.flash-exit-right  { transform: translateX(-40%) rotate(-3deg); opacity: 0; }
.flash-exit-left   { transform: translateX( 40%) rotate( 3deg); opacity: 0; }
.flash-exit-prev   { transform: translateX( 40%) rotate( 3deg); opacity: 0; }
.flash-exit-up     { transform: translateY(-60%) rotate(-2deg) scale(0.96); opacity: 0; }

.flash {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  min-height: 280px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 520ms cubic-bezier(0.22, 1, 0.36, 1), border-color 200ms, box-shadow 200ms;
  box-shadow: var(--shadow-sm);
}
.flash:hover { box-shadow: var(--shadow); }
.flash.flipped { transform: rotateY(180deg); }
.flash.is-hard { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset, var(--shadow-sm); }
.flash.is-learned { border-color: var(--a1); background: color-mix(in oklch, var(--paper) 88%, var(--a1-bg)); }
.flash.is-learned.is-hard { border-color: var(--gold); }

.flash-face {
  position: absolute;
  inset: 0;
  padding: 36px 28px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flash-back { transform: rotateY(180deg); }

.flash-tag {
  position: absolute;
  top: 14px;
  left: 14px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  border: 1px solid var(--gold);
  padding: 2px 6px;
  border-radius: 2px;
}
.flash-tag-learned { color: var(--a1); border-color: var(--a1); }
.flash-hint { font-size: 11px; margin-top: 12px; opacity: 0; transition: opacity 200ms ease 120ms; }
.flash:hover .flash-hint { opacity: 1; }

.flash .de {
  font-family: var(--font-serif);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.flash .pos {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin: 8px 0 18px;
}
.flash .tr {
  font-size: 18px;
  color: var(--ink-soft);
  margin: 4px 0;
}

.flash-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 24px;
}
.flash-mark { min-width: 140px; transition: background 180ms, color 180ms, border-color 180ms, transform 120ms; }
.flash-mark:active { transform: translateY(1px); }
.flash-mark.active { background: var(--gold-soft); border-color: var(--gold); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .flash, .flash-card-wrap, .flash-enter-right, .flash-enter-left { transition: none !important; animation: none !important; }
}

/* ---------- PHRASE HIGHLIGHT (inline in reader) ---------- */
.phrase {
  cursor: pointer;
  padding: 0 1px;
  border-radius: 2px;
  transition: filter 0.1s;
}
.phrase:hover { filter: brightness(0.96); }
.phrase.hl-yellow { background: rgba(244, 211, 106, 0.45); box-shadow: inset 0 -3px 0 rgba(176, 130, 58, 0.45); }
.phrase.hl-green  { background: rgba(122, 168, 117, 0.32); box-shadow: inset 0 -3px 0 rgba(31, 90, 58, 0.45); }
.phrase.hl-pink   { background: rgba(217, 142, 158, 0.38); box-shadow: inset 0 -3px 0 rgba(150, 60, 78, 0.45); }
.phrase.hl-blue   { background: rgba(140, 168, 210, 0.36); box-shadow: inset 0 -3px 0 rgba(42, 70, 130, 0.45); }

::selection { background: rgba(176, 130, 58, 0.32); color: inherit; }
.reader-body { -webkit-user-select: text; user-select: text; }

/* ---------- PHRASE SELECTION POPUP ---------- */
.phrase-pop { width: 320px; padding: 12px; }
.phrase-pop .pp-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.phrase-pop .pp-kind {
  font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(244, 237, 224, 0.55);
}
.phrase-pop .pp-close {
  background: transparent; border: 0; color: rgba(244, 237, 224, 0.6);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.phrase-pop .pp-close:hover { color: var(--bg-soft); }
.phrase-pop .pp-phrase {
  font-family: var(--font-serif);
  font-size: 16px; font-weight: 500;
  color: var(--bg-soft);
  margin-bottom: 6px;
  line-height: 1.35;
}
.phrase-pop .pp-context {
  font-family: var(--font-serif);
  font-size: 11px; font-style: italic;
  color: rgba(244, 237, 224, 0.55);
  margin-bottom: 10px; line-height: 1.4;
  padding-left: 8px;
  border-left: 2px solid rgba(244, 237, 224, 0.18);
}
.phrase-pop .pp-row {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 0;
}
.phrase-pop .pp-label {
  font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(244, 237, 224, 0.55);
}
.phrase-pop .pp-colors { display: flex; gap: 6px; }
.phrase-pop .pp-colors .sw {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: transform 0.1s;
}
.phrase-pop .pp-colors .sw:hover { transform: scale(1.12); border-color: rgba(244, 237, 224, 0.4); }
.phrase-pop .pp-colors .sw.yellow { background: #f4d36a; }
.phrase-pop .pp-colors .sw.green { background: #7aa875; }
.phrase-pop .pp-colors .sw.pink { background: #d98e9e; }
.phrase-pop .pp-colors .sw.blue { background: #8ca8d2; }
.phrase-pop .pp-actions {
  display: flex; gap: 6px; margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(244, 237, 224, 0.12);
}
.phrase-pop .pp-btn {
  flex: 1;
  background: transparent; color: var(--bg-soft);
  border: 1px solid rgba(244, 237, 224, 0.2);
  padding: 6px 10px; border-radius: 4px;
  font-size: 11px; letter-spacing: 0.04em;
  font-family: inherit; cursor: pointer;
}
.phrase-pop .pp-btn:hover { background: rgba(244, 237, 224, 0.08); }
.phrase-pop .pp-btn.primary { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 500; }
.phrase-pop .pp-btn.primary:hover { background: var(--gold); filter: brightness(1.04); }
.phrase-pop .pp-btn.ghost { background: transparent; }

/* word-pop edit button */
.word-pop .wp-edit {
  background: transparent; color: var(--bg-soft);
  border: 1px solid rgba(244, 237, 224, 0.2);
  width: 26px; height: 26px; border-radius: 4px;
  font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 4px;
}
.word-pop .wp-edit:hover { background: rgba(244, 237, 224, 0.08); }

/* ---------- READER SIDEBAR (saved entries) ---------- */
.sv-row {
  display: grid;
  grid-template-columns: 8px 1fr 22px;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  align-items: flex-start;
}
.sv-row.is-phrase { background: linear-gradient(90deg, transparent, transparent 6px, rgba(176, 130, 58, 0.04) 6px, transparent 80%); }
.sv-dot {
  width: 6px; height: 6px; border-radius: 50%;
  margin-top: 7px;
  background: var(--ink-mute);
}
.sv-dot.hl-bg-yellow { background: #f4d36a; }
.sv-dot.hl-bg-green  { background: #7aa875; }
.sv-dot.hl-bg-pink   { background: #d98e9e; }
.sv-dot.hl-bg-blue   { background: #8ca8d2; }
.sv-title {
  font-family: var(--font-serif); font-size: 15px; font-weight: 500;
  line-height: 1.3;
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px;
}
.sv-kind {
  font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.12em;
  background: var(--bg-deep); color: var(--ink-soft);
  padding: 2px 5px; border-radius: 2px; vertical-align: middle;
}
.sv-text { word-break: break-word; }
.sv-tr {
  font-size: 11px; color: var(--ink-soft); margin-top: 3px;
  line-height: 1.4;
}
.sv-ctx {
  font-size: 11px; font-style: italic; color: var(--ink-mute);
  font-family: var(--font-serif);
  margin-top: 4px; line-height: 1.4;
  padding-left: 8px;
  border-left: 2px solid var(--line-soft);
}
.sv-edit {
  background: transparent; border: 1px solid transparent;
  color: var(--ink-mute);
  width: 22px; height: 22px; border-radius: 4px;
  font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  align-self: flex-start;
  margin-top: 2px;
}
.sv-row:hover .sv-edit { border-color: var(--line); color: var(--ink-soft); }
.sv-edit:hover { background: var(--bg-deep); color: var(--ink) !important; }

/* ---------- CARD EDITOR MODAL ---------- */
.modal.card-editor {
  max-width: 740px;
  width: 100%;
  padding: 28px 32px 22px;
}
.card-editor .ce-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 18px; margin-bottom: 18px;
  padding-bottom: 16px; border-bottom: 1px solid var(--line-soft);
}
.card-editor .ce-phrase {
  font-family: var(--font-serif);
  font-size: 26px; font-weight: 500;
  margin: 6px 0 4px;
  line-height: 1.25;
  text-wrap: pretty;
  letter-spacing: -0.005em;
}
.card-editor .ce-dict { font-size: 11px; }
.card-editor .ce-x {
  background: transparent; border: 0; color: var(--ink-mute);
  font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 8px; border-radius: 4px;
}
.card-editor .ce-x:hover { background: var(--bg-deep); color: var(--ink); }
.card-editor .ce-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
}
.card-editor .ce-side {
  border-left: 1px solid var(--line-soft);
  padding-left: 24px;
}
.card-editor .ce-auto {
  background: var(--bg-deep);
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.card-editor .ce-auto .eyebrow { margin-bottom: 6px; }
.card-editor .ce-auto-row {
  display: flex; gap: 8px;
  font-size: 13px; padding: 2px 0;
  color: var(--ink-soft);
}
.card-editor .ce-example {
  display: grid;
  grid-template-columns: 18px 1fr 22px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.card-editor .ce-example input {
  font-family: var(--font-serif);
  font-size: 14px;
}
.card-editor .ce-rm {
  background: transparent; border: 1px solid var(--line);
  color: var(--ink-mute);
  width: 22px; height: 22px; border-radius: 4px;
  cursor: pointer; font-size: 12px;
}
.card-editor .ce-rm:hover { background: var(--b1-bg); border-color: var(--b1); color: var(--b1); }
.card-editor .ce-add {
  background: transparent; border: 1px dashed var(--line);
  color: var(--ink-soft);
  width: 100%;
  padding: 6px 10px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer; margin-top: 2px;
}
.card-editor .ce-add:hover { border-color: var(--ink-soft); background: var(--bg-deep); color: var(--ink); }
.card-editor .ce-colors {
  display: flex; gap: 8px; align-items: center;
}
.card-editor .ce-colors .sw {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer; transition: transform 0.1s;
}
.card-editor .ce-colors .sw:hover { transform: scale(1.1); }
.card-editor .ce-colors .sw.on { border-color: var(--ink); }
.card-editor .ce-colors .sw.yellow { background: #f4d36a; }
.card-editor .ce-colors .sw.green { background: #7aa875; }
.card-editor .ce-colors .sw.pink { background: #d98e9e; }
.card-editor .ce-colors .sw.blue { background: #8ca8d2; }
.card-editor .ce-colors .sw.clear {
  background: transparent;
  border: 2px dashed var(--line);
  color: var(--ink-mute);
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.card-editor .ce-foot {
  display: flex; gap: 8px; align-items: center;
  margin-top: 18px; padding-top: 14px;
  border-top: 1px solid var(--line-soft);
}
@media (max-width: 720px) {
  .card-editor .ce-grid { grid-template-columns: 1fr; }
  .card-editor .ce-side { border-left: 0; padding-left: 0; padding-top: 18px; border-top: 1px solid var(--line-soft); }
}

/* ---------- FLASHCARD EXTRAS (phrases / context / examples / edit) ---------- */
.flash {
  /* allow content to flow on long phrase backs */
  min-height: 280px;
}
.flash-face {
  padding: 28px 28px 32px;
  overflow-y: auto;
  text-align: center;
}
.flash .de.is-phrase {
  font-size: 24px;
  line-height: 1.3;
  font-style: italic;
  letter-spacing: 0;
  text-wrap: pretty;
  max-width: 360px;
  margin: 0 auto;
}
.flash-edit {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-mute);
  width: 26px; height: 26px; border-radius: 4px;
  font-size: 13px; cursor: pointer;
  z-index: 2;
  display: inline-flex; align-items: center; justify-content: center;
}
.flash:hover .flash-edit { border-color: var(--line); }
.flash-edit:hover { background: var(--bg-deep); color: var(--ink) !important; }
.flash-tag-phrase {
  background: var(--gold-soft); color: var(--ink);
  border-color: var(--gold);
  letter-spacing: 0.14em;
}
.flash-ctx {
  font-family: var(--font-serif);
  font-size: 12px; font-style: italic;
  color: var(--ink-mute);
  margin: 14px auto 0;
  max-width: 320px;
  line-height: 1.45;
  text-wrap: pretty;
}
.flash-back-ctx, .flash-back-ex, .flash-back-note {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  text-align: left;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.45;
}
.flash-back-ctx > div, .flash-back-ex > div, .flash-back-note > div {
  margin-top: 4px;
}
.flash-back-ctx > div {
  font-family: var(--font-serif); font-style: italic;
}
.flash-back-ex > div {
  font-family: var(--font-serif);
  padding-left: 10px;
}
.flash-back-note > div {
  background: var(--bg-deep);
  padding: 8px 10px; border-radius: 4px;
  font-size: 12px;
}
.flash-back-ctx .mono, .flash-back-ex .mono, .flash-back-note .mono {
  font-size: 9px; letter-spacing: 0.12em;
}
.flash-empty-tr {
  font-size: 13px; color: var(--ink-mute);
  margin: 14px 0;
  font-style: italic;
}
.flash-link {
  background: transparent; border: 0; padding: 0;
  color: var(--brown); cursor: pointer;
  font-family: inherit; font-size: inherit;
  text-decoration: underline; text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.flash-link:hover { color: var(--ink); }

/* ---------- ADMIN ---------- */
.admin-pill {
  display: inline-block;
  margin-left: 10px;
  background: var(--brown);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  padding: 2px 7px;
  border-radius: 2px;
  vertical-align: 2px;
}
.admin-panel {
  margin-top: 56px;
  padding: 24px 28px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.admin-panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 18px; margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.mono-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-deep);
  padding: 1px 6px;
  border-radius: 3px;
}
.admin-tree {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font-mono);
}
.admin-tree-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}
.admin-tree-row {
  display: grid;
  grid-template-columns: 20px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.admin-tree-row:last-child { border-bottom: 0; }
.admin-tree-row:hover { background: var(--bg-soft); }
.atr-icon { font-size: 13px; opacity: 0.7; }
.atr-name { color: var(--ink); font-weight: 500; letter-spacing: 0.01em; }
.atr-meta { font-size: 10px; letter-spacing: 0.06em; }
.atr-tag {
  font-size: 9px; letter-spacing: 0.12em;
  padding: 2px 6px; border-radius: 2px;
  border: 1px solid;
}
.atr-tag.pub { color: var(--a1); border-color: var(--a1); background: var(--a1-bg); }
.atr-tag.draft { color: var(--gold); border-color: var(--gold); background: var(--gold-soft); }
.atr-actions { display: flex; gap: 4px; }
.atr-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-mute);
  width: 24px; height: 24px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
}
.admin-tree-row:hover .atr-btn { border-color: var(--line); }
.atr-btn:hover { background: var(--bg-deep); color: var(--ink); }
.admin-hint {
  margin-top: 16px;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
}
.admin-hint code {
  background: var(--bg-deep);
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 0.95em;
}

/* ---------- UTIL ---------- */
.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.hr { height: 1px; background: var(--line); margin: 24px 0; border: 0; }
.mono { font-family: var(--font-mono); }
.serif { font-family: var(--font-serif); }
.mute { color: var(--ink-mute); }
.soft { color: var(--ink-soft); }

/* Book grid — shared catalogue/level/deck grid. Desktop columns match the
   previous inline layout exactly; media queries below adjust for tablet/phone. */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

/* Mobile-only elements are hidden on desktop and shown only inside media queries. */
.nav-hamburger { display: none; }
.reader-mobilebar { display: none; }
.reader-backdrop { display: none; }

/* On desktop the nav-menu wrapper is transparent: it lays out the links on the
   left and the controls on the right, exactly as the original inline row did.
   The hamburger is hidden, so nav-inner's middle 1fr track holds this menu. */
.nav-menu {
  grid-column: 2 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
}

/* ===================================================================== */
/* ===== Responsive =====                                                */
/* Everything below is scoped to media queries (or to elements that are  */
/* hidden on desktop), so the desktop layout renders exactly as before.  */
/* Primary phone breakpoint: max-width 640px. Tablet: max-width 900px.    */
/* ===================================================================== */

/* ---------- TABLET (<= 900px) ---------- */
@media (max-width: 900px) {
  /* Two-column book grids on tablet */
  .book-grid { grid-template-columns: repeat(2, 1fr); }

  /* Donation tiers fit better in two columns */
  .donate-tiers { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ---------- PHONE (<= 640px) ---------- */
@media (max-width: 640px) {
  /* --- Page padding / overflow --- */
  .page,
  .page-narrow {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
  }
  html, body { overflow-x: hidden; }

  /* --- Display type scales down to fit --- */
  .h-display { font-size: clamp(30px, 9vw, 48px); }
  .h-section { font-size: clamp(22px, 6vw, 30px); }

  /* --- Header: hamburger menu --- */
  .nav-inner {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 12px 16px;
  }
  .nav-hamburger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--ink);
    border-radius: var(--radius);
    font-size: 17px;
    line-height: 1;
  }
  .nav-menu {
    display: none;
    grid-column: 1 / -1;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }
  .nav-menu.open { display: flex; }
  .nav-menu .nav-links {
    flex-direction: column;
    gap: 2px;
  }
  .nav-menu .nav-link { padding: 10px 12px; font-size: 15px; }
  .nav-menu .nav-right {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
  }

  /* --- Home hero: single column, hide decorative cover stack --- */
  .home-hero {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
    padding: 16px 0 32px !important;
  }
  .hero-stack { display: none; }
  .hero-stats { flex-wrap: wrap; gap: 18px !important; }

  /* --- Author card: stack --- */
  .author-card {
    grid-template-columns: 1fr !important;
    gap: 18px !important;
    padding: 24px !important;
  }

  /* --- Book grids: single column on phones --- */
  .book-grid { grid-template-columns: 1fr; }

  /* --- Library filters: stack vertically --- */
  .library-filters {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .library-filters > div { overflow-x: auto; }

  /* --- Book detail head: stack, cover narrower --- */
  .book-head {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
  .book-head-cover { width: 160px !important; }

  /* --- Vocab table rows: collapse to two columns --- */
  .vocab-row {
    grid-template-columns: 1fr auto !important;
    gap: 4px 12px !important;
    padding: 12px 16px !important;
  }

  /* --- Quiz teaser: stack --- */
  .quiz-teaser { grid-template-columns: 1fr !important; }

  /* --- Profile head: stack --- */
  .profile-head {
    grid-template-columns: auto 1fr !important;
    gap: 16px !important;
  }

  /* --- Stats grid: two columns instead of four --- */
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid .s:nth-child(2) { border-right: 0; }
  .stat-grid .s:nth-child(1),
  .stat-grid .s:nth-child(2) { border-bottom: 1px solid var(--line); }

  /* --- Donate tiers: single column; payment methods stay 3 --- */
  .donate-tiers { grid-template-columns: 1fr !important; }

  /* --- Quiz options / card --- */
  .quiz-card { padding: 24px 18px; }
  .quiz-prompt { font-size: 22px; }

  /* --- Modals: near full width, scrollable --- */
  .modal-back { padding: 12px; align-items: flex-end; }
  .modal {
    width: 92vw;
    max-width: 92vw;
    max-height: 88vh;
    overflow: auto;
    padding: 22px;
  }
  .modal.card-editor { width: 94vw; max-width: 94vw; padding: 22px; }

  /* --- Word + phrase popups become a bottom sheet --- */
  .word-pop {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    top: auto !important;
    bottom: 0 !important;
    width: auto !important;
    max-width: 100%;
    max-height: 70vh;
    overflow: auto;
    border-radius: 12px 12px 0 0;
    box-shadow: var(--shadow-lg);
    z-index: 120;
  }
  .word-pop::after { display: none; } /* hide the desktop arrow */
  .phrase-pop { width: auto !important; }

  /* --- Flashcard deck spacing --- */
  .flash-stage { max-width: 100%; }
  .flash-actions { flex-wrap: wrap; }
  .flash-mark { min-width: 0; flex: 1; }

  /* ---------- READER: full-width text + slide-over drawers ---------- */
  .reader-shell { grid-template-columns: 1fr; }

  .reader-stage { padding: 20px 18px 80px; }
  .reader-body { max-width: 100%; }

  /* Mobile toolbar above the text */
  .reader-mobilebar {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
  }
  .reader-mobilebar .btn {
    flex: 1;
    justify-content: center;
    border: 1px solid var(--line);
  }

  /* Side panes become off-screen slide-overs */
  .reader-pane {
    position: fixed;
    top: 0;
    bottom: 0;
    height: 100vh;
    width: 86%;
    max-width: 340px;
    overflow-y: auto;
    z-index: 110;
    background: var(--bg);
    box-shadow: var(--shadow-lg);
    transition: transform 0.25s ease;
  }
  .reader-pane-left { left: 0; transform: translateX(-100%); border-right: 1px solid var(--line); }
  .reader-pane-right { right: 0; transform: translateX(100%); border-left: 1px solid var(--line); }
  .reader-pane.open { transform: translateX(0); }

  /* Backdrop behind an open drawer */
  .reader-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(26, 19, 11, 0.45);
    z-index: 105;
  }
}
