/* The Million Book — classic book */

:root {
  --bg: #F4EDDF;          /* the desk / outer paper */
  --page: #FFFCF4;        /* the printed page */
  --text: #2B241C;        /* ink */
  --muted: #7B6F5F;
  --line: #DED3BF;
  --accent: #8C2A1E;      /* oxblood, like a ribbon bookmark */
  --accent-ink: #FFF8EC;
  --marker: rgba(214, 168, 62, 0.30);
  --danger: #A3261B;
  --live: #4F7D3A;
  --shadow: 0 20px 40px -24px rgba(70, 45, 10, 0.35), 0 2px 6px rgba(70, 45, 10, 0.06);
  --font: "EB Garamond", Garamond, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}

/* Night reading: only when the reader switches it on (paper is the default) */
:root[data-theme="dark"] {
  --bg: #15120E;
  --page: #1E1A14;
  --text: #EAE1CE;
  --muted: #A69A84;
  --line: #3A3227;
  --accent: #DA8B6C;
  --accent-ink: #1E1A14;
  --marker: rgba(222, 178, 92, 0.22);
  --danger: #F08A7A;
  --live: #86B56F;
  --shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 19px;
  line-height: 1.55;
  font-variant-numeric: oldstyle-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}
.wrap.narrow { max-width: 720px; }
@media (min-width: 768px) {
  .wrap { padding: 0 32px; }
  .wrap.narrow { max-width: 784px; }
}

/* small caps label style, used across the page */
.eyebrow,
.runhead-title,
.section-h,
.page-head,
.stats dt,
.field-label,
.btn,
.footer-links a,
.demo-bar {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.1em;
}

/* ---------- Mode bar (test / demo payments) ---------- */
.demo-bar[hidden] { display: none; }
.demo-bar {
  background: var(--text);
  color: var(--page);
  text-align: center;
  font-size: 15px;
  padding: 4px 16px;
}

/* ---------- Running head (top bar) ---------- */
.runhead {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.runhead-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
}
.runhead-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-decoration: none;
  white-space: nowrap;
}
.runhead-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  color: var(--muted);
  font-style: italic;
  white-space: nowrap;
  font-variant-numeric: oldstyle-nums tabular-nums;
}
#raisedTop { color: var(--text); font-style: normal; font-weight: 600; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 19px;
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid var(--text);
  border-radius: 2px;
  padding: 9px 22px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  background: transparent;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, transform 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--text); color: var(--page); }
.btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.btn-large { font-size: 22px; padding: 11px 30px 13px; }
.btn-small { font-size: 17px; padding: 4px 14px 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.linklike {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.linklike:disabled { cursor: default; }

/* ---------- Title page ---------- */
/* Compact on purpose: the top of the book page should peek above the fold. */
.title-page {
  text-align: center;
  padding-top: 40px;
  padding-bottom: 36px;
}
@media (min-width: 768px) {
  .title-page { padding-top: 64px; padding-bottom: 48px; }
}

.eyebrow {
  font-size: 20px;
  letter-spacing: 0.22em;
  color: var(--muted);
  margin: 0 0 18px;
}
.double-rule {
  width: min(640px, 100%);
  margin: 0 auto;
  border-top: 4px double var(--text);
}
.book-title {
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.05;
  margin: 14px 0 10px;
}
.tagline {
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  margin: 20px 0 8px;
}
.tagline em { color: var(--accent); }
.title-sub {
  font-size: clamp(1.05rem, 1.8vw, 1.2rem);
  font-style: italic;
  color: var(--muted);
  max-width: 540px;
  margin: 0 auto 28px;
}
.title-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 36px;
}

.page-one {
  font-style: italic;
  font-size: 19px;
  color: var(--accent);
  max-width: 520px;
  margin: -14px auto 24px;
}
.page-one strong { font-style: normal; font-weight: 600; }
.page-one[hidden], .page-one-note[hidden] { display: none; }
.page-one-note {
  font-style: italic;
  font-size: 16px;
  color: var(--accent);
  margin: -4px 0 10px;
}

.progress { max-width: 520px; margin: 0 auto; }
.bar {
  height: 3px;
  background: var(--line);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  min-width: 4px;
  background: var(--accent);
  transition: width 0.8s ease;
}
.progress-labels {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 17px;
  font-style: italic;
  color: var(--muted);
  font-variant-numeric: oldstyle-nums tabular-nums;
}
.progress-labels strong { color: var(--text); font-style: normal; font-weight: 600; }

/* ---------- Section headings ---------- */
.section-h {
  text-align: center;
  font-size: clamp(1.5rem, 3vw, 1.9rem);
  font-weight: 600;
  letter-spacing: 0.14em;
  line-height: 1.2;
  margin: 0 0 32px;
}
.section-h::after,
.diamond {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  margin: 14px auto 0;
  border: 1px solid var(--accent);
  transform: rotate(45deg);
}

/* ---------- The page ---------- */
.reading {
  padding: 0 0 80px;
  border-bottom: 1px solid var(--line);
}
.page-intro {
  text-align: center;
  font-size: inherit;
  font-weight: 400;
  margin: 0 0 18px;
}
.page-intro-title {
  display: block;
  font-size: 18px;
  font-weight: 600;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.16em;
}
.page-intro-hint {
  display: block;
  font-style: italic;
  color: var(--muted);
  font-size: 16px;
}

.page-stack {
  position: relative;
  z-index: 0;
  max-width: 760px;
  margin: 0 auto;
}
.page-stack::before,
.page-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--page);
  border: 1px solid var(--line);
}
.page-stack::before { transform: translate(4px, 4px); }
.page-stack::after { transform: translate(8px, 8px); }

.page {
  position: relative;
  background: var(--page);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 32px 22px 28px;
}
@media (min-width: 640px) {
  .page { padding: 48px 72px 40px; }
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 28px;
}
.earlier {
  text-align: center;
  font-size: 16px;
  font-style: italic;
  color: var(--muted);
  margin: 0 0 22px;
}

.story-text {
  font-size: clamp(1.18rem, 2.1vw, 1.36rem);
  line-height: 1.7;
  text-align: justify;
  -webkit-hyphens: auto;
  hyphens: auto;
  font-variant-numeric: oldstyle-nums;
}
.story-text p { margin: 0; }
.story-text .loading { text-align: center; font-style: italic; color: var(--muted); }
.story-text p + p { text-indent: 1.6em; }

.seg {
  cursor: help;
  border-radius: 2px;
  transition: background-color 0.15s;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.seg:hover,
.seg:focus-visible,
.seg.active {
  background: var(--marker);
  outline: none;
}
.seg.mine {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
/* The words a shared link points to (/w/<id>) */
.seg.focus {
  background: var(--marker);
  box-shadow: 0 0 0 3px var(--marker);
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
.earlier.later { margin: 22px 0 0; }
.seg.fresh { animation: fresh 3.5s ease-out; }
@keyframes fresh {
  0%, 30% { background: var(--marker); }
  100% { background: transparent; }
}

.caret {
  display: inline-block;
  width: 1.5px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.12em;
  background: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.page-foot {
  text-align: center;
  font-size: 16px;
  color: var(--muted);
  margin-top: 36px;
  font-variant-numeric: oldstyle-nums tabular-nums;
}

.story-cta {
  text-align: center;
  margin-top: 48px;
}
.cta-note {
  font-style: italic;
  color: var(--muted);
  font-size: 17px;
  margin: 12px 0 0;
}

/* ---------- Sections ---------- */
.section { padding-top: 72px; }
@media (min-width: 768px) { .section { padding-top: 96px; } }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 0;
  text-align: center;
}
.stat { padding: 8px 16px; }
.stat + .stat { border-left: 1px solid var(--line); }
.stats dt {
  font-size: 17px;
  color: var(--muted);
  margin-bottom: 4px;
}
.stats dd {
  margin: 0;
  font-size: clamp(1.9rem, 3.6vw, 2.6rem);
  font-weight: 500;
  line-height: 1.15;
  font-variant-numeric: oldstyle-nums tabular-nums;
}
.stats dd.stat-sub {
  font-size: 15px;
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}

/* ---------- Steps ---------- */
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 40px;
  text-align: center;
}
.step-n {
  display: block;
  font-size: 26px;
  font-style: italic;
  color: var(--accent);
}
.steps h3 {
  font-size: 22px;
  font-weight: 600;
  margin: 4px 0 8px;
}
.steps p { margin: 0; color: var(--muted); }

/* ---------- Latest contributors (table of contents) ---------- */
.toc { list-style: none; margin: 0; padding: 0; }
.toc li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 0;
}
.toc-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}
a.toc-name {
  color: var(--accent);
  text-decoration: none;
}
a.toc-name:hover { text-decoration: underline; text-underline-offset: 3px; }
.toc-dots {
  flex: 1;
  min-width: 16px;
  border-bottom: 2px dotted var(--line);
  transform: translateY(-5px);
}
.toc-meta {
  font-style: italic;
  color: var(--muted);
  white-space: nowrap;
  font-size: 17px;
  font-variant-numeric: oldstyle-nums tabular-nums;
}

/* ---------- FAQ ---------- */
.faq details { border-top: 1px solid var(--line); }
.faq details:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary {
  list-style: none;
  cursor: pointer;
  font-size: 21px;
  font-weight: 500;
  padding: 14px 36px 14px 0;
  position: relative;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 24px;
}
.faq details[open] summary::after { content: "−"; }
.faq details p {
  margin: 0 0 18px;
  color: var(--muted);
  max-width: 620px;
}

/* ---------- Colophon (footer) ---------- */
.colophon {
  margin-top: 112px;
  padding: 0 0 56px;
  text-align: center;
  color: var(--muted);
}
.colophon .diamond { margin: 0 auto 24px; }
.colophon-text {
  font-style: italic;
  font-size: 17px;
  margin: 0 0 16px;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 18px;
}
.footer-links a { text-decoration: none; }
.footer-links a:hover { color: var(--text); }
.copy { font-size: 15px; margin: 16px 0 0; }

/* ---------- Tooltip ---------- */
.tip {
  position: fixed;
  z-index: 50;
  max-width: 290px;
  background: var(--page);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: var(--shadow);
  padding: 10px 14px 12px;
  font-size: 17px;
  line-height: 1.35;
}
.tip[hidden] { display: none; }
.tip-name {
  font-weight: 600;
  font-size: 19px;
}
.tip-link a { color: var(--accent); text-decoration: none; font-style: italic; }
.tip-link a:hover { text-decoration: underline; }
.tip-pending { color: var(--muted); font-size: 15px; font-style: italic; }
.tip-meta {
  color: var(--muted);
  font-size: 15px;
  font-style: italic;
  margin-top: 3px;
  font-variant-numeric: oldstyle-nums;
}
.tip-share {
  display: inline-block;
  margin-top: 6px;
  font-size: 15px;
  color: var(--accent);
  text-underline-offset: 3px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translate(-50%, 0);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--page);
  padding: 10px 22px 12px;
  border-radius: 2px;
  box-shadow: var(--shadow);
  font-style: italic;
  font-size: 18px;
  animation: toast-in 0.25s ease-out;
}
.toast[hidden] { display: none; }
.toast-action {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  font-style: normal;
  font-weight: 600;
  margin-left: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  white-space: nowrap;
  cursor: pointer;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Composer ---------- */
.composer {
  border: 1px solid var(--line);
  padding: 0;
  border-radius: 2px;
  background: var(--page);
  color: var(--text);
  width: min(600px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  box-shadow: 0 30px 60px -20px rgba(40, 25, 5, 0.45);
}
.composer::backdrop {
  background: rgba(30, 22, 12, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.composer form {
  position: relative;
  padding: 30px 32px 26px;
  margin: 8px;
  border: 1px solid var(--line);   /* inner frame, like a bookplate */
}
@media (max-width: 480px) {
  .composer form { padding: 26px 18px 20px; margin: 6px; }
}

.icon-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }

.composer-title {
  text-align: center;
  font-size: 26px;
  font-weight: 600;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.12em;
  margin: 0 0 20px;
}

.moved-on {
  font-style: italic;
  font-size: 16px;
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  padding: 8px 12px;
  margin: 0 0 16px;
}
.moved-on[hidden] { display: none; }

.preview {
  font-size: 18px;
  line-height: 1.6;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding: 2px 0 2px 16px;
  margin: 0 0 22px;
  overflow-wrap: anywhere;
}
.preview mark {
  background: var(--marker);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.field { display: block; margin-bottom: 14px; min-width: 0; }
.field-label {
  display: block;
  font-size: 17px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px;
}
.optional { font-weight: 400; font-style: italic; letter-spacing: 0.02em; }

input:not([type="checkbox"]) {
  width: 100%;
  font: inherit;
  font-size: 19px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 6px 2px;
  transition: border-color 0.15s;
}
input:not([type="checkbox"]):focus {
  outline: none;
  border-bottom-color: var(--accent);
}

/* lined paper */
textarea {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 20px;
  line-height: 32px;
  color: var(--text);
  background-color: var(--page);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 31px,
    var(--line) 31px,
    var(--line) 32px
  );
  background-attachment: local;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 4px 12px 0;
  min-height: 104px;
  resize: vertical;
  transition: border-color 0.15s;
}
textarea:focus { outline: none; border-color: var(--accent); }

::placeholder { color: var(--muted); opacity: 0.7; font-style: italic; }

input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 5px 0 0;
  flex: none;
}

.meter {
  display: flex;
  justify-content: space-between;
  font-size: 17px;
  font-style: italic;
  color: var(--muted);
  margin: -6px 0 10px;
  font-variant-numeric: oldstyle-nums tabular-nums;
}
.meter strong { color: var(--text); font-style: normal; font-size: 20px; }
.meter .over { color: var(--danger); }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 17px;
  margin: 6px 0 12px;
  cursor: pointer;
}
.field-help { font-size: 16px; font-style: italic; color: var(--muted); margin: -6px 0 10px; }

.message { min-height: 24px; font-size: 17px; font-style: italic; margin: 4px 0 12px; color: var(--muted); }
.message.error { color: var(--danger); }
.secure { text-align: center; font-size: 15px; font-style: italic; color: var(--muted); margin: 10px 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); row-gap: 28px; }
  .stat:nth-child(3) { border-left: 0; }
  .steps { grid-template-columns: 1fr; gap: 32px; }
}
@media (max-width: 480px) {
  .row { grid-template-columns: 1fr; gap: 0; }
  .hide-sm { display: none; }
  .runhead-title { font-size: 17px; letter-spacing: 0.1em; }
  .runhead-right { gap: 6px; }
  .theme-toggle { width: 30px; height: 30px; }
  .live { font-size: 16px; gap: 6px; }
  .title-page { padding-top: 28px; padding-bottom: 28px; }
  .eyebrow { font-size: 16px; letter-spacing: 0.14em; margin-bottom: 10px; }
  .book-title { margin: 10px 0 8px; }
  .tagline { margin: 14px 0 6px; }
  .title-sub { font-size: 1rem; margin-bottom: 18px; }
  .title-actions { margin-bottom: 20px; }
  .page { padding-top: 22px; }
  .page-head { margin-bottom: 14px; }
  .earlier { margin-bottom: 14px; }
  .title-actions .btn-ghost { display: none; }  /* the page below already invites reading */
  .btn-large { font-size: 20px; padding: 10px 24px 12px; }
  .stat { padding: 4px 10px; }
  .page-stack::before { transform: translate(3px, 3px); }
  .page-stack::after { transform: translate(6px, 6px); }
  .story-text { text-align: left; }
}

@media (max-width: 370px) {
  .live { display: none; }
}

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