/* ============================================================
   Mythwink -- Global Styles
   "Mythology with a wink."

   Fonts: Baloo 2 (display) + Nunito (body) + Caveat (accents)
   Philosophy: Children's picture book on a screen.
   Bold. Warm. Irreverent. Hand-touched. Approachable.
   Mobile-first, responsive.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@700;800&family=Nunito:wght@400;600;700&family=Caveat:wght@400;700&display=swap');

/* ============================================================
   DESIGN TOKENS
   ============================================================ */

:root {
  /* Global palette */
  --mw-bg:             #FFF8EE;
  --mw-text:           #2D2A26;
  --mw-text-light:     #6B645A;
  --mw-surface:        #FFF0DE;
  --mw-accent:         #FF6B4A;
  --mw-accent-hover:   #E8553A;
  --mw-highlight:      #FFD63F;
  --mw-fun:            #4AC4FF;

  /* Per-story theme tokens -- overridden per story page */
  --story-primary:     var(--color-primary, #FF6B4A);
  --story-secondary:   var(--color-secondary, #FFD63F);
  --story-accent-bg:   var(--color-accent, #FFF3E0);

  /* Typography scale */
  --font-display:  'Baloo 2', 'Comic Sans MS', cursive;
  --font-body:     'Nunito', 'Arial Rounded MT Bold', sans-serif;
  --font-hand:     'Caveat', cursive;

  /* Spacing scale */
  --space-xs:  0.375rem;
  --space-sm:  0.75rem;
  --space-md:  1.25rem;
  --space-lg:  2rem;
  --space-xl:  3rem;
  --space-2xl: 5rem;

  /* Border radius */
  --radius-sm:  8px;
  --radius-md:  16px;
  --radius-lg:  24px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-card:  0 4px 20px rgba(45, 42, 38, 0.10);
  --shadow-lift:  0 12px 40px rgba(45, 42, 38, 0.18);
  --shadow-note:  3px 4px 0 rgba(45, 42, 38, 0.12);
}

/* ============================================================
   RESET & BASE
   ============================================================ */

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

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--mw-text);
  background-color: var(--color-bg, var(--mw-bg));
}

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

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

a:hover,
a:focus-visible {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

a:focus-visible {
  outline: 3px solid var(--story-primary);
  outline-offset: 3px;
  border-radius: 4px;
  text-decoration: none;
}

p {
  margin-bottom: 1.25rem;
}

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

/* ============================================================
   TYPOGRAPHY
   ============================================================ */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.2;
  color: var(--story-primary);
  letter-spacing: 0.01em;
}

/* ============================================================
   READING PROGRESS BAR
   New component. Positioned at very top of viewport.
   Driven by JS if present; CSS-only fallback is a colored strip.
   ============================================================ */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  width: var(--scroll-progress, 0%);
  background: var(--story-primary);
  z-index: 200;
  transition: width 0.1s linear;
  border-radius: 0 2px 2px 0;
}

/* ============================================================
   STORY NAV
   ============================================================ */

.story-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--story-primary);
  color: #fff;
  padding: 0.6rem 1.25rem;
  box-shadow: 0 3px 12px rgba(45, 42, 38, 0.18);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.story-nav__title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

.story-nav__links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  flex: 1;
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Chapter dots in nav */
.story-nav__links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.9);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  white-space: nowrap;
}

.story-nav__links a:hover,
.story-nav__links a:focus-visible {
  background: rgba(255, 255, 255, 0.35);
  color: #fff;
  text-decoration: none;
  transform: scale(1.1);
}

/* "Notes" link is pill-shaped, not a circle */
.story-nav__links a[href="#myth-notes"] {
  width: auto;
  border-radius: var(--radius-pill);
  padding: 0 0.75rem;
  font-size: 0.72rem;
  font-family: var(--font-hand);
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ============================================================
   BACK BAR
   ============================================================ */

.back-bar {
  padding: 0.6rem 1.25rem;
  background: var(--mw-bg);
  border-bottom: 2px solid var(--story-accent-bg, var(--mw-surface));
}

.back-bar a {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--story-primary);
  background: var(--story-accent-bg, var(--mw-surface));
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-pill);
  transition: background 0.15s, transform 0.15s;
}

.back-bar a:hover,
.back-bar a:focus-visible {
  background: var(--story-primary);
  color: #fff;
  text-decoration: none;
  transform: translateX(-2px);
}

/* ============================================================
   STORY HERO
   Full-bleed, large, illustration-first
   ============================================================ */

.story-hero {
  background-color: var(--story-accent-bg, var(--mw-surface));
  text-align: center;
  padding: 2rem 0 0;
}

.story-hero__image {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  padding: 0 1.25rem;
  display: block;
}

.story-hero__text {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 2rem;
}

/* Mythology eyebrow -- now a colorful badge */
.story-hero__eyebrow {
  display: inline-block;
  font-family: var(--font-hand);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--story-primary);
  background: var(--mw-highlight);
  padding: 0.15rem 0.75rem;
  border-radius: var(--radius-pill);
  margin-bottom: 0.75rem;
  letter-spacing: 0.02em;
}

.story-hero__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 8vw, 4rem);
  color: var(--story-primary);
  margin-bottom: 0.75rem;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.story-hero__tagline {
  font-family: var(--font-body);
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 600;
  color: var(--mw-text-light);
  max-width: 560px;
  margin: 0 auto 0.5rem;
  line-height: 1.6;
  font-style: italic;
}

/* Mythology label -- pill badge */
.story-hero__mythology {
  display: inline-block;
  font-family: var(--font-hand);
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  background: var(--story-secondary);
  padding: 0.2rem 0.9rem;
  border-radius: var(--radius-pill);
  margin-top: 0.5rem;
  letter-spacing: 0.02em;
}

/* ============================================================
   STORY CONTAINER
   ============================================================ */

.story-container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ============================================================
   CHAPTER SECTIONS
   ============================================================ */

.chapter {
  padding: var(--space-xl) 0;
  position: relative;
}

/* Playful divider between chapters: wavy colored band */
.chapter + .chapter::before {
  content: '';
  display: block;
  width: 100%;
  height: 3px;
  background: repeating-linear-gradient(
    90deg,
    var(--story-secondary) 0px,
    var(--story-secondary) 12px,
    transparent 12px,
    transparent 18px
  );
  border-radius: 3px;
  margin-bottom: var(--space-xl);
  opacity: 0.7;
}

.chapter:last-of-type {
  /* no extra override needed; the ::before handles visual separation */
}

/* Chapter heading with inline number badge */
.chapter__heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.35rem, 5vw, 2rem);
  color: var(--story-primary);
  margin-bottom: 1.25rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.chapter__image {
  width: 100%;
  max-width: 760px;
  margin: 0 auto 1.75rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: block;
}

/* Story text "page within a page" */
.chapter__body {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(45, 42, 38, 0.06);
}

.chapter__body p {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--mw-text);
  max-width: 60ch;
  margin-bottom: 1.25rem;
}

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

@media (min-width: 720px) {
  .chapter {
    padding: var(--space-2xl) 0;
  }

  .chapter__image {
    /* Let illustrations breathe beyond text column slightly */
    width: calc(100% + 4rem);
    margin-left: -2rem;
    max-width: none;
  }

  .chapter__body {
    padding: 2rem 2.25rem;
  }
}

/* ============================================================
   CHAPTER NUMBER BADGE
   New component: .chapter-badge
   Use inside chapter heading or before .chapter__heading
   ============================================================ */

.chapter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--story-primary);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
  box-shadow: 0 3px 0 rgba(45, 42, 38, 0.18);
  vertical-align: middle;
  margin-right: 0.6rem;
  position: relative;
  top: -2px;
}

/* ============================================================
   NARRATOR ASIDE
   New component: .narrator-aside
   Sticky-note callout box with Caveat handwriting font.
   Slightly rotated for personality.
   ============================================================ */

.narrator-aside {
  background: var(--mw-highlight);
  border-radius: var(--radius-sm);
  padding: 1rem 1.25rem 1rem 1.5rem;
  margin: 2rem 0;
  box-shadow: var(--shadow-note);
  transform: rotate(-1deg);
  position: relative;
  max-width: 520px;
}

.narrator-aside:nth-child(even) {
  transform: rotate(0.8deg);
  background: #E8F7FF;
}

.narrator-aside__text {
  font-family: var(--font-hand);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--mw-text);
  line-height: 1.5;
  margin: 0;
}

/* Optional narrator label above the aside */
.narrator-aside__label {
  font-family: var(--font-hand);
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--mw-text-light);
  display: block;
  margin-bottom: 0.25rem;
}

/* ============================================================
   MYTH FACT BOX
   New component: .myth-fact
   Rounded "Did you know?" panel. Educational tidbits.
   ============================================================ */

.myth-fact {
  background: var(--story-accent-bg, var(--mw-surface));
  border-radius: var(--radius-md);
  border-left: 5px solid var(--story-secondary);
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
}

.myth-fact__header {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--story-primary);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.myth-fact__header::before {
  content: '✦';
  font-size: 0.9rem;
  opacity: 0.8;
}

.myth-fact__text {
  font-size: 0.95rem;
  color: var(--mw-text);
  line-height: 1.65;
  margin: 0;
}

/* ============================================================
   MYTHOLOGY TAG / BADGE
   New component: .myth-tag
   Small colored pill for cards and story headers.
   ============================================================ */

.myth-tag {
  display: inline-block;
  font-family: var(--font-hand);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.18rem 0.7rem;
  border-radius: var(--radius-pill);
  background: var(--story-primary);
  color: #fff;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

/* ============================================================
   MYTH NOTES SECTION
   Redesigned as "Did You Know?" panel list
   ============================================================ */

.myth-notes {
  background: var(--story-accent-bg, var(--mw-surface));
  padding: var(--space-xl) 0;
  margin: var(--space-lg) 0 0;
}

.myth-notes__container {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.myth-notes__heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  color: var(--story-primary);
  margin-bottom: 1.5rem;
  letter-spacing: 0.01em;
}

/* Each note item styled as a mini card */
.myth-notes__list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.myth-notes__list li {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem 0.9rem 1.4rem;
  position: relative;
  font-size: 0.95rem;
  line-height: 1.65;
  color: var(--mw-text);
  box-shadow: 0 2px 6px rgba(45, 42, 38, 0.06);
}

/* Star bullet */
.myth-notes__list li::before {
  content: '✦';
  position: absolute;
  left: 0.5rem;
  top: 1rem;
  font-size: 0.65rem;
  color: var(--story-secondary);
}

/* ============================================================
   AD SLOTS
   Warm, rounded, native-feeling. Not dashed-gray.
   ============================================================ */

.ad-slot {
  background: var(--mw-surface);
  border-radius: var(--radius-md);
  padding: 1.5rem 1rem;
  text-align: center;
  min-height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 2.5rem auto;
  max-width: 728px;
  position: relative;
}

/* "a word from our sponsor" label in Caveat */
.ad-slot::before {
  content: 'a word from our sponsor';
  font-family: var(--font-hand);
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--mw-text-light);
  display: block;
}

/* Hide the raw "Advertisement" text inside the slot; the ::before handles labeling */
.ad-slot span,
.ad-slot > *:not(ins):not(script):not(iframe) {
  font-size: 0.7rem;
  color: var(--mw-text-light);
  letter-spacing: 0.05em;
  opacity: 0.6;
}

/* ============================================================
   FOOTER
   Warm, light, with personality
   ============================================================ */

.site-footer {
  background: var(--mw-surface);
  color: var(--mw-text-light);
  text-align: center;
  padding: 1.75rem 1rem 2rem;
  font-family: var(--font-body);
  font-size: 0.82rem;
  border-top: 3px solid var(--mw-highlight);
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--mw-accent);
  font-weight: 700;
}

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

.site-footer .footer-dot {
  margin: 0 0.5em;
  opacity: 0.5;
}

/* "A Monkeyjack Brands production" in display font for personality */
.site-footer::before {
  content: '';
  display: block;
  width: 2rem;
  height: 2px;
  background: var(--mw-accent);
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}

/* ============================================================
   HOMEPAGE
   ============================================================ */

.homepage {
  background: var(--mw-bg);
}

/* --- Header / Hero --- */

.homepage-header {
  text-align: center;
  padding: 3.5rem 1.25rem 2.75rem;
  background: linear-gradient(160deg, #FFE8D6 0%, var(--mw-bg) 65%);
  position: relative;
  overflow: hidden;
}

/* Decorative scatter: CSS-only stars in the background */
.homepage-header::before {
  content: '✦ ✶ ✦ ✶ ✦ ✶ ✦';
  position: absolute;
  top: 1.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--mw-accent);
  letter-spacing: 2rem;
  opacity: 0.35;
  pointer-events: none;
}

/* Site logo -- giant, bouncy display type */
.homepage-header .site-logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 14vw, 6.5rem);
  color: var(--mw-accent);
  line-height: 1;
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
  display: inline-block;
}

/* Tagline in Caveat handwriting */
.homepage-header .site-tagline {
  font-family: var(--font-hand);
  font-size: clamp(1.1rem, 3.5vw, 1.6rem);
  font-weight: 700;
  color: var(--mw-text-light);
  margin-bottom: 0.9rem;
}

.homepage-header .header-desc {
  font-family: var(--font-body);
  font-size: 0.97rem;
  color: var(--mw-text-light);
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.7;
  font-weight: 400;
}

/* --- Stories Grid Section --- */

.stories-grid {
  padding: 2rem 1.25rem 3rem;
  max-width: 1100px;
  margin: 0 auto;
}

.stories-grid h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--mw-text-light);
  margin-bottom: 1.5rem;
  letter-spacing: 0.01em;
}

/* --- Grid Layout: book-cover portrait cards --- */

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

@media (min-width: 600px) {
  .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
  }
}

@media (min-width: 900px) {
  .grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 1.75rem;
  }
}

@media (min-width: 1200px) {
  .grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* --- Story Card: book-cover feel --- */

.story-card {
  background: var(--card-color, var(--mw-accent));
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

/* Book-cover hover: slight tilt + lift */
.story-card:hover {
  transform: translateY(-6px) rotate(1deg);
  box-shadow: var(--shadow-lift);
}

.story-card:focus-within {
  outline: 3px solid var(--mw-accent);
  outline-offset: 3px;
}

/* Portrait-ratio thumbnail: ~3:4 book-cover proportion */
.story-card-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  /* Warm placeholder while image loads */
  background: color-mix(in srgb, var(--card-color, var(--mw-accent)) 40%, #FFF0DE);
}

.story-card-body {
  padding: 0.85rem 1rem 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

/* Mythology label: small colored pill */
.story-card-mythology {
  font-family: var(--font-hand);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--card-color, var(--mw-accent));
  margin-bottom: 0.25rem;
  letter-spacing: 0.01em;
}

.story-card-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--mw-text);
  margin-bottom: 0.35rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
}

.story-card-tagline {
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--mw-text-light);
  line-height: 1.55;
  flex: 1;
  margin-bottom: 0.75rem;
}

.story-card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--card-color, var(--mw-accent));
  transition: gap 0.15s;
}

.story-card-link:hover {
  gap: 0.55rem;
  text-decoration: none;
}

/* --- Homepage Ad containers --- */

.homepage-ad {
  max-width: 728px;
  margin: 0 auto 1rem;
  padding: 0 1.25rem;
}

/* ============================================================
   STORY-END CTA
   New component: .story-end-cta
   "Read another story" section at the end of each story.
   ============================================================ */

.story-end-cta {
  padding: var(--space-xl) 1.25rem var(--space-2xl);
  background: var(--mw-bg);
  text-align: center;
}

.story-end-cta__heading {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.4rem, 4vw, 2rem);
  color: var(--story-primary);
  margin-bottom: 1.5rem;
}

.story-end-cta__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
  max-width: 680px;
  margin: 0 auto;
}

@media (min-width: 540px) {
  .story-end-cta__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================================
   DECORATIVE DIVIDERS
   New component: .chapter-divider
   Place between chapters as a visual break.
   ============================================================ */

.chapter-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin: var(--space-lg) 0;
  color: var(--story-secondary);
  font-size: 1rem;
  opacity: 0.7;
}

.chapter-divider::before,
.chapter-divider::after {
  content: '';
  flex: 1;
  height: 2px;
  background: var(--story-secondary);
  border-radius: 2px;
}

.chapter-divider span {
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--story-primary);
  white-space: nowrap;
}

/* ============================================================
   UTILITIES
   ============================================================ */

/* Visually hide but keep in accessibility tree */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
