/* ==========================================================================
   Design tokens
   Concept: a letter read in daylight. The desk around it is soft, bright
   linen; the letter itself is a slightly whiter, lifted sheet of paper —
   that contrast is the whole signature, just in a much lighter key.
   ========================================================================== */
:root {
  /* Color */
  --room:        #EAEDF0;   /* ambient background — cool light slate, not flat white */
  --room-deep:    #DEE3E7;   /* gentle depth at the edges of the canvas gradient */
  --room-soft:    #F6F8F9;   /* nav / footer surface, one step lighter than room */
  --page:        #FFFDF7;   /* the letter itself — bright, slightly whiter paper, still warm */
  --page-edge:    #E7DCC2;   /* shadow line under the page edge */
  --ink:         #2B2620;   /* body ink on the page */
  --ink-soft:     #6B5F49;   /* secondary ink — captions, meta */
  --room-text:    #384047;   /* text sitting on the light room (nav, footer) */
  --room-text-dim:#68717A;
  --accent:      #3B5570;   /* fountain-pen blue — links, focus, the note form */
  --accent-soft:  #5A7791;
  --lamp:        #B8862A;   /* warm gold — accent, reaction, bookmark tab */
  --lamp-dim:     #8A6A24;

  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Source Serif 4', Georgia, serif;
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;

  /* Layout */
  --page-width: 680px;
  --page-pad-x: 64px;
  --page-pad-y: 72px;
  --radius: 3px;
}

@media (max-width: 640px) {
  :root {
    --page-pad-x: 28px;
    --page-pad-y: 40px;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--room);
  color: var(--room-text);
  font-family: var(--font-ui);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--lamp);
  color: var(--ink);
  padding: 8px 16px;
  z-index: 100;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
}

a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--lamp);
  outline-offset: 3px;
}

/* ==========================================================================
   Nav — deliberately plain and separate from the book's voice
   ========================================================================== */
.site-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px 32px;
  background: linear-gradient(180deg, var(--room-soft), var(--room));
  border-bottom: 1px solid rgba(56,64,71,0.12);
  box-shadow: 0 1px 0 rgba(56,64,71,0.05);
  font-family: var(--font-ui);
}
.site-nav__links {
  display: flex;
  gap: 28px;
  font-size: 14px;
}
.site-nav__links a {
  color: var(--room-text-dim);
  padding-bottom: 3px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.site-nav__links a:hover,
.site-nav__links a.is-active {
  color: var(--accent);
  border-color: var(--accent);
}

.site-footer {
  text-align: center;
  padding: 40px 20px 60px;
  font-size: 13px;
  color: var(--room-text-dim);
}

/* ==========================================================================
   The room — ambient canvas the page sits in
   ========================================================================== */
.page-canvas {
  min-height: 70vh;
  display: flex;
  justify-content: center;
  padding: 96px 20px 120px;
  position: relative;
  background:
    radial-gradient(ellipse 1100px 650px at 50% -8%, rgba(255,255,255,0.55), transparent 62%),
    radial-gradient(ellipse 700px 500px at 50% 0%, rgba(255,255,255,0.35), transparent 55%),
    linear-gradient(180deg, var(--room) 0%, var(--room-deep) 100%);
}
.page-canvas::before {
  /* fine grain so the light field reads as texture, not a flat fill */
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.025;
  mix-blend-mode: multiply;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* ==========================================================================
   The book page — the signature element
   ========================================================================== */
.book-page {
  position: relative;
  width: 100%;
  max-width: var(--page-width);
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.15'/></svg>"),
    linear-gradient(160deg, #FFFFFF 0%, var(--page) 45%, #F5EBD3 100%);
  color: var(--ink);
  padding: var(--page-pad-y) var(--page-pad-x);
  border-radius: var(--radius);
  box-shadow:
    0 1px 0 var(--page-edge),
    0 30px 60px -30px rgba(90,70,40,0.22),
    0 10px 24px -12px rgba(90,70,40,0.14),
    0 0 0 1px rgba(90,70,40,0.05);
}
.book-page::before {
  /* thin warm edge along the top, like light catching the page */
  content: '';
  position: absolute;
  top: 0;
  left: 6%;
  right: 6%;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--lamp) 50%, transparent);
  opacity: 0.6;
}

.bookmark-tab {
  position: absolute;
  top: -14px;
  left: 40px;
  background: var(--accent);
  color: var(--page);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 8px 14px 10px;
  border-radius: 0 0 4px 4px;
}
@media (max-width: 640px) {
  .bookmark-tab { left: 24px; }
}

.chapter-eyebrow {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 8px 0 6px;
}

.chapter-title {
  font-family: var(--font-display);
  font-optical-sizing: auto;
  font-weight: 600;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.15;
  margin: 0 0 20px;
}

.title-rule {
  width: 56px;
  height: 3px;
  background: linear-gradient(90deg, var(--lamp), var(--lamp-dim));
  border-radius: 2px;
  margin: 0 0 36px;
}

.chapter-body {
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.75;
  max-width: 68ch;
}
.chapter-body p { margin: 0 0 1.4em; }
.chapter-body h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 26px;
  margin: 1.6em 0 0.6em;
}
.chapter-body blockquote {
  margin: 1.6em 0;
  padding-left: 20px;
  border-left: 2px solid var(--accent);
  font-style: italic;
  color: var(--ink-soft);
}

/* ==========================================================================
   Engagement — reaction, share, private note. Quiet, not a comment thread.
   ========================================================================== */
.engagement-row {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--page-edge);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 20px;
  font-family: var(--font-ui);
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--page-edge);
  border-radius: 999px;
  padding: 9px 16px;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.reaction-btn svg { width: 16px; height: 16px; }
.reaction-btn:hover { border-color: var(--lamp); color: var(--ink); }
.reaction-btn.is-active {
  background: rgba(184,134,42,0.12);
  border-color: var(--lamp);
  color: var(--ink);
}
.reaction-btn__count { font-variant-numeric: tabular-nums; color: var(--ink-soft); }

.share-icons {
  display: inline-flex;
  gap: 10px;
  margin-left: auto;
}
.share-icons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: var(--ink-soft);
  border: 1px solid var(--page-edge);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.share-icons a svg { width: 16px; height: 16px; }
.share-icons a:hover { color: var(--accent); border-color: var(--accent); }

.note-toggle {
  display: inline-block;
  margin-top: 20px;
  background: none;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 0;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 15px;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.note-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.note-form {
  margin-top: 20px;
  display: none;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
}
.note-form.is-open { display: flex; }
.note-form textarea,
.note-form input {
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--page-edge);
  border-radius: 4px;
  background: rgba(43,38,32,0.03);
  color: var(--ink);
  resize: vertical;
}
.note-form p.hint {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin: 0;
}
.note-form button {
  align-self: flex-start;
  background: var(--accent);
  color: var(--page);
  border: none;
  border-radius: 4px;
  padding: 9px 18px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.note-form button:hover { background: var(--accent-soft); }
.note-form .note-status {
  font-size: 13px;
  color: var(--ink-soft);
}

/* ==========================================================================
   Chapter-to-chapter navigation — styled like turning the page: a card per
   direction with a folded corner that lifts further on hover.
   ========================================================================== */
.chapter-nav {
  margin-top: 28px;
  display: flex;
  gap: 20px;
  font-family: var(--font-ui);
}
.chapter-nav a {
  position: relative;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 22px 30px;
  border: 1px solid var(--page-edge);
  border-radius: 4px;
  background: linear-gradient(160deg, rgba(255,255,255,0.7), rgba(90,70,40,0.02));
  color: var(--ink-soft);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.chapter-nav a::after {
  content: '';
  position: absolute;
  top: 0;
  width: 0;
  height: 0;
  border-style: solid;
  filter: drop-shadow(0 2px 2px rgba(90,70,40,0.2));
  transition: border-width 0.2s ease, border-color 0.2s ease;
}
.chapter-nav a:not(.next)::after {
  left: 0;
  border-width: 0 0 18px 18px;
  border-color: transparent transparent transparent var(--page-edge);
}
.chapter-nav a.next::after {
  right: 0;
  border-width: 0 18px 18px 0;
  border-color: transparent var(--page-edge) transparent transparent;
}
.chapter-nav a:hover {
  border-color: var(--lamp);
  box-shadow: 0 16px 30px -20px rgba(90,70,40,0.4);
}
.chapter-nav a:not(.next):hover {
  transform: translateX(-4px);
}
.chapter-nav a.next:hover {
  transform: translateX(4px);
}
.chapter-nav a:not(.next):hover::after {
  border-width: 0 0 26px 26px;
  border-color: transparent transparent transparent var(--lamp);
}
.chapter-nav a.next:hover::after {
  border-width: 0 26px 26px 0;
  border-color: transparent var(--lamp) transparent transparent;
}
.chapter-nav .direction {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lamp-dim);
}
.chapter-nav a span:last-child {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.35;
  color: var(--ink);
}
.chapter-nav .next { text-align: right; align-items: flex-end; }

/* ==========================================================================
   Index / table of contents
   ========================================================================== */
.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.toc-list li {
  border-bottom: 1px solid var(--page-edge);
}
.toc-list a {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 18px 10px;
  margin: 0 -10px;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink);
  border-left: 3px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.toc-list a:hover {
  background: rgba(59,85,112,0.06);
  border-left-color: var(--accent);
}
.toc-list .toc-number {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(59,85,112,0.1);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}
.toc-list .toc-excerpt {
  display: block;
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 400;
  color: var(--ink-soft);
  margin-top: 3px;
}

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