/* ==========================================================================
   Nearly Home: a memoir by W. Martins
   Stylesheet. One page, five scenes, and the back seat.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=EB+Garamond:ital@0;1&display=swap');

:root {
  --cream: #F3EEE4;
  --ink: #1E1B18;
  --grey: #6E675E;
  --lamp: #C44A2A;
  --lamp-core: #EE9E70;

  --paper: var(--cream);
  --text: var(--ink);
  --text-soft: var(--grey);
  --line: rgba(30, 27, 24, 0.22);

  --serif: 'EB Garamond', Garamond, 'Apple Garamond', 'Times New Roman', Georgia, serif;
  --measure: 42em;
  --ease-arrive: cubic-bezier(0.2, 0.7, 0.2, 1);
  --gutter: clamp(1.25rem, 6vw, 4rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: var(--ink);
    --text: var(--cream);
    --text-soft: #A79E92;
    --line: rgba(243, 238, 228, 0.22);
  }
}

/* -------------------------------------------------------------- resets */

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

html {
  background: var(--paper);
  color-scheme: light dark;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (min-width: 640px) {
  body { font-size: 20px; }
}

img { max-width: 100%; height: auto; display: block; }

a {
  color: inherit;
  text-decoration-color: var(--line);
  text-underline-offset: 0.2em;
}

a:hover { text-decoration-color: currentColor; }

h1, h2, h3 {
  font-weight: 400;
  line-height: 1.2;
  margin: 0;
}

p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem; top: -6rem;
  background: var(--paper);
  color: var(--text);
  padding: 0.6em 1em;
  border: 1px solid var(--line);
  transition: top 0.2s var(--ease-arrive);
  z-index: 100;
}
.skip-link:focus { top: 1rem; }

/* -------------------------------------------------------------- helpers */

.label-caps {
  font-variant-caps: all-small-caps;
  letter-spacing: 0.14em;
  color: var(--text-soft);
  font-style: normal;
}

.spaced-caps {
  text-transform: uppercase;
  letter-spacing: 0.32em;
  font-size: 0.82em;
}

.measure { max-width: var(--measure); margin-inline: auto; }

.scene {
  position: relative;
  padding: clamp(4rem, 12vh, 7rem) var(--gutter);
}

.scene-inner { max-width: var(--measure); margin-inline: auto; }

/* fade-on-scroll primitive, used by paragraphs, chapter rows, etc. */
.reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.9s var(--ease-arrive), transform 0.9s var(--ease-arrive);
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================ scene 1 */

.hero {
  position: relative;
  min-height: 100svh;
  overflow: hidden;
  background: var(--paper);
}

.hero-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hero-scene svg { width: 100%; height: 100%; display: block; }

.road-line, .road-edge { fill: none; stroke: var(--text); }
.road-edge { stroke-width: 1.6; transition: stroke-dashoffset 1.6s var(--ease-arrive); }
.road-dash { stroke-width: 2.4; stroke-linecap: round; transition: opacity 0.5s var(--ease-arrive); }
.moon-outline { fill: none; stroke: var(--text-soft); stroke-width: 1.4; }
/* The moon is drawn in the phase it had on the night of the Balintore
   chapter, the same phase the book's cover uses. See MOON_DATE in the
   book's production/build/art_cover.py. */
.moon-shadow { fill: url(#hatchMoon); stroke: none; }
.js-moon { transition: opacity 1.1s var(--ease-arrive); }
.grass-hatch { stroke: var(--text-soft); stroke-width: 1; opacity: 0.55; }
.horizon-line { stroke: var(--text); stroke-width: 1.4; transition: opacity 0.7s var(--ease-arrive); }
.js-verge-ticks { transition: opacity 0.7s var(--ease-arrive); }

.car-body { fill: var(--lamp); opacity: 0.9; }
.tail-lamp-glow { fill: var(--lamp); filter: blur(6px); }
.tail-lamp { fill: var(--lamp-core); }
.js-car { transition: opacity 1s var(--ease-arrive); }
.js-car.is-breathing { animation: lamp-breathe 4s ease-in-out infinite; }

@keyframes lamp-breathe {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

.hero-text {
  position: absolute;
  inset: 0;
  z-index: 2;
  text-align: center;
  pointer-events: none;
}

.hero-titleblock {
  position: absolute;
  top: 15vh;
  left: 50%;
  transform: translateX(-50%);
  width: 90vw;
  text-align: center;
}

.hero-title {
  width: 100%;
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 1.1s var(--ease-arrive), transform 1.1s var(--ease-arrive);
}
.hero-title.is-visible { opacity: 1; transform: translateY(0); }

.hero-rule {
  width: 8em;
  height: 1px;
  background: var(--line);
  margin: 0.6em auto 0;
  transform-origin: center;
  transform: scaleX(0);
  transition: transform 1s var(--ease-arrive) 0.3s;
}
.hero-rule.is-visible { transform: scaleX(1); }

.hero-author {
  position: absolute;
  bottom: 6vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.95rem;
  opacity: 0;
  transition: opacity 1.1s var(--ease-arrive) 0.4s;
}
.hero-author.is-visible { opacity: 1; }

.scroll-hint {
  position: absolute;
  bottom: 1.6vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  z-index: 2;
  opacity: 0;
  transition: opacity 1s var(--ease-arrive) 1.8s;
}
.scroll-hint.is-visible { opacity: 0.65; }

/* ============================================================ scene 2 */

.scene-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 70vh;
}

.bubble {
  position: relative;
  background: var(--text);
  color: var(--paper);
  border-radius: 1.3em 1.3em 1.3em 0.3em;
  padding: 0.85em 1.15em;
  font-size: clamp(1.4rem, 4vw, 2rem);
  min-height: 1.6em;
  min-width: 8ch;
}

.bubble .caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  margin-left: 2px;
  vertical-align: -0.15em;
  opacity: 0;
}
.bubble.is-typing .caret {
  opacity: 1;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.delivered {
  margin-top: 0.9em;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  color: var(--text-soft);
  opacity: 0;
  transition: opacity 0.8s var(--ease-arrive);
}
.delivered.is-visible { opacity: 1; }

.message-caption {
  margin-top: 2.2em;
  font-size: 0.78rem;
  opacity: 0;
  transition: opacity 1s var(--ease-arrive);
}
.message-caption.is-visible { opacity: 1; }

/* ============================================================ scene 3 */

.scene-book {
  display: grid;
  gap: clamp(2rem, 6vw, 4rem);
  align-items: center;
}

@media (min-width: 900px) {
  .scene-book { grid-template-columns: 1.15fr 0.85fr; }
  .scene-book .cover-wrap { order: 2; }
  .scene-book .blurb-col { order: 1; }
}

.blurb-col p { color: var(--text); }

.cover-wrap {
  display: flex;
  justify-content: center;
}

.cover-frame {
  width: min(320px, 70vw);
  transition: transform 0.5s var(--ease-arrive);
  transform: rotate(0deg);
}
.cover-frame:hover { transform: rotate(-2.4deg); }

.cover-frame img {
  width: 100%;
  box-shadow: 0 1.5em 3em -1.5em rgba(0,0,0,0.35);
}

.buy-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 1.8rem;
}

.buy-btn {
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  padding: 0.65em 1.5em;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.35s var(--ease-arrive), color 0.35s var(--ease-arrive);
  text-decoration: none;
  display: inline-block;
}
.buy-btn:hover { background: var(--text); color: var(--paper); }

.buy-btn[disabled] {
  cursor: default;
  opacity: 0.5;
  border-style: dashed;
}
.buy-btn[disabled]:hover { background: transparent; color: var(--text); }

.buy-note {
  margin-top: 1.1rem;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/* ============================================================ scene 4 */

.chapters {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(3rem, 8vw, 5rem);
}

.chapter {
  display: grid;
  gap: 1.3rem 2.2rem;
  align-items: center;
}

@media (min-width: 720px) {
  .chapter { grid-template-columns: 190px 1fr; }
  .chapter:nth-child(even) .chapter-plate { order: 2; }
  .chapter:nth-child(even) .chapter-copy { order: 1; }
}

.chapter-plate {
  position: relative;
  width: min(190px, 60vw);
  margin-inline: auto;
}

.chapter-plate img {
  mix-blend-mode: multiply;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.9s var(--ease-arrive);
}

@media (prefers-color-scheme: dark) {
  .chapter-plate img { mix-blend-mode: screen; filter: invert(1); }
}

.chapter.is-visible .chapter-plate img { clip-path: inset(0 0 0 0); }

.chapter-index {
  display: block;
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-bottom: 0.35em;
}

.chapter-title { font-size: clamp(1.5rem, 3.4vw, 2rem); }

.chapter-line {
  color: var(--text-soft);
  margin-top: 0.5em;
  font-size: 0.95em;
}

.chapter-copy {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.9s var(--ease-arrive), transform 0.9s var(--ease-arrive);
}
.chapter.is-visible .chapter-copy {
  opacity: 1;
  transform: translateY(0);
}

/* ============================================================ scene 5 */

.scene-author {
  text-align: left;
}

.author-grid {
  display: grid;
  gap: 2rem;
  align-items: start;
}

@media (min-width: 720px) {
  .author-grid { grid-template-columns: auto 1fr; }
}

/* The caged elephant, the nod to the band playing in Balintore. The shape
   is generated from the book's own control points by scripts/make_elephant.py,
   so the device here and the one on the cover are the same animal. */
.elephant-device { width: 88px; opacity: 0.9; }
.elephant-device .figure { fill: var(--text); stroke: none; }
.elephant-device .cut path { fill: none; stroke: var(--paper); stroke-width: 1; }
.elephant-device .cut circle { fill: var(--paper); stroke: none; }
.elephant-device .ink path {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.5;
  stroke-linecap: round;
}
.elephant-device .ink .tail-tip { stroke-width: 2.4; }
.elephant-device .bars-gap line { stroke: var(--paper); stroke-width: 2.8; }
.elephant-device .bars line { stroke: var(--text); stroke-width: 1.1; }
.elephant-device .cage path { fill: none; stroke: var(--text); stroke-width: 1.5; }

.credit-line {
  margin-top: 2.2rem;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.contact-line { margin-top: 0.6rem; }

.ornament {
  width: 160px;
  margin: 3rem auto 0;
  opacity: 0.8;
  display: block;
}
@media (prefers-color-scheme: dark) {
  .ornament { filter: invert(1); mix-blend-mode: normal; }
}
@media (prefers-color-scheme: light) {
  .ornament { mix-blend-mode: multiply; }
}

.closing {
  position: relative;
  margin-top: clamp(3rem, 10vh, 6rem);
  padding: 3rem 0 4rem;
  text-align: center;
  overflow: hidden;
}

.closing-glow {
  position: absolute;
  left: 50%; bottom: 0;
  width: 60vw;
  max-width: 640px;
  height: 220px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(196,74,42,0.55), rgba(196,74,42,0) 70%);
  opacity: 0;
  pointer-events: none;
}

.closing-glow.is-visible {
  animation: glow-fade 4s var(--ease-arrive) forwards;
}

@keyframes glow-fade {
  0% { opacity: 0; }
  35% { opacity: 1; }
  100% { opacity: 0; }
}

.closing-line {
  position: relative;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-soft);
  opacity: 0;
  transition: opacity 1.4s var(--ease-arrive);
}
.closing-line.is-visible { opacity: 1; }

/* ============================================================ footer nav (404 / backseat) */

.simple-page {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.simple-page .hero-scene { position: absolute; inset: 0; z-index: 0; }
.simple-page-content { position: relative; z-index: 1; margin-bottom: 14vh; }

.simple-page h1 { font-size: clamp(1.8rem, 5vw, 2.4rem); margin-bottom: 0.6em; }

.home-link {
  display: inline-block;
  margin-top: 1.4em;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--line);
}

/* ============================================================ back seat */

body.backseat {
  background: var(--ink);
  color: var(--cream);
}

body.backseat a { text-decoration-color: rgba(243,238,228,0.35); }

.backseat-scene {
  position: relative;
  min-height: 46vh;
  overflow: hidden;
  border-bottom: 1px solid rgba(243,238,228,0.15);
}

.backseat-rain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.backseat-rain line {
  stroke: rgba(243,238,228,0.35);
  stroke-width: 1;
}

.backseat-glow {
  position: absolute;
  right: 8%;
  bottom: 12%;
  width: 90px;
  height: 130px;
  background: radial-gradient(ellipse at center, rgba(243,238,228,0.55), rgba(243,238,228,0) 70%);
  border-radius: 50%;
  opacity: 0.75;
  animation: phone-glow 4.5s ease-in-out infinite;
}

@keyframes phone-glow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.85; }
}

.seatback {
  position: absolute;
  left: -10%;
  bottom: -20%;
  width: 70%;
  height: 90%;
  border-radius: 50% 50% 0 0 / 60% 60% 0 0;
  background: rgba(243,238,228,0.05);
  border: 1px solid rgba(243,238,228,0.12);
}

.backseat-copy { padding: clamp(3rem, 8vh, 5rem) var(--gutter) 1rem; }

.backseat-intro { color: rgba(243,238,228,0.82); }

.playlist-embed {
  margin: 2.5rem 0;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(243,238,228,0.04);
}

.playlist-embed iframe {
  width: 100%;
  border: 0;
  display: block;
}

.tracklist {
  list-style: none;
  margin: 0 0 2.5rem;
  padding: 0;
}

.tracklist li {
  padding: 0.7em 0;
  border-top: 1px solid rgba(243,238,228,0.12);
  display: flex;
  justify-content: space-between;
  gap: 1em;
  flex-wrap: wrap;
}

.tracklist li:last-child { border-bottom: 1px solid rgba(243,238,228,0.12); }

.track-chapter {
  color: rgba(243,238,228,0.55);
  font-size: 0.85em;
  font-style: italic;
}

.backseat-foot {
  padding: 1rem var(--gutter) 4rem;
  font-size: 0.85rem;
  color: rgba(243,238,228,0.6);
}

/* ============================================================ reduced motion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .closing-glow.is-visible { animation: none; opacity: 0.4; }
  .backseat-glow { animation: none; }
}
