/*
 * Base styles for the $PARASITE interactive manga platform.
 *
 * The palette pulls from deep blacks, muted greys and violent purples/reds to evoke
 * the emotional gravity of betrayal and debt. Layout is designed mobile‑first
 * with responsive grids for chapters, arcs and submissions. A glitch effect is
 * applied to key headlines to reinforce the unsettling narrative.
 */

/* Color variables */
:root {
  --color-bg: #0d0d0d;
  --color-surface: #141414;
  --color-fg: #e6e6e6;
  --color-muted: #999;
  --color-accent: #c41464; /* red‑magenta accent */
  --color-accent-alt: #7e2ac8; /* purple accent */
  --color-link: #ff3860;
  --font-primary: 'Share Tech Mono', monospace;
  --font-secondary: 'Roboto', sans-serif;
}

/* Reset & basic layout */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-primary);
  background-color: var(--color-bg);
  color: var(--color-fg);
  line-height: 1.6;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover,
a:focus {
  text-decoration: underline;
}

.container {
  width: 90%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 0;
}

/* Navigation */
.site-header {
  position: sticky;
  top: 0;
  width: 100%;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(4px);
  z-index: 1000;
  border-bottom: 1px solid #222;
}

.nav-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
}

.site-logo a {
  font-family: var(--font-primary);
  font-size: 1.5rem;
  color: var(--color-fg);
  font-weight: bold;
}

.site-nav a {
  margin-left: 20px;
  font-family: var(--font-secondary);
  font-weight: 500;
  color: var(--color-fg);
  transition: color 0.2s ease;
}

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

/* Hero section */
.hero-section {
  position: relative;
  min-height: 80vh;
  color: var(--color-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: url('assets/hero-bg.png') center/cover no-repeat fixed;
}

.hero-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, rgba(0,0,0,0.65) 0%, rgba(0,0,0,0.85) 100%);
  z-index: 1;
}

.hero-content {
  position: relative;
  z-index: 2;
  padding: 40px 20px;
}

.hero-title {
  font-size: 4rem;
  font-family: var(--font-secondary);
  margin-bottom: 10px;
}

.hero-subtitle {
  font-family: var(--font-secondary);
  font-weight: 300;
  font-size: 1.2rem;
  margin-bottom: 20px;
  color: var(--color-muted);
}

.hero-tagline {
  font-size: 1.4rem;
  letter-spacing: 2px;
  margin-bottom: 30px;
  position: relative;
  display: inline-block;
  color: var(--color-accent);
}

/* Glitch effect */
.glitch {
  position: relative;
  color: var(--color-accent);
  font-weight: 600;
  font-family: var(--font-secondary);
  overflow: hidden;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.glitch::before {
  animation: glitch-top 2s infinite linear;
  color: var(--color-accent-alt);
}

.glitch::after {
  animation: glitch-bottom 3s infinite linear;
  color: var(--color-link);
}

@keyframes glitch-top {
  0% {
    clip: rect(0, 900px, 0, 0);
    transform: translate(0.5px, -0.5px);
  }
  10% {
    clip: rect(5px, 900px, 45px, 0);
    transform: translate(-1px, -1px);
  }
  20% {
    clip: rect(10px, 900px, 60px, 0);
    transform: translate(-3px, 1px);
  }
  30% {
    clip: rect(15px, 900px, 90px, 0);
    transform: translate(3px, 0);
  }
  40% {
    clip: rect(0, 900px, 70px, 0);
    transform: translate(1px, 1px);
  }
  50% {
    clip: rect(20px, 900px, 65px, 0);
    transform: translate(-4px, 2px);
  }
  60% {
    clip: rect(10px, 900px, 40px, 0);
    transform: translate(2px, -2px);
  }
  70% {
    clip: rect(20px, 900px, 80px, 0);
    transform: translate(-1px, 3px);
  }
  80% {
    clip: rect(5px, 900px, 50px, 0);
    transform: translate(2px, 1px);
  }
  90% {
    clip: rect(15px, 900px, 85px, 0);
    transform: translate(-2px, -1px);
  }
  100% {
    clip: rect(0, 900px, 0, 0);
    transform: translate(0, 0);
  }
}

@keyframes glitch-bottom {
  0% {
    clip: rect(0, 900px, 0, 0);
    transform: translate(-0.5px, 0.5px);
  }
  10% {
    clip: rect(45px, 900px, 90px, 0);
    transform: translate(1px, 1px);
  }
  20% {
    clip: rect(60px, 900px, 120px, 0);
    transform: translate(-1px, -1px);
  }
  30% {
    clip: rect(70px, 900px, 140px, 0);
    transform: translate(-3px, 1px);
  }
  40% {
    clip: rect(50px, 900px, 110px, 0);
    transform: translate(4px, 2px);
  }
  50% {
    clip: rect(65px, 900px, 130px, 0);
    transform: translate(-2px, -2px);
  }
  60% {
    clip: rect(40px, 900px, 100px, 0);
    transform: translate(3px, 0);
  }
  70% {
    clip: rect(80px, 900px, 160px, 0);
    transform: translate(-1px, -3px);
  }
  80% {
    clip: rect(50px, 900px, 120px, 0);
    transform: translate(2px, 2px);
  }
  90% {
    clip: rect(85px, 900px, 150px, 0);
    transform: translate(-2px, 1px);
  }
  100% {
    clip: rect(0, 900px, 0, 0);
    transform: translate(0, 0);
  }
}

/* Scroll CTA */
.cta-scroll {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 20px;
  background: transparent;
  border: 2px solid var(--color-accent);
  color: var(--color-accent);
  border-radius: 4px;
  font-family: var(--font-secondary);
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 1px;
  transition: background 0.3s, color 0.3s;
}

.cta-scroll:hover {
  background: var(--color-accent);
  color: #fff;
}

/* Section headings */
.section-title {
  font-family: var(--font-secondary);
  font-weight: 500;
  font-size: 2rem;
  margin-bottom: 10px;
  color: var(--color-fg);
}

.section-lead {
  font-family: var(--font-secondary);
  font-weight: 300;
  color: var(--color-muted);
  margin-bottom: 30px;
}

/* Chapters grid */
.chapters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}

/* Chapter group layout for the home page.  We break the chapter
   preview into multiple groups of cards so that only a couple of
   chapters are visible at a time.  Each group fades and slides
   into view as the user scrolls down. */
.chapter-groups {
  display: flex;
  flex-direction: column;
  gap: 60px;
}

/* Each group contains up to two cards.  They are displayed side by
   side on larger screens.  Groups start hidden and translate
   downward so they can slide up into position. */
.chapter-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  opacity: 0;
  transform: translateY(80px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}

/* When a group becomes visible, fade it in and reset transform */
.chapter-group.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Single groups (for the last chapter) centre their card */
.chapter-group.single {
  justify-content: center;
}

/* The rising animation for the final chapter card */
.chapter-group.rise .chapter-card {
  /* Start slightly lower; transition handled by group visibility */
  transform-origin: bottom center;
}

.chapter-card {
  background: var(--color-surface);
  border: 1px solid #222;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.3s;
}

.chapter-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.chapter-card img {
  width: 100%;
  height: 280px;
  object-fit: cover;
  display: block;
}

.chapter-info {
  padding: 10px;
}

.chapter-info h3 {
  font-family: var(--font-secondary);
  font-weight: 500;
  margin-bottom: 5px;
  font-size: 1.1rem;
}

.chapter-info .meta {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-family: var(--font-secondary);
}

.coming-soon {
  opacity: 0.4;
  pointer-events: none;
}

.note {
  font-size: 0.8rem;
  color: var(--color-muted);
  font-family: var(--font-secondary);
  text-align: center;
  margin-top: -10px;
}

/* Story summary */
.story-summary {
  background: var(--color-surface);
  padding: 40px 0;
  border-top: 1px solid #222;
  border-bottom: 1px solid #222;
}

.story-text {
  font-family: var(--font-secondary);
  font-weight: 300;
  max-width: 800px;
  margin: 0 auto;
  font-size: 1rem;
}

.story-text .manga-quote {
  display: block;
  margin-top: 20px;
  font-style: italic;
  color: var(--color-accent);
}

/* Story arcs */
.story-arcs {
  background: var(--color-bg);
  padding: 40px 0;
}

.arcs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.arc-block {
  background: var(--color-surface);
  border: 1px solid #222;
  border-radius: 6px;
  overflow: hidden;
  padding-bottom: 10px;
  transition: transform 0.2s;
  cursor: pointer;
}

.arc-block:hover {
  transform: translateY(-3px);
}

/* Hide arc descriptions by default; expand when parent has .open */
.arc-block .arc-desc {
  display: none;
  padding: 0 10px 10px;
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  color: var(--color-muted);
}

.arc-block.open .arc-desc {
  display: block;
}

.arc-block img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid #222;
}

.arc-block h3 {
  font-family: var(--font-secondary);
  font-weight: 500;
  margin: 10px;
  font-size: 1.2rem;
}

.arc-block p {
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 0 10px 10px;
}

/* Share section */
.share-section {
  background: var(--color-surface);
  padding: 40px 0;
  text-align: center;
  border-top: 1px solid #222;
  border-bottom: 1px solid #222;
}

.button {
  display: inline-block;
  padding: 12px 24px;
  background: var(--color-accent);
  color: #fff;
  border-radius: 4px;
  font-family: var(--font-secondary);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: background 0.3s ease;
}

.button:hover {
  background: var(--color-accent-alt);
}

.button.secondary {
  background: transparent;
  border: 2px solid var(--color-accent);
  color: var(--color-accent);
}

.button.secondary:hover {
  background: var(--color-accent);
  color: #fff;
}

/* Token section on home */
.token-section-home {
  background: var(--color-bg);
  padding: 40px 0;
  text-align: center;
}

.token-section-home .token-note {
  max-width: 700px;
  margin: 0 auto 20px;
  color: var(--color-muted);
  font-family: var(--font-secondary);
  font-size: 0.9rem;
}

/* Footer */
.site-footer {
  background: #111;
  border-top: 1px solid #222;
  padding: 20px 0;
  font-size: 0.9rem;
}

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

.footer-left p {
  font-family: var(--font-secondary);
  color: var(--color-muted);
  margin-bottom: 10px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}

.footer-links a {
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  color: var(--color-muted);
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--color-accent);
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .hero-title {
    font-size: 3rem;
  }
  .chapters-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
  .chapter-card img {
    height: 200px;
  }
  .nav-container {
    flex-direction: column;
    align-items: flex-start;
  }
  .site-nav {
    margin-top: 10px;
  }
  .site-nav a {
    margin-left: 0;
    margin-right: 15px;
  }
}

/* Reader page styles */
.reader-page .reader-main {
  padding-top: 100px;
  min-height: 80vh;
}

.reader-container {
  max-width: 900px;
  margin: 0 auto;
  text-align: center;
}

.reader-title {
  font-family: var(--font-secondary);
  font-weight: 500;
  font-size: 2rem;
  margin-bottom: 5px;
}

.reader-meta {
  font-family: var(--font-secondary);
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-bottom: 20px;
}

.reader-embed-wrapper {
  background: var(--color-surface);
  border: 1px solid #222;
  border-radius: 4px;
  overflow: hidden;
  padding: 10px;
}

/* Light mode overrides */
body.light-mode {
  background-color: #f8f8f8;
  color: #222;
}
body.light-mode .site-header {
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid #ddd;
}
body.light-mode .site-nav a {
  color: #222;
}
body.light-mode .site-nav a:hover {
  color: #c41464;
}
body.light-mode .chapter-card {
  background: #fff;
  border-color: #ccc;
}
body.light-mode .chapter-info h3 {
  color: #222;
}
body.light-mode .chapter-info .meta {
  color: #666;
}
body.light-mode .note {
  color: #999;
}
body.light-mode .reader-embed-wrapper {
  background: #fff;
  border-color: #ccc;
}
body.light-mode .footer-links a,
body.light-mode .footer-left p {
  color: #555;
}
body.light-mode .footer-links a:hover {
  color: #c41464;
}

/*
 * Header action area containing the theme toggle and logo download link.
 * This flex container sits inside .nav-container and pushes itself to
 * the far right using margin-left:auto so it doesn't interfere with the
 * site navigation. Items within it are spaced evenly.
 */
.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

/*
 * Theme toggle switch. Built with a visually-hidden checkbox and a
 * custom label that represents the track and handle. The handle slides
 * when the checkbox state changes. Colours invert between light and
 * dark modes to convey day/night. Icons for sun and moon sit inside
 * the handle and fade between states.
 */
.theme-toggle {
  position: relative;
  width: 48px;
  height: 24px;
}
.theme-toggle input {
  /* Hide the native checkbox but keep it accessible */
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-toggle label {
  display: block;
  width: 100%;
  height: 100%;
  background: #333;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid #444;
  transition: background-color 0.3s ease;
  position: relative;
}
.theme-toggle .handle {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #f1c40f; /* Sun default colour */
  transition: transform 0.3s ease, background-color 0.3s ease, color 0.3s ease;
}
.theme-toggle .handle .moon {
  display: none;
}

/* Position the icons centrally within the handle */
.theme-toggle .handle .sun,
.theme-toggle .handle .moon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Track and handle adjustments in light mode (checkbox checked) */
.theme-toggle input:checked + label {
  background: #ddd;
  border-color: #bbb;
}
.theme-toggle input:checked + label .handle {
  transform: translateX(24px);
  background: #111;
  color: #f5f5f5; /* Moon colour */
}

/* Swap icons depending on state: show sun when unchecked, moon when checked */
.theme-toggle input:not(:checked) + label .handle .sun {
  display: block;
}
.theme-toggle input:not(:checked) + label .handle .moon {
  display: none;
}
.theme-toggle input:checked + label .handle .sun {
  display: none;
}
.theme-toggle input:checked + label .handle .moon {
  display: block;
}

/* Logo download link. We keep it subtle and small. */
.logo-download {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid #444;
  border-radius: 4px;
  overflow: hidden;
  transition: border-color 0.2s ease;
}
.logo-download:hover {
  border-color: var(--color-accent);
}
.logo-download-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
