:root {
  --surround: #0e1014;
  --page: #0e1014;
  --text: #e9e3d6;
  --muted: #8b8d96;
  --rule: #2a2d34;
  --brass: #b5924f;
  --oxblood: #9a2a33;
  --focus: #d6b46a;
  --read-size: 20px;
  --measure: 34em;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --surround: #e4ddcd;
  --page: #efe9dc;
  --text: #1d1a16;
  --muted: #6b655b;
  --rule: #cfc6b4;
  --brass: #7a5d24;
  --oxblood: #7d1f26;
  --focus: #7a5d24;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surround);
  color: var(--text);
  font-family: "Spectral", Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 18px;
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--brass); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 2px; }
button { font: inherit; color: inherit; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 1rem; top: 1rem; background: var(--page); padding: 0.5rem 0.8rem; z-index: 10; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem max(1rem, env(safe-area-inset-left)) 0.7rem max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--surround) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--rule);
  font-size: 0.95rem;
}
.bar:empty { display: none; }
.bar .home { color: var(--text); text-decoration: none; font-weight: 500; white-space: nowrap; }
.bar .where { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.bar .tools { display: flex; gap: 0.25rem; margin-left: auto; }
.tool {
  background: none; border: 1px solid transparent; border-radius: 4px;
  padding: 0.3rem 0.6rem; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.tool:hover { color: var(--text); border-color: var(--rule); }
.readbar { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--oxblood); width: 0; transition: width 0.15s linear; }

/* ---------- shared layout ---------- */
.wrap { max-width: 46rem; margin: 0 auto; padding: 3rem 1.25rem 5rem; }
.title-xl { font-weight: 300; font-size: clamp(2.4rem, 7vw, 3.6rem); line-height: 1.05; letter-spacing: -0.015em; margin: 0 0 1rem; }
.lede { color: var(--muted); font-size: 1.1rem; max-width: 32em; margin: 0 0 2.5rem; }
.btn {
  display: inline-block; padding: 0.75rem 1.2rem; border-radius: 4px;
  background: var(--text); color: var(--surround); border: 0; cursor: pointer;
  text-decoration: none; font-weight: 500;
}
.btn:hover { opacity: 0.9; }
.btn-quiet { background: none; color: var(--brass); border: 1px solid var(--rule); }
.muted { color: var(--muted); }
.notice { border-left: 2px solid var(--oxblood); padding: 0.2rem 0 0.2rem 1rem; margin: 0 0 2rem; }

/* ---------- sign in ---------- */
.door { min-height: 100vh; display: grid; align-content: center; }
.door .actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-top: 0.5rem; }
.door .fine { margin-top: 3rem; font-size: 0.9rem; color: var(--muted); max-width: 32em; }

/* ---------- library ledger ---------- */
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 3rem 0 0.5rem; }
.shelf-head h2 { font-weight: 400; font-size: 1.15rem; margin: 0; }
.shelf-head span { color: var(--muted); font-size: 0.9rem; }
.ledger { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--rule); }
.entry { border-bottom: 1px solid var(--rule); position: relative; }
.entry a {
  display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 1rem; align-items: baseline;
  padding: 1.1rem 0 1.25rem; color: var(--text); text-decoration: none;
}
.entry a:hover .t { color: var(--brass); }
.entry .t { font-size: clamp(1.35rem, 3.6vw, 1.7rem); font-weight: 300; line-height: 1.2; }
.entry .sub { grid-column: 1; color: var(--muted); font-size: 0.95rem; }
.entry .state { grid-row: 1; grid-column: 2; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.entry .state.is-reading { color: var(--brass); }
.entry .line { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--oxblood); }
.entry.has-cover a { grid-template-columns: 3.2rem 1fr auto; }
.entry.has-cover img { grid-row: 1 / span 2; width: 3.2rem; aspect-ratio: 2 / 3; object-fit: cover; border: 1px solid var(--rule); }
.entry.has-cover .t, .entry.has-cover .sub { grid-column: 2; }
.entry.has-cover .state { grid-column: 3; }

/* ---------- book page ---------- */
.book-head { margin-bottom: 2rem; }
.book-head .imprint { color: var(--muted); margin: 0 0 0.75rem; }
.book-head p.blurb { max-width: 32em; }
.contents { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); counter-reset: none; }
.contents li { border-bottom: 1px solid var(--rule); }
.contents a { display: flex; gap: 1rem; justify-content: space-between; padding: 0.8rem 0; text-decoration: none; color: var(--text); }
.contents a:hover span:first-child { color: var(--brass); }
.contents .n { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.contents li.here a span:first-child { color: var(--brass); }

/* ---------- reading ---------- */
.page { background: var(--page); min-height: 100vh; }
.reading { max-width: var(--measure); margin: 0 auto; padding: 3.5rem 1.35rem 4rem; font-size: var(--read-size); line-height: 1.7; }
.reading .ch-of { color: var(--muted); font-size: 0.85em; margin: 0 0 0.4rem; }
.reading h1 { font-weight: 300; font-size: 2em; line-height: 1.15; letter-spacing: -0.01em; margin: 0 0 2.2rem; }
.prose p { margin: 0 0 1.05em; hyphens: auto; -webkit-hyphens: auto; }
.prose h2, .prose h3, .prose h4 { font-weight: 500; line-height: 1.3; margin: 2em 0 0.8em; }
.prose h2 { font-size: 1.25em; } .prose h3 { font-size: 1.1em; } .prose h4 { font-size: 1em; font-style: italic; font-weight: 400; }
.prose blockquote { margin: 1.5em 0; padding: 0 0 0 1.2em; border-left: 1px solid var(--brass); color: color-mix(in srgb, var(--text) 85%, var(--muted)); }
.prose hr { border: 0; text-align: center; margin: 2.2em 0; }
.prose hr::after { content: "\2042"; color: var(--muted); }
.prose img { display: block; max-width: 100%; height: auto; margin: 2em auto 0.6em; }
.prose figure { margin: 2em 0; } .prose figcaption { color: var(--muted); font-size: 0.85em; text-align: center; }
.prose table { border-collapse: collapse; margin: 1.5em 0; font-size: 0.9em; width: 100%; }
.prose td, .prose th { border-bottom: 1px solid var(--rule); padding: 0.4em 0.6em 0.4em 0; text-align: left; vertical-align: top; }
.turn { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3.5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); font-size: 1rem; }
.turn a { text-decoration: none; max-width: 48%; }
.turn .next { margin-left: auto; text-align: right; }
.turn small { display: block; color: var(--muted); }
.end { color: var(--muted); text-align: center; margin-top: 3.5rem; font-size: 1rem; }

/* ---------- panels (contents, type settings) ---------- */
.panel-back { position: fixed; inset: 0; background: rgb(0 0 0 / 0.45); z-index: 20; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(24rem, 92vw); z-index: 21;
  background: var(--surround); border-left: 1px solid var(--rule); overflow-y: auto;
  padding: 1.25rem 1.25rem 3rem;
}
.panel h2 { font-weight: 400; font-size: 1.1rem; margin: 0 0 1rem; display: flex; justify-content: space-between; align-items: center; }
.setting { margin: 1.5rem 0; }
.setting .label { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 0.45rem 0.9rem; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--text); color: var(--surround); }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--text); color: var(--surround); padding: 0.6rem 1rem; border-radius: 4px;
  font-size: 0.95rem; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.loading { color: var(--muted); padding: 4rem 0; }
.foot { margin-top: 4rem; color: var(--muted); font-size: 0.9rem; display: flex; gap: 1.25rem; flex-wrap: wrap; }
.foot button { background: none; border: 0; padding: 0; color: var(--brass); cursor: pointer; text-decoration: underline; text-underline-offset: 0.18em; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
@media print { .bar, .turn, .toast { display: none; } }

/* Case Book reveals: hint and answer stay covered until asked for */
.prose details { border-top: 1px solid var(--rule); margin: 0; padding: 0.2em 0; }
.prose details:last-of-type { border-bottom: 1px solid var(--rule); margin-bottom: 1.5em; }
.prose details + details { border-top: 1px solid var(--rule); }
.prose summary { cursor: pointer; color: var(--brass); padding: 0.6em 0; font-size: 0.95em; list-style-position: inside; }
.prose details[open] summary { color: var(--muted); }
.prose details > p { margin-top: 0.2em; }
.prose h3 + p { margin-top: 0; }
