/* ────────────────────────────────────────────
   in Yuna — Optimized Stylesheet v2
   Water, light & warm keepsake aesthetic
   ──────────────────────────────────────────── */

/* ─── Design Tokens ─── */
:root {
  --bg: #f7f0e5;
  --bg-deep: #efe0cc;
  --ink: #33241b;
  --muted: #715c50;
  --line: rgba(94, 66, 48, 0.14);
  --card: rgba(255, 252, 247, 0.72);
  --card-strong: rgba(255, 249, 241, 0.92);
  --gold: #b88d52;
  --gold-light: #d4a968;
  --gold-soft: rgba(184, 141, 82, 0.12);
  --rose: #d9b3a7;
  --water: #c9d9dd;
  --shadow: 0 24px 60px rgba(94, 66, 48, 0.10);
  --shadow-hover: 0 28px 56px rgba(94, 66, 48, 0.16);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --font-display: "Fraunces", "Noto Serif SC", serif;
  --font-body: "Manrope", sans-serif;
  --transition-smooth: 600ms cubic-bezier(0.22, 1, 0.36, 1);
  --ripple-color: rgba(184, 141, 82, 0.25);
}

/* ─── Dark Mode tokens ─── */
body.theme-dark {
  --bg: #1a1614;
  --bg-deep: #141110;
  --ink: #ede4d8;
  --muted: #a89888;
  --line: rgba(218, 192, 140, 0.12);
  --card: rgba(38, 32, 28, 0.72);
  --card-strong: rgba(44, 36, 30, 0.92);
  --gold: #daa855;
  --gold-light: #e8c47d;
  --gold-soft: rgba(218, 168, 85, 0.1);
  --rose: #c4988c;
  --water: #5e7a80;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  --shadow-hover: 0 28px 56px rgba(0, 0, 0, 0.36);
  --ripple-color: rgba(218, 168, 85, 0.25);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-dark):not(.theme-light) {
    --bg: #1a1614;
    --bg-deep: #141110;
    --ink: #ede4d8;
    --muted: #a89888;
    --line: rgba(218, 192, 140, 0.12);
    --card: rgba(38, 32, 28, 0.72);
    --card-strong: rgba(44, 36, 30, 0.92);
    --gold: #daa855;
    --gold-light: #e8c47d;
    --gold-soft: rgba(218, 168, 85, 0.1);
    --rose: #c4988c;
    --water: #5e7a80;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 28px 56px rgba(0, 0, 0, 0.36);
    --ripple-color: rgba(218, 168, 85, 0.25);
  }
}

/* ─── Reset ─── */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.7), transparent 26%),
    radial-gradient(circle at 80% 12%, rgba(217,179,167,0.22), transparent 24%),
    radial-gradient(circle at 70% 78%, rgba(201,217,221,0.28), transparent 28%),
    linear-gradient(180deg, #fbf6ee 0%, var(--bg) 46%, #f1e5d5 100%);
  font-family: var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 500ms ease, color 400ms ease;
}

body.theme-dark {
  background:
    radial-gradient(circle at top left, rgba(255,255,255,0.04), transparent 26%),
    radial-gradient(circle at 80% 12%, rgba(196,152,140,0.08), transparent 24%),
    radial-gradient(circle at 70% 78%, rgba(94,122,128,0.10), transparent 28%),
    linear-gradient(180deg, #1e1a17 0%, var(--bg) 46%, #110f0d 100%);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) {
    background:
      radial-gradient(circle at top left, rgba(255,255,255,0.04), transparent 26%),
      radial-gradient(circle at 80% 12%, rgba(196,152,140,0.08), transparent 24%),
      radial-gradient(circle at 70% 78%, rgba(94,122,128,0.10), transparent 28%),
      linear-gradient(180deg, #1e1a17 0%, var(--bg) 46%, #110f0d 100%);
  }
}

/* Grid texture overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at center, black, transparent 78%);
  z-index: 0;
}

body.theme-dark::before {
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light)::before {
    background-image:
      linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  }
}

/* ─── Ambient Canvas ─── */
.ambient-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ─── Theme Toggle Button ─── */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08);
  transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 300ms ease;
}

.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.theme-toggle:active { transform: scale(1.05); }

.theme-toggle svg {
  width: 20px;
  height: 20px;
  position: absolute;
  transition: opacity 300ms ease, transform 300ms ease;
}

body:not(.theme-dark) .icon-sun { opacity: 0; transform: scale(0.5) rotate(-90deg); }
body:not(.theme-dark) .icon-moon { opacity: 1; transform: scale(1) rotate(0); }

body.theme-dark .icon-sun { opacity: 1; transform: scale(1) rotate(0); }
body.theme-dark .icon-moon { opacity: 0; transform: scale(0.5) rotate(90deg); }

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .icon-sun { opacity: 1; transform: scale(1) rotate(0); }
  body:not(.theme-light) .icon-moon { opacity: 0; transform: scale(0.5) rotate(90deg); }
}

/* ─── Page Glows ─── */
.page-glow {
  position: fixed;
  width: 42rem;
  height: 42rem;
  border-radius: 999px;
  filter: blur(60px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
  animation: glowDrift 16s ease-in-out infinite alternate;
}

.page-glow-left {
  top: -14rem;
  left: -12rem;
  background: rgba(240, 205, 142, 0.28);
}

.page-glow-right {
  right: -10rem;
  bottom: -12rem;
  background: rgba(180, 211, 218, 0.32);
  animation-delay: -8s;
}

body.theme-dark .page-glow-left {
  background: rgba(218, 168, 85, 0.12);
}

body.theme-dark .page-glow-right {
  background: rgba(94, 122, 128, 0.14);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .page-glow-left { background: rgba(218, 168, 85, 0.12); }
  body:not(.theme-light) .page-glow-right { background: rgba(94, 122, 128, 0.14); }
}

@keyframes glowDrift {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, 20px) scale(1.06); }
}

/* ─── Water Ripples (CSS) ─── */
.water-ripples {
  position: fixed;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  mix-blend-mode: soft-light;
}

.ripple {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  border: 1.5px solid var(--ripple-color);
  transform: translate(-50%, -50%);
  animation: rippleExpand 6s ease-out infinite;
}

.ripple-1 { animation-delay: 0s; }
.ripple-2 { animation-delay: 2s; }
.ripple-3 { animation-delay: 4s; }

@keyframes rippleExpand {
  0% {
    width: 40px;
    height: 40px;
    opacity: 0.6;
    border-width: 2px;
  }
  100% {
    width: 500px;
    height: 500px;
    opacity: 0;
    border-width: 0.5px;
  }
}

/* ─── Layout Shell ─── */
.shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 32px 0 56px;
}

/* ─── Section Cards ─── */
.hero,
.story,
.chapters {
  position: relative;
  margin-bottom: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255,253,250,0.85), rgba(255,248,239,0.68));
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: box-shadow 400ms ease;
}

body.theme-dark .hero,
body.theme-dark .story,
body.theme-dark .chapters {
  background: linear-gradient(180deg, rgba(44,36,30,0.85), rgba(32,26,22,0.68));
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .hero,
  body:not(.theme-light) .story,
  body:not(.theme-light) .chapters {
    background: linear-gradient(180deg, rgba(44,36,30,0.85), rgba(32,26,22,0.68));
  }
}

.hero { padding: 28px; }

/* ─── Reveal Animation (dramatic) ─── */
.reveal {
  opacity: 0;
  transform: translate3d(0, 40px, 0);
  will-change: transform, opacity;
  transition: opacity 700ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal-child {
  opacity: 0;
  transform: translate3d(0, 30px, 0) scale3d(0.96, 0.96, 1);
  will-change: transform, opacity;
  transition: opacity 600ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal.revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.reveal-child.revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
}

/* Free up GPU after animation settles */
.reveal.revealed,
.reveal-child.revealed {
  transition: opacity 700ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 700ms cubic-bezier(0.22, 1, 0.36, 1);
  will-change: auto;
}

/* ─── Typography ─── */
.eyebrow,
.section-kicker,
.chapter-label,
.note-label,
.story-index,
.intro,
.panel-title,
.footer-brand {
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.eyebrow,
.section-kicker,
.note-label,
.panel-title,
.footer-brand {
  margin-bottom: 16px;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 700;
}

/* ─── Hero ─── */
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.9fr);
  gap: 24px;
  align-items: stretch;
}

.hero-copy,
.hero-panel,
.story-card,
.chapter-item {
  border-radius: var(--radius-lg);
}

.hero-copy { padding: 12px 8px 4px; }

.intro {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

h1, h2, h3, .cn-name {
  font-family: var(--font-display);
  font-weight: 400;
}

h1 {
  font-size: clamp(3.6rem, 10vw, 6.8rem);
  line-height: 1.02;
  padding-bottom: 0.12em;
}

h1 span {
  display: block;
  color: rgba(51, 36, 27, 0.7);
}

body.theme-dark h1 span { color: rgba(237, 228, 216, 0.6); }

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) h1 span { color: rgba(237, 228, 216, 0.6); }
}

/* Shimmer on the title */
.title-shimmer {
  background: linear-gradient(
    100deg,
    var(--ink) 30%,
    var(--gold) 50%,
    var(--ink) 70%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmerMove 5s ease-in-out infinite;
}

@keyframes shimmerMove {
  0%, 100% { background-position: 0% center; }
  50%      { background-position: 100% center; }
}

.cn-name {
  margin-top: 16px;
  font-size: clamp(1.4rem, 3vw, 2rem);
  color: var(--muted);
}

.lead {
  width: min(34rem, 100%);
  margin-top: 22px;
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.8;
}

/* ─── Hero Note Cards ─── */
.hero-notes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 30px;
}

.note-card,
.story-card,
.chapter-item,
.hero-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(94, 66, 48, 0.10);
  background: var(--card);
}

body.theme-dark .note-card,
body.theme-dark .story-card,
body.theme-dark .chapter-item,
body.theme-dark .hero-panel {
  border-color: rgba(218, 192, 140, 0.08);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .note-card,
  body:not(.theme-light) .story-card,
  body:not(.theme-light) .chapter-item,
  body:not(.theme-light) .hero-panel {
    border-color: rgba(218, 192, 140, 0.08);
  }
}

.note-card { padding: 18px 18px 20px; }

/* Glass sheen */
.note-card::after,
.story-card::after,
.chapter-item::after,
.hero-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(145deg, rgba(255,255,255,0.2), transparent 45%);
}

body.theme-dark .note-card::after,
body.theme-dark .story-card::after,
body.theme-dark .chapter-item::after,
body.theme-dark .hero-panel::after {
  background: linear-gradient(145deg, rgba(255,255,255,0.04), transparent 45%);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .note-card::after,
  body:not(.theme-light) .story-card::after,
  body:not(.theme-light) .chapter-item::after,
  body:not(.theme-light) .hero-panel::after {
    background: linear-gradient(145deg, rgba(255,255,255,0.04), transparent 45%);
  }
}

.note-text,
.panel-quote,
.story-card p,
.chapter-item p,
.footer-copy {
  color: var(--muted);
  line-height: 1.7;
}

/* ─── Hero Panel (aside) ─── */
.hero-panel {
  padding: 26px;
  background:
    radial-gradient(circle at top right, rgba(255,255,255,0.58), transparent 30%),
    linear-gradient(180deg, rgba(255,247,236,0.92), rgba(249,239,227,0.82));
  min-height: 100%;
}

body.theme-dark .hero-panel {
  background:
    radial-gradient(circle at top right, rgba(255,255,255,0.04), transparent 30%),
    linear-gradient(180deg, rgba(50,42,36,0.92), rgba(38,30,24,0.82));
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .hero-panel {
    background:
      radial-gradient(circle at top right, rgba(255,255,255,0.04), transparent 30%),
      linear-gradient(180deg, rgba(50,42,36,0.92), rgba(38,30,24,0.82));
  }
}

/* Decorative orbits */
.panel-orbit {
  position: absolute;
  border-radius: 999px;
  border: 1px solid rgba(184, 141, 82, 0.16);
  animation: orbitSpin 40s linear infinite;
}

.orbit-one {
  inset: 32px 18px auto auto;
  width: 160px;
  height: 160px;
}

.orbit-two {
  inset: auto auto 24px 20px;
  width: 110px;
  height: 110px;
  animation-direction: reverse;
  animation-duration: 30s;
}

.panel-orbit-dot {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.6;
}

.dot-one {
  top: 38px;
  right: 28px;
  animation: dotOrbit1 20s linear infinite;
}

.dot-two {
  bottom: 32px;
  left: 22px;
  animation: dotOrbit2 14s linear infinite reverse;
}

@keyframes orbitSpin {
  to { transform: rotate(360deg); }
}

@keyframes dotOrbit1 {
  0%   { transform: rotate(0deg) translateX(78px) rotate(0deg); }
  100% { transform: rotate(360deg) translateX(78px) rotate(-360deg); }
}

@keyframes dotOrbit2 {
  0%   { transform: rotate(0deg) translateX(53px) rotate(0deg); }
  100% { transform: rotate(360deg) translateX(53px) rotate(-360deg); }
}

.panel-quote {
  position: relative;
  z-index: 1;
  margin: 42px 0 94px;
  max-width: 19rem;
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1.7;
}

.panel-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ─── Story & Chapters ─── */
.story,
.chapters {
  padding: 30px 28px 32px;
}

.section-heading {
  display: grid;
  grid-template-columns: minmax(0, 0.36fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 28px;
}

.section-heading.compact {
  grid-template-columns: minmax(0, 0.32fr) minmax(0, 1fr);
}

h2 {
  font-size: clamp(1.9rem, 4vw, 3rem);
  line-height: 1.12;
  letter-spacing: -0.03em;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.story-card,
.chapter-item {
  padding: 22px 20px 24px;
}

.story-index {
  margin-bottom: 32px;
  color: rgba(184, 141, 82, 0.72);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h3 {
  margin-bottom: 12px;
  font-size: 1.45rem;
}

.chapter-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.chapter-label {
  margin-bottom: 24px;
  color: rgba(113, 92, 80, 0.78);
  font-size: 0.72rem;
  font-weight: 700;
}

body.theme-dark .chapter-label {
  color: rgba(168, 152, 136, 0.78);
}

@media (prefers-color-scheme: dark) {
  body:not(.theme-light) .chapter-label { color: rgba(168, 152, 136, 0.78); }
}

/* ─── Footer ─── */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 10px 8px;
}

.footer-copy {
  font-size: 0.95rem;
}

/* ─── Hover Interactions ─── */
@media (hover: hover) {
  .note-card,
  .story-card,
  .chapter-item,
  .hero-panel {
    transition:
      transform 280ms cubic-bezier(0.22, 1, 0.36, 1),
      border-color 280ms ease,
      box-shadow 280ms ease;
    will-change: transform;
  }

  .note-card:hover,
  .story-card:hover,
  .chapter-item:hover,
  .hero-panel:hover {
    transform: translate3d(0, -6px, 0);
    border-color: rgba(184, 141, 82, 0.32);
    box-shadow: var(--shadow-hover);
  }

  .card-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.18) 50%,
      transparent 100%
    );
    pointer-events: none;
    transition: left 700ms ease;
  }

  body.theme-dark .card-shine {
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.06) 50%,
      transparent 100%
    );
  }

  @media (prefers-color-scheme: dark) {
    body:not(.theme-light) .card-shine {
      background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.06) 50%,
        transparent 100%
      );
    }
  }

  .note-card:hover .card-shine,
  .story-card:hover .card-shine,
  .chapter-item:hover .card-shine {
    left: 150%;
  }
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .shell {
    width: min(100% - 1rem, 1120px);
    padding-top: 16px;
  }

  .hero,
  .story,
  .chapters {
    padding-left: 18px;
    padding-right: 18px;
  }

  .hero-grid,
  .section-heading,
  .section-heading.compact,
  .story-grid,
  .chapter-list {
    grid-template-columns: 1fr;
  }

  .hero-notes {
    grid-template-columns: 1fr;
  }

  .panel-quote {
    margin-bottom: 64px;
  }

  .footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .water-ripples {
    width: 300px;
    height: 300px;
    opacity: 0.35;
  }

  .ripple-1, .ripple-2, .ripple-3 {
    animation-duration: 5s;
  }
}

@media (max-width: 560px) {
  .hero { padding-top: 22px; }
  h1 { font-size: 3.35rem; }
  .lead { font-size: 0.98rem; }
  .panel-quote { font-size: 1.1rem; }
  h2 { font-size: 1.72rem; }
  h3 { font-size: 1.24rem; }

  .theme-toggle {
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
  }
}

/* ─── Reduced Motion ─── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reveal,
  .reveal-child {
    opacity: 1;
    transform: none;
  }

  .ambient-canvas,
  .water-ripples,
  .page-glow,
  .card-shine {
    display: none;
  }
}

/* ─── Focus styles ─── */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ─── Selection color ─── */
::selection {
  background: rgba(184, 141, 82, 0.22);
  color: var(--ink);
}
