/* ========== DESIGN TOKENS ======== */
:root {
  /* Light mode — whitish, low glare */
  --parchment: #FBFBFC;      /* body background */
  --surface:   #FFFFFF;      /* cards, panels */
  --text:      #24262B;      /* body text */
  --text-muted:#6B6F78;      /* captions, metadata */
  --border:    #E8E9EC;      /* dividers, outlines */
  --indigo:      #5B5BD6;
  --indigo-deep: #3D3B8E;
  --amber:       #E8A33D;
  --shadow:  0 2px 8px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.10);

  --radius: 8px;
  --max: 1120px;
  --reader: 680px;

  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-serif: 'Lora', Georgia, serif;
  --font-display: 'Fraunces', Georgia, serif;

  --reader-size: 19px;
  --reader-font: var(--font-serif);

  color-scheme: light;
}

[data-theme="dark"] {
  /* Dark mode — soft charcoal, no pure black */
  --parchment: #242832;
  --surface:   #2E3340;
  --text:      #DCDFE4;
  --text-muted:#9AA0AC;
  --border:    #3A404D;
  --indigo:      #7C7CF0;
  --indigo-deep: #9A9AFF;
  --amber:       #F0B459;
  --shadow:  0 2px 8px rgba(0,0,0,.35);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.55);

  color-scheme: dark;
}

/* ========== RESET / BASE ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--parchment);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.6;
  transition: background .25s ease, color .25s ease;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--indigo); text-decoration: none; transition: color .15s; }
a:hover { color: var(--indigo-deep); }
img { max-width: 100%; display: block; }
button { font: inherit; cursor: pointer; }

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 24px; }

/* ========== HEADER ========== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--parchment) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px; gap: 16px;
}
.wordmark {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 600; letter-spacing: -.01em;
  color: var(--text);
}
.wordmark .dot { color: var(--amber); }
.nav { display: flex; gap: 22px; align-items: center; }
.nav a { color: var(--text-muted); font-size: 14px; font-weight: 500; }
.nav a:hover { color: var(--text); }

.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px;
  transition: border-color .15s, color .15s, background .15s;
}
.icon-btn:hover { border-color: var(--indigo); color: var(--indigo); }
.icon-btn:focus-visible,
.btn:focus-visible,
.card:focus-visible,
a:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
}

/* ========== HERO ========== */
.hero {
  padding: 72px 0 56px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(1200px 500px at 15% -10%,
      color-mix(in srgb, var(--indigo) 6%, transparent), transparent 60%);
}
.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(34px, 6vw, 58px);
  line-height: 1.1; letter-spacing: -.02em;
  margin: 0 0 16px; max-width: 16ch;
}
.hero p {
  font-size: clamp(16px, 2vw, 19px);
  color: var(--text-muted); max-width: 52ch; margin: 0 0 28px;
}
.btn {
  display: inline-block; padding: 12px 22px; border-radius: var(--radius);
  background: var(--indigo); color: #fff; font-weight: 600; font-size: 15px;
  border: none; transition: background .15s, transform .1s;
}
.btn:hover { background: var(--indigo-deep); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: none; color: var(--text); border: 1px solid var(--border);
}
.btn.ghost:hover {
  border-color: var(--indigo); color: var(--indigo);
  background: color-mix(in srgb, var(--indigo) 6%, transparent);
}

/* ========== SECTION ========== */
.section { padding: 56px 0; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 28px; gap: 16px;
}
.section-head h2 {
  font-family: var(--font-display); font-size: 26px;
  margin: 0; letter-spacing: -.01em;
}

/* ========== STORY CARDS ========== */
.grid {
  display: grid; gap: 28px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.card {
  display: block; color: inherit; border-radius: var(--radius);
  transition: transform .15s;
}
.card:hover { transform: translateY(-3px); color: inherit; }
.card .cover {
  aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow); margin-bottom: 14px;
  position: relative;
}
.card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card .cover .ph {
  width: 100%; height: 100%; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 32px; color: var(--text-muted);
  background: linear-gradient(160deg, var(--surface), var(--border));
}
.card h3 {
  font-family: var(--font-serif); font-size: 17px; font-weight: 600;
  margin: 0 0 6px; line-height: 1.3;
}
.card .meta { font-size: 13px; color: var(--text-muted); }

.tag {
  display: inline-block; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--indigo) 12%, transparent);
  color: var(--indigo);
}
.tag.amber {
  background: color-mix(in srgb, var(--amber) 18%, transparent);
  color: var(--amber);
}

/* ========== SKELETON ========== */
.skel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  animation: pulse 1.4s infinite;
}
.skel.cover { aspect-ratio: 2/3; margin-bottom: 14px; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .55 } }

/* ========== STORY PAGE HEADER ========== */
.story-head { padding: 48px 0; border-bottom: 1px solid var(--border); }
.story-head .layout { display: flex; gap: 40px; flex-wrap: wrap; }
.story-head .cover-lg {
  width: 220px; flex: 0 0 auto; aspect-ratio: 2/3;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  background: var(--surface);
}
.story-head .cover-lg img { width: 100%; height: 100%; object-fit: cover; }
.story-head .info { flex: 1 1 320px; min-width: 280px; }
.story-head h1 {
  font-family: var(--font-display); font-size: clamp(28px, 5vw, 42px);
  line-height: 1.15; margin: 8px 0 14px; letter-spacing: -.02em;
}
.story-head .synopsis { color: var(--text-muted); max-width: 60ch; margin: 0 0 20px; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 24px; }

/* ========== CHAPTER LIST ========== */
.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list li { border-bottom: 1px solid var(--border); }
.chapter-list a {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 4px; color: var(--text);
  transition: color .15s, padding-left .15s;
}
.chapter-list a:hover { color: var(--indigo); padding-left: 10px; }
.chapter-list .num {
  flex: 0 0 auto; font-family: var(--font-ui); font-size: 13px;
  font-weight: 600; color: var(--text-muted); min-width: 34px;
}
.chapter-list .t { flex: 1; font-family: var(--font-serif); font-size: 16px; }
.chapter-list .d { font-size: 13px; color: var(--text-muted); }

/* ========== READER ========== */
.reading-bar {
  position: fixed; top: 0; left: 0; height: 3px; z-index: 100;
  background: var(--indigo); width: 0; transition: width .1s linear;
}
.reader {
  max-width: var(--reader);
  margin: 0 auto;
  padding: 64px 24px 120px;
}
.reader .chapter-eyebrow {
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--indigo); margin-bottom: 12px;
}
.reader h1 {
  font-family: var(--font-display); font-size: clamp(26px, 5vw, 36px);
  line-height: 1.2; letter-spacing: -.01em; margin: 0 0 12px;
}
.reader .byline { color: var(--text-muted); font-size: 14px; margin-bottom: 40px; }
.reader-content {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: 1.75;
  color: var(--text);
}
.reader-content p { margin: 0 0 1.2em; }
.reader-content h2, .reader-content h3 {
  font-family: var(--font-display); line-height: 1.3; margin: 2em 0 .6em;
}
.reader-content blockquote {
  border-left: 3px solid var(--amber); margin: 1.5em 0;
  padding: .2em 0 .2em 1.2em; color: var(--text-muted); font-style: italic;
}
.reader-content hr {
  border: none; text-align: center; margin: 2.5em 0; color: var(--text-muted);
}
.reader-content hr::before { content: "· · ·"; letter-spacing: .5em; }

.chapter-nav {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 64px; padding-top: 32px; border-top: 1px solid var(--border);
}

/* ========== SETTINGS POPOVER ========== */
.settings {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
}
.settings-panel {
  position: absolute; right: 0; bottom: 52px;
  width: 220px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: none;
}
.settings-panel.open { display: block; }
.settings-panel label {
  display: block; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); margin: 0 0 8px;
}
.settings-panel .row { margin-bottom: 18px; }
.settings-panel .row:last-child { margin-bottom: 0; }
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 6px 0; font-size: 13px;
  background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text-muted);
  transition: border-color .15s, color .15s;
}
.seg button.on {
  border-color: var(--indigo); color: var(--indigo); font-weight: 600;
}

/* ========== FOOTER ========== */
.site-footer {
  border-top: 1px solid var(--border); padding: 40px 0;
  color: var(--text-muted); font-size: 14px;
}
.site-footer .wrap {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 640px) {
  .wrap { padding: 0 18px; }
  .hero { padding: 48px 0 40px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 18px; }
  .story-head .cover-lg { width: 150px; }
  .reader { padding: 40px 20px 100px; }
  .chapter-list .d { display: none; }
}
