:root {
  --app-chrome: #211814;
  --ink: #2c2926;
  --ink-soft: #5e5750;
  --paper: #eee4cf;
  --paper-light: #f7f0df;
  --paper-dark: #d5c6aa;
  --rule: rgba(88, 74, 61, 0.18);
  --red: #782e29;
  --red-dark: #321817;
  --shadow: rgba(4, 3, 2, 0.56);
  --serif: Georgia, "Times New Roman", serif;
  --hand: "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
  background: #171310;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(9, 7, 6, 0.28), rgba(9, 7, 6, 0.58)),
    repeating-linear-gradient(4deg, transparent 0 18px, rgba(132, 104, 77, 0.08) 19px, transparent 21px),
    #211a16;
  font-family: var(--serif);
  line-height: 1.75;
}

.rp-back {
  position: fixed;
  z-index: 50;
  top: max(0.75rem, var(--tg-content-safe-area-inset-top, env(safe-area-inset-top)));
  left: max(0.75rem, var(--tg-content-safe-area-inset-left, env(safe-area-inset-left)));
  min-height: 44px;
  padding: 0 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid rgba(235, 221, 195, 0.22);
  color: #e9dcc6;
  background: rgba(30, 22, 18, 0.86);
  box-shadow: 0 0.6rem 1.8rem rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(12px);
  font-family: var(--hand);
  font-size: 0.8rem;
  text-decoration: none;
}

.rp-back::before {
  content: "←";
  font-family: var(--serif);
}

.rp-back:hover,
.rp-back:focus-visible {
  border-color: rgba(235, 221, 195, 0.46);
  background: rgba(52, 35, 27, 0.94);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: 0.07;
  mix-blend-mode: screen;
  background-image:
    repeating-linear-gradient(107deg, transparent 0 9px, rgba(255, 255, 255, 0.12) 10px, transparent 11px),
    repeating-linear-gradient(17deg, transparent 0 17px, rgba(0, 0, 0, 0.18) 18px, transparent 19px);
}

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

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  padding: 0.65rem 1rem;
  color: #fff;
  background: #111;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 3.5rem 0 6rem;
}

.paper {
  position: relative;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 0 7.2%, rgba(119, 62, 55, 0.18) 7.35%, transparent 7.5%),
    repeating-linear-gradient(0deg, transparent 0 30px, var(--rule) 31px, transparent 32px),
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.64), transparent 30%),
    radial-gradient(circle at 85% 86%, rgba(111, 81, 49, 0.12), transparent 35%);
  border: 1px solid rgba(85, 66, 48, 0.45);
  box-shadow:
    0 34px 70px var(--shadow),
    inset 0 0 70px rgba(104, 77, 44, 0.11);
}

.paper::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.2;
  background:
    linear-gradient(112deg, transparent 0 48%, rgba(80, 62, 43, 0.14) 49%, transparent 50%),
    linear-gradient(23deg, transparent 0 76%, rgba(255, 255, 255, 0.22) 77%, transparent 78%);
}

.cover {
  min-height: min(840px, 92vh);
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(270px, 0.75fr);
  gap: clamp(2rem, 7vw, 7rem);
  align-items: center;
  padding: clamp(3rem, 8vw, 7.5rem);
  overflow: hidden;
}

.cover::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: linear-gradient(transparent, rgba(82, 57, 38, 0.3) 15%, rgba(255, 255, 255, 0.4) 50%, rgba(82, 57, 38, 0.3) 85%, transparent);
  box-shadow: -12px 0 28px rgba(48, 34, 24, 0.13), 12px 0 28px rgba(255, 255, 255, 0.18);
}

.cover-copy,
.cover-side {
  position: relative;
  z-index: 1;
}

.eyebrow,
.chapter-number,
.entry-label {
  margin: 0 0 0.7rem;
  color: var(--red);
  font-family: var(--hand);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 8ch;
  margin-bottom: 1.2rem;
  font-family: var(--hand);
  font-size: clamp(4rem, 10vw, 8.7rem);
  font-weight: 500;
  letter-spacing: -0.08em;
  line-height: 0.83;
  transform: rotate(-2deg);
}

.cover-lede {
  max-width: 43rem;
  margin-bottom: 2rem;
  color: var(--ink-soft);
  font-size: clamp(1.08rem, 2vw, 1.35rem);
}

.inside-note {
  position: relative;
  max-width: 40rem;
  margin: 2.3rem 0 0;
  padding: 1.25rem 1.6rem 1.15rem 2rem;
  font-family: var(--hand);
  font-size: 1.05rem;
  line-height: 1.55;
  transform: rotate(-1deg);
}

.inside-note::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(75, 60, 47, 0.3);
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 3px 4px 0 rgba(82, 55, 38, 0.08);
  transform: skew(-1deg);
  z-index: -1;
}

.cover-mark {
  width: 8rem;
  height: 8rem;
  margin: 0 auto 2.5rem;
  border: 3px solid var(--ink);
  border-radius: 50%;
  position: relative;
  opacity: 0.82;
  transform: rotate(5deg);
}

.cover-mark::before,
.cover-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 3px;
  height: 5.8rem;
  background: var(--ink);
  transform-origin: center bottom;
}

.cover-mark::before {
  top: 1rem;
  transform: rotate(31deg);
}

.cover-mark::after {
  top: 0.8rem;
  transform: rotate(-28deg);
}

.toc {
  padding: 1.6rem 1.75rem;
  border: 1px solid rgba(75, 60, 47, 0.34);
  background: rgba(255, 255, 255, 0.16);
  transform: rotate(1deg);
}

.toc h2 {
  margin-bottom: 1rem;
  font-family: var(--hand);
  font-size: 1.35rem;
}

.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc li + li {
  border-top: 1px dashed rgba(74, 58, 45, 0.28);
}

.toc a {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0;
  text-decoration: none;
}

.toc a:hover,
.toc a:focus-visible {
  color: var(--red);
}

.toc span:last-child {
  color: var(--ink-soft);
  font-family: var(--hand);
}

.origin {
  width: min(900px, calc(100% - 1rem));
  margin: 4rem auto 5rem;
  padding: clamp(2rem, 5vw, 4.5rem);
  transform: rotate(-0.4deg);
}

.origin h2,
.chapter-header h2 {
  margin-bottom: 1rem;
  font-family: var(--hand);
  font-size: clamp(2rem, 5vw, 4rem);
  font-weight: 500;
  line-height: 1;
}

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

.chapter {
  margin: 7rem 0 9rem;
  scroll-margin-top: 1.5rem;
}

.chapter-header {
  width: min(760px, 92%);
  margin: 0 auto 3rem;
  padding: 2.3rem clamp(2rem, 5vw, 4rem);
  text-align: center;
  transform: rotate(-0.5deg);
}

.chapter-header p:last-child {
  margin-bottom: 0;
  color: var(--ink-soft);
}

.entries {
  display: grid;
  gap: 3.5rem;
}

.entry {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 1.1fr);
  gap: clamp(2rem, 5vw, 5rem);
  align-items: center;
  min-height: 520px;
  padding: clamp(2rem, 6vw, 5.5rem);
  overflow: hidden;
  scroll-margin-top: 4.5rem;
}

.entry:nth-child(even) .entry-copy {
  order: 2;
}

.entry:nth-child(even) .memory-figure {
  order: 1;
  transform: rotate(-1.2deg);
}

.entry:nth-child(odd) .memory-figure {
  transform: rotate(1.1deg);
}

.entry h3 {
  margin-bottom: 1rem;
  font-family: var(--hand);
  font-size: clamp(1.65rem, 3vw, 2.65rem);
  font-weight: 500;
  line-height: 1.08;
}

.entry-copy p:last-child {
  margin-bottom: 0;
}

.memory-figure {
  position: relative;
  margin: 0;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(78, 61, 45, 0.26);
  box-shadow: 7px 12px 25px rgba(54, 38, 25, 0.23);
  transition: transform 220ms ease, box-shadow 220ms ease;
}

.memory-figure::before {
  content: "";
  position: absolute;
  top: -0.6rem;
  left: 38%;
  width: 30%;
  height: 1.25rem;
  background: rgba(191, 172, 133, 0.5);
  box-shadow: inset 0 0 0 1px rgba(93, 72, 48, 0.13);
  transform: rotate(-2deg);
}

.memory-figure:hover {
  transform: rotate(0deg) scale(1.012) !important;
  box-shadow: 10px 18px 35px rgba(43, 29, 20, 0.3);
}

.memory-figure a {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: rgba(229, 218, 197, 0.55);
}

.memory-figure img {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  object-fit: cover;
  object-position: center;
  filter: sepia(0.08) contrast(0.97);
}

.memory-figure figcaption {
  padding: 0.75rem 0.4rem 0.15rem;
  color: var(--ink-soft);
  font-family: var(--hand);
  font-size: 0.86rem;
  line-height: 1.4;
  text-align: center;
}

.cycle-two .entry {
  background-color: #e7dcc6;
}

.cycle-three .entry {
  background-color: #ddd0ba;
}

.cycle-three .memory-figure {
  opacity: 0.93;
  filter: contrast(1.05);
}

.blank-page {
  border-style: dashed;
}

.finale {
  position: relative;
  color: #eee5d8;
  background:
    radial-gradient(circle at 50% 50%, rgba(119, 45, 38, 0.22), transparent 28%),
    linear-gradient(145deg, #171313, #281515 50%, #100d0d) !important;
  border-color: rgba(153, 65, 57, 0.65);
  box-shadow:
    0 36px 80px rgba(0, 0, 0, 0.75),
    inset 0 0 100px rgba(137, 42, 34, 0.16);
}

.finale::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(24deg, transparent 0 17px, rgba(145, 45, 38, 0.08) 18px, transparent 20px);
}

.finale .entry-copy,
.finale .memory-figure {
  position: relative;
  z-index: 1;
}

.finale .entry-label,
.finale h3 {
  color: #d77a70;
}

.finale p,
.finale figcaption {
  color: #d8cdc2;
}

.finale .memory-figure {
  background: rgba(10, 8, 8, 0.65);
  border-color: rgba(151, 67, 58, 0.55);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.65);
}

.finale .memory-figure a {
  aspect-ratio: 3 / 2;
}

.finale .memory-figure img {
  filter: none;
}

.revelation {
  margin: 2rem 0 0;
  padding: 1.3rem 1.5rem;
  border-left: 3px solid #a64b42;
  color: #f1e4d8;
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--hand);
  font-size: 1.16rem;
}

.site-footer {
  width: min(760px, calc(100% - 1rem));
  margin: 0 auto;
  padding: 2rem 2.5rem;
  text-align: center;
  transform: rotate(0.35deg);
}

.site-footer p {
  margin: 0;
  color: var(--ink-soft);
  font-family: var(--hand);
}

@media (max-width: 850px) {
  .site-shell {
    width: min(100% - 1rem, 720px);
    padding-top: 0.5rem;
  }

  .cover {
    min-height: auto;
    grid-template-columns: 1fr;
    padding: 3.4rem 2rem 3rem;
  }

  .cover::before,
  .cover-mark {
    display: none;
  }

  .cover-side {
    margin-top: 0.5rem;
  }

  .entry {
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 2.5rem 1.6rem 3rem;
  }

  .entry:nth-child(even) .entry-copy,
  .entry:nth-child(even) .memory-figure {
    order: initial;
  }

  .entry-copy {
    padding-left: 0.5rem;
  }

  .memory-figure {
    width: min(100%, 560px);
    justify-self: center;
  }
}

@media (max-width: 520px) {
  body {
    line-height: 1.65;
  }

  .paper {
    background-image:
      repeating-linear-gradient(0deg, transparent 0 27px, var(--rule) 28px, transparent 29px),
      radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.6), transparent 30%);
  }

  .cover {
    padding: 3rem 1.35rem 2.2rem;
  }

  h1 {
    font-size: clamp(3.6rem, 21vw, 5.8rem);
  }

  .inside-note,
  .toc {
    padding-left: 1.2rem;
    padding-right: 1.2rem;
  }

  .origin,
  .chapter-header,
  .entry {
    border-left: 0;
    border-right: 0;
  }

  .chapter {
    margin: 5rem 0 6rem;
  }

  .entry {
    padding: 2rem 1.1rem 2.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .memory-figure {
    transition: none;
  }
}

/* The damage belongs to the paper and individual words, not the whole screen. */
.entry-copy {
  position: relative;
  z-index: 2;
}

.entry {
  content-visibility: auto;
  contain-intrinsic-size: auto 680px;
}

.motion-managed .entry:not(.is-visible) .slip,
.motion-managed .entry:not(.is-visible) .memory-figure img,
.page-hidden .slip,
.page-hidden .memory-figure img {
  animation-play-state: paused;
}

@media (hover: none), (max-width: 850px) {
  body::before { display: none; }
  .rp-back { backdrop-filter: none; background: #211814; }
  .paper { box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26); }
  .entry { contain-intrinsic-size: auto 950px; }
  .memory-figure { box-shadow: 3px 5px 12px rgba(54, 38, 25, 0.2); }
  .cycle-three .memory-figure,
  .memory-figure img { filter: none; }
  .lost-word { filter: none; opacity: 0.6; }
}

.entry-copy > p:not(.entry-label) {
  font-family: var(--hand);
  font-size: 1.08rem;
  letter-spacing: 0.015em;
  line-height: 1.8;
}

.entry-copy s,
.inside-note s,
.origin s {
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(72, 32, 32, 0.8);
}

.entry-copy > .margin-thought {
  width: fit-content;
  max-width: 100%;
  margin: 1.7rem 0 0 auto;
  padding: 0.3rem 0.6rem;
  color: #82433d;
  border-bottom: 1px solid currentColor;
  font-size: 0.86rem;
  font-style: italic;
  line-height: 1.35;
  transform: rotate(-4deg);
}

.page-scrawl {
  position: absolute;
  right: 0.5rem;
  top: 0.5rem;
  z-index: 3;
  width: clamp(75px, 12vw, 145px);
  height: 80px;
  fill: none;
  stroke: #412d2a;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.36;
  transform: rotate(9deg);
  pointer-events: none;
}

.entry:nth-child(even) .page-scrawl {
  top: auto;
  right: 1rem;
  bottom: 0.5rem;
  transform: rotate(-12deg);
}

.cover > .page-scrawl {
  top: auto;
  bottom: 1.5rem;
  right: 2rem;
}

.pencil-ticks {
  display: block;
  margin-top: 1.2rem;
  color: rgba(58, 39, 36, 0.5);
  font-family: var(--hand);
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  transform: rotate(-5deg);
}

.lost-word {
  letter-spacing: 0.15em;
  opacity: 0.64;
  filter: blur(0.4px);
}

.ink-block {
  padding: 0 0.16em;
  color: #40302c;
  background: repeating-linear-gradient(171deg, transparent 0 1px, rgba(45, 30, 28, 0.8) 2px 3px, transparent 4px 5px);
  text-decoration: line-through;
  word-break: break-word;
}

.broken-line {
  text-decoration: line-through;
  text-decoration-style: wavy;
  transform: rotate(-2deg);
  letter-spacing: 0.08em;
}

.slip {
  display: inline-block;
  animation: thought-skip 9.7s infinite;
  animation-delay: var(--scar-delay, 0s);
}

.cycle-two .page-scrawl {
  stroke: #713a36;
  opacity: 0.5;
}

.cycle-three .page-scrawl {
  stroke: #73292c;
  stroke-width: 1.6;
  opacity: 0.65;
}

.cycle-two .memory-figure img,
.cycle-three .memory-figure img {
  animation: memory-skip 14.3s infinite;
  animation-delay: var(--scar-delay, 0s);
}

.finale .page-scrawl,
.finale .pencil-ticks {
  color: #b66561;
  stroke: #c26763;
}

.finale .ink-block {
  color: #c89d98;
}

@keyframes thought-skip {
  0%, 89%, 93%, 100% { transform: translate(0); text-shadow: none; }
  90%, 92% { transform: translateX(1.5px); text-shadow: -1.5px 0 rgba(158, 39, 49, 0.6), 1.5px 0 rgba(58, 79, 110, 0.45); }
  91% { transform: translateX(-1px); text-shadow: 2px 0 rgba(158, 39, 49, 0.4); }
}

@keyframes memory-skip {
  0%, 93%, 96%, 100% { transform: translate(0); }
  94% { transform: translate(2px, -1px); }
  95% { transform: translate(-2px, 1px); }
}

@media (max-width: 520px) {
  .page-scrawl {
    width: 75px;
    height: 50px;
    opacity: 0.28;
  }

  .cycle-three .page-scrawl { opacity: 0.42; }
  .entry-copy > p:not(.entry-label) { font-size: 1rem; }
  .entry-copy > .margin-thought { font-size: 0.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .slip,
  .cycle-two .memory-figure img,
  .cycle-three .memory-figure img { animation: none; }
}

@media print {
  .slip,
  .cycle-two .memory-figure img,
  .cycle-three .memory-figure img { animation: none; }

  .rp-back { display: none; }

  body {
    background: #fff;
  }

  body::before,
  .toc,
  .cover-mark {
    display: none;
  }

  .site-shell {
    width: 100%;
    padding: 0;
  }

  .paper,
  .entry,
  .cover,
  .origin,
  .chapter-header,
  .site-footer {
    box-shadow: none;
    break-inside: avoid;
  }

  .entry {
    min-height: 0;
  }
}
