/* ================================================================
   style.css — The Brothers of Cloverhollow Reader
   ================================================================

   Table of contents:
     1. CSS Custom Properties (design tokens)
     2. Reset & base
     3. Background image
     4. Reading area & scrollbar
     5. Chapter content typography
     6. Hamburger menu button
     7. Slide-in chapter menu
     8. Menu backdrop
     9. Navigation arrows
    10. Responsive adjustments
   ================================================================ */


/* ----------------------------------------------------------------
   1. CSS Custom Properties
   Change values here to retheme the entire reader.
   ---------------------------------------------------------------- */
:root {
  /* Text colours */
  --color-text:            #f0e6d0;   /* warm parchment — body text          */
  --color-heading:         #ffffff;   /* white — book title & chapter title  */
  --color-chapter-num:     #b09a72;   /* muted gold — "Chapter N" label      */
  --color-scene-break:     #c8a96e;   /* gold — ✦ ✦ ✦ scene break marker    */
  --color-hr:              rgba(200, 169, 110, 0.30);

  /* Panel & surface colours */
  --color-panel-bg:        rgba(6, 4, 3, 0.74);   /* reading area background  */
  --color-menu-bg:         rgba(8, 5, 3, 0.97);   /* slide-in menu background */
  --color-menu-item-hover: rgba(255, 255, 255, 0.06);
  --color-menu-item-active:rgba(200, 169, 110, 0.18);
  --color-menu-border-active: #c8a96e;

  /* Navigation button colours */
  --color-nav-btn:         rgba(255, 255, 255, 0.13);
  --color-nav-btn-hover:   rgba(255, 255, 255, 0.26);
  --color-nav-btn-disabled:rgba(255, 255, 255, 0.04);

  /* Typography */
  --font-serif:  Georgia, 'Times New Roman', serif;
  --font-sans:   -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;

  /* Layout */
  --reading-max-width: 700px;    /* max width of the text column            */
  --top-clearance:      16px;    /* gap from top of viewport to reading area */
  --nav-height:         88px;    /* height reserved at bottom for nav arrows */
  --side-padding:       36px;    /* left/right padding inside reading area   */
}


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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;   /* only the reading area scrolls, not the page */
}

body {
  font-family: var(--font-serif);
  color: var(--color-text);
  background-color: #080604;   /* fallback if background image fails to load */
}


/* ----------------------------------------------------------------
   3. Background image

   A fixed pseudo-element is used instead of background-attachment: fixed
   on <body> because iOS Safari does not render that property correctly
   when the page contains fixed-position children.
   ---------------------------------------------------------------- */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url('dark-forest-page-background-image.jpg');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  z-index: 0;
}


/* ----------------------------------------------------------------
   4. Reading area & scrollbar
   ---------------------------------------------------------------- */
#reading-area {
  position: fixed;
  top: var(--top-clearance);
  bottom: var(--nav-height);
  left: 50%;
  transform: translateX(-50%);
  width: min(var(--reading-max-width), 92vw);

  overflow-y: auto;
  -webkit-overflow-scrolling: touch;   /* momentum scrolling on iOS */

  background: var(--color-panel-bg);
  border-radius: 6px;
  padding: 44px var(--side-padding) 52px;

  z-index: 10;
}

/* Thin, gold-tinted scrollbar (Webkit / Blink — Chrome, Safari, Edge) */
#reading-area::-webkit-scrollbar        { width: 5px; }
#reading-area::-webkit-scrollbar-track  { background: transparent; }
#reading-area::-webkit-scrollbar-thumb  {
  background: rgba(200, 169, 110, 0.28);
  border-radius: 3px;
}


/* ----------------------------------------------------------------
   5. Chapter content typography
   ---------------------------------------------------------------- */

/* Book title  —  # The Brothers of Cloverhollow */
#chapter-content h1 {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: normal;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
  color: var(--color-heading);
  margin-bottom: 0.25em;
}

/* Thematic break  —  --- */
#chapter-content hr {
  border: none;
  border-top: 1px solid var(--color-hr);
  margin: 1em auto 1.6em;
  width: 55%;
}

/* Chapter number label  —  ## Chapter 1 */
#chapter-content h2 {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-chapter-num);
  text-align: center;
  margin-bottom: 0.5em;
}

/* Chapter title  —  ### The Harvest Warren */
#chapter-content h3 {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: normal;
  color: var(--color-heading);
  text-align: center;
  line-height: 1.3;
  margin-bottom: 2.2em;
}

/* Body paragraphs */
#chapter-content p {
  font-size: 1.2rem;
  line-height: 1.85;
  color: var(--color-text);
  margin-bottom: 0;                  /* spacing comes from line-height;       */
  padding-bottom: 1.1em;             /* padding used so last-child looks right */
  text-indent: 1.6em;
}

/* Remove indent from the first paragraph after any heading or scene break,
   and from the subtitle line that sits directly after the book title. */
#chapter-content h1 + p,
#chapter-content h2 + p,
#chapter-content h3 + p,
#chapter-content hr + p,
#chapter-content .scene-break + p {
  text-indent: 0;
}

/* Scene break  —  ✦  ✦  ✦ */
.scene-break {
  text-align: center;
  color: var(--color-scene-break);
  font-size: 1.05rem;
  letter-spacing: 0.6em;
  margin: 2.2em 0;
  user-select: none;
}

/* Inline formatting */
#chapter-content em     { font-style: italic; }
#chapter-content strong { font-weight: bold; }

/* The book subtitle (*Book One: Into the Dark Forest*) renders as
   a paragraph containing only an <em> tag. Centre and mute it. */
#chapter-content h1 + p > em:only-child {
  display: block;
  text-indent: 0;
  text-align: center;
  color: var(--color-chapter-num);
  font-size: 1rem;
}

/* Loading / error state messages */
.loading-text,
.error-text {
  text-align: center;
  font-family: var(--font-sans);
  font-size: 1rem;
  color: var(--color-chapter-num);
  padding: 5em 0;
  text-indent: 0;
}


/* ----------------------------------------------------------------
   6. Hamburger menu button
   ---------------------------------------------------------------- */
#menu-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 200;

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;

  width: 44px;
  height: 44px;
  padding: 10px;

  background: rgba(6, 4, 3, 0.60);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

#menu-btn:hover {
  background: rgba(6, 4, 3, 0.90);
}

#menu-btn:focus-visible {
  outline: 2px solid rgba(200, 169, 110, 0.55);
  outline-offset: 2px;
}

/* The three lines that make up the hamburger icon */
.hamburger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
  transition: transform 0.22s ease, opacity 0.22s ease;
}

/* Animate the three lines into an × when the menu is open.
   The aria-expanded attribute is toggled by JavaScript. */
#menu-btn[aria-expanded="true"] .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}
#menu-btn[aria-expanded="true"] .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
#menu-btn[aria-expanded="true"] .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}


/* ----------------------------------------------------------------
   7. Slide-in chapter menu
   ---------------------------------------------------------------- */
#chapter-menu {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 82vw);

  background: var(--color-menu-bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;

  /* Slide off-screen to the left by default */
  transform: translateX(-100%);
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);

  z-index: 300;
}

#chapter-menu.open {
  transform: translateX(0);
}

/* Menu header bar: "Chapters" label + close button */
#menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--color-hr);
  position: sticky;
  top: 0;
  background: var(--color-menu-bg);   /* stays visible when the list scrolls */
}

#menu-title {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--color-chapter-num);
}

#menu-close-btn {
  background: none;
  border: none;
  color: var(--color-text);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.6;
  border-radius: 4px;
  transition: opacity 0.15s;
  line-height: 1;
}

#menu-close-btn:hover { opacity: 1; }

/* Chapter list */
#chapter-list {
  list-style: none;
  padding: 10px 0 20px;
}

/* Each chapter is a full-width button */
.menu-chapter-btn {
  display: block;
  width: 100%;
  padding: 13px 18px 13px 21px;

  background: none;
  border: none;
  border-left: 3px solid transparent;

  color: var(--color-text);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  text-align: left;
  line-height: 1.4;
  cursor: pointer;

  transition: background 0.15s, border-left-color 0.15s;
}

.menu-chapter-btn:hover {
  background: var(--color-menu-item-hover);
}

/* Active (currently displayed) chapter */
.menu-chapter-btn.active {
  background: var(--color-menu-item-active);
  border-left-color: var(--color-menu-border-active);
  color: #ffffff;
}

/* Small "CHAPTER 1" label above each chapter title */
.menu-chapter-label {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-chapter-num);
  margin-bottom: 3px;
}

.menu-chapter-btn.active .menu-chapter-label {
  color: var(--color-scene-break);
}


/* ----------------------------------------------------------------
   8. Menu backdrop
   A dark overlay behind the open menu. Clicking it closes the menu.
   ---------------------------------------------------------------- */
#menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 250;

  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s;
}

#menu-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}


/* ----------------------------------------------------------------
   9. Navigation arrows
   Fixed at the bottom corners. The nav element itself is
   pointer-events: none so the gap between the two buttons is
   still "clickable through" to the reading area behind it.
   ---------------------------------------------------------------- */
#chapter-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  z-index: 20;

  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;

  pointer-events: none;   /* pass clicks through to reading area */
}

#prev-btn,
#next-btn {
  pointer-events: auto;   /* re-enable clicks for the buttons themselves */

  width: 58px;
  height: 58px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--color-nav-btn);
  border: none;
  border-radius: 50%;
  color: var(--color-text);
  font-size: 1.5rem;
  cursor: pointer;

  /* Frosted glass effect (supported on Safari / recent Chrome) */
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);

  transition: background 0.18s, transform 0.1s;
}

#prev-btn:hover,
#next-btn:hover {
  background: var(--color-nav-btn-hover);
}

#prev-btn:active,
#next-btn:active {
  transform: scale(0.90);
}

#prev-btn:disabled,
#next-btn:disabled {
  background: var(--color-nav-btn-disabled);
  color: rgba(240, 230, 208, 0.20);
  cursor: default;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#prev-btn:focus-visible,
#next-btn:focus-visible {
  outline: 2px solid rgba(200, 169, 110, 0.55);
  outline-offset: 3px;
}


/* ----------------------------------------------------------------
   10. Responsive adjustments
   ---------------------------------------------------------------- */

/* Slightly reduce padding on small phone screens */
@media (max-width: 480px) {
  :root {
    --side-padding:  20px;
    --nav-height:    76px;
    --top-clearance: 12px;
  }

  #chapter-content h3 { font-size: 1.5rem; }
  #chapter-content p  { font-size: 1.1rem; }
}
