/* Dream Catcher — one stylesheet, no framework. */

:root {
  --bg: #101821;
  --bg-raised: #151f2a;
  --surface: #18232f;
  --ink: #f2ece2;
  --ink-soft: #d9d3c8;
  --muted: #a9abb4;
  --accent: #bda88a;
  --accent-strong: #d6c19f;
  --rule: rgba(189, 168, 138, 0.28);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 40px -24px rgba(0, 0, 0, 0.7);

  --serif: Literata, "Iowan Old Style", Charter, Georgia, serif;
  --display: "Cormorant Garamond", "Cormorant", Garamond, "Times New Roman", serif;

  --measure: 34rem;
  --gutter: clamp(1.25rem, 5vw, 2.5rem);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f5f0e6;
  --bg-raised: #efe8db;
  --surface: #ebe3d4;
  --ink: #26221d;
  --ink-soft: #3a342d;
  --muted: #6c655b;
  --accent: #8a6a3a;
  --accent-strong: #6e5226;
  --rule: rgba(138, 106, 58, 0.3);
  --shadow: 0 20px 40px -28px rgba(60, 40, 10, 0.45);
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 4rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.0625rem, 0.98rem + 0.35vw, 1.1875rem);
  line-height: 1.7;
  font-optical-sizing: auto;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

main { flex: 1; }

a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 0.2em; }
a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip {
  position: absolute; left: 1rem; top: -3rem; z-index: 10;
  background: var(--ink); color: var(--bg); padding: 0.5rem 0.9rem; border-radius: 4px;
}
.skip:focus { top: 1rem; }

/* ── top bar ───────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.1rem var(--gutter);
  max-width: 72rem; width: 100%; margin: 0 auto;
}
.brand {
  font-family: var(--display); font-weight: 600; font-size: 1.2rem;
  letter-spacing: 0.14em; text-transform: uppercase; text-decoration: none;
  color: var(--ink-soft);
}
.home .brand { visibility: hidden; }
.tools { display: flex; align-items: center; gap: 1rem; font-size: 0.85rem; }
.langs { display: flex; align-items: center; gap: 0.45rem; letter-spacing: 0.08em; }
.lang { text-decoration: none; color: var(--muted); padding: 0.4rem 0.15rem; }
.lang.is-current { color: var(--ink); }
.sep { color: var(--rule); }
.theme-toggle {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border-radius: 50%; border: 1px solid var(--rule); background: transparent;
  color: var(--muted); cursor: pointer; padding: 0;
}
.theme-toggle:hover { color: var(--accent-strong); border-color: var(--accent); }

/* ── home ──────────────────────────────────────────────── */
.hero {
  text-align: center;
  max-width: 40rem; margin: 0 auto;
  padding: clamp(2rem, 8vw, 5.5rem) var(--gutter) clamp(2.5rem, 7vw, 4.5rem);
}
.eyebrow, .ep, .ps-label {
  font-family: var(--serif); font-size: 0.72rem; font-weight: 500;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent);
  margin: 0;
}
.site-title {
  font-family: var(--display); font-weight: 500;
  font-size: clamp(3.2rem, 2rem + 6vw, 6.25rem);
  line-height: 0.95; letter-spacing: -0.01em;
  margin: 0.9rem 0 1.4rem;
}
.intro { color: var(--ink-soft); font-size: 1.05em; }
.intro p { margin: 0 0 0.4rem; }
.intro p + p { color: var(--muted); font-size: 0.92em; font-style: italic; }
.byline {
  margin: 1.8rem 0 0; font-family: var(--display); font-size: 1.35rem; font-style: italic;
  color: var(--ink-soft);
}
.byline span { color: var(--muted); }

.tiles {
  list-style: none; margin: 0 auto; padding: 0 var(--gutter) clamp(3rem, 8vw, 6rem);
  max-width: 72rem;
  display: grid; gap: clamp(1rem, 2.5vw, 1.75rem);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 52rem) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 72rem) { .tiles { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
/* on two-column phones the published story gets a full-width row */
@media (max-width: 51.99rem) { .tiles > .tile:not(.is-soon):first-child { grid-column: 1 / -1; } }

.tile { position: relative; }
.tile > a { display: block; text-decoration: none; color: inherit; }
.cover {
  aspect-ratio: 3 / 4; border-radius: 3px; overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
}
.tile:not(.is-soon):first-child .cover { aspect-ratio: 3 / 4; }
@media (max-width: 51.99rem) { .tile:not(.is-soon):first-child .cover { aspect-ratio: 4 / 3; } }
.cover-art { display: block; width: 100%; height: 100%; object-fit: cover; }
.tile > a .cover-art { transition: transform 0.8s cubic-bezier(.2, .7, .2, 1); }
.tile > a:hover .cover-art, .tile > a:focus-visible .cover-art { transform: scale(1.035); }
.tile-meta { padding: 0.85rem 0.1rem 0; }
.tile-title {
  font-family: var(--display); font-weight: 500; font-size: 1.45rem; line-height: 1.1;
  margin: 0.3rem 0 0.35rem;
}
.tile-cta { font-size: 0.82rem; color: var(--muted); }
.tile > a:hover .tile-cta { color: var(--accent-strong); }
.tile.is-soon .cover { filter: grayscale(0.85) brightness(0.55) contrast(0.9); }
.tile.is-soon .tile-title { color: var(--muted); }
.tile.is-soon .tile-cta { font-style: italic; }

/* ── story ─────────────────────────────────────────────── */
.progress { position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 5; pointer-events: none; }
.progress span { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); }

.reading { padding: 0 var(--gutter); }
.story-head { text-align: center; max-width: 44rem; margin: 0 auto; padding-top: clamp(1.5rem, 6vw, 4rem); }
.story-title {
  font-family: var(--display); font-weight: 500;
  font-size: clamp(2.6rem, 1.6rem + 5vw, 4.75rem); line-height: 1; letter-spacing: -0.01em;
  margin: 0.8rem 0 0.9rem; text-wrap: balance;
}
.story-meta { color: var(--muted); font-size: 0.85rem; font-style: italic; margin: 0; }
.story-cover {
  margin: clamp(2rem, 6vw, 3.5rem) auto 0; max-width: 26rem;
  aspect-ratio: 3 / 4; border-radius: 3px; overflow: hidden; box-shadow: var(--shadow);
}
.cover-art { object-position: 50% 32%; }

.story, .postscript { max-width: var(--measure); margin: 0 auto; }
.story { padding-top: clamp(2.5rem, 7vw, 4.5rem); hanging-punctuation: first; }
.story p { margin: 0 0 1.15em; color: var(--ink); hyphens: auto; -webkit-hyphens: auto; text-wrap: pretty; }
.story > p:first-of-type::first-letter {
  font-family: var(--display); font-weight: 500; color: var(--accent);
  float: left; font-size: 4.1em; line-height: 0.82; margin: 0.08em 0.12em 0 0;
}
.story > p:first-of-type::first-line { font-variant: small-caps; letter-spacing: 0.04em; }

.story blockquote {
  margin: 1.8em 0; padding: 0.2em 0 0.2em 1.3em;
  border-left: 1px solid var(--accent);
  color: var(--ink-soft); font-style: italic;
}
.story blockquote p { margin-bottom: 0.9em; }
.story blockquote p:last-child { margin-bottom: 0; }
.story em { font-style: italic; }
.story blockquote em { font-style: normal; }

.story hr, .end-mark {
  border: 0; margin: 2.4em auto; text-align: center; color: var(--accent);
}
.story hr::before { content: "⁂"; font-size: 1.1rem; letter-spacing: 0.4em; }
.end-mark { font-size: 1.6rem; margin: 2.2rem 0 0; line-height: 1; }

.postscript {
  margin-top: clamp(3rem, 8vw, 5rem);
  padding: clamp(1.75rem, 5vw, 2.75rem) clamp(1.25rem, 5vw, 2.5rem);
  background: var(--bg-raised);
  border-top: 1px solid var(--rule);
  border-radius: 3px;
  font-size: 0.93em; line-height: 1.68; color: var(--ink-soft);
  max-width: calc(var(--measure) + 5rem);
}
.ps-title {
  font-family: var(--display); font-weight: 500; font-size: clamp(1.9rem, 1.5rem + 1.5vw, 2.4rem);
  line-height: 1.1; margin: 0.5rem 0 0.4rem; color: var(--ink);
}
.postscript > p:first-of-type { font-style: italic; color: var(--muted); margin-top: 0; }
.postscript p { margin: 0 0 1em; hyphens: auto; -webkit-hyphens: auto; text-wrap: pretty; }
.postscript strong { font-weight: 600; color: var(--ink); }
.postscript p:last-child { margin-bottom: 0; }

.story-nav {
  max-width: var(--measure); margin: 0 auto; padding: clamp(2.5rem, 7vw, 4rem) var(--gutter) 1rem;
  display: grid; gap: 1.2rem; grid-template-columns: 1fr 1fr; align-items: start;
}
.story-nav a { text-decoration: none; }
.story-nav .prev span, .story-nav .next span {
  display: block; font-size: 0.72rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent);
}
.story-nav .prev, .story-nav .next { font-family: var(--display); font-size: 1.35rem; line-height: 1.2; }
.story-nav .next, .story-nav .more-soon { text-align: right; }
.story-nav .more-soon { margin: 0; color: var(--muted); font-style: italic; font-size: 0.92rem; }
.story-nav .back {
  grid-column: 1 / -1; justify-self: center; margin-top: 1.5rem;
  font-size: 0.9rem; color: var(--muted);
  border: 1px solid var(--rule); border-radius: 999px; padding: 0.55rem 1.1rem;
}
.story-nav .back:hover { border-color: var(--accent); }

.resume {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 6; font: inherit; font-size: 0.88rem; cursor: pointer;
  background: var(--ink); color: var(--bg); border: 0; border-radius: 999px;
  padding: 0.7rem 1.2rem; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

/* ── footer ────────────────────────────────────────────── */
.footer {
  text-align: center; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.04em;
  padding: 2.5rem var(--gutter) calc(2.5rem + env(safe-area-inset-bottom));
}
.footer a { text-decoration: none; }

.notfound .hero { padding-top: 12vh; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .topbar, .story-nav, .resume, .progress, .footer, .story-cover { display: none !important; }
  body { background: #fff; color: #000; font-size: 11.5pt; }
  .postscript { background: none; }
}
