:root {
  color-scheme: light;
  --paper: #f8f8f5;
  --paper-deep: #eeeeeb;
  --ink: #252525;
  --ink-soft: #686863;
  --ink-muted: #8a8a83;
  --line: #d8d8d1;
  --button: #1f1f1d;
  --button-text: #fbfbf7;
  --field: color-mix(in srgb, var(--paper) 72%, white);
  --measure: 68ch;
  --ui-font:
    "PP Kyoto", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --reader-font:
    "PP Kyoto", Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  font-family:
    var(--reader-font);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #151515;
  --paper-deep: #20201f;
  --ink: #eeeeea;
  --ink-soft: #bdbdb5;
  --ink-muted: #898981;
  --line: #3b3b36;
  --button: #efefea;
  --button-text: #181818;
  --field: #1f1f1d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.55;
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

:where(a, button, input, textarea):focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
}

.icon {
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: -80px;
  left: 14px;
  z-index: 100;
  border: 1px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 12px;
  font-family: var(--ui-font);
  font-size: 0.92rem;
  text-decoration: none;
  transition: top 160ms ease;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: 14px;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(360px, 0.86fr) minmax(340px, 0.68fr);
  gap: clamp(28px, 5.5vw, 92px);
  align-items: stretch;
  padding: clamp(18px, 4vw, 58px);
}

.compose-panel {
  min-width: 0;
  max-width: 820px;
  display: grid;
  align-content: center;
}

.kicker,
.book-cover p,
.reader-meta,
.reader-tools,
label span {
  font-family: var(--ui-font);
  letter-spacing: 0;
}

.kicker {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0 0 clamp(18px, 3vw, 30px);
  max-width: 8.4ch;
  font-size: clamp(4rem, 12vw, 9.2rem);
  line-height: 0.84;
  font-weight: 500;
}

.lede {
  max-width: 43ch;
  margin: 0 0 clamp(24px, 4vw, 42px);
  color: var(--ink-soft);
  font-size: clamp(1.08rem, 1.6vw, 1.34rem);
  line-height: 1.45;
}

.ingest-form {
  display: grid;
  gap: 14px;
  max-width: 720px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  color: var(--ink-soft);
  font-size: 0.78rem;
  text-transform: uppercase;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 13px 14px;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

input:focus,
textarea:focus {
  outline: 0;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent);
}

textarea {
  resize: vertical;
  min-height: clamp(150px, 18svh, 230px);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.primary-action,
.tool-button,
.cover-share {
  border: 1px solid var(--button);
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
}

.primary-action {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  justify-self: start;
  min-height: 48px;
  padding: 0 20px;
  font-family: var(--ui-font);
  font-size: 0.95rem;
}

.primary-action:disabled {
  cursor: wait;
  opacity: 0.7;
}

.form-result {
  min-height: 32px;
  margin-top: 18px;
  color: var(--ink-soft);
  font-family: var(--ui-font);
  font-size: 0.92rem;
}

.recent-editions {
  margin-top: clamp(28px, 5vw, 56px);
}

.recent-editions h2 {
  margin: 0 0 14px;
  color: var(--ink-soft);
  font-family: var(--ui-font);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: uppercase;
}

.edition-list {
  display: grid;
  gap: 8px;
  max-width: 680px;
}

.edition-link {
  display: grid;
  grid-template-columns: 19px minmax(0, 1fr);
  column-gap: 10px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding: 12px 0;
  text-decoration: none;
}

.edition-link .icon {
  margin-top: 0.18em;
  color: var(--ink-muted);
}

.edition-copy {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.edition-link strong {
  display: block;
  font-weight: 500;
  line-height: 1.16;
  overflow-wrap: normal;
  word-break: normal;
}

.edition-meta,
.empty-state {
  color: var(--ink-soft);
  font-family: var(--ui-font);
  font-size: 0.9rem;
  line-height: 1.35;
}

.sample-reader {
  align-self: stretch;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 24px;
  min-width: 0;
}

.book-cover {
  min-height: min(58svh, 620px);
  display: grid;
  align-content: center;
  gap: 18px;
  border: 1px solid var(--line);
  background: var(--paper-deep);
  padding: clamp(28px, 5vw, 64px);
}

.book-cover h2,
.cover-title {
  margin: 0;
  max-width: 12ch;
  font-size: clamp(3rem, 10vw, 8rem);
  line-height: 0.9;
  font-weight: 500;
}

.sample-reader .book-cover h2 {
  font-size: clamp(3.15rem, 5.8vw, 6.35rem);
}

.book-cover p,
.book-cover span {
  margin: 0;
  color: var(--ink-soft);
}

.cover-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  max-width: 44ch;
  margin-top: 16px;
  color: var(--ink-soft);
  font-family: var(--ui-font);
  font-size: 0.9rem;
}

.cover-meta span,
.cover-meta a {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  color: var(--ink-soft);
}

.cover-begin {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-self: start;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 0.92rem;
  text-decoration-color: var(--line);
  text-underline-offset: 0.24em;
}

.cover-begin:focus-visible,
.cover-meta a:focus-visible {
  text-decoration-thickness: 0.12em;
}

.cover-share {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  justify-self: start;
  min-height: 44px;
  margin-top: 10px;
  padding: 0 16px;
  font-family: var(--ui-font);
  font-size: 0.92rem;
}

.preview-copy {
  align-self: start;
  max-width: 38ch;
  color: var(--ink-soft);
  font-size: 1.02rem;
}

.reader-layout {
  min-height: 100svh;
}

.reader-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(16px);
  padding: 12px clamp(16px, 4vw, 44px);
  font-family: var(--ui-font);
}

.reader-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.tool-button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 38px;
  padding: 0 12px;
  background: transparent;
  color: var(--ink);
  font-family: var(--ui-font);
  font-size: 0.92rem;
}

.tool-button[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.tool-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.icon-button {
  padding-inline: 11px;
}

.segmented-control {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented-control .tool-button {
  border: 0;
  border-radius: 0;
}

.segmented-control .tool-button + .tool-button {
  border-left: 1px solid var(--line);
}

.reader-shell {
  padding: clamp(26px, 5vw, 70px) clamp(18px, 6vw, 84px) 88px;
}

.reader-cover {
  min-height: calc(100svh - 62px);
  margin-bottom: clamp(48px, 10vw, 140px);
}

.reader-body {
  max-width: var(--measure);
  margin: 0 auto;
}

.reader-body h2 {
  scroll-margin-top: 88px;
  margin: 2.4em 0 0.75em;
  font-size: clamp(1.6rem, 4vw, 3rem);
  line-height: 1.08;
  font-weight: 500;
}

.reader-body p {
  margin: 0 0 1.15em;
  font-size: clamp(1.18rem, 2vw, 1.42rem);
  line-height: 1.68;
}

.reader-body p:first-of-type::first-letter {
  float: left;
  padding: 0.08em 0.08em 0 0;
  font-size: 4.7em;
  line-height: 0.82;
}

.preview-copy p:first-of-type::first-letter {
  float: none;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
}

.reader-body[data-mode="paged"] {
  max-width: min(920px, calc(100vw - 36px));
}

.reader-body[data-mode="paged"] .page {
  min-height: min(72svh, 760px);
  display: none;
  align-content: center;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-deep) 72%, var(--paper));
  padding: clamp(24px, 5vw, 68px);
}

.reader-body[data-mode="paged"] .page.is-active {
  display: grid;
}

.reader-body[data-mode="paged"] p:first-of-type::first-letter {
  float: none;
  padding: 0;
  font-size: inherit;
  line-height: inherit;
}

.page-status {
  color: var(--ink-soft);
  min-width: 8ch;
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 30px;
  }

  h1 {
    max-width: 7.8ch;
    font-size: clamp(3.7rem, 18vw, 5.8rem);
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .sample-reader {
    display: block;
  }

  .reader-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .reader-tools {
    width: 100%;
  }

  .segmented-control {
    order: 2;
    width: 100%;
  }

  .segmented-control .tool-button {
    flex: 1;
  }

  .book-cover {
    min-height: min(72svh, 620px);
  }

  .reader-cover {
    min-height: calc(100svh - 160px);
  }

  .button-label {
    display: none;
  }

  .cover-share .button-label,
  .primary-action .button-label {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  :root,
  :root[data-theme="dark"] {
    --paper: #fff;
    --paper-deep: #fff;
    --ink: #111;
    --ink-soft: #555;
    --line: #cfcfcf;
    color-scheme: light;
  }

  @page {
    margin: 0.72in;
  }

  body {
    min-width: 0;
    background: #fff;
    color: #111;
    font-size: 12pt;
    line-height: 1.5;
  }

  a {
    text-decoration-color: #aaa;
  }

  .reader-header,
  .reader-tools,
  .cover-share,
  .cover-begin {
    display: none;
  }

  .reader-shell {
    padding: 0;
  }

  .book-cover,
  .reader-cover {
    min-height: 9.4in;
    margin: 0;
    break-after: page;
    border: 1px solid #cfcfcf;
    background: #fff;
    padding: 0.72in;
  }

  .cover-title {
    max-width: 11ch;
    font-size: 52pt;
    line-height: 0.95;
  }

  .cover-meta {
    font-size: 10pt;
  }

  .reader-body,
  .reader-body[data-mode="paged"] {
    max-width: none;
    margin: 0;
  }

  .reader-body[data-mode="paged"] .page,
  .reader-body[data-mode="paged"] .page.is-active {
    display: block;
    min-height: 0;
    border: 0;
    background: transparent;
    padding: 0;
  }

  .reader-body h2 {
    break-after: avoid;
    margin: 1.8em 0 0.55em;
    font-size: 21pt;
    line-height: 1.1;
  }

  .reader-body p {
    orphans: 3;
    widows: 3;
    font-size: 12.5pt;
    line-height: 1.62;
  }

  .reader-body p:first-of-type::first-letter {
    float: left;
    padding: 0.06em 0.08em 0 0;
    font-size: 3.8em;
    line-height: 0.82;
  }
}
