/* FictionBooks: site styles. Dark "observatory" theme, cream paper for reading. */
:root {
  --bg: #0a0f1e;
  --bg-2: #10172e;
  --card: rgba(16, 23, 46, 0.72);
  --card-line: rgba(160, 180, 255, 0.14);
  --ink: #e8ebf5;
  --muted: #9ba4c2;
  --gold: #d9b36c;
  --gold-2: #f0d39a;
  --blue: #8fb3ff;
  --danger: #ff9b8a;
  --paper: #f5eedc;
  --paper-edge: #e6dcc3;
  --paper-ink: #2b2620;
  --paper-muted: #7a6d5c;
  --radius: 14px;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --book: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 700px at 85% -10%, #1a2550 0%, transparent 60%),
              radial-gradient(900px 600px at 0% 110%, #2a2238 0%, transparent 55%),
              var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--ui);
  display: flex;
  flex-direction: column;
}
a { color: var(--gold-2); text-decoration-color: rgba(240, 211, 154, 0.4); text-underline-offset: 3px; }
a:hover { color: #fff; }
img, svg { display: block; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("/assets/backdrop.svg") center / cover no-repeat;
  opacity: 0.5;
  pointer-events: none;
}
.is-story .backdrop { opacity: 0.18; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--card-line);
  background: rgba(10, 15, 30, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font: 600 19px/1 var(--serif); letter-spacing: 0.01em; }
.brand b { color: var(--gold); font-weight: 600; }
.nav { display: flex; gap: clamp(10px, 2.4vw, 28px); font-size: 15px; }
.nav a { color: var(--muted); text-decoration: none; padding: 4px 0; border-bottom: 1px solid transparent; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--gold); }

/* ---------- generic ---------- */
main { flex: 1; width: 100%; }
.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 20px 50px -30px rgba(0, 0, 0, 0.8);
}
.eyebrow { margin: 0 0 10px; color: var(--gold); font: 600 12px/1 var(--ui); letter-spacing: 0.22em; text-transform: uppercase; }
.small { font-size: 13.5px; color: var(--muted); }
.button, button {
  display: inline-block;
  font: 600 15px/1 var(--ui);
  color: #1b1408;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  border: 0;
  border-radius: 10px;
  padding: 13px 20px;
  cursor: pointer;
  text-decoration: none;
}
.button:hover, button:hover { filter: brightness(1.06); color: #1b1408; }
button:disabled { opacity: 0.6; cursor: progress; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 12px 0 0; }
.tags li { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--card-line); color: var(--blue); }

/* ---------- home ---------- */
.home { max-width: 1180px; margin: 0 auto; padding: clamp(28px, 6vw, 72px) clamp(16px, 4vw, 40px) 40px; }
.hero { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.about h1 { font: 500 clamp(28px, 4vw, 44px)/1.15 var(--serif); margin: 0 0 22px; letter-spacing: -0.01em; }
.about p { color: #cdd3e6; max-width: 64ch; }
.stats { display: flex; flex-wrap: wrap; gap: 14px 36px; list-style: none; padding: 0; margin: 28px 0 0; }
.stats b { display: block; font: 600 28px/1.1 var(--serif); color: var(--gold-2); }
.stats span { font-size: 13px; color: var(--muted); }

.login { padding: 26px; position: sticky; top: 96px; }
.login h2 { margin: 0; font: 600 22px/1.2 var(--serif); }
.login .hint { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login input {
  width: 100%;
  font: 16px/1.2 var(--ui);
  color: var(--ink);
  background: rgba(5, 8, 18, 0.6);
  border: 1px solid var(--card-line);
  border-radius: 10px;
  padding: 12px 14px;
}
.login input:focus { outline: 2px solid rgba(217, 179, 108, 0.55); outline-offset: 1px; border-color: transparent; }
.login button { width: 100%; margin-top: 18px; }
.login .small { margin: 16px 0 0; }
.login-status { display: flex; align-items: center; gap: 10px; margin-top: 14px; color: var(--muted); font-size: 14px; }
.login-status[hidden], .login-error[hidden] { display: none; }
.login-error {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 120, 100, 0.1);
  border: 1px solid rgba(255, 155, 138, 0.35);
  color: var(--danger);
  font-size: 14px;
}
.spinner { width: 52px; height: 32px; flex: none; }
.spinner path { fill: none; stroke: var(--gold); stroke-width: 1.6; transform-box: fill-box; transform-origin: center; }
.sp-a { animation: spin-cw 1.6s linear infinite; }
.sp-b { animation: spin-ccw 1.12s linear infinite; }
@keyframes spin-cw { to { transform: rotate(360deg); } }
@keyframes spin-ccw { to { transform: rotate(-360deg); } }

.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 24px; margin: 72px 0 20px; }
.section-head h2, .how h2 { margin: 0; font: 500 30px/1.2 var(--serif); }
.section-head p { margin: 0; color: var(--muted); font-size: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 22px; }
.story-card { padding: 24px 26px; display: flex; flex-direction: column; }
.story-card .meta { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.badge { font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); border: 1px solid rgba(217, 179, 108, 0.4); border-radius: 6px; padding: 3px 7px; }
.story-card h3 { margin: 14px 0 4px; font: 600 26px/1.2 var(--serif); }
.story-card h3 a { color: var(--ink); text-decoration: none; }
.story-card h3 a:hover { color: var(--gold-2); }
.byline { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); }
.byline span { color: var(--ink); }
.story-card > p:not(.byline) { color: #cdd3e6; margin: 0; }
.read { margin-top: 18px; font-weight: 600; text-decoration: none; align-self: flex-start; }

.how { margin-top: 72px; }
.steps { list-style: none; counter-reset: s; display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; padding: 0; margin: 20px 0 0; }
.steps li { counter-increment: s; padding: 18px 20px; border-left: 1px solid rgba(217, 179, 108, 0.45); }
.steps li::before { content: "0" counter(s); display: block; font: 600 12px/1 ui-monospace, Menlo, monospace; color: var(--gold); letter-spacing: 0.12em; margin-bottom: 10px; }
.steps b { display: block; font: 600 18px/1.3 var(--serif); margin-bottom: 4px; }
.steps span { color: var(--muted); font-size: 14.5px; }

/* ---------- documents ---------- */
.doc { max-width: 860px; margin: 0 auto; padding: clamp(28px, 6vw, 64px) clamp(16px, 4vw, 32px); }
.prose { padding: clamp(24px, 5vw, 52px); }
.prose h1 { font: 500 clamp(30px, 4vw, 40px)/1.15 var(--serif); margin: 0 0 18px; }
.prose h2 { font: 600 21px/1.3 var(--serif); margin: 34px 0 8px; color: var(--gold-2); }
.prose p, .prose li { color: #cdd3e6; }
.prose .lead { font-size: 18px; color: var(--ink); }
.prose ul { padding-left: 20px; }
.prose li { margin: 6px 0; }
.faq details { border-top: 1px solid var(--card-line); padding: 4px 0; }
.faq details:last-of-type { border-bottom: 1px solid var(--card-line); }
.faq summary { cursor: pointer; padding: 14px 0; font: 600 18px/1.35 var(--serif); list-style: none; display: flex; justify-content: space-between; gap: 16px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--gold); font: 400 22px/1 var(--ui); }
.faq details[open] summary::after { content: "\2212"; }
.faq details p { margin: 0 0 16px; }
.faq details { scroll-margin-top: 90px; }
.faq details:target summary { color: var(--gold-2); }
.center { text-align: center; }
.lost { display: grid; place-items: center; min-height: 60vh; }

/* ---------- footer ---------- */
.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 24px;
  padding: 28px clamp(16px, 4vw, 48px);
  border-top: 1px solid var(--card-line);
  color: var(--muted);
  font-size: 13px;
}
.foot-links { display: flex; gap: 18px; }
.foot-links a { color: var(--muted); }
.is-story .foot { display: none; }

/* ---------- reader ---------- */
.reader { display: flex; flex-direction: column; padding: 14px clamp(10px, 3vw, 32px) 18px; }
.reader-bar { display: flex; align-items: center; gap: 16px; max-width: 1240px; width: 100%; margin: 0 auto 12px; font-size: 14px; }
.back { text-decoration: none; color: var(--muted); white-space: nowrap; }
.reader-title { color: var(--ink); font-family: var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-title em { color: var(--muted); font-style: normal; }

.book { --gap: 88px; --pad-x: 56px; --pad-y: 46px; max-width: 1240px; width: 100%; margin: 0 auto; }
.paper {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 6px;
  padding: var(--pad-y) var(--pad-x);
  box-shadow: 0 1px 0 var(--paper-edge), 0 30px 60px -30px rgba(0, 0, 0, 0.9), inset 0 0 80px rgba(120, 90, 40, 0.08);
  max-width: 720px;
  margin: 0 auto;
}
.flow { font: 18.5px/1.62 var(--book); hyphens: auto; -webkit-hyphens: auto; text-align: justify; }
.flow p { margin: 0; text-indent: 1.6em; orphans: 2; widows: 2; }
.flow p.lead { text-indent: 0; }
.flow p.lead::first-letter { float: left; font: 600 3.3em/0.82 var(--serif); padding: 0.06em 0.08em 0 0; color: #7b4f22; }
.flow h2.chapter { font: 600 1.3em/1.25 var(--serif); text-align: center; margin: 1.2em 0 1em; color: #4a3826; }
.flow hr.scene { border: 0; margin: 0.9em 0; height: 1.2em; text-align: center; }
.flow hr.scene::after { content: "\2042"; color: var(--paper-muted); font-size: 1.1em; }
.titlepage { text-align: center; padding: 8% 0 0; }
.tp-kicker { font: 600 11px/1.4 var(--ui); letter-spacing: 0.2em; text-transform: uppercase; color: var(--paper-muted); margin: 0 0 2.4em; text-indent: 0; }
.titlepage h1 { font: 500 2.6em/1.1 var(--serif); margin: 0 0 0.4em; color: #2a1e12; }
.tp-author { font: italic 1.15em/1.3 var(--serif); margin: 0; color: #5a4632; text-indent: 0 !important; }
.tp-rule { margin: 1.8em 0; color: #9a7442; font-size: 1.2em; }
.tp-meta { font: 14px/1.6 var(--ui); color: var(--paper-muted); text-indent: 0 !important; }
.titlepage .tags { justify-content: center; margin-top: 1.4em; }
.titlepage .tags li { color: #6b5638; border-color: #d8ccb0; }
.the-end { text-align: center; text-indent: 0 !important; margin-top: 1.6em !important; font: italic 1em/1.4 var(--serif); color: var(--paper-muted); }
.pager { display: none; }

/* paged mode, enabled by book.js */
html.paged, html.paged body.is-story { height: 100%; overflow: hidden; }
.paged .is-story .reader { flex: 1; min-height: 0; }
.paged .book { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.paged .paper { max-width: none; width: 100%; position: relative; }
.paged .book.spread .paper {
  background-image: linear-gradient(90deg, transparent calc(50% - 46px), rgba(90, 60, 20, 0.10) calc(50% - 2px), rgba(60, 40, 10, 0.18) 50%, rgba(90, 60, 20, 0.10) calc(50% + 2px), transparent calc(50% + 46px));
}
.paged .viewport { overflow: hidden; height: var(--vp-h, 70vh); }
.paged .flow {
  height: 100%;
  column-count: var(--cols, 1);
  column-gap: var(--gap);
  column-fill: auto;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1);
  will-change: transform;
}
.paged .titlepage { break-after: column; height: 100%; }
.paged .flow h2.chapter { break-before: column; margin-top: 2.2em; }
.paged .pager { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin-top: 14px; }
.pager button { padding: 10px 18px; font-size: 18px; background: rgba(245, 238, 220, 0.12); color: var(--ink); border: 1px solid var(--card-line); }
.pager button:hover { background: rgba(245, 238, 220, 0.2); color: #fff; }
.pager button:disabled { opacity: 0.3; cursor: default; }
.pager-label { text-align: center; color: var(--muted); font: 14px/1 var(--ui); font-variant-numeric: tabular-nums; }
.progress { grid-column: 1 / -1; height: 2px; background: rgba(255, 255, 255, 0.08); border-radius: 2px; overflow: hidden; }
.progress span { display: block; height: 100%; width: var(--progress, 0%); background: var(--gold); transition: width 0.3s; }

@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; }
  .login { position: static; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .brand span { display: none; }
  .nav { gap: 16px; font-size: 14px; }
  .book { --pad-x: 22px; --pad-y: 26px; --gap: 44px; }
  .flow { font-size: 17.5px; line-height: 1.58; }
  .reader { padding: 10px 8px 12px; }
  .reader-bar { margin-bottom: 8px; padding: 0 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .paged .flow, .progress span { transition: none; }
  .sp-a, .sp-b { animation-duration: 4s; }
}
