/* =========================================================
   global.css — Variables, Reset, Typography, Nav, Footer
   ========================================================= */

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

/* --- CSS Custom Properties --- */
:root {
  /* Colors */
  --bg:           #0e0d0b;
  --bg-raised:    #141310;
  --bg-card:      #1a1915;
  --bg-glass:     rgba(14, 13, 11, 0.72);
  --text:         #e8e4da;
  --text-muted:   #4a4740;
  --text-dim:     #7a766e;
  --accent:       #2d5a3d;
  --accent-light: #3d7a54;
  --accent-glow:  rgba(45, 90, 61, 0.18);
  --crimson:      #8b2635;
  --crimson-light:#b03040;
  --border:       rgba(232, 228, 218, 0.08);
  --border-mid:   rgba(232, 228, 218, 0.14);

  /* Typography */
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'Courier Prime', 'Courier New', monospace;

  /* Spacing */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  16px;
  --space-lg:  24px;
  --space-xl:  40px;
  --space-2xl: 64px;
  --space-3xl: 96px;

  /* Layout */
  --nav-height:   64px;
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-lg:    12px;

  /* Transitions */
  --ease:         cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --duration:     220ms;

  /* Reader mode */
  --reader-bg:    #0e0d0b;
  --reader-text:  #e8e4da;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Grain / noise texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.032;
  background-image: 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)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 180px 180px;
}

/* Page fade-in animation */
@keyframes pageFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.page-content {
  animation: pageFadeIn 0.38s var(--ease) both;
}

/* Hero cover slideshow animation */
@keyframes coverScroll {
  0%   { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

/* --- Base Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.2;
  color: var(--text);
}

h1 { font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 400; }
h2 { font-size: clamp(1.5rem, 3vw, 2.25rem); font-weight: 400; }
h3 { font-size: clamp(1.2rem, 2vw, 1.6rem); font-weight: 500; }
h4 { font-size: 1.15rem; }

p { margin-bottom: 1em; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent-light);
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}
a:hover { color: var(--text); }

img { display: block; max-width: 100%; }

/* Underline draw-in animation */
.underline-hover {
  position: relative;
  display: inline-block;
}
.underline-hover::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--accent-light);
  transition: width var(--duration) var(--ease);
}
.underline-hover:hover::after { width: 100%; }

/* --- Navigation --- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  padding: 0 4rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.nav-logo {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: color var(--duration) var(--ease);
  white-space: nowrap;
}
.nav-logo:hover { color: var(--accent-light); }

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
  list-style: none;
}

.nav-links a {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-decoration: none;
  padding-bottom: 3px;
  border-bottom: 1px solid transparent;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}

.nav-links a:hover { color: var(--text); }

.nav-links a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.nav-search {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  transition: color var(--duration) var(--ease);
  display: flex;
  align-items: center;
}
.nav-search:hover { color: var(--text); }
.nav-search svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; }

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
}
.nav-toggle span {
  display: block;
  width: 22px;
  height: 1.5px;
  background: var(--text-dim);
  transition: all var(--duration) var(--ease);
}

/* --- Search Overlay --- */
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(14, 13, 11, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10vh 2rem 4rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.search-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.search-overlay-close {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.5rem;
  transition: color var(--duration) var(--ease);
}
.search-overlay-close:hover { color: var(--text); }

.search-input-wrap {
  width: 100%;
  max-width: 640px;
  position: relative;
  margin-bottom: var(--space-xl);
}

.search-input-wrap svg {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  stroke: var(--text-muted); fill: none; stroke-width: 1.75;
  pointer-events: none;
}

#searchInput {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1.1rem;
  padding: 0.9rem 1rem 0.9rem 3rem;
  outline: none;
  transition: border-color var(--duration) var(--ease);
}
#searchInput:focus { border-color: var(--accent); }
#searchInput::placeholder { color: var(--text-muted); }

.search-results {
  width: 100%;
  max-width: 640px;
  overflow-y: auto;
  max-height: 60vh;
}
.search-results::-webkit-scrollbar { width: 3px; }
.search-results::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 999px; }

.search-empty {
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  padding: var(--space-xl) 0;
}

.search-section-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-md) 0 var(--space-sm);
  border-top: 1px solid var(--border);
  margin-top: var(--space-sm);
}
.search-section-label:first-child { border-top: none; margin-top: 0; }

.search-result-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
  border: 1px solid transparent;
}
.search-result-item:hover {
  background: var(--bg-card);
  border-color: var(--border-mid);
}

.search-result-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--text);
}
.search-result-item:hover .search-result-title { color: var(--accent-light); }

.search-result-excerpt {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Footer --- */
.site-footer {
  margin-top: var(--space-3xl);
  padding: var(--space-xl) 4rem;
  border-top: 1px solid var(--border);
  text-align: center;
}

.footer-inner {
  width: 100%;
}

.footer-name {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: var(--space-md);
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: var(--space-lg);
  list-style: none;
  margin-bottom: var(--space-md);
}

.footer-links a {
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--duration) var(--ease);
}
.footer-links a:hover { color: var(--text-dim); }

.footer-copy {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Shared Components --- */

/* Section label */
.section-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

/* Tags / pills */
.tag {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-mid);
  color: var(--text-dim);
  background: transparent;
  white-space: nowrap;
}

.tag--accent {
  color: var(--accent-light);
  border-color: var(--accent);
  background: var(--accent-glow);
}

.tag--crimson {
  color: var(--crimson-light);
  border-color: var(--crimson);
  background: rgba(139, 38, 53, 0.12);
}

/* Divider */
hr.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-xl) 0;
}

/* Content wrapper — full width with tasteful side padding */
.content-wrap {
  width: 100%;
  padding: 0 4rem;
}

/* Shelf (horizontal card row) */
.shelf {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

/* Card base */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--duration) var(--ease), transform var(--duration) var(--ease);
  cursor: pointer;
}
.card:hover {
  border-color: var(--border-mid);
  transform: translateY(-2px);
}

/* Cover placeholder */
.cover-placeholder {
  aspect-ratio: 2/3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.2rem;
  text-align: center;
  line-height: 1.35;
  color: rgba(232, 228, 218, 0.7);
}

/* Blockquote */
blockquote {
  border-left: 2px solid var(--accent);
  padding: var(--space-sm) var(--space-md);
  margin: var(--space-lg) 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text-dim);
  line-height: 1.6;
}

/* Code */
code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(232, 228, 218, 0.06);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--accent-light);
}

/* --- Reader Light/Dark Mode --- */
.reader-wrap {
  background: var(--reader-bg);
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
  position: relative;
}

.reader-light .reader-wrap {
  --reader-bg: #f5f0e8;
  --reader-text: #1a1814;
  background: #f5f0e8;
  color: #1a1814;
}

.reader-light .reader-wrap .chapter-body,
.reader-light .reader-wrap .chapter-title,
.reader-light .reader-wrap .chapter-story-link,
.reader-light .reader-wrap .chapter-number,
.reader-light .reader-wrap .chapter-meta,
.reader-light .reader-wrap .chapter-back,
.reader-light .reader-wrap .chapter-nav-direction,
.reader-light .reader-wrap .chapter-nav-title {
  color: #1a1814;
}

.reader-light .reader-wrap .chapter-body p {
  color: #2a2620;
}

.reader-light .reader-wrap hr.divider {
  border-top-color: rgba(26, 24, 20, 0.15);
}

.reader-light .reader-wrap .chapter-nav {
  border-top-color: rgba(26, 24, 20, 0.15);
}

.reader-light .reader-wrap .chapter-nav-link:hover .chapter-nav-title {
  color: var(--accent);
}

/* Reader mode toggle button */
.reader-mode-btn {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  z-index: 10;
}
.reader-mode-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}
.reader-light .reader-mode-btn {
  background: rgba(26, 24, 20, 0.08);
  border-color: rgba(26, 24, 20, 0.2);
  color: #4a4440;
}
.reader-light .reader-mode-btn:hover {
  background: rgba(26, 24, 20, 0.12);
  border-color: var(--accent);
  color: #1a1814;
}

/* --- Wiki Character Image Float --- */
.wiki-character-img {
  float: right;
  width: 200px;
  max-width: 200px;
  height: auto;
  object-fit: cover;
  margin: 0 0 1rem 2rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* --- Social Links (About page) --- */
.social-links-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  margin-top: var(--space-xl);
}

.social-card {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-dim);
  font-size: 0.88rem;
  transition: all var(--duration) var(--ease);
  white-space: nowrap;
}
.social-card:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-glow);
}
.social-card-icon { font-size: 1.1rem; line-height: 1; }
.social-card-name { font-family: var(--font-body); font-weight: 500; }

/* --- View Toggle Buttons (shared across Library/Wiki/Blog) --- */
.view-toggle-btn {
  background: none;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--duration) var(--ease);
}
.view-toggle-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.75; }
.view-toggle-btn:hover { color: var(--text); border-color: var(--accent); }
.view-toggle-btn.active {
  color: var(--accent-light);
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* --- Responsive --- */
@media (max-width: 1280px) {
  .site-nav { padding: 0 2.5rem; }
  .content-wrap { padding: 0 2.5rem; }
  .site-footer { padding: var(--space-xl) 2.5rem; }
}

@media (max-width: 1024px) {
  .shelf { grid-template-columns: repeat(2, 1fr); }
  .site-nav { padding: 0 2rem; }
  .content-wrap { padding: 0 2rem; }
  .site-footer { padding: var(--space-xl) 2rem; }
}

@media (max-width: 768px) {
  :root { --nav-height: 56px; }

  .shelf { grid-template-columns: repeat(2, 1fr); }

  .nav-links {
    display: none;
    position: fixed;
    inset: var(--nav-height) 0 0 0;
    background: var(--bg);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xl);
    z-index: 99;
  }
  .nav-links.open { display: flex; }
  .nav-links a { font-size: 1.1rem; }

  .nav-toggle { display: flex; }
  .nav-search { display: none; }

  .site-nav { padding: 0 1.25rem; }
  .content-wrap { padding: 0 1.25rem; }
  .site-footer { padding: var(--space-xl) 1.25rem; }
  .footer-links { flex-wrap: wrap; gap: var(--space-md); }

  .wiki-character-img {
    float: none;
    display: block;
    margin: 0 auto var(--space-lg);
    max-width: 160px;
  }

  .social-links-grid { gap: var(--space-sm); }
}

@media (max-width: 480px) {
  .shelf { grid-template-columns: 1fr; }
  .site-nav { padding: 0 1rem; }
  .content-wrap { padding: 0 1rem; }
}
