@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;1,500;1,600&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  --ink: #f5f0e9;
  --ink-soft: #b9b2c6;
  --ink-faint: #82798f;
  --bg: #111021;
  --bg-deep: #0b0a14;
  --panel: rgba(29, 25, 47, 0.82);
  --panel-solid: #1d1930;
  --line: rgba(227, 216, 246, 0.13);
  --line-strong: rgba(227, 216, 246, 0.24);
  --portal: #c99af4;
  --portal-soft: rgba(201, 154, 244, 0.15);
  --gold: #e7c988;
  --gold-soft: rgba(231, 201, 136, 0.14);
  --green: #9ed9ba;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.32);
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'DM Sans', Arial, sans-serif;
  --measure: 69ch;
}

:root.theme-light {
  color-scheme: light;
  --ink: #241e32;
  --ink-soft: #655a72;
  --ink-faint: #948aa0;
  --bg: #f3efe8;
  --bg-deep: #e8e0d5;
  --panel: rgba(255, 252, 246, 0.88);
  --panel-solid: #fffaf2;
  --line: rgba(36, 30, 50, 0.13);
  --line-strong: rgba(36, 30, 50, 0.25);
  --portal: #8555b2;
  --portal-soft: rgba(133, 85, 178, 0.11);
  --gold: #ad7927;
  --gold-soft: rgba(173, 121, 39, 0.12);
  --green: #3f8a67;
  --shadow: 0 28px 80px rgba(75, 55, 32, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
  transition: background .35s ease, color .35s ease;
}
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
::selection { color: var(--bg-deep); background: var(--gold); }

.noise {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  opacity: .032;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
}

.site-header {
  width: min(1240px, calc(100% - 48px));
  margin: 0 auto;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  z-index: 5;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-family: var(--serif);
  font-size: 26px;
  font-style: italic;
  font-weight: 600;
  letter-spacing: -.02em;
}
.wordmark-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border: 1px solid var(--portal);
  border-radius: 50% 50% 45% 45%;
  color: var(--portal);
  font-family: var(--sans);
  font-size: 13px;
  font-style: normal;
  transform: rotate(-8deg);
  box-shadow: 0 0 0 5px var(--portal-soft);
}
.header-actions { display: flex; align-items: center; gap: 12px; }
.header-link, .icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease, transform .2s ease;
}
.header-link { padding: 10px 12px; font-size: 13px; font-weight: 600; }
.header-link:hover, .header-link:focus-visible { color: var(--ink); }
.login-link { color: var(--portal); }
.user-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 190px; overflow: hidden; color: var(--ink-soft); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.user-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 18%, transparent); }
.icon-button {
  width: 39px;
  height: 39px;
  display: grid;
  place-items: center;
  border-color: var(--line);
  border-radius: 50%;
}
.icon-button:hover, .icon-button:focus-visible { color: var(--portal); border-color: var(--portal); background: var(--portal-soft); transform: translateY(-1px); }
.icon-button svg { width: 17px; height: 17px; }

.home-main { overflow: hidden; }
.hero {
  width: min(1240px, calc(100% - 48px));
  min-height: 570px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, .95fr);
  align-items: center;
  gap: 40px;
  padding: 52px 0 76px;
  position: relative;
}
.hero::before {
  content: '';
  position: absolute;
  top: 2%;
  left: -20%;
  width: 72%;
  height: 80%;
  background: radial-gradient(circle, var(--portal-soft), transparent 67%);
  pointer-events: none;
}
.eyebrow, .chapter-kicker, .meta-label, .archive-label {
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  line-height: 1.4;
  text-transform: uppercase;
}
.hero-copy { position: relative; z-index: 1; max-width: 650px; }
.hero h1 {
  max-width: 720px;
  margin: 18px 0 17px;
  font-family: var(--serif);
  font-size: clamp(72px, 11vw, 148px);
  font-weight: 500;
  letter-spacing: -.07em;
  line-height: .73;
}
.hero h1 em { color: var(--portal); font-weight: 400; }
.hero-lede {
  max-width: 510px;
  margin: 0;
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1.65;
}
.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 31px; }
.signed-note { margin: 19px 0 0; color: var(--ink-faint); font-size: 12px; line-height: 1.55; }
.primary-button, .ghost-button {
  min-height: 47px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .02em;
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.primary-button { padding: 0 20px; border: 1px solid var(--portal); color: #180f22; background: var(--portal); box-shadow: 0 12px 26px rgba(161, 105, 203, .2); }
.primary-button:hover, .primary-button:focus-visible { transform: translateY(-2px); box-shadow: 0 16px 30px rgba(161, 105, 203, .3); }
.ghost-button { padding: 0 18px; border: 1px solid var(--line-strong); background: transparent; color: var(--ink); }
.ghost-button:hover, .ghost-button:focus-visible { border-color: var(--portal); color: var(--portal); transform: translateY(-2px); }
.text-arrow { font-size: 18px; line-height: 0; }

.portal-art { min-height: 430px; display: grid; place-items: center; position: relative; }
.portal-glow { position: absolute; width: 80%; height: 80%; border-radius: 50%; background: radial-gradient(circle, rgba(201,154,244,.23), transparent 64%); filter: blur(12px); animation: breathe 8s ease-in-out infinite; }
.portal-ring { position: absolute; border: 1px solid rgba(201,154,244,.24); border-radius: 50%; transform: rotate(-19deg); }
.portal-ring.one { width: 78%; height: 48%; }
.portal-ring.two { width: 62%; height: 82%; transform: rotate(28deg); border-color: rgba(231,201,136,.25); }
.portal-ring.three { width: 45%; height: 92%; transform: rotate(76deg); border-color: rgba(201,154,244,.18); }
.portal-core { width: 215px; height: 300px; border: 1px solid var(--portal); border-radius: 50% 50% 46% 46%; transform: rotate(13deg); background: radial-gradient(ellipse at center, rgba(201,154,244,.18), rgba(17,16,33,.15) 55%, transparent 73%); box-shadow: 0 0 0 15px rgba(201,154,244,.045), 0 0 70px rgba(201,154,244,.22), inset 0 0 45px rgba(201,154,244,.1); position: relative; }
.portal-core::before, .portal-core::after { content: '✦'; position: absolute; color: var(--gold); font-size: 13px; animation: drift 6s ease-in-out infinite; }
.portal-core::before { top: 19%; left: -32%; }
.portal-core::after { bottom: 22%; right: -27%; font-size: 10px; animation-delay: -2.2s; }
.portal-caption { position: absolute; right: 2%; bottom: 7%; max-width: 160px; color: var(--ink-faint); font-family: var(--serif); font-size: 18px; font-style: italic; line-height: 1.15; }
.portal-caption::before { content: ''; display: block; width: 42px; border-top: 1px solid var(--gold); margin-bottom: 10px; }
@keyframes breathe { 0%,100% { transform: scale(.96); opacity: .78; } 50% { transform: scale(1.04); opacity: 1; } }
@keyframes drift { 0%,100% { transform: translate(0,0) rotate(0); } 50% { transform: translate(7px,-9px) rotate(13deg); } }

.stats-strip { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 25px 0 29px; display: flex; align-items: center; flex-wrap: wrap; gap: 42px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.stat { display: flex; align-items: baseline; gap: 10px; }
.stat strong { font-family: var(--serif); color: var(--ink); font-size: 31px; font-weight: 500; }
.stat span { color: var(--ink-faint); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; }
.global-progress { flex: 1 1 250px; min-width: 210px; margin-left: auto; }
.progress-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; color: var(--ink-faint); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.progress-track { height: 3px; overflow: hidden; background: var(--line); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--portal), var(--gold)); transition: width .45s ease; }

.section { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 78px 0 112px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 29px; }
.section-heading h2 { margin: 8px 0 0; font-family: var(--serif); font-size: clamp(38px, 5vw, 62px); font-weight: 500; letter-spacing: -.04em; line-height: .93; }
.section-note { max-width: 270px; margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.6; text-align: right; }
.search-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; border-bottom: 1px solid var(--line-strong); }
.search-wrap svg { width: 17px; color: var(--ink-faint); }
.search-input { width: 100%; padding: 15px 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 15px; }
.search-input::placeholder { color: var(--ink-faint); }
.chapter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.chapter-card { min-height: 214px; display: flex; flex-direction: column; justify-content: space-between; padding: 23px 24px 20px; border: 1px solid var(--line); background: var(--panel); position: relative; overflow: hidden; transition: transform .25s ease, border-color .25s ease, background .25s ease; }
.chapter-card::after { content: ''; position: absolute; right: -40px; bottom: -65px; width: 170px; height: 170px; border: 1px solid var(--line); border-radius: 50%; transition: transform .35s ease, border-color .35s ease; }
.chapter-card:hover { border-color: var(--portal); transform: translateY(-3px); background: var(--portal-soft); }
.chapter-card:hover::after { border-color: rgba(201,154,244,.35); transform: scale(1.1); }
.card-top { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.card-number { color: var(--portal); font-family: var(--serif); font-size: 37px; line-height: .85; }
.card-status { padding-top: 4px; color: var(--green); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.card-status.unread { color: var(--ink-faint); }
.chapter-card h3 { max-width: 420px; margin: 24px 0 7px; font-family: var(--serif); font-size: 32px; font-weight: 500; letter-spacing: -.03em; line-height: .96; }
.chapter-card p { max-width: 480px; margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.55; }
.card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.card-meta { color: var(--ink-faint); font-size: 11px; }
.card-link { position: relative; z-index: 1; color: var(--gold); font-size: 12px; font-weight: 700; }
.empty-state { padding: 32px 0; color: var(--ink-soft); font-family: var(--serif); font-size: 24px; font-style: italic; }

.editor-panel { width: min(1240px, calc(100% - 48px)); margin: 0 auto 110px; padding: 34px; border: 1px solid color-mix(in srgb, var(--portal) 42%, var(--line)); background: linear-gradient(135deg, var(--portal-soft), var(--panel)); box-shadow: var(--shadow); }
.editor-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.editor-heading h2 { margin: 8px 0 0; font-family: var(--serif); font-size: clamp(34px, 4vw, 52px); font-weight: 500; letter-spacing: -.04em; line-height: .95; }
.editor-badge { padding: 7px 10px; border: 1px solid var(--gold); color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.editor-intro { max-width: 650px; margin: 16px 0 26px; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
.editor-toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.editor-mode { color: var(--ink-faint); font-size: 12px; }
.editor-fields { display: grid; grid-template-columns: .65fr .9fr 1fr 1.5fr; gap: 12px; margin-bottom: 14px; }
.editor-panel label { display: flex; flex-direction: column; gap: 7px; color: var(--ink-faint); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.editor-panel input, .editor-panel select, .editor-panel textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 2px; outline: 0; background: var(--panel-solid); color: var(--ink); font-family: var(--sans); font-size: 14px; letter-spacing: normal; text-transform: none; }
.editor-panel input, .editor-panel select { height: 43px; padding: 0 12px; }
.editor-panel textarea { min-height: 260px; padding: 13px; resize: vertical; font-family: var(--serif); font-size: 18px; line-height: 1.45; }
.editor-panel input:focus, .editor-panel select:focus, .editor-panel textarea:focus { border-color: var(--portal); box-shadow: 0 0 0 3px var(--portal-soft); }
.editor-actions { display: flex; align-items: center; gap: 15px; margin-top: 16px; }
.editor-status { color: var(--green); font-size: 12px; }

.site-footer { width: min(1240px, calc(100% - 48px)); margin: 0 auto; padding: 26px 0 40px; border-top: 1px solid var(--line); color: var(--ink-faint); display: flex; justify-content: space-between; gap: 20px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }

.reader-main { padding-bottom: 92px; }
.reader-top { width: min(840px, calc(100% - 48px)); margin: 0 auto; padding: 38px 0 40px; }
.reader-topline { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 46px; }
.back-link { color: var(--ink-soft); font-size: 12px; font-weight: 600; }
.back-link:hover, .back-link:focus-visible { color: var(--portal); }
.reader-progress { display: flex; align-items: center; gap: 12px; color: var(--ink-faint); font-size: 11px; }
.reader-progress .progress-track { width: 115px; }
.chapter-heading { max-width: 710px; }
.chapter-heading h1 { margin: 16px 0 15px; font-family: var(--serif); font-size: clamp(54px, 8vw, 100px); font-weight: 500; letter-spacing: -.065em; line-height: .82; }
.chapter-heading .chapter-dek { max-width: 620px; margin: 0; color: var(--ink-soft); font-family: var(--serif); font-size: 22px; font-style: italic; line-height: 1.25; }
.reader-divider { display: flex; align-items: center; gap: 12px; margin: 30px 0 0; color: var(--gold); font-size: 12px; }
.reader-divider::before, .reader-divider::after { content: ''; height: 1px; flex: 1; background: var(--line); }
.reader-body { width: min(760px, calc(100% - 48px)); margin: 0 auto; padding: 28px 0 30px; }
.story-paragraph { margin: 0 auto 19px; color: var(--ink); font-family: var(--serif); font-size: 21px; line-height: 1.59; letter-spacing: .005em; }
.story-paragraph:first-child::first-letter { float: left; margin: 5px 8px 0 0; color: var(--portal); font-size: 4.4em; font-weight: 500; line-height: .69; }
.dialogue { max-width: 710px; margin: 23px auto; padding: 13px 18px 14px 20px; border-left: 2px solid var(--portal); background: linear-gradient(90deg, var(--portal-soft), transparent 76%); }
.dialogue-speaker { display: block; margin-bottom: 2px; color: var(--gold); font-family: var(--sans); font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.dialogue-text { display: block; color: var(--ink); font-family: var(--serif); font-size: 20px; line-height: 1.47; }
.chapter-ending { margin: 58px auto 20px; padding: 22px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .18em; text-align: center; text-transform: uppercase; }
.reader-nav { width: min(840px, calc(100% - 48px)); margin: 0 auto; padding: 30px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.nav-card { min-height: 98px; display: flex; flex-direction: column; justify-content: center; padding: 16px 19px; border: 1px solid var(--line); background: var(--panel); transition: border-color .2s ease, transform .2s ease; }
.nav-card:hover, .nav-card:focus-visible { border-color: var(--portal); transform: translateY(-2px); }
.nav-card.next { text-align: right; }
.nav-direction { color: var(--ink-faint); font-size: 10px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.nav-title { margin-top: 8px; font-family: var(--serif); font-size: 25px; line-height: 1; }
.reader-float { position: fixed; right: 24px; bottom: 24px; z-index: 4; display: flex; align-items: center; gap: 8px; padding: 9px 12px; border: 1px solid var(--line-strong); background: var(--panel-solid); box-shadow: var(--shadow); color: var(--ink-soft); font-size: 11px; }
.reader-float .mini-track { width: 75px; height: 3px; background: var(--line); }
.reader-float .mini-fill { height: 100%; background: var(--portal); }

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

.page-enter { animation: pageIn .55s ease both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; padding-top: 42px; }
  .portal-art { min-height: 340px; margin-top: -35px; }
  .portal-core { width: 170px; height: 240px; }
  .section-heading { align-items: start; flex-direction: column; }
  .section-note { max-width: 480px; text-align: left; }
  .chapter-grid { grid-template-columns: 1fr; }
  .editor-fields { grid-template-columns: 1fr 1fr; }
  .editor-fields label:last-child { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .site-header, .hero, .stats-strip, .section, .site-footer { width: min(100% - 30px, 1240px); }
  .site-header { min-height: 74px; }
  .header-link { display: none; }
  .user-chip { display: none; }
  .hero { min-height: unset; padding: 54px 0 55px; }
  .hero h1 { font-size: clamp(68px, 22vw, 108px); }
  .hero-lede { font-size: 15px; }
  .portal-art { min-height: 270px; margin-top: -10px; }
  .portal-core { width: 138px; height: 195px; }
  .portal-ring.one { width: 90%; }
  .portal-caption { right: 0; bottom: -3px; font-size: 16px; }
  .stats-strip { gap: 18px 26px; }
  .stat strong { font-size: 26px; }
  .global-progress { flex-basis: 100%; margin-left: 0; }
  .section { padding: 58px 0 76px; }
  .chapter-card { min-height: 190px; padding: 19px; }
  .chapter-card h3 { font-size: 29px; }
  .site-footer { flex-direction: column; padding-bottom: 28px; }
  .reader-top, .reader-body, .reader-nav { width: min(100% - 30px, 840px); }
  .reader-top { padding-top: 20px; }
  .reader-topline { margin-bottom: 39px; }
  .reader-progress .progress-track { width: 66px; }
  .chapter-heading h1 { font-size: clamp(58px, 17vw, 86px); }
  .chapter-heading .chapter-dek { font-size: 19px; }
  .story-paragraph { font-size: 19px; line-height: 1.55; }
  .dialogue-text { font-size: 18px; }
  .reader-nav { grid-template-columns: 1fr; }
  .nav-card.next { text-align: left; }
  .reader-float { right: 15px; bottom: 15px; }
  .editor-panel { width: min(100% - 30px, 1240px); padding: 23px 18px; }
  .editor-heading { flex-direction: column; }
  .editor-fields { grid-template-columns: 1fr; }
  .editor-fields label:last-child { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
