/* ============================================
   My Life — interactive memoir reader
   Shares the palette of the main site (home.css)
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #faf8f4;
  --color-bg-alt: #f4f1ea;
  --color-text: #16150f;
  --color-muted: #6c685c;
  --color-faint: #9b978a;
  --color-border: #e4dfd3;
  --color-border-strong: #d6d0c1;
  --color-surface: #ffffff;

  --accent: #0f6b54;
  --accent-soft: #1c8a6e;
  --accent-wash: #e7f2ee;
  --accent-rgb: 15, 107, 84;

  --font-serif: 'Georgia', 'Times New Roman', serif;

  --reading: 1.125rem;          /* adjustable base reading size */
  --measure: 34rem;             /* line length for body text */
  --transition: 0.25s cubic-bezier(.4,0,.2,1);
}

html[data-theme="dark"] {
  --color-bg: #14130f;
  --color-bg-alt: #1c1a15;
  --color-text: #f3f0e8;
  --color-muted: #a8a496;
  --color-faint: #76736a;
  --color-border: #2c2a23;
  --color-border-strong: #3a382f;
  --color-surface: #1c1a15;

  --accent: #4cc7a4;
  --accent-soft: #6fe0bf;
  --accent-wash: #15302a;
  --accent-rgb: 76, 199, 164;
}

html { scroll-behavior: smooth; }

body.book-body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-serif);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color var(--transition), color var(--transition);
}

::selection { background: var(--accent); color: #fff; }

a { color: var(--accent); text-underline-offset: 3px; text-decoration-color: var(--color-border-strong); }
a:hover { text-decoration-color: var(--accent); }

/* ============================================
   Reading bar
   ============================================ */
.reader-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 56px;
  padding: 0 clamp(0.75rem, 3vw, 1.75rem);
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--color-border);
}

.bar-home {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--color-muted);
  white-space: nowrap;
}
.bar-home:hover { color: var(--accent); }

.bar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 0.86rem;
  color: var(--color-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-style: italic;
}

.bar-tools { display: flex; align-items: center; gap: 0.35rem; }

.bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-serif);
  font-size: 0.85rem;
  color: var(--color-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.bar-btn:hover { background: var(--color-bg-alt); border-color: var(--color-border); }
.bar-btn.icon { min-width: 38px; justify-content: center; font-weight: 600; }
.bar-btn-label { letter-spacing: 0.02em; }
@media (max-width: 640px) { .bar-btn-label { display: none; } }

.toc-toggle .bars { display: inline-flex; flex-direction: column; gap: 3px; width: 16px; }
.toc-toggle .bars span { height: 2px; background: currentColor; border-radius: 2px; }

.theme-toggle { position: relative; overflow: hidden; }
.theme-icon { font-size: 1rem; line-height: 1; }
html[data-theme="dark"] .theme-icon.moon { display: none; }
html:not([data-theme="dark"]) .theme-icon.sun { display: none; }

/* per-chapter progress bar, sits under the bar */
.reader-progress {
  position: sticky;
  top: 56px;
  z-index: 55;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  transition: width 0.1s linear;
}

/* ============================================
   Contents drawer
   ============================================ */
.toc {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(360px, 86vw);
  z-index: 80;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  transform: translateX(-104%);
  transition: transform var(--transition);
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(0,0,0,0.12);
}
.toc.open { transform: translateX(0); }

.toc-inner { padding: 1.25rem 1.25rem 3rem; }
.toc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toc-eyebrow { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent); }
.toc-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: var(--color-muted); cursor: pointer; }
.toc-close:hover { color: var(--color-text); }

.toc-part {
  margin: 1.5rem 0 0.5rem;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--color-faint);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.4rem;
}
.toc-part:first-child { margin-top: 0; }

.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2px solid transparent;
  font-family: var(--font-serif);
  color: var(--color-text);
  padding: 0.5rem 0.5rem 0.5rem 0.7rem;
  cursor: pointer;
  line-height: 1.35;
  border-radius: 0 6px 6px 0;
  transition: background var(--transition), border-color var(--transition);
}
.toc-item:hover { background: var(--color-bg-alt); }
.toc-item .toc-num { color: var(--color-faint); font-size: 0.78rem; margin-right: 0.5rem; }
.toc-item .toc-name { font-size: 0.98rem; }
.toc-item.current { border-left-color: var(--accent); background: var(--accent-wash); color: var(--accent); }
.toc-item.read .toc-name { color: var(--color-muted); }

.toc-scrim {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.32);
  opacity: 0; transition: opacity var(--transition);
}
.toc-scrim.show { opacity: 1; }

/* ============================================
   Reading surface
   ============================================ */
.reader { min-height: calc(100vh - 59px); }

/* hidden attribute must win over .cover's display:flex */
.page[hidden] { display: none !important; }

.page { max-width: var(--measure); margin: 0 auto; padding: clamp(2rem, 6vw, 4.5rem) clamp(1.25rem, 5vw, 2rem) 5rem; }

/* fade-in on chapter change */
.page.turning { opacity: 0; transform: translateY(8px); }
.page { opacity: 1; transform: none; transition: opacity 0.32s ease, transform 0.32s ease; }
@media (prefers-reduced-motion: reduce) { .page { transition: none; } }

/* ---------- Cover ---------- */
.cover {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 59px);
  text-align: center;
  max-width: 46rem;
}
.cover-inner { padding: 2rem 0; }
.cover-kicker { font-size: 0.8rem; letter-spacing: 0.28em; text-transform: uppercase; color: var(--accent); margin-bottom: 1.4rem; }
.cover-title {
  font-size: clamp(3rem, 12vw, 6rem);
  line-height: 0.95;
  font-weight: 400;
  letter-spacing: -0.01em;
}
.cover-author { margin-top: 1.6rem; font-size: clamp(1.2rem, 4vw, 1.7rem); }
.cover-years { color: var(--color-muted); font-style: italic; margin-top: 0.3rem; letter-spacing: 0.04em; }
.cover-rule { width: 64px; height: 2px; background: var(--accent); margin: 2rem auto; }
.cover-note { color: var(--color-muted); font-size: 0.98rem; max-width: 32rem; margin: 0 auto 2.4rem; font-style: italic; }

.btn-read {
  font-family: var(--font-serif);
  font-size: 1.02rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.6rem;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}
.btn-read:hover { background: var(--accent-soft); transform: translateY(-1px); }
.cover-resume { margin-top: 1.1rem; font-size: 0.92rem; }
.cover-resume a { cursor: pointer; }

/* ---------- Chapter ---------- */
.chapter-head { margin-bottom: 2.4rem; }
.chapter-eyebrow {
  font-size: 0.78rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 0.7rem;
}
.chapter-title {
  font-size: clamp(1.9rem, 6vw, 2.9rem);
  line-height: 1.1;
  font-weight: 400;
  letter-spacing: -0.01em;
}
.chapter-meta { margin-top: 0.9rem; color: var(--color-faint); font-size: 0.86rem; font-style: italic; }

.chapter-body { font-size: var(--reading); }
.chapter-body p { margin: 0 0 1.25rem; hyphens: auto; }

/* drop cap on the first paragraph */
.chapter-body > p.lead-para::first-letter {
  float: left;
  font-size: 3.4em;
  line-height: 0.78;
  padding: 0.05em 0.12em 0 0;
  color: var(--accent);
  font-weight: 600;
}

.chapter-body h3.sub {
  font-size: 1.32rem;
  font-weight: 400;
  margin: 2.6rem 0 1rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text);
  letter-spacing: -0.01em;
}

/* figures (press cuttings) */
.chapter-body figure {
  margin: 2.2rem 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.6rem;
  box-shadow: 0 8px 30px rgba(0,0,0,0.06);
}
.chapter-body figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: #fff;
}
.chapter-body figcaption {
  margin-top: 0.7rem;
  padding: 0 0.4rem 0.3rem;
  font-size: 0.84rem;
  font-style: italic;
  color: var(--color-muted);
  line-height: 1.5;
}

/* ---------- Chapter nav ---------- */
.chapter-nav {
  display: flex;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
}
.page-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  font-family: var(--font-serif);
  color: var(--color-text);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  min-width: 0;
}
.page-btn:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.page-btn:disabled { opacity: 0.35; cursor: default; }
.page-btn.next { text-align: right; align-items: flex-end; }
.page-btn-dir { font-size: 0.74rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.page-btn-name { font-size: 0.98rem; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

@media (max-width: 480px) {
  .page-btn-name { font-size: 0.86rem; }
}
