/* Snapp — stylesheet. No external fonts or CDNs: everything is local. */

:root {
  --paper: #faf6ef;
  --paper-2: #fffdf8;
  --ink: #20272e;
  --ink-soft: #46535f;
  --muted: #7c8794;
  --line: #e7dfd1;
  --line-strong: #d8cdbb;
  --teal: #0e7c71;
  --teal-dark: #0a5f57;
  --teal-soft: #e4f2ef;
  --coral: #dd6442;
  --coral-soft: #fdece6;
  --amber: #e5a63c;
  --amber-soft: #fdf3e0;
  --green: #2f8a58;
  --green-soft: #e8f5ec;
  --red: #bf4331;
  --red-soft: #fbeae7;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(32, 39, 46, 0.04), 0 10px 28px rgba(32, 39, 46, 0.06);
  --shadow-lift: 0 2px 4px rgba(32, 39, 46, 0.06), 0 18px 40px rgba(32, 39, 46, 0.1);
  --sans: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 88% -10%, rgba(14, 124, 113, 0.09), transparent 60%),
    radial-gradient(900px 500px at -5% 0%, rgba(221, 100, 66, 0.07), transparent 55%),
    var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--teal-dark); }
a:hover { color: var(--teal); }

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}
h1 { font-size: clamp(1.9rem, 3.6vw, 2.8rem); }
h2 { font-size: clamp(1.35rem, 2.2vw, 1.75rem); }
h3 { font-size: 1.15rem; }
h4 { font-family: var(--sans); font-size: 0.98rem; font-weight: 700; letter-spacing: 0; }

p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* ---------- Layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(250, 246, 239, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  box-shadow: 0 4px 10px rgba(14, 124, 113, 0.3);
}
.nav { display: flex; align-items: center; gap: 0.25rem; }
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.93rem;
  font-weight: 600;
}
button.nav-link { background: none; border: 0; cursor: pointer; font: inherit; }
.nav-link:hover { background: rgba(14, 124, 113, 0.07); color: var(--teal-dark); }
.nav-link.is-active { background: var(--teal); color: #fff; }
.nav-link.subtle { color: var(--muted); font-weight: 500; }
.nav-user {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon { width: 18px; height: 18px; }

.wrap {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  flex: 1;
}
.wrap-wide { max-width: 1240px; }
.narrow { max-width: 640px; margin: 0 auto; }
.narrow-wide { max-width: 900px; margin: 0 auto; }
.wide-text { max-width: 980px; margin: 0 auto; }

.footer {
  border-top: 1px solid var(--line);
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- Type helpers ---------- */

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--coral);
  margin: 0 0 0.4rem;
}
.lead { font-size: 1.08rem; color: var(--ink-soft); max-width: 62ch; }
.backlink {
  display: inline-block;
  margin-bottom: 0.9rem;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
}
.backlink:hover { color: var(--teal); }
.hint { font-size: 0.83rem; color: var(--muted); margin: 0.35rem 0 0; }
.hint.warning { color: var(--amber); font-weight: 600; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.62rem 1.05rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--teal); color: #fff; box-shadow: 0 6px 16px rgba(14, 124, 113, 0.25); }
.btn-primary:hover { background: var(--teal-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.7); border-color: var(--teal); color: var(--teal-dark); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #a53526; color: #fff; }
.btn-danger-ghost { background: transparent; border-color: var(--red-soft); color: var(--red); }
.btn-danger-ghost:hover { background: var(--red-soft); }
.btn-small { padding: 0.42rem 0.85rem; font-size: 0.87rem; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-btn:hover { color: var(--red); border-color: var(--red); }

/* ---------- Cards ---------- */

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.35rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}
.card.soft { background: rgba(255, 253, 248, 0.6); box-shadow: none; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  align-items: start;
}
.grid-2 > * { min-width: 0; }
.grid-2 > .card { margin-bottom: 0; }

.alert {
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.25rem;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 0.94rem;
}
.alert strong { display: inline-block; margin-right: 0.25rem; }
.alert-error { background: var(--red-soft); border-color: #f0c8c0; color: #8d2d1f; }
.alert-warn { background: var(--amber-soft); border-color: #f0dcb4; color: #7a5410; }
.alert-ok { background: var(--green-soft); border-color: #c5e4d0; color: #22633f; }
ul.tight { margin: 0.4rem 0 0; padding-left: 1.1rem; }
ul.tight li { margin-bottom: 0.15rem; }

/* ---------- Library ---------- */

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  padding: 1rem 0 1.75rem;
  flex-wrap: wrap;
}
.hero h1 { margin-bottom: 0.4rem; }
.hero-stats { display: flex; gap: 0.75rem; }
.hero-stats div {
  background: rgba(255, 253, 248, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  text-align: center;
  min-width: 84px;
}
.hero-stats strong { display: block; font-family: var(--serif); font-size: 1.5rem; color: var(--teal-dark); }
.hero-stats span { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

.filters {
  display: flex;
  gap: 0.85rem;
  align-items: flex-end;
  flex-wrap: wrap;
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 2rem;
}
.filters .field { margin: 0; }
.filters .grow { flex: 1 1 220px; }
.filters .btn { margin-bottom: 1px; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section-head h2 { margin: 0; font-size: 1.15rem; font-family: var(--sans); font-weight: 700; }

.lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.1rem;
}
.lesson-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}
.lesson-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.lesson-card-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.subject {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--coral);
}
.lesson-title { margin: 0; font-size: 1.2rem; }
.lesson-title a { color: var(--ink); text-decoration: none; }
.lesson-title a:hover { color: var(--teal-dark); }
.lesson-meta { font-size: 0.82rem; color: var(--muted); margin: 0; }
.lesson-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.35rem; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--teal-soft);
  color: var(--teal-dark);
  white-space: nowrap;
}
.badge-new { background: #eef1f5; color: #5d6b7a; }
.badge-text { background: var(--amber-soft); color: #7a5410; }
.badge-chapters { background: #eceafc; color: #544aa2; }
.badge-prompt { background: #e6f0fb; color: #2c5f92; }
.badge-ready { background: var(--green-soft); color: var(--green); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3.5rem 1.5rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.55);
}
.empty-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 1.8rem;
  margin: 0 auto 1rem;
  transform: rotate(-4deg);
}

/* ---------- Forms ---------- */

.form .field { margin-bottom: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label, fieldset legend {
  font-size: 0.87rem;
  font-weight: 700;
  color: var(--ink-soft);
}
input[type="text"], input[type="search"], input[type="password"], input[type="number"],
input[type="file"], input:not([type]), select, textarea {
  font: inherit;
  font-size: 0.95rem;
  padding: 0.58rem 0.75rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(14, 124, 113, 0.25);
  border-color: var(--teal);
}
input[type="file"] { padding: 0.45rem; background: var(--paper-2); }
input.num { width: 72px; }
fieldset.field { border: 0; padding: 0; margin: 0 0 1.1rem; }
.radio {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 0.4rem;
  background: #fff;
  font-size: 0.92rem;
  cursor: pointer;
}
.radio input { margin-top: 0.28rem; width: auto; }
.radio:hover { border-color: var(--teal); }
.access-field { margin-top: 0.2rem; }
.access-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 17rem;
  margin-top: 0.55rem;
  padding: 0.35rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.access-item {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}
.access-item:hover { background: var(--teal-soft); }
.access-item input {
  width: auto;
  margin-top: 0.2rem;
  flex: 0 0 auto;
}
.access-text { display: flex; flex-direction: column; min-width: 0; gap: 0.1rem; }
.access-text strong { font-size: 0.9rem; line-height: 1.3; }
.access-text .small { font-size: 0.72rem; }
/* Without JavaScript the list stays usable; the script dims it in "all" mode. */
.access-field[data-mode="all"] .access-list { opacity: 0.45; }
.access-field[data-mode="all"] .access-list .access-item { cursor: default; }
.access-field[data-mode="all"] .access-list .access-item:hover { background: transparent; }
.form-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 1.1rem;
}
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.check-inline input { width: auto; }
.code-area {
  font-family: "Cascadia Code", "SF Mono", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: vertical;
  background: #fdfbf6;
}
.code-block, pre {
  font-family: "Cascadia Code", "SF Mono", Consolas, monospace;
  font-size: 0.8rem;
  background: #fdfbf6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem;
  overflow: auto;
  max-height: 320px;
  white-space: pre-wrap;
}

/* ---------- Steps / progress ---------- */

.steps {
  list-style: none;
  display: flex;
  gap: 0.35rem;
  padding: 0.75rem 0.9rem;
  margin: 0 0 1.4rem;
  background: rgba(255, 253, 248, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.step {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.step-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: inline-block;
}
.step-done { color: var(--teal-dark); }
.step-done .step-dot { background: var(--teal); border-color: var(--teal); }
.step-current { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.06); }
.step-current .step-dot { border-color: var(--coral); background: var(--coral-soft); }

.steps-hint { padding-left: 1.2rem; margin: 0; }
.steps-hint li { margin-bottom: 0.35rem; font-size: 0.93rem; }

.progress {
  height: 8px;
  border-radius: 999px;
  background: #ece4d7;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), #3aa79b);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.job-head { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 0.92rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* ---------- Lesson detail ---------- */

.lesson-head { margin-bottom: 1.25rem; }
.head-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.5rem; }
.action-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }

.next-step {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(23, 160, 140, 0.35);
  border-radius: var(--radius);
  background: rgba(23, 160, 140, 0.06);
}
.next-step h2 { margin: 0.15rem 0 0.25rem; font-size: 1.15rem; }
.next-step p { margin: 0; }
.next-step-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.action-menu { margin-bottom: 1.25rem; }
.action-list { list-style: none; margin: 0; padding: 0; }
.action-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
}
.action-list li:first-child { border-top: 0; padding-top: 0; }
.action-list li:last-child { padding-bottom: 0; }
.action-list strong { display: block; }
.action-list span { color: var(--ink-soft); font-size: 0.88rem; }
.action-control { flex: 0 0 auto; }

.page-list { display: flex; flex-direction: column; gap: 0.35rem; }
.page-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.15rem 0.75rem;
}
.page-row summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  cursor: pointer;
  font-size: 0.88rem;
  flex-wrap: wrap;
}
.page-number { font-weight: 700; color: var(--teal-dark); min-width: 44px; }
.page-source { color: var(--ink-soft); font-size: 0.84rem; }
.page-preview { padding: 0 0 0.85rem; border-top: 1px dashed var(--line); margin-top: 0.1rem; padding-top: 0.6rem; }
.page-preview p { font-size: 0.9rem; color: var(--ink-soft); }
.conf {
  margin-left: auto;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}
.conf-good { background: var(--green-soft); color: var(--green); }
.conf-mid { background: var(--amber-soft); color: #7a5410; }
.conf-low { background: var(--red-soft); color: var(--red); }

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table-scroll { overflow-x: auto; min-width: 0; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--line-strong);
}
.table td { padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table a { text-decoration: none; font-weight: 600; }

.danger-zone { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }

/* ---------- Chapter boundary editor ---------- */

.tips { margin: 0; padding-left: 1.1rem; font-size: 0.92rem; color: var(--ink-soft); }
.tips li { margin-bottom: 0.45rem; }

.chapter-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 1.25rem;
  align-items: start;
}
.chapter-layout > * { min-width: 0; }
.chapter-form { margin-bottom: 1.25rem; }
.chapter-summary {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
}
.chapter-summary.is-invalid { color: #8d2d1f; background: var(--red-soft); }

.chapter-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.chapter-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 34px;
  gap: 0.6rem;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 0.75rem;
}
.chapter-order {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 800;
  font-size: 0.82rem;
}
.chapter-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 0.55rem 0.85rem;
  align-items: end;
}
.chapter-meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.field-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.field-note {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted);
}
.chapter-row input { width: 100%; }
.chapter-row .start-input { text-align: center; }
.chapter-row .start-input.is-fixed { background: var(--paper); color: var(--muted); }
.chapter-range { font-size: 0.85rem; color: var(--ink-soft); }
.chapter-range.is-invalid { color: var(--red); font-weight: 600; }

.boundary-preview { margin: 0; min-width: 0; }
.boundary-preview summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--teal-dark);
  font-weight: 600;
}
.boundary-preview p {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: pre-line;
  max-height: 9rem;
  overflow: auto;
}

.chapter-pages {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
}
.chapter-pages .page-list { overflow-y: auto; padding-right: 0.25rem; }
.page-chapter {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  white-space: nowrap;
}

/* ---------- Prompt / import ---------- */

.prompt-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.row-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.file-list { margin: 0.5rem 0 0.75rem; padding-left: 1.1rem; font-size: 0.9rem; }
details.card > summary { cursor: pointer; }

/* ---------- Study ---------- */

.study-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 2.25rem;
  align-items: start;
}
.study-layout > * { min-width: 0; }
.study-nav {
  position: sticky;
  top: 84px;
  background: rgba(255, 253, 248, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.study-nav h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-family: var(--sans); }
.chapter-links { display: flex; flex-direction: column; gap: 0.2rem; margin: 0.5rem 0 1rem; }
.chapter-link {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
}
.chapter-link:hover { background: rgba(14, 124, 113, 0.07); color: var(--teal-dark); }
.chapter-link.is-active { background: var(--teal); color: #fff; }
.chapter-link.is-active .muted { color: rgba(255, 255, 255, 0.75); }
.chapter-link .muted { font-weight: 500; }
.study-nav-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.study-tip {
  background: var(--teal-soft);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  color: var(--teal-dark);
  margin-bottom: 1.5rem;
}
.chapter-section {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.6rem 1.8rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  scroll-margin-top: 92px;
}
.chapter-header { margin-bottom: 1rem; }
.chapter-index {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--coral);
}
.chapter-header h2 { margin: 0.15rem 0 0.2rem; }
.chapter-footer { margin-top: 1.1rem; }

.source-pages {
  margin-top: 1.25rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--line);
}
.source-pages > summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--teal-dark);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.source-pages .hint { margin: 0.45rem 0 0; }
.source-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.source-image {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink-soft);
  text-decoration: none;
}
.source-image img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  background: #f7f4ee;
}
.source-image span {
  display: block;
  padding: 0.4rem 0.55rem;
  font-size: 0.82rem;
  font-weight: 700;
}
.source-image:hover { border-color: var(--teal); color: var(--teal-dark); }

.prose { font-size: 1.02rem; color: var(--ink-soft); }
.prose p { margin-bottom: 0.9rem; }
.prose strong { color: var(--ink); }
.prose ul { padding-left: 1.2rem; margin-bottom: 0.9rem; }

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.concept-card {
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--coral);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.95rem;
}
.concept-card h4 { margin: 0 0 0.25rem; color: var(--ink); }
.concept-card p { font-size: 0.9rem; color: var(--ink-soft); margin: 0; }

.study-end {
  text-align: center;
  padding: 2.5rem 1.5rem;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.6);
}

/* ---------- Exam ---------- */

.exam-wrap { max-width: 760px; margin: 0 auto; }
.exam-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.exam-head .backlink { margin: 0; }
.exam-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 1.8rem;
  box-shadow: var(--shadow-lift);
  margin-top: 1.25rem;
}
.question { font-size: clamp(1.3rem, 2.4vw, 1.65rem); margin-bottom: 1.35rem; }
.options { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.25rem; }
.option {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.06s ease;
}
.option:hover { border-color: var(--teal); transform: translateY(-1px); }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option-letter {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.option-text { flex: 1; font-size: 0.98rem; }
.option:has(input:checked) { border-color: var(--teal); background: var(--teal-soft); }
.option:has(input:checked) .option-letter { background: var(--teal); border-color: var(--teal); color: #fff; }
.option-correct { border-color: var(--green); background: var(--green-soft); }
.option-correct .option-letter { background: var(--green); border-color: var(--green); color: #fff; }
.option-wrong { border-color: var(--red); background: var(--red-soft); }
.option-wrong .option-letter { background: var(--red); border-color: var(--red); color: #fff; }
.option-dim { opacity: 0.65; }
.option-mark {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.option-correct .option-mark { color: var(--green); }
.option-wrong .option-mark { color: var(--red); }

.feedback {
  border-radius: 14px;
  padding: 1rem 1.15rem;
  border: 1px solid;
  margin-top: 0.5rem;
}
.feedback h3 { margin: 0 0 0.35rem; font-family: var(--sans); font-size: 1rem; }
.feedback p { font-size: 0.95rem; margin: 0; }
.feedback-ok { background: var(--green-soft); border-color: #bfe0ca; color: #225c3c; }
.feedback-wrong { background: var(--red-soft); border-color: #f0c8c0; color: #8d2d1f; }
.feedback-extra { margin-top: 0.5rem !important; font-weight: 600; }

.dots { display: flex; gap: 5px; justify-content: center; margin-top: 1.5rem; flex-wrap: wrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #e0d6c6; }
.dot-done { background: var(--teal); }
.dot-now { background: var(--coral); transform: scale(1.35); }

/* ---------- Result ---------- */

.result-wrap { max-width: 900px; margin: 0 auto; }
.result-card {
  text-align: center;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 2.25rem 1.75rem;
  box-shadow: var(--shadow-lift);
  margin-bottom: 1.5rem;
}
.grade-ring {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  margin: 1.25rem auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  background:
    radial-gradient(closest-side, var(--paper-2) 78%, transparent 79%),
    conic-gradient(var(--teal) 0 var(--pct, 0%), #ece4d7 var(--pct, 0%) 100%);
  border: 0;
}
.grade-ring span { font-family: var(--serif); font-size: 3.1rem; line-height: 1; color: var(--teal-dark); }
.grade-ring small { font-size: 1rem; color: var(--muted); }
.result-card h1 { margin-bottom: 0.35rem; }
.result-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin-top: 1.25rem; }

.missed {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 0.35rem 0.75rem;
  margin-bottom: 0.45rem;
}
.missed summary { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.45rem 0; cursor: pointer; font-size: 0.9rem; }
.missed-mark { color: var(--red); font-weight: 700; }
.missed-body { border-top: 1px dashed var(--line); padding: 0.6rem 0; font-size: 0.9rem; }
.missed-body p { margin-bottom: 0.35rem; }

/* ---------- EPUB reader ---------- */

.reader-body .footer { display: none; }
.reader-body .wrap { padding-bottom: 1.1rem; }

/* The script turns the reading page into a fixed frame: the text is split into
   screen-sized columns, so a page never needs scrolling, whatever the screen.
   Without JavaScript the page keeps the normal, scrollable layout. */
html.reader-js { height: 100%; overflow: hidden; }
html.reader-js .reader-body {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
html.reader-js .reader-body .wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
html.reader-js .reader { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
html.reader-js .reader-top { flex: none; }
html.reader-js .reader-sheet {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
html.reader-js .reader-sheet > .reader-kicker { flex: none; }
html.reader-js .reader-text { flex: 1 1 auto; min-height: 0; overflow: hidden; }
html.reader-js .reader-pager { flex: none; }
/* Set by the script once it knows how much text fits on one screen. */
.reader-text.reader-paged {
  overflow: hidden;
  touch-action: pan-y;
  orphans: 2;
  widows: 2;
}
.reader-text.reader-paged .reader-end-actions { break-inside: avoid-column; }
/* The end card is one block, never split over two columns. It is compact so it
   fits the shortest screen-height column. */
.reader-text.reader-paged .reader-end {
  break-inside: avoid-column;
  margin-top: 0;
  padding: 0.7rem 0.8rem;
}
.reader-text.reader-paged .reader-end-mark { font-size: 0.6rem; margin-bottom: 0.15rem; }
.reader-text.reader-paged .reader-end h3 { font-size: 1rem; margin-bottom: 0.15rem; }
.reader-text.reader-paged .reader-end .muted {
  font-size: 0.78rem;
  line-height: 1.45;
  margin-bottom: 0.4rem;
}
.reader-text.reader-paged .reader-end-actions { gap: 0.4rem; margin-top: 0.45rem; }
.reader-text.reader-paged .reader-end-actions .btn {
  min-height: 38px;
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.lesson-resume {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.7rem;
  font-size: 0.85rem;
  color: var(--teal-dark);
}
.lesson-resume .icon { width: 16px; height: 16px; }

.reader {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

/* Top: navigation, title and progress */

.reader-top { margin-bottom: 1rem; }
.reader-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.reader-top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.reader-flash-toggle {
  display: none;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
html.reader-js .reader-flash-toggle { display: inline-flex; }
.reader-flash-toggle:hover { color: var(--teal-dark); border-color: var(--teal); }
.reader-flash-toggle[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.reader-flash-toggle .icon { width: 17px; height: 17px; }
.reader-flash-toggle:focus-visible { outline: 3px solid var(--teal-soft); outline-offset: 2px; }
.reader-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.4rem 0.8rem 0.4rem 0.55rem;
  margin-left: -0.55rem;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}
.reader-back .icon { width: 18px; height: 18px; }
.reader-back:hover { background: rgba(255, 255, 255, 0.78); color: var(--teal-dark); }

.reader-meta {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}
.reader-meta-text { min-width: 0; }
.reader-subject {
  margin: 0 0 0.2rem;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal-dark);
}
.reader-book-title {
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.35rem, 2.8vw, 1.8rem);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.reader-count {
  flex: 0 0 auto;
  color: var(--teal-dark);
  font-family: var(--serif);
  font-size: 1.35rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.reader-count strong { font-weight: 600; }
.reader-count small {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.reader-progress {
  height: 5px;
  margin-top: 0.9rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.reader-progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), #5fbfae);
  transition: width 0.25s ease;
}

/* Chapter menu */

.reader-toc { position: relative; }
.reader-toc > summary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 42px;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.78);
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
  list-style: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.reader-toc > summary::-webkit-details-marker { display: none; }
.reader-toc > summary .icon { width: 17px; height: 17px; }
.reader-toc > summary::after {
  content: "";
  width: 0.42rem;
  height: 0.42rem;
  margin-left: 0.1rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
  transition: transform 0.15s ease;
}
.reader-toc[open] > summary {
  border-color: var(--teal);
  background: var(--paper-2);
  color: var(--teal-dark);
}
.reader-toc[open] > summary::after { transform: rotate(-135deg) translateY(-1px); }
.reader-toc-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 30;
  width: min(23rem, calc(100vw - 2rem));
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper-2);
  box-shadow: var(--shadow-lift);
}
.reader-toc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 0;
  padding: 0.35rem 0.55rem 0.45rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.reader-toc-list {
  display: flex;
  flex-direction: column;
  max-height: min(45vh, 22rem);
  padding: 0;
  overflow: auto;
}
.reader-toc-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.55rem;
  border-radius: 9px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.3;
}
.reader-toc-link > span:first-child { min-width: 0; }
.reader-toc-page {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.reader-toc-link:hover { background: var(--teal-soft); color: var(--teal-dark); }
.reader-toc-link.is-active {
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-weight: 700;
}
.reader-toc-link.is-active .reader-toc-page { color: var(--teal-dark); }
.reader-jump {
  margin-top: 0.25rem;
  padding: 0.7rem 0.55rem 0.35rem;
  border-top: 1px dashed var(--line);
}
.reader-jump label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.reader-jump-row { display: flex; gap: 0.45rem; }
.reader-jump-row input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.reader-jump-row input:focus {
  border-color: var(--teal);
  outline: 2px solid var(--teal-soft);
}
.reader-jump-row .btn { flex: 0 0 auto; }
.reader-toc-note {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0.3rem 0 0;
  padding: 0.3rem 0.55rem 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}
.reader-toc-note .icon { width: 15px; height: 15px; flex: 0 0 auto; color: var(--teal); }

/* Flash reading: one word at a time, with the middle letter pinned to a fixed
   spot. The paged text stays behind the toggle, so normal reading is unchanged. */
.reader-flash { display: none; }
.reader.is-flashing .reader-text { display: none; }
.reader.is-flashing .reader-kicker { display: none; }
.reader.is-flashing .reader-flash:not([hidden]) {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}
.reader-flash-stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 150px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.reader-flash-stage:focus-visible { outline: 3px solid var(--teal-soft); outline-offset: 4px; }
.reader-flash-word {
  position: relative;
  display: block;
  width: 100%;
  height: 1.2em;
  font-family: var(--sans);
  /* One size for every word. It stays small enough for a long compound on a
     narrow phone, because words must not jump while reading. */
  font-size: clamp(1.7rem, 8vw, 3rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.01em;
}
.reader-flash-left,
.reader-flash-pivot,
.reader-flash-right {
  position: absolute;
  top: 0;
  line-height: 1.2;
  white-space: pre;
}
.reader-flash-pivot {
  left: 50%;
  transform: translateX(-50%);
  color: var(--red);
}
.reader-flash-left { right: calc(50% + var(--flash-pivot-half, 0px)); }
.reader-flash-right { left: calc(50% + var(--flash-pivot-half, 0px)); }
.reader-flash-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.2rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--muted);
  pointer-events: none;
}
.reader-flash-controls {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}
.reader-flash-label {
  flex: none;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.reader-flash-speed {
  flex: 1 1 auto;
  min-width: 110px;
  height: 32px;
  accent-color: var(--teal);
  cursor: pointer;
}
.reader-flash-wpm {
  flex: none;
  min-width: 8.6rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
}
.reader-flash-status {
  flex: none;
  display: flex;
  justify-content: flex-end;
  margin: 0.25rem 0 0;
  font-family: var(--sans);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* The page itself */

.reader-sheet {
  position: relative;
  padding: clamp(1.4rem, 4.5vw, 3rem) clamp(1.2rem, 6vw, 3.4rem) clamp(1.8rem, 5vw, 3.2rem);
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 253, 248, 0) 42%),
    var(--paper-2);
  box-shadow: 0 1px 2px rgba(32, 39, 46, 0.04), 0 18px 45px rgba(32, 39, 46, 0.08);
  animation: reader-page-in 0.22s ease both;
}
@keyframes reader-page-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.reader-sheet::before {
  content: "";
  position: absolute;
  top: 0;
  left: clamp(1.2rem, 6vw, 3.4rem);
  right: clamp(1.2rem, 6vw, 3.4rem);
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(90deg, var(--teal), var(--amber), transparent);
  opacity: 0.75;
}
.reader-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0 0 1.2rem;
  color: var(--teal-dark);
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.reader-kicker::before {
  content: "";
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--teal);
}
.reader-text {
  color: #28303a;
  font-family: var(--serif);
  font-size: clamp(1.08rem, 0.6vw + 0.95rem, 1.24rem);
  line-height: 1.8;
}
.reader-text p { margin: 0 0 1.1em; }
.reader-text p:last-child { margin-bottom: 0; }
.reader-text ul { margin: 0 0 1.1em; padding-left: 1.25rem; }
.reader-text li { margin-bottom: 0.45rem; }
.reader-text strong { color: var(--ink); }

/* Page buttons */

.reader-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-top: 1.1rem;
}
.reader-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 52px;
  padding: 0.65rem 1.15rem;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--paper-2);
  color: var(--ink-soft);
  text-decoration: none;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
              transform 0.15s ease, box-shadow 0.15s ease;
}
.reader-step .icon { width: 20px; height: 20px; }
.reader-step:hover {
  border-color: var(--teal);
  background: #fff;
  color: var(--teal-dark);
}
.reader-step:active { transform: translateY(1px); }
.reader-step:focus-visible { outline: 3px solid var(--teal-soft); outline-offset: 2px; }
.reader-step.is-next {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  box-shadow: 0 8px 20px rgba(14, 124, 113, 0.25);
}
.reader-step.is-next:hover {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
  color: #fff;
  box-shadow: 0 10px 24px rgba(14, 124, 113, 0.3);
}
.reader-step.is-disabled {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
  opacity: 0.48;
  box-shadow: none;
  cursor: default;
  pointer-events: none;
}
.reader-pager-count {
  flex: 1 1 auto;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.reader-pager-count strong { color: var(--ink); font-size: 0.95rem; }
.reader-inpage {
  color: var(--teal-dark);
  font-weight: 600;
  white-space: nowrap;
}

/* End of the book */

.reader-end {
  margin-top: 1.6rem;
  padding: 1.2rem 1.1rem;
  border: 1px solid #cfe4df;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--teal-soft), #fdf6e7);
  text-align: center;
}
.reader-end-mark {
  margin: 0 0 0.35rem;
  color: var(--teal-dark);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.reader-end h3 { margin-bottom: 0.3rem; }
.reader-end p { margin-bottom: 0.4rem; }
.reader-end-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .chapter-layout { grid-template-columns: 1fr; }
  .chapter-pages { position: static; max-height: none; }
  .study-layout { grid-template-columns: 1fr; }
  .study-nav { position: static; }
  .chapter-links { flex-direction: row; flex-wrap: wrap; }
  .chapter-link { flex: 1 1 45%; }
  .exam-card { padding: 1.25rem; }
}

/* Phone-specific rules live at the end of this file, so they also override the
   playful layer and the admin editor styles declared below. */

/* ---------- Print ---------- */

@media print {
  body { background: #fff; }
  .topbar, .footer, .study-nav-actions, .action-row, .backlink, .study-tip, .study-end, .source-pages { display: none; }
  .study-layout { grid-template-columns: 1fr; }
  .chapter-section { box-shadow: none; border: 0; padding: 0 0 1rem; page-break-after: always; }
  .concept-card { break-inside: avoid; }
}

/* ==========================================================================
   Playful layer
   Small, purely visual touches for younger students. No external assets.
   ========================================================================== */

:root {
  --violet: #7c6fd0;
  --violet-soft: #eceafc;
}

body {
  background:
    radial-gradient(circle at 1px 1px, rgba(32, 39, 46, 0.05) 1px, transparent 1.6px) 0 0 / 24px 24px,
    radial-gradient(1200px 600px at 88% -10%, rgba(14, 124, 113, 0.09), transparent 60%),
    radial-gradient(900px 500px at -5% 0%, rgba(221, 100, 66, 0.07), transparent 55%),
    var(--paper);
}

/* Brand mark: a slightly tilted sticker that wiggles on hover. */
.brand-mark {
  border-radius: 12px 12px 12px 4px;
  transform: rotate(-6deg);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.brand:hover .brand-mark { transform: rotate(6deg) scale(1.08); }

/* Hero: marker highlight behind the verb. */
.hero h1 .mark {
  color: var(--teal-dark);
  background: linear-gradient(
    180deg,
    transparent 58%,
    rgba(229, 166, 60, 0.55) 58%,
    rgba(229, 166, 60, 0.55) 90%,
    transparent 90%
  );
  padding: 0 0.06em;
  border-radius: 4px;
}

.hero-stats div {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.hero-stats div:nth-child(1) {
  background: #fff6e2;
  border-color: #f0dcb4;
  transform: rotate(-2.5deg);
}
.hero-stats div:nth-child(2) {
  background: var(--teal-soft);
  border-color: #bfe0da;
  transform: rotate(2.5deg);
}
.hero-stats div:hover { transform: rotate(0deg) translateY(-3px); box-shadow: var(--shadow); }

/* Lesson cards: washi tape, a tiny tilt, and a straighten on hover. */
.lesson-card { position: relative; }
.lesson-card::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 20px;
  width: 58px;
  height: 18px;
  border-radius: 2px;
  background: rgba(229, 166, 60, 0.6);
  box-shadow: 0 1px 2px rgba(32, 39, 46, 0.1);
  transform: rotate(-4deg);
  pointer-events: none;
}
.lesson-grid .lesson-card:nth-child(4n+1)::before { background: rgba(221, 100, 66, 0.42); }
.lesson-grid .lesson-card:nth-child(4n+2)::before {
  left: auto;
  right: 20px;
  background: rgba(14, 124, 113, 0.3);
  transform: rotate(4deg);
}
.lesson-grid .lesson-card:nth-child(4n+3)::before { background: rgba(124, 111, 208, 0.34); }
.lesson-grid .lesson-card:nth-child(4n+4)::before {
  left: auto;
  right: 20px;
  background: rgba(47, 138, 88, 0.3);
  transform: rotate(3deg);
}
.lesson-grid .lesson-card:nth-child(odd) { transform: rotate(-0.5deg); }
.lesson-grid .lesson-card:nth-child(even) { transform: rotate(0.6deg); }
.lesson-grid .lesson-card:hover { transform: translateY(-4px) rotate(0deg); box-shadow: var(--shadow-lift); }

/* Primary buttons get a chunky, pressable feel. */
.btn-primary {
  box-shadow: 0 3px 0 var(--teal-dark), 0 8px 18px rgba(14, 124, 113, 0.22);
}
.btn-primary:hover {
  background: #0f8a7d;
  transform: translateY(-2px);
  box-shadow: 0 5px 0 var(--teal-dark), 0 10px 20px rgba(14, 124, 113, 0.26);
}
.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--teal-dark);
}

/* Steps: checkmarks for finished work, a gentle pulse on the current step. */
.step-done .step-dot { position: relative; }
.step-done .step-dot::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.step-current .step-dot { animation: snapp-pulse 2s ease-out infinite; }
@keyframes snapp-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(221, 100, 66, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(221, 100, 66, 0); }
}

/* Study: coloured chapter labels and alternating concept-card edges. */
.chapter-index {
  display: inline-block;
  padding: 0.16rem 0.62rem;
  border-radius: 999px;
  letter-spacing: 0.08em;
}
.chapter-section:nth-of-type(3n+1) .chapter-index { background: var(--coral-soft); color: #b14a2e; }
.chapter-section:nth-of-type(3n+2) .chapter-index { background: var(--teal-soft); color: var(--teal-dark); }
.chapter-section:nth-of-type(3n+3) .chapter-index { background: var(--violet-soft); color: #544aa2; }

.concept-card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.chapter-section .concept-card:nth-child(4n+1) { border-left-color: var(--teal); }
.chapter-section .concept-card:nth-child(4n+3) { border-left-color: var(--amber); }
.chapter-section .concept-card:nth-child(4n+4) { border-left-color: var(--violet); }
.chapter-section .concept-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(32, 39, 46, 0.08);
}

.chapter-link.is-active {
  background: linear-gradient(135deg, var(--teal), #2f9d8f);
  box-shadow: 0 4px 10px rgba(14, 124, 113, 0.25);
  transform: translateX(2px);
}

/* Exam: pastel option letters, and clearer correct/wrong states. */
.option:nth-child(1) .option-letter { background: var(--coral-soft); border-color: #f4cbbb; color: #b14a2e; }
.option:nth-child(2) .option-letter { background: var(--teal-soft); border-color: #bfe0da; color: var(--teal-dark); }
.option:nth-child(3) .option-letter { background: var(--amber-soft); border-color: #f0dcb4; color: #8a5d14; }
.option:nth-child(4) .option-letter { background: var(--violet-soft); border-color: #d5d0f0; color: #544aa2; }
.option:has(input:checked) .option-letter {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.option.option-correct .option-letter {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.option.option-wrong .option-letter {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
/* Keep the answered state visible on the whole row, not just the letter. */
.options .option.option-correct { border-color: var(--green); background: var(--green-soft); }
.options .option.option-wrong { border-color: var(--red); background: var(--red-soft); }

.dot-now { box-shadow: 0 0 0 4px rgba(221, 100, 66, 0.15); }

/* Feedback: a round badge carries the verdict at a glance. */
.feedback { position: relative; padding-left: 3.55rem; border-width: 2px; }
.feedback-badge {
  position: absolute;
  left: 1rem;
  top: 0.95rem;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1;
}
.feedback-ok .feedback-badge { background: var(--green); }
.feedback-wrong .feedback-badge { background: var(--red); }
.feedback h3 { font-size: 1.05rem; }

/* Result: star rating, grade-coloured ring, and a one-shot confetti burst. */
.stars {
  display: flex;
  justify-content: center;
  gap: 0.18rem;
  font-size: 1.7rem;
  line-height: 1;
  margin: 0.15rem 0 0.8rem;
}
.star { color: #e2d8c8; }
.star.is-on { color: var(--amber); text-shadow: 0 2px 6px rgba(229, 166, 60, 0.35); }

.grade-ring {
  background:
    radial-gradient(closest-side, var(--paper-2) 78%, transparent 79%),
    conic-gradient(var(--ring-color, var(--teal)) 0 var(--pct, 0%), #ece4d7 var(--pct, 0%) 100%);
}
.grade-ring span { color: var(--ring-color, var(--teal-dark)); }

.confetti {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  pointer-events: none;
}
.confetti i {
  position: absolute;
  top: -16px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation-name: snapp-fall;
  animation-timing-function: linear;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
}
@keyframes snapp-fall {
  0% { opacity: 1; transform: translate3d(0, -10vh, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate3d(var(--drift, 0), 105vh, 0) rotate(540deg); }
}

/* Optional online route (Gemini). */
.gemini-card {
  border-color: #c9d7f7;
  background: linear-gradient(180deg, #f7f9ff 0%, #ffffff 70%);
}
.gemini-card > summary,
.gemini-settings > summary {
  cursor: pointer;
  font-weight: 700;
}
.gemini-settings {
  margin-top: 0.9rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}
.gemini-form { margin-top: 0.75rem; }
.gemini-form .field { max-width: 34rem; }
.gemini-card .alert { margin-top: 0.75rem; }
.manual-fallback {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fdfbf6;
}
.manual-fallback > summary {
  cursor: pointer;
  font-weight: 700;
}
.manual-fallback[open] > summary { margin-bottom: 0.75rem; }
.manual-fallback .card { margin-top: 0.75rem; }
.manual-fallback .card:first-of-type { margin-top: 0; }
.job-online .progress > span {
  width: 35% !important;
  background: repeating-linear-gradient(
    45deg,
    var(--teal) 0 12px,
    #55b9ad 12px 24px
  );
  animation: snapp-stripes 1.1s linear infinite;
}
@keyframes snapp-stripes {
  from { background-position: 0 0; }
  to { background-position: 34px 0; }
}

/* New-lesson camera capture: each shot is added to the page list. */
[hidden] { display: none !important; }
.visually-hidden,
input.visually-hidden,
textarea.visually-hidden,
select.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.camera-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.camera-actions label.btn { cursor: pointer; }
.photo-status {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.8rem;
  border: 1px solid #bfe0da;
  border-radius: 10px;
  background: var(--teal-soft);
  color: var(--teal-dark);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Respect reduced-motion preferences: no falling, just a static sprinkle. */
@media (prefers-reduced-motion: reduce) {
  .confetti { display: block; }
  .confetti i {
    animation: none !important;
    top: auto;
    opacity: 0.9;
    transform: rotate(24deg);
  }
  .confetti i:nth-child(3n+1) { bottom: 6%; transform: rotate(70deg); }
  .confetti i:nth-child(3n+2) { bottom: 14%; transform: rotate(-30deg); }
  .confetti i:nth-child(3n) { bottom: 22%; transform: rotate(20deg); }
  .step-current .step-dot { animation: none; }
  .job-online .progress > span { animation: none; }
  .brand-mark, .hero-stats div, .lesson-grid .lesson-card, .btn-primary { transition: none; }
  .reader-sheet { animation: none; }
  .reader-step, .reader-progress > span { transition: none; }
}

/* ---------- Admin lesson editor ---------- */
.editor-grid { margin-top: 1.25rem; }
.edit-list { list-style: none; margin: 0; padding: 0; }
.edit-list li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
}
.edit-list li:last-child { border-bottom: 0; }
.edit-list a { font-weight: 600; text-decoration: none; }
.repeat-fieldset { margin-top: 0.35rem; }
.repeat-rows { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.55rem; }
.repeat-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper-2);
}
.repeat-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.repeat-fields textarea { resize: vertical; }
.repeat-row .icon-btn { flex: none; }
.option-edit { align-items: center; }
.option-pick {
  flex: none;
  position: relative;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: #fff;
  font-weight: 800;
  color: var(--ink-soft);
  cursor: pointer;
}
.option-pick input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.option-pick:has(input:checked) {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

@media print {
  .confetti, .lesson-card::before { display: none !important; }
  .lesson-grid .lesson-card,
  .hero-stats div,
  .brand-mark,
  .chapter-link.is-active { transform: none; }
}

/* ==========================================================================
   Phone layout
   Breakpoint at 560px covers common phones in portrait (and small landscape).
   Declared last so it wins over the playful layer and the admin editor rules.
   ========================================================================== */

@media (max-width: 560px) {
  /* Chrome */
  .wrap { padding: 1.15rem 0.95rem 2.75rem; }
  .topbar-inner { padding: 0.55rem 0.85rem; gap: 0.5rem; }
  .nav { gap: 0.1rem; }
  .nav-link { padding: 0.55rem; min-height: 40px; }
  .nav-link span { display: none; }
  .footer { padding: 1rem 0.95rem; }

  /* Typography */
  .lead { font-size: 1rem; }
  .hero { gap: 0.9rem; padding: 0.5rem 0 1.25rem; }
  .hero h1 { font-size: clamp(1.7rem, 8vw, 2.2rem); }

  /* Library */
  .hero-stats { width: 100%; gap: 0.55rem; }
  .hero-stats div { flex: 1; min-width: 0; padding: 0.5rem 0.7rem; }
  .hero-stats strong { font-size: 1.3rem; }
  .hero-stats div,
  .hero-stats div:hover,
  .lesson-grid .lesson-card,
  .lesson-grid .lesson-card:hover { transform: none; }
  .lesson-grid { grid-template-columns: 1fr; gap: 1rem; }

  .filters { padding: 0.85rem; gap: 0.7rem; margin-bottom: 1.5rem; }
  .filters .field,
  .filters .grow,
  .filters .btn { flex: 1 1 100%; width: 100%; }
  .filters .btn { margin-bottom: 0; }

  /* Cards and forms */
  .card { padding: 1rem; }
  .card-head { gap: 0.5rem; }
  .btn { white-space: normal; text-align: center; min-height: 42px; }
  .btn-small { padding: 0.42rem 0.75rem; }
  .icon-btn { width: 36px; height: 36px; }
  .form-actions { gap: 0.5rem; }
  .form-actions > .btn,
  .form-actions > form { flex: 1 1 100%; }
  .form-actions > form .btn { width: 100%; }

  /* Keep inputs at 16px so mobile browsers do not zoom on focus. */
  input[type="text"], input[type="search"], input[type="password"], input[type="number"],
  input[type="file"], input:not([type]), select, textarea { font-size: 16px; }
  textarea.code-area { font-size: 0.8rem; }

  /* Steps and lesson overview */
  .steps { flex-wrap: wrap; overflow-x: visible; border-radius: var(--radius-sm); padding: 0.6rem; }
  .step { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
  .next-step { padding: 0.9rem 1rem; }
  .next-step-actions { width: 100%; }
  .next-step-actions .btn { flex: 1 1 auto; }
  .action-list li { gap: 0.5rem; }
  .action-control { flex: 1 1 100%; }
  .action-control .btn { width: 100%; }

  /* Chapter boundary editor */
  .chapter-section { padding: 1.1rem; }
  .chapter-fields { grid-template-columns: 1fr; }
  .chapter-row { grid-template-columns: 24px minmax(0, 1fr) 30px; padding: 0.6rem; gap: 0.5rem; }
  .chapter-summary { border-radius: var(--radius-sm); }

  /* Study */
  .study-nav { padding: 0.9rem; }
  .chapter-links { gap: 0.35rem; }
  .chapter-link { flex: 1 1 100%; }
  .concept-grid { grid-template-columns: 1fr; }
  .source-image-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

  /* Exam */
  .exam-card { padding: 1.05rem; border-radius: 18px; }
  .question { font-size: 1.2rem; }
  .option { padding: 0.7rem 0.8rem; gap: 0.65rem; }
  .option-text { font-size: 0.95rem; }
  .feedback { padding-left: 3.1rem; }
  .feedback-badge { left: 0.75rem; top: 0.75rem; width: 30px; height: 30px; font-size: 1rem; }

  /* Result */
  .result-card { padding: 1.5rem 1rem; border-radius: 18px; }
  .grade-ring { width: 140px; height: 140px; }
  .grade-ring span { font-size: 2.7rem; }
  .result-actions { gap: 0.5rem; }
  .result-actions > form,
  .result-actions > .btn { flex: 1 1 100%; }
  .result-actions .btn { width: 100%; }

  /* Admin lesson editor */
  .edit-list li { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
  .edit-list li > .small { overflow-wrap: anywhere; }
  .repeat-row { padding: 0.6rem; }

  /* Tables: drop the least important columns instead of scrolling sideways. */
  .hide-phone { display: none !important; }
  .table { font-size: 0.88rem; }
  .table th { font-size: 0.68rem; padding: 0.4rem 0.35rem; letter-spacing: 0.04em; }
  .table td { padding: 0.5rem 0.35rem; }
  .table a { overflow-wrap: anywhere; }
  .table td.nowrap,
  .table td:last-child { white-space: normal; }
  .table td .badge { white-space: normal; }
  .table td .btn { padding: 0.38rem 0.6rem; margin-bottom: 0.3rem; white-space: nowrap; }
  .table td .btn:last-child { margin-bottom: 0; }
  .table td form.inline { display: block; }
  .table td form.inline .btn { width: 100%; }
  .table-scroll { overflow-x: visible; }

  /* EPUB reader: on a phone the book text gets as much of the screen as
     possible. The app bar, book title, page counter, progress bar and chapter
     label are dropped while reading; the back link and contents menu stay. */
  html.reader-js .topbar { display: none; }
  .reader-body .wrap {
    padding-top: 0.5rem;
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0px));
  }
  .reader { max-width: none; }
  .reader-top { margin-bottom: 0.35rem; }
  .reader-top-row { margin-bottom: 0; }
  .reader-back { margin-left: -0.4rem; padding-left: 0.45rem; }
  .reader-meta,
  .reader-progress,
  .reader-kicker { display: none; }
  .reader-sheet {
    padding: 0.8rem 0.85rem 0.75rem;
    border-radius: 14px;
  }
  .reader-text { font-size: 1.05rem; line-height: 1.72; }
  .reader-toc > summary { min-height: 42px; }
  .reader-toc-link { min-height: 46px; }
  .reader-jump-row input { font-size: 16px; }

  /* The page buttons stay at the bottom of the fixed frame. */
  .reader-pager {
    gap: 0.5rem;
    margin-top: 0.45rem;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .reader-step {
    flex: 1 1 0;
    min-width: 0;
    min-height: 46px;
    padding: 0.4rem 0.6rem;
    border-radius: 12px;
    font-size: 0.9rem;
  }
  .reader-step .icon { width: 18px; height: 18px; }
  .reader-pager-count { flex: 0 0 auto; font-size: 0.72rem; }
  .reader-pager-count strong { font-size: 0.86rem; }
  .reader-end-actions > * { flex: 1 1 100%; }

  /* Long unbroken strings (file names, URLs) may never widen the page. */
  .prose p, .prose li, .file-list li, .page-preview p, .missed-body p,
  .reader-text p, .reader-text li, .reader-toc-link span { overflow-wrap: anywhere; }
}

/* A short screen (a phone held sideways): shed decoration so the page text
   keeps a real height instead of collapsing to nothing. */
@media (max-height: 560px) {
  html.reader-js .topbar { display: none; }
  .reader-body .wrap {
    padding-top: 0.45rem;
    padding-bottom: calc(0.3rem + env(safe-area-inset-bottom, 0px));
  }
  .reader-top { margin-bottom: 0.35rem; }
  .reader-top-row { margin-bottom: 0; }
  .reader-meta,
  .reader-progress,
  .reader-kicker { display: none; }
  .reader-toc > summary { min-height: 38px; padding: 0.35rem 0.7rem; }
  .reader-sheet { padding: 0.7rem 0.95rem 0.65rem; border-radius: 12px; }
  .reader-text { font-size: 1rem; line-height: 1.6; }
  .reader-text p, .reader-text li, .reader-toc-link span { overflow-wrap: anywhere; }
  .reader-pager { gap: 0.4rem; margin-top: 0.4rem; }
  .reader-step { min-height: 42px; padding: 0.35rem 0.6rem; }
  .reader-text.reader-paged .reader-end .muted { display: none; }
  .reader-text.reader-paged .reader-end { padding: 0.55rem 0.7rem; }
  .reader-end { margin-top: 0.8rem; padding: 0.8rem; }
}

@media (max-height: 430px) {
  .reader-top { margin-bottom: 0.3rem; }
  .reader-end h3 { font-size: 1rem; }
}

@media (max-width: 360px) {
  .wrap { padding-left: 0.75rem; padding-right: 0.75rem; }
  .hero-stats strong { font-size: 1.15rem; }
  .hero-stats span { letter-spacing: 0.04em; }
  .grade-ring { width: 126px; height: 126px; }
  .grade-ring span { font-size: 2.4rem; }
}

