@import url("https://fonts.googleapis.com/css2?family=Courier+Prime:wght@400;700&family=Special+Elite&display=swap");

/* Site-wide design tokens. Most visual tuning can start here: paper warmth,
   faded ink strength, page width, type size, and navigation control scale. */
:root {
  color-scheme: light;
  --ink: rgba(31, 29, 26, 0.56);
  --ink-strong: rgba(31, 29, 26, 0.68);
  --ink-ghost: rgba(31, 29, 26, 0.065);
  --paper: #f0e4ca;
  --rule: rgba(31, 29, 26, 0.2);
  --link: var(--ink);
  --focus: #7f3529;
  --max-page: 790px;
  --text-measure: 540px;
  --page-pad-y: clamp(36px, 6.2vw, 72px);
  --page-pad-x: clamp(30px, 7vw, 86px);
  --type-size: clamp(0.78rem, 1.18vw, 0.88rem);
  --type-line: 1.62;
  --control-size: 1.95rem;
  --nav-hit-size: 2.75rem;
  --control-stroke: 2px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Special Elite", "Courier Prime", monospace;
  font-size: var(--type-size);
  line-height: var(--type-line);
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.16em;
}

a:hover {
  color: var(--ink-strong);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

/* Keyboard-only escape hatch. It stays off-canvas until focused. */
.skip-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 20;
  padding: 0.32rem 0.62rem 0.12rem;
  background: var(--ink-strong);
  color: var(--paper);
  text-decoration: none;
  transform: translateY(calc(-100% - 24px));
}

.skip-link:focus,
.skip-link.is-focused {
  color: var(--paper);
  transform: translateY(0);
}

.book-shell:focus {
  outline: 0;
}

/* Hidden SVG filter defined in the HTML shell; used to roughen printed text,
   page marks, and illustrations so they feel less digitally perfect. */
.print-filter {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* The page is the whole background. There are intentionally no shadows or
   gradients so the viewport feels like a flat extension of the paper. */
.book-shell {
  width: min(100% - 28px, 1000px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 42px 0;
  display: grid;
  place-items: center;
}

.page {
  position: relative;
  width: min(100%, var(--max-page));
  min-height: min(980px, calc(100vh - 84px));
  padding: var(--page-pad-y) var(--page-pad-x);
  background: var(--paper);
  overflow: hidden;
}

.page::before {
  content: none;
}

.page::after {
  content: none;
}

/* Reversed duplicate of the next page, clipped to the inner paper area. */
.verso-impression {
  position: absolute;
  inset: var(--page-pad-y) var(--page-pad-x);
  z-index: 0;
  color: var(--ink-ghost);
  transform: scaleX(-1) rotate(0.24deg) translateX(-0.6%);
  mix-blend-mode: multiply;
  opacity: 0.82;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.contents-impression {
  opacity: 0.46;
  transform: scaleX(-1) rotate(0.18deg) translateX(-1.4%);
}

.verso-impression * {
  color: inherit !important;
}

.verso-impression .page-header,
.verso-impression .poem-date,
.verso-impression .page-footer {
  color: rgba(34, 47, 43, 0.07) !important;
}

.verso-impression .home-mark {
  opacity: 0.075;
}

.verso-impression h1 {
  opacity: 0.5;
}

.verso-impression p:nth-child(2n) {
  opacity: 0.7;
}

.verso-inner {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* Poem pages can grow taller than the viewport for essays and long stories,
   while the footer stays after the natural end of the work. */
.poem-page .page-inner::before {
  content: none;
}

.page-inner {
  position: relative;
  z-index: 2;
  min-height: calc(min(980px, 100vh - 84px) - var(--page-pad-y) - var(--page-pad-y));
  display: flex;
  flex-direction: column;
}

.poem-page {
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.poem-page > .page-inner {
  flex: 0 1 auto;
  min-height: auto;
}

.poem-page > .page-footer {
  position: relative;
  z-index: 3;
}

/* Running header: site, Bowen mark, section. It uses the same typewriter face
   and size as the work text so the page furniture feels typed too. */
.page-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  color: var(--ink);
  font-size: var(--type-size);
  line-height: var(--type-line);
}

.page-header span:nth-child(3) {
  justify-self: end;
}

.home-link {
  justify-self: start;
  color: inherit;
  text-decoration: none;
}

.page-header .home-link:hover {
  color: var(--ink-strong);
}

.page-number {
  justify-self: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.index-page-header {
  margin-bottom: clamp(24px, 5vw, 50px);
}

.title-block {
  width: min(100%, var(--text-measure));
  margin: 0 auto clamp(32px, 6vw, 54px);
  text-align: center;
}

.kicker {
  margin: 0 0 18px;
  color: var(--ink);
  font-size: var(--type-size);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: var(--type-size);
  font-weight: 400;
  line-height: var(--type-line);
}

.subtitle {
  max-width: 28rem;
  margin: 22px auto 0;
  color: var(--ink);
  font-size: var(--type-size);
}

.ornament {
  display: none;
}

/* Table of contents leaders use CSS dots instead of typed periods, keeping the
   link target clean while preserving the book-index rhythm. */
.toc {
  width: min(100%, 590px);
  margin: 0;
}

.section {
  margin: 0 0 42px;
}

.section-title {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: var(--type-size);
  font-weight: 400;
}

.section-description {
  margin: 0 0 18px;
  color: var(--ink);
  font-size: var(--type-size);
}

.toc-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.toc-link {
  display: flex;
  align-items: end;
  gap: 10px;
  min-height: 38px;
  color: var(--ink);
  font-size: var(--type-size);
  text-decoration: none;
}

.toc-link::after {
  order: 2;
  flex: 1 1 auto;
  margin-bottom: 0.55em;
  border-bottom: 1px dotted var(--rule);
  content: "";
}

.toc-link:hover .toc-title {
  color: var(--ink-strong);
}

.toc-title {
  order: 1;
  flex: 0 1 auto;
}

.toc-number {
  order: 3;
  flex: 0 0 auto;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.poem-header {
  width: min(100%, var(--text-measure));
  margin: clamp(36px, 6vw, 58px) 0 clamp(24px, 4vw, 36px);
  text-align: left;
}

.poem-header h1 {
  font-size: var(--type-size);
}

.work-author {
  margin: 0.75em 0 0;
  color: var(--ink);
  font-size: var(--type-size);
}

.work-author a {
  color: inherit;
  text-decoration: none;
}

.work-author a:hover {
  color: var(--ink-strong);
}

.poem-date {
  margin: 0.45em 0 0;
  color: var(--ink);
  font-size: var(--type-size);
}

/* Main work text. Markdown line breaks become <br>, so stanza and draft-like
   spacing are controlled mostly by paragraph margins here. */
.poem {
  width: min(100%, var(--text-measure));
  margin: 0;
  color: var(--ink);
  font-size: var(--type-size);
}

.poem p {
  margin: 0 0 1.35em;
}

/* Blockquotes use a typed quotation mark rather than a modern rule/bar. */
.poem blockquote {
  position: relative;
  margin: 1.7em 0 1.7em 1.25em;
  padding-left: 1.1em;
  color: var(--ink);
}

.poem blockquote::before {
  content: '"';
  position: absolute;
  left: -0.85em;
  top: 0;
  color: var(--ink);
  font-size: var(--type-size);
  line-height: var(--type-line);
  opacity: 0.68;
  transform: rotate(-4deg);
}

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

.poem hr {
  width: 7rem;
  margin: 2rem auto;
  border: 0;
  border-top: 1px solid var(--rule);
}

.typed-break,
.end-mark {
  color: var(--ink);
  font-size: var(--type-size);
  letter-spacing: 0.2em;
  text-align: center;
}

.typed-break {
  margin: 2.2em 0;
}

.end-mark {
  margin: clamp(38px, 7vw, 70px) 0 0;
}

.printed-figure {
  width: min(100%, 32rem);
  margin: clamp(28px, 5vw, 48px) 0;
}

.printed-figure img {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0.56;
  mix-blend-mode: multiply;
  filter: url("#print-roughen");
}

.printed-figure figcaption {
  max-width: 26rem;
  margin: 0.85em 0 0;
  color: var(--ink);
  font-size: var(--type-size);
  line-height: var(--type-line);
}

/* Credits and blogroll reuse the poem text system so the final page still feels
   like part of the same manuscript. */
.credits-header {
  margin-bottom: clamp(24px, 4vw, 34px);
}

.credits-list,
.blogroll-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.credits-list {
  display: grid;
  gap: 0.9em;
}

.credits-list li {
  display: grid;
  grid-template-columns: minmax(7rem, 0.45fr) 1fr;
  gap: 1rem;
}

.credits-list span:first-child,
.blogroll h2 {
  color: var(--ink);
}

.blogroll {
  margin-top: clamp(34px, 6vw, 56px);
}

.blogroll h2 {
  margin: 0 0 0.9em;
  font-size: var(--type-size);
  font-weight: 400;
}

.blogroll-list {
  display: grid;
  gap: 0.45em;
}

/* Footer navigation. On small screens these sit at the bottom of the page; a
   desktop media query turns them into sticky side-gutter controls. */
.page-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
  margin-top: auto;
  padding-top: clamp(38px, 7vw, 72px);
  color: var(--ink);
  font-size: var(--type-size);
  line-height: var(--type-line);
}

.page-footer a {
  min-height: 34px;
  color: var(--ink);
  text-decoration: none;
}

.page-footer a:hover {
  color: var(--ink-strong);
}

.prev {
  justify-self: start;
}

.next {
  justify-self: end;
}

.page-arrow {
  width: var(--nav-hit-size);
  min-width: var(--nav-hit-size);
  height: var(--nav-hit-size);
  min-height: var(--nav-hit-size);
  border: 0;
  border-radius: 0;
  background: transparent;
  display: inline-grid;
  place-items: center;
  color: var(--ink-strong);
  font-size: 0;
  line-height: 1;
  text-decoration: none;
  position: relative;
  transform: rotate(-3deg);
}

.page-footer .page-arrow {
  color: var(--ink-strong);
}

.page-arrow:hover {
  background: transparent;
  color: var(--ink);
}

.page-footer .page-arrow:hover {
  color: var(--ink);
}

.page-arrow::before {
  content: "<";
  display: block;
  color: currentColor;
  font-size: 1.3rem;
  line-height: 1;
  transform: translateY(0.03rem) rotate(-2deg);
}

.page-arrow.prev::before {
  content: "<";
  transform: translateY(0.03rem) rotate(-2deg);
}

.page-arrow.next::before {
  content: ">";
  transform: translateY(0.03rem) rotate(2deg);
}

/* Prefer custom chevron artwork when CSS masks are supported; fall back to
   ordinary text glyphs in older browsers. */
@supports ((mask: url("")) or (-webkit-mask: url(""))) {
  .page-arrow::before {
    content: "";
    width: 58%;
    height: 58%;
    background: currentColor;
    -webkit-mask: url("/nav-chevron-left.png") center / contain no-repeat;
    mask: url("/nav-chevron-left.png") center / contain no-repeat;
    transform: translateX(-0.02rem) rotate(-2deg);
  }

  .page-arrow.prev::before {
    content: "";
    transform: translateX(-0.02rem) rotate(-2deg);
  }

  .page-arrow.next::before {
    content: "";
    -webkit-mask: url("/nav-chevron-right.png") center / contain no-repeat;
    mask: url("/nav-chevron-right.png") center / contain no-repeat;
    transform: translateX(0.02rem) rotate(2deg);
  }
}

/* Bowen cross home mark. The image is oversized inside its box to match the
   visual weight of the custom navigation arrows. */
.home-mark {
  justify-self: center;
  width: var(--control-size);
  height: var(--control-size);
  min-height: var(--control-size);
  display: inline-grid;
  place-items: center;
  opacity: 0.68;
  mix-blend-mode: multiply;
  text-decoration: none;
  transform: rotate(1.2deg);
}

.home-mark:hover {
  opacity: 0.78;
}

.home-mark img {
  display: block;
  width: 148%;
  height: 148%;
  object-fit: contain;
}

/* High Contrast / forced-color mode swaps paper and ink to system colors so
   the site remains readable even if the printed-paper illusion is disabled. */
@media (forced-colors: active) {
  :root {
    --ink: CanvasText;
    --ink-strong: CanvasText;
    --link: LinkText;
    --focus: Highlight;
    --paper: Canvas;
    --rule: CanvasText;
  }

  .page-arrow::before,
  .home-mark img {
    forced-color-adjust: auto;
  }
}

.empty-state {
  width: min(100%, 560px);
  margin: 0 auto;
  color: var(--ink);
  text-align: center;
}

@media (min-width: 1080px) {
  .book-shell {
    padding: 52px 0;
  }
}

@media (min-width: 900px) {
  .poem-page > .page-footer {
    position: absolute;
    inset: 0;
    display: block;
    margin: 0;
    padding: 0;
    pointer-events: none;
  }

  .poem-page > .page-footer > span:not(.page-number) {
    display: none;
  }

  .poem-page > .page-footer .page-arrow {
    position: fixed;
    top: 50vh;
    pointer-events: auto;
    z-index: 4;
  }

  .poem-page > .page-footer .page-arrow.prev {
    left: max(8px, calc(((100vw - var(--max-page)) / 4) - (var(--nav-hit-size) / 2)));
    transform: translateY(-50%) rotate(-3deg);
  }

  .poem-page > .page-footer .page-arrow.next {
    right: max(8px, calc(((100vw - var(--max-page)) / 4) - (var(--nav-hit-size) / 2)));
    left: auto;
    transform: translateY(-50%) rotate(3deg);
  }

  .poem-page > .page-footer .page-number {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    pointer-events: auto;
  }
}

@media (max-width: 640px) {
  .book-shell {
    width: 100%;
    padding: 0;
  }

  .page {
    --page-pad-y: 28px;
    --page-pad-x: 22px;
    min-height: 100vh;
  }

  .page::after {
    inset: 10px;
  }

  .verso-impression {
    inset: var(--page-pad-y) var(--page-pad-x);
    opacity: 0.58;
    filter: blur(1.2px);
  }

  .page-header {
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
  }

  .page-footer {
    text-align: center;
  }

  .credits-list li {
    grid-template-columns: 1fr;
    gap: 0.1em;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .page {
    animation: settle 420ms ease-out both;
  }

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