:root {
  color-scheme: light;
  font-family: Charter, Georgia, serif;
  color: #18201d;
  background: #ded8cc;
  --surface: #f6f1e8;
  --surface-strong: #efe7da;
  --border: #b7ada0;
  --border-strong: #908576;
  --text-muted: #666053;
  --accent: #9b3e26;
  --shadow: 0 18px 40px rgb(24 32 29 / 10%);
}

* { box-sizing: border-box; }
body { min-height: 100vh; margin: 0; }
button, select, input { font: inherit; }
a { color: inherit; }

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

.home-page,
.results-page,
.work-page {
  min-height: 100vh;
}

.home-page,
.results-page {
  display: grid;
  align-items: center;
  justify-items: center;
  padding: clamp(1.5rem, 5vw, 5rem);
}

.home-page {
  background:
    linear-gradient(90deg, transparent 49.9%, rgb(24 32 29 / 7%) 50%, transparent 50.1%),
    radial-gradient(circle at 75% 30%, #f4efe4 0 12%, transparent 45%),
    #ded8cc;
}

.search-hero {
  width: min(42rem, 100%);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: min(100%, 42rem);
  padding: 0.85rem 1rem;
  background: rgb(246 241 232 / 86%);
  border: 1px solid rgb(24 32 29 / 10%);
  border-radius: 999px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #18201d;
}

.search-bar input::placeholder { color: #8d8578; }
.search-bar input[data-state="submitted"] { color: #8c8478; }
.search-bar input[data-state="editing"] { color: #18201d; }
.search-bar button {
  border: 0;
  border-radius: 999px;
  padding: 0.6rem 1rem;
  color: #f8f4ec;
  background: #18201d;
  cursor: pointer;
}

.search-bar--home {
  width: min(100%, 40rem);
  justify-self: center;
}

.search-bar--sticky {
  position: sticky;
  top: 1rem;
  z-index: 20;
  margin: 0 auto 1.5rem;
}

.results-page {
  align-items: start;
  padding-top: 1rem;
}

.results-shell {
  width: min(1320px, 100%);
  padding-bottom: 3rem;
}

.results-summary {
  display: grid;
  gap: 0.35rem;
  margin: 1rem 0 1.5rem;
}

.results-summary h1,
.work-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 0.95;
}

.results-summary p,
.work-author,
.work-section p,
.edition-description,
.results-empty,
.purchase-empty,
.reader-unavailable {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.result-card {
  display: block;
  min-height: 14rem;
  perspective: 1200px;
  text-decoration: none;
}

.result-card__inner {
  position: relative;
  display: grid;
  min-height: 14rem;
  transform-style: preserve-3d;
  transition: transform 260ms ease;
}

.result-card__face {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: space-between;
  gap: 1rem;
  padding: 1rem;
  backface-visibility: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}

.result-card__face--front {
  justify-items: start;
}

.result-card__face--back {
  transform: rotateY(180deg);
  background: var(--surface-strong);
}

.result-card:hover .result-card__inner,
.result-card:focus-visible .result-card__inner,
.result-card:focus-within .result-card__inner {
  transform: rotateY(180deg);
}

.result-card__title {
  font-size: 1.35rem;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.result-card__author {
  font: 600 0.78rem/1.3 "Avenir Next", Avenir, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.result-card__snippet {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #303531;
}

.work-page {
  position: relative;
  padding: 1rem clamp(1rem, 3vw, 2rem) 3rem;
}

.work-return {
  position: sticky;
  top: 1rem;
  z-index: 30;
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  color: #18201d;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgb(246 241 232 / 90%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.work-stack {
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 1rem 0 2rem;
  display: grid;
  justify-items: center;
  gap: 1.5rem;
}

.work-header,
.work-section {
  width: min(100%, 42rem);
  text-align: center;
}

.section-label {
  margin: 0 0 0.75rem;
  font: 700 0.72rem/1.2 "Avenir Next", Avenir, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}

.work-author {
  font: 600 0.85rem/1.4 "Avenir Next", Avenir, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.work-section {
  padding: 0;
}

.work-section p {
  max-width: 60ch;
  margin-inline: auto;
}

.work-section__header {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  justify-content: center;
  gap: 1rem;
}

.edition-picker {
  position: relative;
}

.edition-picker__button {
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}

.edition-picker__menu {
  position: absolute;
  left: 50%;
  top: calc(100% + 0.45rem);
  z-index: 40;
  display: grid;
  gap: 0.35rem;
  min-width: max(18rem, 100%);
  max-width: 30rem;
  padding: 0.45rem;
  background: rgb(246 241 232 / 98%);
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.edition-picker:hover .edition-picker__menu,
.edition-picker:focus-within .edition-picker__menu,
.edition-picker[data-open="true"] .edition-picker__menu {
  opacity: 1;
  pointer-events: auto;
}

.edition-picker__option {
  padding: 0.65rem 0.8rem;
  text-align: left;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 0.7rem;
  cursor: pointer;
}

.edition-picker__option[aria-selected="true"] {
  background: rgb(155 62 38 / 10%);
}

.edition-picker__option:hover,
.edition-picker__option:focus-visible {
  background: rgb(24 32 29 / 7%);
}

.edition-description {
  margin-top: 0.75rem;
}

.reader-host {
  width: 100%;
  min-height: min(78vh, 860px);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.reader-host .reader-shell {
  min-height: inherit;
}

.purchase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.purchase-link {
  display: inline-grid;
  place-items: center;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.purchase-link:hover,
.purchase-link:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.eyebrow {
  margin: 0 0 1rem;
  color: var(--accent);
  font: 700 0.72rem/1.2 "Avenir Next", Avenir, sans-serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.reader-page { min-height: 100vh; padding: clamp(1rem, 3vw, 2.5rem); }
.reader-page #reader-mount { max-width: 1540px; margin: auto; }

.lab-page { min-height: 100vh; padding: 2rem; }
.lab-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  max-width: 1680px;
  margin: 0 auto 1.5rem;
}
.lab-header h1 { margin: 0; font-size: clamp(2rem, 4vw, 4rem); font-weight: 400; letter-spacing: -0.03em; }
.lab-header > p { max-width: 38ch; margin: 0; color: #5f675f; }

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  max-width: 1680px;
  margin: 0 auto 1rem;
  padding: 0.75rem;
  background: #f2eee5;
  border: 1px solid #c9c1b3;
}
.lab-controls label { display: flex; align-items: center; gap: 0.5rem; font: 600 0.72rem/1 "Avenir Next", Avenir, sans-serif; }
.lab-controls select, .lab-controls button { padding: 0.45rem 0.6rem; color: inherit; background: #fff; border: 1px solid #aaa296; }
.lab-controls button { cursor: pointer; }

.lab-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 1rem;
  max-width: 1680px;
  margin: auto;
}
.lab-diagnostics {
  height: min(88vh, 940px);
  overflow: auto;
  padding: 1rem;
  font-family: "Avenir Next", Avenir, sans-serif;
  background: #202723;
  color: #e9e5dc;
}
.lab-diagnostics h2, .lab-diagnostics h3 { margin: 0 0 1rem; font-family: Charter, Georgia, serif; font-weight: 400; }
.lab-diagnostics h3 { margin-top: 1.5rem; font-size: 1rem; color: #c5bfb2; }
.lab-diagnostics dl { display: grid; grid-template-columns: 1fr 1.6fr; margin: 0; font-size: 0.72rem; }
.lab-diagnostics dt, .lab-diagnostics dd { min-width: 0; margin: 0; padding: 0.35rem 0; border-bottom: 1px solid #39423d; overflow-wrap: anywhere; }
.lab-diagnostics dt { color: #b6ada0; }
.lab-diagnostics ol { margin: 0; padding: 0; list-style: none; }
.lab-diagnostics li { display: grid; gap: 0.2rem; padding: 0.5rem 0; border-top: 1px solid #39423d; font-size: 0.68rem; }
.lab-diagnostics time { color: #a59e93; }
.lab-diagnostics code { overflow-wrap: anywhere; color: #d6b395; }

@media (max-width: 1100px) {
  .lab-grid { grid-template-columns: 1fr; }
  .lab-diagnostics { height: 360px; }
}

@media (max-width: 800px) {
  .search-bar,
  .search-bar--home {
    width: 100%;
  }

  .search-bar--sticky {
    top: 0.5rem;
  }

  .work-stack,
  .work-header,
  .work-section {
    width: 100%;
  }

  .work-return {
    top: 0.5rem;
  }
}

:root {
  --reader-ink: #18201d;
  --reader-muted: #677069;
  --reader-paper: #f7f4ec;
  --reader-panel: #ebe5d8;
  --reader-line: #c9c1b3;
  --reader-accent: #9b3e26;
  --reader-shadow: 0 24px 70px rgb(28 31 27 / 18%);
}

.reader-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: min(88vh, 940px);
  min-height: 620px;
  overflow: hidden;
  color: var(--reader-ink);
  background: var(--reader-paper);
  border: 1px solid var(--reader-line);
  box-shadow: var(--reader-shadow);
}

.reader-shell:fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  border: 0;
}

.reader-toolbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  min-height: 68px;
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, var(--reader-paper) 92%, white);
  border-bottom: 1px solid var(--reader-line);
}

.reader-identity,
.reader-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.reader-actions {
  justify-content: flex-end;
}

.reader-kicker {
  color: var(--reader-accent);
  font: 700 0.68rem/1.2 "Avenir Next", Avenir, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.reader-title {
  overflow: hidden;
  font: 500 1rem/1.2 Charter, Georgia, serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-status {
  color: var(--reader-muted);
  font: 600 0.77rem/1 "Avenir Next", Avenir, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
}

.reader-toolbar button,
.reader-return {
  padding: 0.55rem 0.75rem;
  color: inherit;
  font: 600 0.75rem/1 "Avenir Next", Avenir, sans-serif;
  text-decoration: none;
  background: transparent;
  border: 1px solid var(--reader-line);
  border-radius: 2px;
  cursor: pointer;
}

.reader-toolbar button:hover,
.reader-toolbar button:focus-visible,
.reader-return:hover,
.reader-return:focus-visible {
  color: var(--reader-accent);
  border-color: var(--reader-accent);
  outline: none;
}

.reader-stage {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  min-height: 0;
  padding: 20px 0;
  background:
    radial-gradient(circle at 50% -10%, rgb(255 255 255 / 75%), transparent 42%),
    linear-gradient(135deg, #e7e0d3, #d8d0c2);
}

.reader-viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: white;
  box-shadow: 0 8px 32px rgb(26 29 25 / 14%);
}

.reader-shell[data-spread="two"] .reader-viewport::after {
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  content: "";
  pointer-events: none;
  background: linear-gradient(transparent, rgb(0 0 0 / 8%) 8%, rgb(0 0 0 / 8%) 92%, transparent);
  box-shadow: 0 0 18px 5px rgb(0 0 0 / 4%);
}

.reader-viewport--settled iframe {
  animation: reader-fade 140ms ease-out;
}

@keyframes reader-fade {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

.reader-page-control {
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--reader-ink);
  font: 400 1.4rem/1 Georgia, serif;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.reader-page-control:hover,
.reader-page-control:focus-visible {
  color: var(--reader-accent);
  outline: 2px solid transparent;
}

.reader-loading {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.8rem;
  padding: 2rem;
  color: var(--reader-muted);
  font: 500 0.82rem/1.4 "Avenir Next", Avenir, sans-serif;
  text-align: center;
  background: var(--reader-paper);
}

.reader-loading[hidden] {
  display: none;
}

.reader-loading > span:first-child:empty {
  width: 24px;
  height: 24px;
  border: 2px solid var(--reader-line);
  border-top-color: var(--reader-accent);
  border-radius: 50%;
  animation: reader-spin 800ms linear infinite;
}

@keyframes reader-spin { to { transform: rotate(360deg); } }

.reader-toc {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(390px, calc(100% - 80px));
  overflow: auto;
  padding: 1.5rem;
  background: color-mix(in srgb, var(--reader-paper) 96%, white);
  border-right: 1px solid var(--reader-line);
  box-shadow: 24px 0 60px rgb(24 32 29 / 18%);
}

.reader-toc[hidden] { display: none; }

.reader-toc-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--reader-line);
}

.reader-toc-heading h2 {
  margin: 0;
  font: 500 1.4rem/1.2 Charter, Georgia, serif;
}

.reader-toc-heading button,
.reader-toc-list button {
  color: inherit;
  font: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.reader-toc-heading button {
  color: var(--reader-muted);
  font: 600 0.72rem/1 "Avenir Next", Avenir, sans-serif;
}

.reader-toc-list {
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.reader-toc-list .reader-toc-list {
  margin: 0 0 0 1rem;
  border-left: 1px solid var(--reader-line);
}

.reader-toc-list button {
  width: 100%;
  padding: 0.62rem 0.25rem;
  font: 500 0.92rem/1.35 Charter, Georgia, serif;
  text-align: left;
}

.reader-toc-list button:hover,
.reader-toc-list button:focus-visible {
  color: var(--reader-accent);
  outline: none;
}

@media (max-width: 760px) {
  .reader-shell { min-height: 560px; }
  .reader-toolbar { grid-template-columns: 1fr auto; }
  .reader-status { display: none; }
  .reader-kicker { display: none; }
  .reader-stage { grid-template-columns: 42px minmax(0, 1fr) 42px; padding: 12px 0; }
}

@media (prefers-reduced-motion: reduce) {
  .reader-viewport--settled iframe,
  .reader-loading > span:first-child:empty { animation: none; }
}
