/* ========================================
   Artemis Wells — Midnight Library
   ======================================== */

:root {
  --bg: #0c0a09;
  --bg-raised: #14110f;
  --bg-surface: #1a1714;
  --bg-surface-hover: #221e1a;
  --text: #cdc5b4;
  --text-secondary: #8c8475;
  --text-muted: #5a554d;
  --accent: #b8935a;
  --accent-light: #d4ad6e;
  --accent-dim: rgba(184, 147, 90, 0.1);
  --border: #262220;
  --border-light: #332e29;
  --display: 'Cormorant Garamond', Georgia, serif;
  --serif: 'Source Serif 4', Georgia, serif;
  --sans: 'Outfit', system-ui, sans-serif;
  --container: 900px;
  --content: 900px;
}

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

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

body {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(184, 147, 90, 0.03) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Film grain */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.022;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
}

main { flex: 1; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.25s ease;
}

a:hover { color: var(--accent-light); }

::selection {
  background: rgba(184, 147, 90, 0.2);
  color: var(--text);
}

/* --- Layout --- */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 2rem;
}

.container-narrow {
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 2rem;
}

/* --- Site Header --- */
.site-header {
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(12, 10, 9, 0.85);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-logo {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-secondary);
  transition: color 0.25s ease;
}

.site-logo:hover { color: var(--accent); }

.header-nav {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-link {
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  transition: color 0.25s ease;
}

.nav-link:hover, .nav-link.active { color: var(--accent); }

.search-trigger {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  transition: color 0.25s ease;
  display: flex;
  align-items: center;
}

.search-trigger:hover { color: var(--accent); }

/* --- Hero --- */
.hero {
  padding: 10rem 0 2rem;
  text-align: center;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 400px;
  background: radial-gradient(ellipse, rgba(184, 147, 90, 0.06) 0%, transparent 70%);
  pointer-events: none;
}

.hero-title {
  font-family: var(--display);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 300;
  letter-spacing: 0.12em;
  color: var(--text);
  text-shadow: 0 0 80px rgba(184, 147, 90, 0.1);
  position: relative;
}

/* --- Ornament --- */
.ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 2.5rem auto 0;
}

.ornament::before,
.ornament::after {
  content: '';
  width: 48px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.4;
}

.ornament-diamond {
  width: 5px;
  height: 5px;
  background: var(--accent);
  transform: rotate(45deg);
  opacity: 0.5;
}

/* --- Section Label --- */
.section-label {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 3rem;
}

/* --- Stories Grid --- */
.stories {
  padding: 4rem 0 8rem;
}

.stories-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.story-card {
  display: block;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 2px;
  padding: 2rem 2rem 2rem 2.25rem;
  color: var(--text);
  transition: all 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
  opacity: 0;
  animation: cardReveal 0.5s ease-out forwards;
}

.story-card:nth-child(1) { animation-delay: 0.05s; }
.story-card:nth-child(2) { animation-delay: 0.12s; }
.story-card:nth-child(3) { animation-delay: 0.19s; }
.story-card:nth-child(4) { animation-delay: 0.26s; }
.story-card:nth-child(5) { animation-delay: 0.33s; }
.story-card:nth-child(6) { animation-delay: 0.40s; }
.story-card:nth-child(7) { animation-delay: 0.47s; }
.story-card:nth-child(8) { animation-delay: 0.54s; }

.story-card:hover {
  border-left-color: var(--accent-light);
  background: var(--bg-surface-hover);
  transform: translateX(4px);
  box-shadow: -4px 0 20px rgba(184, 147, 90, 0.06);
  color: var(--text);
}

.story-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.story-card-genre {
  font-family: var(--sans);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.6;
}

.story-card-title {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.story-card-desc {
  color: var(--text-secondary);
  font-family: var(--serif);
  font-size: 0.88rem;
  line-height: 1.6;
  margin-bottom: 0;
  font-style: italic;
}

.story-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.story-card-status {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-family: var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.story-card-status.status-wip {
  color: var(--accent);
}

.story-card-bottom {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1.25rem;
}

.story-card-chapters {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--sans);
  white-space: nowrap;
}

.story-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

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

/* --- Story Cover Images --- */
.story-card-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.22;
  transition: opacity 0.35s ease;
}

.story-card-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(12, 10, 9, 0.2), rgba(12, 10, 9, 0.6));
}

.story-card:hover .story-card-bg {
  opacity: 0.3;
}

.story-card > *:not(.story-card-bg) {
  position: relative;
  z-index: 1;
}

.story-cover {
  margin: 1rem 0 1.5rem;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.story-cover img {
  display: block;
  width: 100%;
  height: auto;
}

.story-cover-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4rem 2rem 1.5rem;
  background: linear-gradient(to bottom, transparent, rgba(12, 10, 9, 0.85));
}

.story-cover-content .story-title,
.story-cover-content .chapter-title {
  text-shadow: 0 2px 16px var(--bg), 0 1px 4px var(--bg);
}

.story-cover-content .story-desc {
  text-shadow: 0 1px 8px var(--bg);
}

/* --- Story Page --- */
.story-page {
  padding: 6rem 0 8rem;
  animation: pageReveal 0.5s ease-out;
}

.story-header {
  margin-bottom: 3.5rem;
}

.story-header .back-link {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  transition: color 0.25s ease;
  letter-spacing: 0.02em;
}

.story-header .back-link:hover { color: var(--accent); }

.story-title {
  font-family: var(--display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 400;
  margin-bottom: 0.75rem;
  line-height: 1.15;
  letter-spacing: 0.02em;
}

.story-desc {
  color: var(--text-secondary);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.65;
  font-style: italic;
}

.story-meta-row {
  margin-top: 0.75rem;
}

.story-cover + .story-header .story-meta-row {
  margin-top: 0;
}

.story-status {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: var(--sans);
  letter-spacing: 0.03em;
}

.story-status.status-wip {
  color: var(--accent);
}

/* Chapter list with editorial spine */
.chapter-list {
  position: relative;
  padding-left: 2rem;
  margin-top: 0.5rem;
}

.chapter-list::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 1.25rem;
  bottom: 1.25rem;
  width: 1px;
  background: var(--border-light);
}

.chapter-item {
  display: flex;
  align-items: center;
  padding: 1.15rem 0;
  color: var(--text);
  transition: all 0.25s ease;
  position: relative;
}

.chapter-dot {
  position: absolute;
  left: -2rem;
  top: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: var(--bg);
  transition: all 0.25s ease;
  flex-shrink: 0;
}

.chapter-item:hover .chapter-dot {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(184, 147, 90, 0.3);
}

.chapter-item:hover {
  padding-left: 0.5rem;
}

.chapter-item .chapter-title {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 500;
  flex: 1;
  letter-spacing: 0.01em;
}

.chapter-item .chapter-meta {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: 2rem;
}

/* --- Chapter Page --- */
.chapter-page {
  padding: 6rem 0 6rem;
  animation: pageReveal 0.4s ease-out;
}

.chapter-header {
  margin-bottom: 3.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.back-link {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.75rem;
  transition: color 0.25s ease;
  letter-spacing: 0.02em;
}

.back-link:hover { color: var(--accent); }

.chapter-page .chapter-title {
  font-family: var(--display);
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 400;
  line-height: 1.2;
  margin-bottom: 1rem;
  letter-spacing: 0.02em;
}

.chapter-page .chapter-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0;
}

.meta-sep { opacity: 0.3; }

/* --- Prose --- */
.prose {
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.9;
  color: var(--text);
}

.prose p { margin-bottom: 1.5em; }
.prose p:last-child { margin-bottom: 0; }

/* Drop cap */
.prose > p:first-of-type::first-letter {
  font-family: var(--display);
  float: left;
  font-size: 3.6em;
  line-height: 0.78;
  padding-right: 0.08em;
  padding-top: 0.06em;
  color: var(--accent);
  font-weight: 400;
}

.prose em { font-style: italic; }
.prose strong { font-weight: 600; }

.prose blockquote {
  border-left: 2px solid var(--accent);
  padding-left: 1.5rem;
  margin: 2em 0;
  color: var(--text-secondary);
  font-style: italic;
}

.prose blockquote p:last-child { margin-bottom: 0; }

/* Scene breaks */
.prose hr {
  border: none;
  margin: 3.5em 0;
  text-align: center;
  overflow: visible;
  height: 0;
}

.prose hr::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(184, 147, 90, 0.4);
  box-shadow:
    -18px 0 0 rgba(184, 147, 90, 0.4),
    18px 0 0 rgba(184, 147, 90, 0.4);
}

.prose h2 {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 500;
  margin: 3em 0 1em;
  letter-spacing: 0.02em;
}

.prose h3 {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 500;
  margin: 2.5em 0 0.75em;
}

/* --- Chapter Nav --- */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--border);
}

.chapter-nav-link {
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  transition: all 0.25s ease;
}

.chapter-nav-link:hover {
  border-color: rgba(184, 147, 90, 0.25);
  background: var(--bg-surface-hover);
  color: var(--text);
}

.chapter-nav-link.next {
  text-align: right;
  align-items: flex-end;
}

.chapter-nav-label {
  font-family: var(--sans);
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.chapter-nav-title {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 500;
}

/* --- Reading Progress --- */
.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  z-index: 1000;
  transition: width 0.1s linear;
}

/* --- Footer --- */
.site-footer {
  padding: 4rem 0 3rem;
  text-align: center;
}

.footer-ornament {
  width: 20px;
  height: 1px;
  background: var(--border-light);
  margin: 0 auto 1.5rem;
}

.site-footer p {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

/* --- Tags --- */
.tag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border-light);
  border-radius: 2px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

a.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.story-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

/* Tag & terms pages */
.tag-page,
.tags-page {
  padding: 6rem 0 8rem;
  animation: pageReveal 0.5s ease-out;
}

.tag-header,
.tags-header {
  margin-bottom: 3rem;
}

.page-title {
  font-family: var(--display);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.tag-count {
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 2rem;
}

.tag-lg {
  font-size: 0.75rem;
  padding: 0.4rem 0.9rem;
}

/* --- Search Overlay --- */
.search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 9, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 500;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 18vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.search-overlay.active {
  opacity: 1;
  visibility: visible;
}

.search-inner {
  width: 100%;
  max-width: 520px;
  padding: 0 2rem;
  transform: translateY(-8px);
  transition: transform 0.2s ease;
}

.search-overlay.active .search-inner {
  transform: translateY(0);
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.75rem;
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--display);
  font-size: 1.4rem;
  font-weight: 400;
  outline: none;
  letter-spacing: 0.01em;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-close {
  background: none;
  border: 1px solid var(--border-light);
  border-radius: 2px;
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.search-close:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.search-results {
  margin-top: 1.5rem;
}

.search-result-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  transition: all 0.15s ease;
  gap: 1rem;
}

.search-result-item:first-child {
  border-top: 1px solid var(--border);
}

.search-result-item:hover {
  padding-left: 0.5rem;
}

.search-result-title {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 500;
}

.search-result-context {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.search-empty {
  color: var(--text-muted);
  font-family: var(--serif);
  font-style: italic;
  text-align: center;
  padding: 2rem 0;
}

/* --- Animations --- */
@keyframes pageReveal {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .stories-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .hero { padding: 7rem 0 2rem; }
  .hero-title { letter-spacing: 0.06em; }
  .stories { padding: 3rem 0 5rem; }
  .story-page { padding: 4rem 0 5rem; }
  .chapter-nav { grid-template-columns: 1fr; }
  .chapter-nav-link.next { text-align: left; align-items: flex-start; }
  .container, .container-narrow { padding: 0 1.25rem; }
  .prose { font-size: 1.05rem; }
  .prose > p:first-of-type::first-letter { font-size: 3em; }
  .chapter-list { padding-left: 1.75rem; }
}

@media (max-width: 480px) {
  .hero { padding: 5rem 0 1.5rem; }
  .story-card { padding: 1.5rem 1.5rem 1.5rem 1.75rem; }
  .story-card-title { font-size: 1.3rem; }
  .chapter-page { padding: 3rem 0 4rem; }
}
