/* ==========================================================================
   The 5 AM Club — Web Book
   
   Design philosophy: invisible. The reader should forget they're on a website.
   Three colors. Two fonts. One purpose: reading.
   ========================================================================== */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #141218;
  --text: #e8e4df;
  --text-muted: #b0aaa4;
  --accent: #c9a86c;
  --surface: #1c1a20;
  --border: #2a2730;
  --measure: 68ch;
  --font-body: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Segoe UI Mono', Menlo, monospace;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--text-muted) var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.72;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle page fade-in */
body {
  animation: fadeIn 400ms ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
}

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

/* ---------- Page Layout ---------- */
.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  .page {
    padding: 6rem 2rem 8rem;
  }
}

/* ---------- Cover Page ---------- */
.cover {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 80vh;
  text-align: center;
}

.cover-rule {
  width: 3rem;
  height: 1px;
  background: var(--accent);
  border: none;
  margin: 2rem auto;
}

.cover-title {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 6vw, 3.8rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.cover-subtitle {
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 0.25rem;
}

.cover-author {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-top: 1.5rem;
}

.cover-tagline {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-style: italic;
}


/* ---------- Table of Contents ---------- */
.toc {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  padding-top: 3rem;
}

.toc-heading {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2rem;
  text-align: center;
}

.toc-list {
  list-style: none;
}

.toc-item {
  border-bottom: 1px solid var(--border);
}

.toc-item:first-child {
  border-top: 1px solid var(--border);
}

.toc-link {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 0;
  min-height: 44px;
  text-decoration: none;
  color: var(--text);
  transition: color 150ms ease;
}

.toc-link:hover {
  color: var(--accent);
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
  flex-shrink: 0;
  min-width: 2rem;
}

.toc-chapter-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
}

/* ---------- Chapter Header ---------- */
.chapter-header {
  text-align: center;
  margin-bottom: 4rem;
  padding-bottom: 3rem;
  border-bottom: 1px solid var(--border);
}

.chapter-number {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.5rem;
  display: block;
}

.chapter-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 2.8rem);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.chapter-subtitle {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.75rem;
}


/* ---------- Content Blocks ---------- */
.content {
  /* Container for all blocks */
}

/* -- Prose -- */
.block-prose p {
  margin-bottom: 1.25rem;
}

.block-prose p:last-child {
  margin-bottom: 0;
}

.block-prose + .block-prose {
  margin-top: 1.25rem;
}

/* -- Quote -- */
.block-quote {
  margin: 2.5rem 0;
  padding: 0 0 0 1.5rem;
  border-left: 2px solid var(--accent);
}

.block-quote p {
  font-size: 1.05rem;
  font-style: italic;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.block-quote p:last-child {
  margin-bottom: 0;
}

.block-quote .attribution {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-style: normal;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  margin-top: 0.75rem;
}

/* -- Scene -- */
.block-scene {
  margin: 2.5rem 0;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border-radius: 4px;
}

.block-scene p {
  font-style: italic;
  color: var(--text);
  line-height: 1.75;
  margin-bottom: 1.25rem;
}

.block-scene p:last-child {
  margin-bottom: 0;
}

/* -- Mirror (direct address to reader) -- */
.block-mirror {
  margin: 2.5rem 0;
  padding: 2rem 1.5rem;
  border-left: 2px solid var(--accent);
  background: rgba(201, 168, 108, 0.04);
  border-radius: 0 4px 4px 0;
}

.block-mirror p {
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 1.25rem;
}

.block-mirror p:last-child {
  margin-bottom: 0;
}

/* -- Aside -- */
.block-aside {
  margin: 2.5rem 0;
  padding: 0 0 0 1.5rem;
}

.block-aside p {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 0.75rem;
}

.block-aside p:last-child {
  margin-bottom: 0;
}

/* Block spacing */
.content > * + * {
  margin-top: 1.75rem;
}

/* ---------- Progress Indicator ---------- */
.progress {
  text-align: center;
  margin-bottom: 2rem;
}

.progress-text {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.progress-bar {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 0.5rem;
}

.progress-dot {
  width: 6px;
  height: 2px;
  background: var(--border);
  border-radius: 1px;
}

.progress-dot.active {
  background: var(--accent);
}

/* ---------- Navigation ---------- */
.nav {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.nav-link {
  text-decoration: none;
  color: var(--text);
  transition: color 150ms ease;
  max-width: 45%;
  min-height: 44px;
  padding: 0.75rem 0;
}

.nav-link:hover {
  color: var(--accent);
}

.nav-link--next {
  text-align: right;
  margin-left: auto;
}

.nav-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.35rem;
}

.nav-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 600;
}

/* TOC return link */
.toc-return {
  text-align: center;
  margin-top: 3rem;
}

.toc-return a {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 150ms ease;
}

.toc-return a:hover {
  color: var(--accent);
}

/* ---------- Footer ---------- */
.footer {
  text-align: center;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.footer p {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

/* ---------- Focus Styles (a11y) ---------- */
a:focus-visible,
.nav-link:focus-visible,
.toc-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- Skip Link ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 4px;
}
.skip-link:focus {
  top: 0;
}

/* ---------- Scroll Progress Bar ---------- */
@supports (animation-timeline: scroll()) {
  .reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    background: var(--accent);
    width: 0;
    z-index: 100;
    animation: grow-progress linear;
    animation-timeline: scroll();
  }
  @keyframes grow-progress { to { width: 100%; } }
}

#progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0;
  z-index: 100;
  transition: width 0.1s linear;
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ---------- Print ---------- */
@media print {
  body { background: white; color: black; font-size: 12pt; }
  .progress, .nav, .toc-return, .skip-link, #progress-bar, .reading-progress { display: none; }
  .page { max-width: 100%; padding: 1rem; }
  .block-scene { background: #f5f5f5; -webkit-print-color-adjust: exact; }
  .block-quote { border-left-color: #333; }
  .block-mirror { border-left-color: #666; background: #f9f9f9; -webkit-print-color-adjust: exact; }
  a { color: inherit; text-decoration: none; }
  .chapter-header { break-after: avoid; }
}

/* ---------- Small Screen Fallback ---------- */
@media (max-width: 374px) {
  html { font-size: 16px; }
}
