/* ═══════════════════════════════════════════════════════
   STUDIO VALENSI — Story Reader & Library
   Dark gothic base · Crimson & gold accents
   Cinzel Decorative headers · Raleway body
   ═══════════════════════════════════════════════════════ */

/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --crimson:        #9b1b30;
  --crimson-light:  #c0243a;
  --gold:           #c9a84c;
  --gold-dim:       #a6893e;

  --bg-primary:     #0d0d0f;
  --bg-secondary:   #141417;
  --bg-elevated:    #1a1a1f;
  --bg-surface:     #222228;
  --text-primary:   #e8e4df;
  --text-secondary: #9a958e;
  --text-muted:     #5e5a54;
  --border:         #2a2a30;
  --border-subtle:  #1e1e24;

  --font-display:   'Cinzel Decorative', 'Cinzel', serif;
  --font-heading:   'Cinzel Decorative', 'Cinzel', serif;
  --font-body:      'Raleway', 'Segoe UI', sans-serif;

  --content-width:  720px;
  --content-narrow: 680px;
  --gutter:         1.5rem;

  --ease-out:       cubic-bezier(0.22, 1, 0.36, 1);
  --transition:     0.3s var(--ease-out);
}

/* ── Light Theme ───────────────────────────────────── */
[data-theme="light"] {
  --bg-primary:     #f5f0e8;
  --bg-secondary:   #ece6db;
  --bg-elevated:    #e3ddd2;
  --bg-surface:     #d9d3c8;
  --text-primary:   #1a1714;
  --text-secondary: #5c564e;
  --text-muted:     #8a847c;
  --border:         #cdc7bb;
  --border-subtle:  #d9d3c8;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  line-height: 1.7;
  transition: background-color var(--transition), color var(--transition);
  overflow-x: hidden;
}

a {
  color: var(--gold);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--crimson-light); }

::selection {
  background: var(--crimson);
  color: #fff;
}

/* ═══════════════════════════════════════════════════════
   NAVIGATION
   ═══════════════════════════════════════════════════════ */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: transparent;
  transition: background var(--transition), box-shadow var(--transition);
}
.nav--scrolled {
  background: rgba(13, 13, 15, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 0 var(--border-subtle);
}
[data-theme="light"] .nav--scrolled {
  background: rgba(245, 240, 232, 0.92);
}

.nav__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--gutter);
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav__brand {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  text-transform: uppercase;
  transition: color var(--transition);
}
.nav__brand:hover { color: var(--gold); }

.nav__links {
  display: flex;
  align-items: center;
  gap: 2rem;
  list-style: none;
}

.nav__link {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-secondary);
  position: relative;
  padding: 0.25em 0;
  transition: color var(--transition);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.nav__link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--crimson);
  transition: width var(--transition);
}
.nav__link:hover { color: var(--text-primary); }
.nav__link:hover::after { width: 100%; }
.nav__link--active { color: var(--gold); }
.nav__link--active::after { width: 100%; background: var(--gold); }

/* ── Chapters Dropdown ─────────────────────────────── */
.nav__dropdown {
  position: relative;
}

.nav__link--dropdown {
  cursor: pointer;
}

/* Panel: hidden by default with display:none */
.nav__dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 260px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 100;
}
/* Only visible when parent has .open */
.nav__dropdown.open .nav__dropdown-panel {
  display: block;
}
[data-theme="light"] .nav__dropdown-panel {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.nav__dropdown-header {
  padding: 0.75rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}
.nav__dropdown-series {
  font-family: var(--font-heading);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-dim);
}

.nav__dropdown-list {
  list-style: none;
  padding: 0.4rem 0;
}

.nav__dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--text-secondary);
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.6em;
}
.nav__dropdown-item:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}
.nav__dropdown-item--active {
  color: var(--gold);
  background: rgba(201, 168, 76, 0.06);
}
.nav__dropdown-item--active::before {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--crimson-light);
  flex-shrink: 0;
}

.nav__dropdown-num {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-width: 1.6em;
  flex-shrink: 0;
}

/* scrollbar inside dropdown */
.nav__dropdown-panel::-webkit-scrollbar { width: 4px; }
.nav__dropdown-panel::-webkit-scrollbar-track { background: transparent; }
.nav__dropdown-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.theme-toggle:hover {
  color: var(--gold);
  border-color: var(--gold-dim);
  background: rgba(201, 168, 76, 0.06);
}
.theme-toggle__icon { width: 16px; height: 16px; }
[data-theme="dark"] .theme-toggle__icon--sun  { display: none; }
[data-theme="dark"] .theme-toggle__icon--moon { display: block; }
[data-theme="light"] .theme-toggle__icon--sun  { display: block; }
[data-theme="light"] .theme-toggle__icon--moon { display: none; }

/* Mobile nav toggle */
.nav__toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.nav__toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 1px;
  transition: transform var(--transition), opacity var(--transition);
}
.nav__toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav__toggle.active span:nth-child(2) { opacity: 0; }
.nav__toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ═══════════════════════════════════════════════════════
   HERO
   ═══════════════════════════════════════════════════════ */
.hero {
  position: relative;
  height: 25vh;
  min-height: 200px;
  max-height: 300px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(155, 27, 48, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(201, 168, 76, 0.12) 0%, transparent 50%),
    linear-gradient(175deg, #0d0d0f 0%, #1a1018 40%, #15101a 70%, #0d0d0f 100%);
}
[data-theme="light"] .hero {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(155, 27, 48, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 30%, rgba(201, 168, 76, 0.08) 0%, transparent 50%),
    linear-gradient(175deg, #e8e0d4 0%, #ded4c6 40%, #e0d8cc 70%, #ece6db 100%);
}

.hero__overlay {
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
}

.hero__content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 0 var(--gutter) 2rem;
  animation: heroFadeUp 0.8s var(--ease-out) both;
}

.hero__kicker {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--crimson-light);
  margin-bottom: 0.5rem;
}

.hero__title {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 4vw, 2.8rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 0.6rem;
  letter-spacing: 0.02em;
}

.hero__meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
}
.hero__sep { color: var(--border); }

.hero__fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(to top, var(--bg-primary), transparent);
  z-index: 3;
}

@keyframes heroFadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════
   ARTICLE (reader)
   ═══════════════════════════════════════════════════════ */
.article {
  padding: 2rem var(--gutter) 4rem;
}

.article__container {
  max-width: var(--content-width);
  margin: 0 auto;
}

.article__header {
  text-align: center;
  margin-bottom: 2rem;
  animation: fadeIn 0.6s 0.2s var(--ease-out) both;
}

.article__title {
  font-family: var(--font-heading);
  font-size: clamp(1.3rem, 3vw, 1.8rem);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

.article__summary {
  font-size: 1.05rem;
  font-weight: 300;
  color: var(--text-secondary);
  line-height: 1.65;
  max-width: var(--content-narrow);
  margin: 0 auto;
  font-style: italic;
}

.article__byline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  animation: fadeIn 0.6s 0.3s var(--ease-out) both;
}
.article__byline-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.article__byline-author {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
}
.article__byline-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.article__read-time {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-elevated);
  padding: 0.3em 0.8em;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
}

.article__rule {
  border: none;
  height: 1px;
  background: var(--border);
  margin-bottom: 2rem;
}

/* ── Story body ────────────────────────────────────── */
.article__body {
  font-size: 1.08rem;
  line-height: 1.8;
  color: var(--text-primary);
  animation: fadeIn 0.6s 0.4s var(--ease-out) both;
}

.article__body p { margin-bottom: 1.4em; max-width: var(--content-width); }

.article__body h1,
.article__body h2,
.article__body h3 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  margin-top: 2em;
  margin-bottom: 0.6em;
  line-height: 1.3;
}
.article__body h1 { font-size: 1.8rem; }
.article__body h2 { font-size: 1.4rem; }
.article__body h3 { font-size: 1.15rem; }

.article__body blockquote {
  border-left: 3px solid var(--crimson);
  padding: 0.6em 1.2em;
  margin: 1.5em 0;
  font-style: italic;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border-radius: 0 4px 4px 0;
}

.article__body em { font-style: italic; color: var(--text-secondary); }
.article__body strong { font-weight: 600; color: var(--text-primary); }

.article__body hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 2.5em auto;
  width: 40%;
}

.article__body ul,
.article__body ol { padding-left: 1.5em; margin-bottom: 1.4em; }
.article__body li { margin-bottom: 0.5em; }

/* Drop cap */
.dropcap > p:first-of-type::first-letter {
  float: left;
  font-family: var(--font-display);
  font-size: 3.6em;
  line-height: 0.8;
  font-weight: 700;
  color: var(--crimson);
  padding-right: 0.08em;
  padding-top: 0.06em;
  margin-right: 0.02em;
}

.article__loading {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 3rem 0;
}

/* ── Share row ─────────────────────────────────────── */
.article__share-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 2.5rem;
  animation: fadeIn 0.6s 0.5s var(--ease-out) both;
}
.article__share-row-author { font-size: 0.85rem; color: var(--text-secondary); }
.article__share-row-author strong { color: var(--text-primary); }

.article__share-buttons { display: flex; gap: 0.5rem; }

.share-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.share-btn svg { width: 15px; height: 15px; }
.share-btn:hover {
  color: var(--text-primary);
  border-color: var(--gold-dim);
  background: rgba(201, 168, 76, 0.08);
  transform: translateY(-2px);
}
.share-btn.copied { border-color: var(--crimson); color: var(--crimson-light); }

/* ── Next story ────────────────────────────────────── */
.article__next {
  text-align: center;
  padding: 2.5rem 0 1rem;
  border-top: 1px solid var(--border);
}
.article__next-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.8em 1.8em;
  border: 1px solid var(--crimson);
  border-radius: 3px;
  background: transparent;
  color: var(--crimson-light);
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: all var(--transition);
}
.btn svg { width: 16px; height: 16px; transition: transform var(--transition); }
.btn:hover {
  background: var(--crimson);
  color: #fff;
  box-shadow: 0 4px 20px rgba(155, 27, 48, 0.3);
}
.btn:hover svg { transform: translateX(4px); }
.btn:disabled { opacity: 0.35; cursor: default; pointer-events: none; }

.article__next--hidden { display: none; }

/* ═══════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════ */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 3rem var(--gutter) 1.5rem;
  margin-top: 2rem;
}

.footer__grid {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: 2rem;
  align-items: start;
}

.footer__logo-area { display: flex; flex-direction: column; align-items: flex-start; gap: 0.75rem; }
.footer__logo {
  width: 100px;
  height: 100px;
  object-fit: contain;
  opacity: 0.9;
  transition: opacity var(--transition);
}
.footer__logo:hover { opacity: 1; }
.footer__logo-text {
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.footer__newsletter { text-align: center; }
.footer__newsletter-heading {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
  letter-spacing: 0.04em;
}
.footer__newsletter-sub { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 1rem; }
.footer__newsletter-form { display: flex; gap: 0; max-width: 360px; margin: 0 auto; }
.footer__newsletter-input {
  flex: 1;
  padding: 0.6em 1em;
  font-family: var(--font-body);
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 3px 0 0 3px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition);
}
.footer__newsletter-input::placeholder { color: var(--text-muted); }
.footer__newsletter-input:focus { border-color: var(--gold-dim); }
.footer__newsletter-btn {
  padding: 0.6em 1.2em;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid var(--crimson);
  border-radius: 0 3px 3px 0;
  background: var(--crimson);
  color: #fff;
  cursor: pointer;
  transition: all var(--transition);
}
.footer__newsletter-btn:hover { background: var(--crimson-light); border-color: var(--crimson-light); }

.footer__links { display: flex; flex-direction: column; align-items: flex-end; gap: 0.6rem; }
.footer__links-heading {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.footer__link { font-size: 0.82rem; color: var(--text-secondary); transition: color var(--transition); }
.footer__link:hover { color: var(--gold); }

.footer__bottom { text-align: center; padding-top: 2rem; margin-top: 2rem; border-top: 1px solid var(--border-subtle); }
.footer__copyright { font-size: 0.72rem; color: var(--text-muted); letter-spacing: 0.04em; }

/* ═══════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════
   PROGRESS BAR
   ═══════════════════════════════════════════════════════ */
.progress-bar {
  position: fixed;
  top: 64px;
  left: 0;
  width: 0%;
  height: 2px;
  background: linear-gradient(90deg, var(--crimson), var(--gold));
  z-index: 999;
  transition: width 0.1s linear;
}

/* ═══════════════════════════════════════════════════════
   ERROR STATE
   ═══════════════════════════════════════════════════════ */
.article__error { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.article__error-title { font-family: var(--font-heading); font-size: 1.3rem; color: var(--crimson-light); margin-bottom: 0.5rem; }
.article__error-msg { font-size: 0.9rem; }

/* ═══════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.6em 1.4em;
  border-radius: 4px;
  font-size: 0.82rem;
  font-family: var(--font-body);
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s var(--ease-out);
  z-index: 9999;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .nav__toggle { display: flex; }
  .nav__links {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 1rem 0;
    transform: translateY(-120%);
    opacity: 0;
    transition: transform var(--transition), opacity var(--transition);
    pointer-events: none;
  }
  .nav__links.open { transform: translateY(0); opacity: 1; pointer-events: all; }
  .nav__links li { width: 100%; text-align: center; }
  .nav__link { display: block; padding: 0.75rem 1rem; }
  .nav__theme { padding-top: 0.5rem; }

  /* Dropdown on mobile: full width panel */
  .nav__dropdown-panel {
    position: static;
    transform: none;
    min-width: 100%;
    max-height: 300px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    box-shadow: none;
  }
  .nav__dropdown.open .nav__dropdown-panel {
    transform: none;
  }

  .hero { min-height: 180px; }
  .hero__title { font-size: clamp(1.3rem, 5vw, 2rem); }

  .footer__grid { grid-template-columns: 1fr; text-align: center; }
  .footer__logo-area { align-items: center; }
  .footer__links { align-items: center; }
  .article__share-row { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .article__byline { flex-direction: column; align-items: flex-start; }
  .hero__meta { font-size: 0.7rem; }
}

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }