/**
 * Modern Literary Chapter Header Styling
 */

/* Variables */
:root[data-mode="light"] {
  --ch-primary: #1a1a24;
  --ch-primary-soft: rgba(26, 26, 36, 0.88);
  --ch-secondary: rgba(60, 60, 75, 0.75);
  --ch-tertiary: rgba(100, 100, 115, 0.65);
  --ch-accent: #4a7fd5;
  --ch-accent-light: #6b9ee8;
  --ch-backdrop: rgba(255, 255, 255, 0.65);
  --ch-border: rgba(0, 0, 0, 0.08);
  --ch-divider: rgba(0, 0, 0, 0.12);
  --ch-badge-bg: linear-gradient(135deg, rgba(74, 127, 213, 0.12), rgba(107, 158, 232, 0.08));
  --ch-badge-border: rgba(74, 127, 213, 0.25);
  --ch-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --ch-glow: 0 0 12px rgba(74, 127, 213, 0.15);
  --ch-title-gradient: linear-gradient(135deg, #1a1a24 0%, #2d2d3f 100%);
}

:root[data-mode="dark"] {
  --ch-primary: #e8e8f2;
  --ch-primary-soft: rgba(232, 232, 242, 0.90);
  --ch-secondary: rgba(210, 210, 225, 0.72);
  --ch-tertiary: rgba(180, 180, 195, 0.62);
  --ch-accent: #7daaf2;
  --ch-accent-light: #9fc0f5;
  --ch-backdrop: rgba(25, 25, 35, 0.7);
  --ch-border: rgba(255, 255, 255, 0.08);
  --ch-divider: rgba(255, 255, 255, 0.12);
  --ch-badge-bg: linear-gradient(135deg, rgba(125, 170, 242, 0.15), rgba(159, 192, 245, 0.10));
  --ch-badge-border: rgba(125, 170, 242, 0.3);
  --ch-shadow: 0 2px 12px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.4);
  --ch-glow: 0 0 16px rgba(125, 170, 242, 0.2);
  --ch-title-gradient: linear-gradient(135deg, #e8e8f2 0%, #c8c8e0 100%);
}

/* Main Container */
.chapter__headline {
  margin: 0 auto 1.8rem;
  text-align: center;
  max-width: 620px;
  position: relative;
}

/* Top decorative line */
.chapter__headline::before {
  content: "";
  display: block;
  width: 40px;
  height: 2px;
  background: var(--ch-divider);
  margin: 0 auto 1rem;
  border-radius: 1px;
}

/* Meta Bar (Story + Author) */
.chapter-meta-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
}

.chapter-story-container {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.chapter__story-link {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ch-accent);
  text-decoration: none;
  position: relative;
  transition: color 0.2s ease, text-shadow 0.2s ease;
  letter-spacing: 0.01em;
}

.chapter__story-link::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--ch-accent-light);
  transition: width 0.25s ease;
}

.chapter__story-link:hover {
  color: var(--ch-accent-light);
}

.chapter__story-link:hover::after {
  width: 100%;
}


/* Divider */
.chapter-divider {
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ch-divider), transparent);
  margin: 0.7rem auto;
  position: relative;
}

.chapter-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 3px;
  background: var(--ch-accent);
  border-radius: 50%;
  opacity: 0.4;
}

/* Title Container with backdrop blur */
.chapter-title-container {
  padding: 1rem 1.2rem;
  margin: 0 auto;
  background: var(--ch-backdrop);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--ch-border);
  border-radius: 8px;
  box-shadow: var(--ch-shadow);
  position: relative;
}

/* Badge Wrapper */
.chapter-badge-wrapper {
  margin-bottom: 0.6rem;
}

/* Chapter Group Badge */
.chapter__group {
  font-size: 0.7rem;
  font-weight: 600;
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
  color: var(--ch-accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: inline-block;
  padding: 0.3rem 0.75rem;
  background: var(--ch-badge-bg);
  border: 1px solid var(--ch-badge-border);
  border-radius: 12px;
  position: relative;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.chapter__group:hover {
  box-shadow: var(--ch-glow);
  transform: translateY(-1px);
}

/* Main Title with gradient */
.chapter__title {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--ch-title-gradient);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0 auto 0.4rem;
  line-height: 1.3;
  letter-spacing: -0.02em;
  position: relative;
}

/* Fallback for browsers without gradient text support */
@supports not (background-clip: text) {
  .chapter__title {
    color: var(--ch-primary);
    background: none;
  }
}

/* Second Title */
.chapter__second-title,
:where(article, .content-section) .chapter-title-container .chapter__second-title,
.chapter-title-container h2.chapter__second-title,
header .chapter__second-title,
body .chapter__headline .chapter__second-title {
  font-size: 0.88rem !important;
  font-weight: 400 !important;
  font-style: italic !important;
  color: var(--ch-secondary) !important;
  margin: 0.5rem auto 0 !important;
  line-height: 1.4 !important;
  letter-spacing: 0.01em !important;
  text-transform: none !important;
  opacity: 0.95;
}

/* Password protected indicator */
.chapter__title._password::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--ch-accent);
  border-radius: 50%;
  margin-left: 0.5rem;
  opacity: 0.4;
  box-shadow: 0 0 0 2px var(--ch-badge-border);
  vertical-align: middle;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.1); }
}

/* Responsive */
@media (max-width: 768px) {
  .chapter__headline {
    max-width: 95%;
    margin-bottom: 1.5rem;
  }

  .chapter-title-container {
    padding: 0.85rem 1rem;
  }

  .chapter__title {
    font-size: 1.35rem;
  }

  .chapter__second-title,
  :where(article, .content-section) .chapter-title-container .chapter__second-title,
  header .chapter__second-title {
    font-size: 0.84rem !important;
  }
}

@media (max-width: 480px) {
  .chapter__headline::before {
    width: 30px;
    margin-bottom: 0.8rem;
  }

  .chapter-meta-bar {
    font-size: 0.78rem;
    gap: 0.4rem;
  }

  .chapter__story-link {
    font-size: 0.78rem;
  }

  .chapter-title-container {
    padding: 0.75rem 0.85rem;
    border-radius: 6px;
  }

  .chapter__title {
    font-size: 1.2rem;
    letter-spacing: -0.01em;
  }

  .chapter__group {
    font-size: 0.65rem;
    padding: 0.25rem 0.65rem;
  }

  .chapter__second-title,
  :where(article, .content-section) .chapter-title-container .chapter__second-title,
  header .chapter__second-title {
    font-size: 0.8rem !important;
  }
}

/* Print styles */
@media print {
  .chapter__headline::before,
  .chapter-divider,
  .chapter__group:hover {
    display: none;
  }

  .chapter-title-container {
    background: none;
    border: none;
    box-shadow: none;
  }

  .chapter__title {
    color: #000;
    background: none;
    -webkit-text-fill-color: initial;
  }
}
