:root {
  --paper: #fbf7ef;
  --card: #ffffff;
  --ink: #1f2b26;
  --muted: #5d6963;
  --rule: #e3dbc9;
  --leaf: #2e7d52;
  --leaf-dark: #1f5c3b;
  --leaf-wash: #e6f1ea;
  --sun: #f4c15d;
  --sun-wash: #fdf1d3;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}

a { color: var(--leaf-dark); text-underline-offset: 2px; }
a:hover { color: var(--leaf); }

:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 4px; }

h1, h2 { font-family: var(--serif); font-weight: 700; line-height: 1.15; margin: 0; }

code { background: #efe8d8; padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.92em; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

/* ---------------------------------------------------------------- frame */

.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  color: var(--leaf); text-decoration: none;
  font: 700 1.45rem/1 var(--serif);
}
.brand span { color: var(--ink); }
.site-header nav { display: flex; gap: 1.25rem; font-weight: 600; }
.site-header nav a { text-decoration: none; }
.site-header nav a:hover { text-decoration: underline; }

main { max-width: 1240px; margin: 0 auto; padding: 1.5rem clamp(1rem, 4vw, 2.5rem) 3rem; min-height: 70vh; }
main:focus { outline: none; }

.site-footer {
  border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.875rem;
  padding: 1.25rem clamp(1rem, 4vw, 2.5rem); text-align: center;
}
.site-footer p { margin: 0 auto; max-width: 60rem; }

.loading { color: var(--muted); padding: 3rem 0; text-align: center; }
.notice-page { max-width: 38rem; margin: 3rem auto; text-align: center; }
.notice-page p { color: var(--muted); }

.button {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1.05rem; border-radius: 999px;
  border: 1.5px solid var(--leaf); background: var(--card); color: var(--leaf-dark);
  font: 600 0.95rem/1.2 var(--sans); text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--leaf-wash); color: var(--leaf-dark); }
.button.primary { background: var(--leaf); color: #fff; }
.button.primary:hover { background: var(--leaf-dark); color: #fff; }

.badge {
  display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; line-height: 1.4;
}
.badge.award { background: var(--sun-wash); color: #6b4a05; }
.badge.text { background: var(--leaf-wash); color: var(--leaf-dark); }

.crumbs { margin: 0 0 1rem; font-weight: 600; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0; }

label { font-size: 0.85rem; font-weight: 600; color: var(--muted); display: block; }
input[type="search"], input:not([type]), input[type="text"], select, textarea {
  display: block; width: 100%; margin-top: 0.25rem;
  padding: 0.5rem 0.65rem; border: 1.5px solid var(--rule); border-radius: 8px;
  background: var(--card); color: var(--ink); font: 400 1rem/1.3 var(--sans);
}
input:focus, select:focus, textarea:focus { border-color: var(--leaf); outline: none; box-shadow: 0 0 0 3px var(--leaf-wash); }
label.check { display: flex; align-items: center; gap: 0.5rem; color: var(--ink); font-weight: 500; font-size: 0.92rem; }
label.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--leaf); margin: 0; }

/* ---------------------------------------------------------------- browse */

.intro { max-width: 46rem; margin: 0.75rem 0 1.5rem; }
.intro h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); }
.intro p { color: var(--muted); font-size: 1.1rem; margin: 0.6rem 0 0; }

.filters {
  background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 1rem; display: grid; gap: 0.9rem;
}
.filters .search input { font-size: 1.1rem; padding: 0.7rem 0.9rem; margin: 0; }
.filters fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.filters legend { font-size: 0.85rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 0.3rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.4rem; padding: 0.35rem 0.7rem; border-radius: 999px;
  border: 1.5px solid var(--rule); background: var(--paper); color: var(--ink); font-size: 0.95rem; font-weight: 600;
}
.chip input:hover + span { border-color: var(--leaf); }
.chip input:checked + span { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--sun); outline-offset: 2px; }
.selects { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: end; }
.selects label:not(.check) { flex: 1 1 11rem; max-width: 16rem; }
.selects .check { padding-bottom: 0.55rem; }

.result-count { color: var(--muted); margin: 1.1rem 0 0.8rem; }

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 1.4rem 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card { display: block; color: inherit; text-decoration: none; }
.card:hover .cover, .card:focus-visible .cover { transform: translateY(-3px); box-shadow: 0 10px 22px rgba(31, 43, 38, 0.2); }
.card-text { display: block; padding-top: 0.6rem; }
.card-title { display: block; font: 700 1rem/1.25 var(--serif); }
.card:hover .card-title { color: var(--leaf-dark); text-decoration: underline; }
.card-author, .card-meta, .card-series { display: block; color: var(--muted); font-size: 0.85rem; }
.card-meta { margin-bottom: 0.3rem; }
.card .badge { margin: 0 0.2rem 0.2rem 0; }

.cover {
  position: relative; display: flex; align-items: center; justify-content: center;
  aspect-ratio: 2 / 3; overflow: hidden; border-radius: 6px;
  box-shadow: 0 3px 10px rgba(31, 43, 38, 0.16);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  color: #fff; text-align: center;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-title { padding: 0.8rem; font: 700 1rem/1.25 var(--serif); overflow-wrap: anywhere; }
.tone-0 { background: #2e7d52; }
.tone-1 { background: #35628a; }
.tone-2 { background: #8a4f35; }
.tone-3 { background: #6a4c8c; }
.tone-4 { background: #9a6a14; }
.tone-5 { background: #3b6f73; }

/* ---------------------------------------------------------------- book */

.book { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: clamp(1rem, 4vw, 2.5rem); align-items: start; }
.book-cover .cover-title { font-size: 1.3rem; }
.book-info h1 { font-size: clamp(1.8rem, 4vw, 2.6rem); }
.byline { color: var(--muted); font-size: 1.1rem; margin: 0.4rem 0 1rem; }
.facts { list-style: none; padding: 0; margin: 0 0 0.9rem; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.facts li { background: var(--card); border: 1px solid var(--rule); border-radius: 999px; padding: 0.2rem 0.75rem; font-size: 0.9rem; }
.awards { margin: 0 0 0.8rem; }
.awards .badge { font-size: 0.82rem; padding: 0.2rem 0.7rem; }
.subjects { color: var(--muted); font-size: 0.9rem; margin: 0 0 0.8rem; }
.links { display: flex; flex-wrap: wrap; gap: 1.2rem; margin: 0; font-size: 0.92rem; font-weight: 600; }

.chapters { margin-top: 2.2rem; max-width: 52rem; }
.chapters h2 { font-size: 1.6rem; margin-bottom: 0.7rem; }
.status {
  margin: 0 0 1.1rem; padding: 0.7rem 0.95rem; border-radius: 8px;
  background: var(--card); border: 1px solid var(--rule); border-left: 5px solid var(--rule);
}
.status-verified-text, .status-verified, .status-whole-book { border-left-color: var(--leaf); }
.status-single-source, .status-unknown, .status-edition { border-left-color: var(--sun); }
.chapter-actions { margin: 0 0 1rem; }
.chapter-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.chapter-list li + li { border-top: 1px solid var(--rule); }
.chapter-list a {
  display: grid; grid-template-columns: 6.5rem 1fr auto; gap: 0.8rem; align-items: baseline;
  padding: 0.7rem 1rem; color: var(--ink); text-decoration: none;
}
.chapter-list a:hover, .chapter-list a:focus-visible { background: var(--leaf-wash); }
.chapter-label { font-weight: 700; color: var(--leaf-dark); white-space: nowrap; }
.chapter-title { font-family: var(--serif); font-size: 1.05rem; }
.chapter-go { color: var(--leaf-dark); font-size: 0.85rem; font-weight: 600; white-space: nowrap; opacity: 0; }
.chapter-list a:hover .chapter-go, .chapter-list a:focus-visible .chapter-go { opacity: 1; }
.chapter-form { display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: end; }
.chapter-form input[name="n"] { width: 6rem; }
.chapter-form .grow { flex: 1 1 14rem; }

/* ---------------------------------------------------------------- worksheet */

.workspace { display: grid; grid-template-columns: minmax(250px, 310px) minmax(0, 1fr); gap: clamp(1rem, 3vw, 2.2rem); align-items: start; }
.controls { position: sticky; top: 1rem; background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.1rem; }
.controls h1 { font-size: 1.6rem; margin-bottom: 0.9rem; }
.controls h1 span { display: block; font-size: 1.05rem; font-weight: 400; color: var(--muted); margin-top: 0.25rem; }
.controls form { display: grid; gap: 0.65rem; }
.controls .row { display: grid; grid-template-columns: 1.5fr 1fr; gap: 0.7rem; }
.controls .hint { margin: 0; }
.controls > .hint { margin-top: 0.8rem; }
.specifics { border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.specifics summary { cursor: pointer; font-weight: 600; color: var(--leaf-dark); }
.specifics label { margin-top: 0.6rem; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.3rem; }
.actions .button { flex: 1 1 auto; }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--rule); font-weight: 600; font-size: 0.92rem; }
.pager a { text-decoration: none; }
.pager a:hover { text-decoration: underline; }

.paper { display: grid; gap: 1.5rem; justify-items: center; min-width: 0; }

.sheet {
  --line-gap: 9.5mm;
  width: 100%; max-width: 8.5in; min-height: 11in;
  background: #fff; color: #111;
  padding: 0.6in 0.65in;
  box-shadow: 0 2px 4px rgba(31, 43, 38, 0.1), 0 14px 34px rgba(31, 43, 38, 0.14);
  font: 12.5pt/1.4 var(--serif);
  display: flex; flex-direction: column;
}
.sheet.tier-0 { --line-gap: 12mm; font-size: 15pt; }
.sheet.tier-1 { --line-gap: 9mm; font-size: 13pt; }
.sheet.tier-2 { --line-gap: 8.5mm; font-size: 12pt; }
.sheet.tier-3 { --line-gap: 8mm; font-size: 11.5pt; }

.sheet-head { display: flex; justify-content: space-between; gap: 1.5rem; align-items: flex-start; border-bottom: 2px solid #111; padding-bottom: 0.7rem; margin-bottom: 1rem; }
.sheet-head h2 { font-size: 1.45em; }
.sheet-book { margin: 0 0 0.15rem; font: 600 0.72em/1.3 var(--sans); letter-spacing: 0.06em; text-transform: uppercase; color: #444; }
.sheet-author { margin: 0.15rem 0 0; font-size: 0.8em; color: #444; font-style: italic; }
.name-date { display: grid; gap: 1.1rem; min-width: 2.3in; padding-top: 0.5rem; font: 500 10pt/1 var(--sans); color: #333; }
.name-date span { display: block; border-bottom: 1px solid #333; padding-bottom: 2px; }
.no-name .name-date { display: none; }

.sheet-summary { margin: 0 0 1rem; padding: 0.6rem 0.8rem; border: 1px solid #999; border-radius: 6px; font-size: 0.92em; }

.questions { list-style: none; margin: 0; padding: 0; counter-reset: q; }
.question { position: relative; counter-increment: q; padding-left: 2em; margin-bottom: 1.1em; break-inside: avoid; }
.question::before { content: counter(q) "."; position: absolute; left: 0; top: 0; font-weight: 700; }
.question .skill { display: block; font: 700 0.6em/1.2 var(--sans); letter-spacing: 0.07em; text-transform: uppercase; color: #555; margin: 0.25em 0 0.15em; }
.question .skill:empty, .no-labels .question .skill { display: none; }
.question-text { margin: 0; border-radius: 4px; outline-offset: 3px; }
.question-text:hover { background: #f6f3ea; }
.question-text:focus { background: #fffbe8; outline: 2px solid var(--sun); }
.question blockquote { margin: 0.5em 0 0; padding: 0.35em 0.8em; border-left: 3px solid #777; font-style: italic; color: #222; }
.question blockquote strong { font-style: normal; text-decoration: underline; text-underline-offset: 3px; }
.lines span { display: block; height: var(--line-gap); border-bottom: 1px solid #8a8a8a; }
.tier-0 .lines span { border-bottom-width: 1.5px; }
.draw-box { height: 55mm; margin-top: 0.6em; border: 1.5px solid #555; border-radius: 8px; }
.sheet:not(.tier-0) .draw-box { height: 45mm; }
.compact .lines span:nth-child(n+3) { display: none; }
.compact .question { margin-bottom: 0.7em; }
.compact .sheet .draw-box { height: 36mm; }
.stars { font-size: 2em; letter-spacing: 0.2em; line-height: 1.2; margin-top: 0.2em; }

.tools { position: absolute; top: -0.4rem; right: 0; display: flex; gap: 0.3rem; opacity: 0; transition: opacity 0.1s; }
.question:hover .tools, .question:focus-within .tools { opacity: 1; }
.tools button {
  border: 1px solid var(--rule); background: var(--card); color: var(--leaf-dark); border-radius: 999px;
  padding: 0.15rem 0.6rem; font: 600 0.72rem/1.4 var(--sans); cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.tools button:hover { background: var(--leaf-wash); }
.tools button:disabled { color: var(--muted); cursor: default; }

.sheet-foot { margin-top: auto; padding-top: 0.8rem; font: 400 8pt/1.3 var(--sans); color: #777; text-align: right; }

/* ---------------------------------------------------------------- about */

.prose { max-width: 42rem; }
.prose h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); margin-bottom: 0.8rem; }
.prose h2 { font-size: 1.35rem; margin: 1.8rem 0 0.5rem; }
.prose p, .prose li { font-size: 1.05rem; }

/* ---------------------------------------------------------------- small screens */

@media screen and (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { position: static; }
  .sheet { padding: 1.4rem 1.1rem; min-height: 0; }
  .sheet-head { flex-direction: column; gap: 0.6rem; }
  .name-date { min-width: 0; width: 100%; }
  .tools { opacity: 1; position: static; margin-top: 0.4rem; }
}
@media screen and (max-width: 560px) {
  .book { grid-template-columns: 1fr; }
  .book-cover { max-width: 160px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 1.1rem 0.8rem; }
  .chapter-list a { grid-template-columns: 1fr; gap: 0.1rem; }
  .chapter-go { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------------------------------------------------------------- print */

@page { margin: 13mm 15mm; }

@media print {
  body { background: #fff; }
  .site-header, .site-footer, .controls, .tools, .skip { display: none !important; }
  main { max-width: none; margin: 0; padding: 0; min-height: 0; }
  .workspace, .paper { display: block; }
  .sheet {
    max-width: none; min-height: 0; padding: 0; box-shadow: none; display: block;
    break-after: page;
  }
  .sheet:last-child { break-after: auto; }
  .question-text:hover, .question-text:focus { background: none; outline: none; }
  .sheet-foot { margin-top: 1.5rem; }
}
