/* FlowerMoon reading edition — Emil-led detail and long-form layer
   Scope: main content only. The shared site header/navigation remains upstream-owned.
   Apply after site.css, archive/read/styles.css, or wechat-reading/style.css. */

:root {
  --reader-paper: #f5f0e8;
  --reader-paper-deep: #ebe2d6;
  --reader-ink: #241c1b;
  --reader-muted: #726663;
  --reader-rule: #d3c5ba;
  --reader-berry: #702d3a;
  --reader-berry-deep: #4f1f2b;
  --reader-berry-wash: #ead8d8;
  --reader-measure: 44rem;
  --reader-wide: 78rem;
  --reader-radius: 2px;
  --reader-ease-out: cubic-bezier(.23, 1, .32, 1);
  color-scheme: light;
}

html { background: var(--reader-paper); }
body {
  background: var(--reader-paper);
  color: var(--reader-ink);
  font-family:-apple-system, BlinkMacSystemFont, "FMC Sans SC", "PingFang SC", "苹方-简", "Helvetica Neue", Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

/* Keep scope below the shared header. */
body > main,
body > #app { box-sizing: border-box; }
body > main :where(a),
body > #app :where(a) { color: var(--reader-berry); text-decoration-thickness: .08em; text-underline-offset: .18em; }
body > main :where(a:hover, a:focus-visible),
body > #app :where(a:hover, a:focus-visible) { color: var(--reader-berry-deep); }

/* Film detail: factual masthead first, then discoverable material. */
main.wrap,
main.reader {
  max-width: var(--reader-wide);
  margin-inline: auto;
  padding-block: clamp(2.2rem, 6vw, 5.5rem) clamp(4rem, 8vw, 8rem);
}
main.wrap > .back-link,
main.reader > .back-link,
main > .back {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  margin-bottom: clamp(2rem, 5vw, 4.5rem);
  color: var(--reader-muted);
  font-size:12px;
  letter-spacing: .06em;
}
main.wrap > .eyebrow,
main.reader > .eyebrow {
  margin:0 0 12px;
  color: var(--reader-berry);
  font-size:12px;
  font-weight: 700;
  letter-spacing: .14em;
  line-height: 1.4;
  text-transform: uppercase;
}
main.wrap > h1,
main.reader > h1 {
  max-width: 13ch;
  margin: 0;
  color: var(--reader-ink);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size: clamp(2.5rem, 7vw, 6.4rem);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height:1;
  text-wrap: balance;
}
main.wrap > .lead {
  max-width: 42rem;
  margin:24px 0 0;
  color: var(--reader-muted);
  font-size: clamp(1rem, 1.8vw, 1.25rem);
  line-height:1.5;
}

/* Static, useful film navigation: emitted only when real h2 count > 1. */
.reader-toc {
  max-width: var(--reader-measure);
  margin:32px auto clamp(2.8rem, 6vw, 5.5rem);
  padding:16px 0 16px;
  border-block: 1px solid var(--reader-rule);
}
.reader-toc-label {
  margin:0 0 8px;
  color: var(--reader-muted);
  font-size:12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.reader-toc ol {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap:4px 28px;
  margin: 0;
  padding-left: 1.35rem;
}
.reader-toc li { padding:4px 0; }
.reader-toc a { font-size:15px; line-height:1.4; }

/* Actual archive detail/directory templates beyond archive/read/. */
main.archive-detail .reader-body,
main.translation-page .reader-body,
main.archive-directory-page .archive-directory {
  max-width: var(--reader-measure);
  margin-inline: auto;
}
main.archive-detail .reader-body > h2,
main.translation-page .reader-body > h2,
main.archive-detail .reader-body > h3,
main.translation-page .reader-body > h3 {
  margin:44px 0 16px;
  padding-top: 1rem;
  border-top: 1px solid var(--reader-rule);
  color: var(--reader-berry-deep);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size: clamp(1.35rem, 2.7vw, 2rem);
  font-weight: 500;
}
main.archive-detail .reader-credit,
main.archive-detail .source-links,
main.archive-detail .archive-functions {
  max-width: var(--reader-measure);
  margin:12px auto;
  color: var(--reader-muted);
  font-size:14px;
  line-height: 1.7;
}
main.archive-detail .reader-body :where(p, li),
main.archive-detail .reader-body :where(blockquote) {
  font-size: clamp(1rem, 1.25vw, 1.1rem);
  line-height:1.8;
}
main.archive-directory-page .archive-directory { padding-left: 1.35rem; }
main.archive-directory-page .archive-directory li { margin:0 0 20px; }
main.archive-directory-page .archive-directory p { margin:4px 0 0; color: var(--reader-muted); line-height:1.6; }

/* Reader letters: form/thread remain functional; only the content rail is styled. */
body > main > .hero,
body > main > .panel,
body > main > .thread-area {
  max-width: var(--reader-measure);
  margin-inline: auto;
}
body > main > .hero { margin-bottom: clamp(3rem, 7vw, 6rem); }
body > main > .hero h1,
body > main > .panel h2,
body > main > .thread-area h2 {
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-weight: 500;
  letter-spacing: -.03em;
}
body > main > .hero h1 { font-size: clamp(2.4rem, 7vw, 5rem); line-height: 1; }
body > main > .panel,
body > main > .thread-area { margin-top: 2rem; }

/* Topic/language switches are orientation, not a second title. */
.topic-languages {
  display: flex;
  flex-wrap: wrap;
  gap:4px 12px;
  margin:20px 0 clamp(2.8rem, 6vw, 5.5rem);
  color: var(--reader-muted);
  font-size:12px;
  letter-spacing: .05em;
}
.topic-current { color: var(--reader-ink); font-weight: 700; }

/* Film details and prose share a calm editorial measure. */
main.wrap > section,
main.wrap > details,
main.reader > article,
main.wrap > article {
  max-width: var(--reader-measure);
  margin-inline: auto;
}
main.wrap > section:first-of-type,
main.wrap > article:first-of-type,
main.reader > article { margin-top: clamp(3rem, 8vw, 8rem); }
main.wrap section + section,
main.wrap article + section,
main.reader article + section { margin-top: clamp(2.5rem, 6vw, 5.5rem); }

main.wrap section > h2,
main.wrap section > h3,
main.reader article > h2,
main.reader article > h3 {
  margin:0 0 20px;
  padding-top: 1rem;
  border-top: 1px solid var(--reader-rule);
  color: var(--reader-berry-deep);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  font-weight: 500;
  letter-spacing: -.025em;
  line-height: 1.1;
}
main.wrap section > p,
main.wrap article > p,
main.reader article > p,
main.reader article > blockquote,
main.reader article > ul,
main.reader article > ol {
  max-width: var(--reader-measure);
  margin:0 0 20px;
  font-size: clamp(1rem, 1.25vw, 1.14rem);
  line-height:1.8;
}
main.reader article > p:first-child { font-size:16px; }
main.reader article > h1 { display: none; }
main.reader article > :where(h4, h5, h6) {
  margin:44px 0 12px;
  color: var(--reader-berry-deep);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-weight: 600;
}
main.reader article > blockquote {
  margin-block: 2.25rem;
  padding:20px 24px;
  border-inline-start: 3px solid var(--reader-berry);
  background: var(--reader-berry-wash);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size: 1.16em;
}
main.reader article > :where(ul, ol) { padding-inline-start: 1.35em; }

/* Source-book contents: keep extracted entries distinct at narrow widths. */
.reader-source-toc {
  max-width: var(--reader-measure);
  margin:0 0 32px;
  padding:16px 0 16px;
  border-block: 1px solid var(--reader-rule);
}
.reader-source-toc-title {
  margin:0 0 12px;
  color: var(--reader-muted);
  font-size:12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.reader-source-toc ul {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
  gap:4px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.reader-source-toc li {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--reader-ink);
  font-size:15px;
  line-height:1.4;
}
@media (max-width: 700px) {
  .reader-source-toc ul { grid-template-columns: 1fr; }
}

/* Resource discovery: visible without scripting, collapsible with native details. */
main :where(details) {
  border-block: 1px solid var(--reader-rule);
  background: color-mix(in srgb, var(--reader-paper-deep) 42%, transparent);
}
main :where(details + details) { border-top: 0; }
main :where(summary) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap:16px;
  min-height: 3.7rem;
  padding:12px 0;
  cursor: pointer;
  color: var(--reader-berry-deep);
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size:17px;
  list-style: none;
}
main :where(summary::-webkit-details-marker) { display: none; }
main :where(summary)::after { content: "+"; font-family: -apple-system, sans-serif; font-size:22px; font-weight: 300; }
main :where(details[open] > summary)::after { content: "−"; }
main :where(details > :not(summary)) { padding-bottom: 1.25rem; }
main :where(details a, main details button) { font-size:15px; }

/* Preserve media playback, but make it belong to the page. */
main :where(audio, video, iframe) { display: block; max-width: 100%; }
main :where(audio) { width: 100%; margin:24px 0 32px; }
main :where(video, iframe) { width: min(100%, 60rem); margin:32px auto; border: 1px solid var(--reader-rule); background: #1d1717; }
main :where(figure) { margin:44px 0; }
main :where(figure img) { display: block; width: 100%; height: auto; }
main :where(figcaption) { margin-top: .65rem; color: var(--reader-muted); font-size:12px; letter-spacing: .04em; }

/* Long WeChat article: preserve every paragraph/image, improve rhythm only. */
body > main:not(.reader):not(.wrap) {
  max-width: var(--reader-measure);
  margin-inline: auto;
  padding:32px 16px 96px;
}
body > main:not(.reader):not(.wrap) > article > h1 {
  margin:0 0 16px;
  font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif;
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  font-weight: 500;
  letter-spacing: -.045em;
  line-height: 1;
}
body > main:not(.reader):not(.wrap) > article > p { margin:0 0 20px; line-height:1.8; }
body > main:not(.reader):not(.wrap) > article > p:nth-of-type(1) { color: var(--reader-muted); font-size:14px; }
body > main:not(.reader):not(.wrap) figure.illustration { margin-block: 2.5rem; }
body > main:not(.reader):not(.wrap) figure.illustration img { width: 100%; }

/* Archive reader app: works while data loads and after JS renders attachments. */
body:has(> .topbar) { background: var(--reader-paper); }
body > .topbar + #app,
body > #app {
  max-width: var(--reader-wide);
  margin-inline: auto;
  padding:clamp(2rem, 5vw, 5rem) 16px 112px;
}
#app :where(.notice, .error, .loading) {
  max-width: var(--reader-measure);
  margin:32px auto;
  padding:16px 20px;
  border-inline-start: 3px solid var(--reader-berry);
  background: var(--reader-berry-wash);
  line-height: 1.7;
}
#app :where(.attachment, .document, .archive-item, article) { max-width: var(--reader-measure); margin-inline: auto; }
#app :where(h1, h2, h3) { font-family:Georgia, "FMC Sans SC", "Songti SC", "STSong", serif; font-weight: 500; letter-spacing: -.03em; }
#app :where(p, li) { font-size:17px; line-height:1.8; }
#app :where(img) { max-width: 100%; height: auto; }

:where(button, a, summary, input, select):focus-visible { outline: 2px solid var(--reader-berry); outline-offset: 4px; }
:where(a, button, summary) { transition:color var(--dur-2) var(--reader-ease-out), background-color var(--dur-2) var(--reader-ease-out); }
:where(button, summary) { transition-property: color, background-color, transform; }
:where(button, summary):active { transform: scale(.98); }

@media (min-width: 720px) {
  main.wrap, main.reader { padding-inline: 2rem; }
  body > main:not(.reader):not(.wrap) { padding-inline: 2rem; }
  main.wrap > section, main.wrap > article, main.reader > article { margin-left: clamp(8rem, 18vw, 18rem); }
  main.wrap > section:first-of-type, main.wrap > article:first-of-type, main.reader > article { position: relative; }
  main.wrap > section:first-of-type::before, main.reader > article::before {
    content: "";
    position: absolute;
    top: .15rem;
    right: calc(100% + 2rem);
    width: 5rem;
    border-top: 1px solid var(--reader-berry);
  }
}

@media (max-width: 520px) {
  main.wrap, main.reader { padding-inline: 1rem; }
  main.wrap > h1, main.reader > h1 { font-size: clamp(2.35rem, 14vw, 4rem); }
  main :where(p, li) { line-height:1.8; }
  main :where(figure) { margin-inline: -.15rem; }
}

@media (prefers-reduced-motion: reduce) {
  :where(a, button, summary) { transition-duration: 0ms; }
}

@media (prefers-color-scheme: dark) {
  html[data-theme="dark"] { color-scheme: dark; }
}
html[data-theme="dark"] {
  --reader-paper: #201a1b;
  --reader-paper-deep: #2b2223;
  --reader-ink: #eee5dc;
  --reader-muted: #b9aaa4;
  --reader-rule: #55464a;
  --reader-berry: #d18a93;
  --reader-berry-deep: #efb2b8;
  --reader-berry-wash: #3c292e;
}


/**
  Reading finish17: width, hierarchy and edge-case legibility.
  Scoped to reading screens; the discovery homepage is intentionally excluded.
*/
main:not(.discovery-home) .reader,
main:not(.discovery-home) .reader-body,
main:not(.discovery-home) .translation-page,
main:not(.discovery-home) .archive-directory-page {
  min-width: 0;
}

main.reader,
main.wrap.reader,
main:not(.discovery-home) .reader-body,
main:not(.discovery-home) .archive-directory,
main:not(.discovery-home) .translation-page {
  --reader-measure: 68ch;
  width: min(100%, var(--reader-measure));
  max-width: 100%;
}

/* Titles, translations, and source lines must yield before the viewport does. */
main:not(.discovery-home) .reader :where(a, p, li, dt, dd, h1, h2, h3, h4, h5, h6, figcaption, summary),
main:not(.discovery-home) .reader-body :where(a, p, li, dt, dd, h1, h2, h3, h4, h5, h6, figcaption, summary),
main:not(.discovery-home) .translation-page :where(a, p, li, dt, dd, h1, h2, h3, h4, h5, h6, figcaption, summary) {
  min-width: 0;
  overflow-wrap: anywhere;
}
main:not(.discovery-home) .reader > h1,
main:not(.discovery-home) .wrap.reader > h1 {
  max-width: min(100%, 20ch);
  text-wrap: balance;
}
main:not(.discovery-home) .reader article > p,
main:not(.discovery-home) .reader article > li,
main:not(.discovery-home) .reader-body :where(p, li) {
  line-height: clamp(1.65, 1.8vw, 1.95);
}

/* At 200% zoom the editorial side rail must not consume the reading width. */
@media (min-width: 720px) {
  main:not(.discovery-home) .wrap > section,
  main:not(.discovery-home) .wrap > article,
  main:not(.discovery-home).reader > article {
    width: min(100%, var(--reader-measure));
    margin-inline: auto;
  }
  main:not(.discovery-home) .wrap > section:first-of-type::before,
  main:not(.discovery-home).reader > article::before {
    display: none;
  }
}

/* Empty, loading, and error states stay legible without inventing content. */
main:not(.discovery-home) :where(.empty, .empty-state, .no-results, .empty-note, .notice, .error, .loading) {
  max-width: min(100%, var(--reader-measure));
  margin-inline: auto;
  padding:20px 20px;
  border-inline-start: 3px solid var(--reader-berry);
  background: var(--reader-paper-deep);
  color: var(--reader-ink);
  line-height: 1.7;
}

/* Tables and media scroll or shrink inside the rail instead of pushing the page. */
main:not(.discovery-home) :where(table) {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}
main:not(.discovery-home) :where(iframe, video, audio, img) {
  max-width: 100%;
  height: auto;
}

/* The live site uses night; retain pure white day and high-contrast night text. */
html[data-theme="night"] {
  color-scheme: dark;
  --reader-ink: #f5f5f7;
  --reader-muted: #b5b5ba;
  --reader-rule: #48484a;
  --reader-berry: #64b5ff;
  --reader-berry-deep: #8abfff;
  --reader-berry-wash: #2c2c2e;
}


/* The main element itself carries .reader on film/long-form pages. */
main:not(.discovery-home).reader :where(a, p, li, dt, dd, h1, h2, h3, h4, h5, h6, figcaption, summary) {
  min-width: 0;
  overflow-wrap: anywhere;
}
main:not(.discovery-home).reader > h1 {
  max-width: min(100%, 20ch);
  text-wrap: balance;
}


html[data-theme="night"] main:not(.discovery-home).reader,
html[data-theme="night"] main:not(.discovery-home) .reader-body,
html[data-theme="night"] main:not(.discovery-home) .translation-page {
  background: var(--reader-paper);
  color: var(--reader-ink);
}


/* Reading canvases stay pure white by day, independent of the untouched homepage. */
main.reader,
main.wrap.reader,
main:not(.discovery-home) .reader-body,
main:not(.discovery-home) .translation-page {
  --reader-paper: #fff;
  --reader-paper-deep: #f5f5f7;
  background: var(--reader-paper);
}
html[data-theme="night"] main.reader,
html[data-theme="night"] main.wrap.reader,
html[data-theme="night"] main:not(.discovery-home) .reader-body,
html[data-theme="night"] main:not(.discovery-home) .translation-page {
  --reader-paper: #1c1c1e;
  --reader-paper-deep: #2c2c2e;
}


/* Keep article titles prominent without letting a long translated title dominate the page. */
main:not(.discovery-home).reader > h1,
main:not(.discovery-home).wrap.reader > h1 {
  font-size: clamp(2.35rem, 5vw, 4.5rem);
  line-height:1.1;
}
