/* ============================================
   MARGINALIA — Digital Garden Design System
   ============================================ */

/* --- Google Fonts Import --- */
@import url('https://fonts.googleapis.com/css2?family=UnifrakturMaguntia&family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400;1,700&family=Caveat:wght@400;500;600;700&family=Source+Sans+3:ital,wght@0,300;0,400;0,600;0,700;1,400;1,600&family=JetBrains+Mono:wght@300;400;500&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Foundation — Black Hours / Illuminated Manuscript */
  --bg-primary: #0A0E1A;           /* Deep midnight blue-black */
  --bg-paper: #E8E2D6;             /* Cool parchment */
  --bg-paper-alt: #D9D2C4;         /* Darker parchment */

  /* Accent Colors */
  --gold: #D4AF37;                 /* Bright gold leaf */
  --gold-light: #F0D060;           /* Luminous gold — hover/glow */
  --gold-dim: #9A7B2C;             /* Antique gold — subtle details */
  --navy: #162044;                 /* Deep lapis lazuli */
  --navy-light: #1E2D5E;          /* Lighter ultramarine */
  --lapis: #1A3A6E;               /* Rich lapis blue — key accent */
  --lapis-light: #2550A0;         /* Brighter lapis — hovers */
  --sage: #2E5E4E;                /* Deep forest — cooler green */
  --sage-light: #3D7A66;          /* Lighter sage */
  --crimson: #8B1A2B;             /* Deep manuscript crimson */
  --crimson-light: #A82040;       /* Brighter crimson */

  /* Text */
  --text-cream: #E8E2D6;          /* Cool parchment text on dark */
  --text-dark: #0A0E1A;           /* Text on parchment */
  --text-muted: #7A8099;          /* Cool muted text on dark */
  --text-muted-light: #6B6560;    /* Muted text on parchment */

  /* Utility */
  --border-gold: rgba(212, 175, 55, 0.35);
  --border-cream: rgba(232, 226, 214, 0.1);
  --border-lapis: rgba(26, 58, 110, 0.5);
  --shadow: rgba(0, 0, 0, 0.5);

  /* Typography */
  --font-display: 'UnifrakturMaguntia', cursive;
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-handwritten: 'Caveat', cursive;
  --font-body: 'Source Sans 3', 'Source Sans Pro', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  --space-2xl: 5rem;
  --space-3xl: 8rem;

  /* Layout */
  --max-width: 1200px;
  --nav-height: 70px;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  scrollbar-color: var(--gold-dim) var(--bg-primary);
}

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

/* Subtle background texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  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)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* --- Custom Cursor --- */
.cursor-dot {
  width: 8px;
  height: 8px;
  background: var(--gold);
  border-radius: 50%;
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  transition: transform 0.1s ease;
  mix-blend-mode: difference;
}

.cursor-ring {
  width: 32px;
  height: 32px;
  border: 1.5px solid var(--gold);
  border-radius: 50%;
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  transition: transform 0.15s ease, width 0.2s ease, height 0.2s ease, border-color 0.2s ease;
  transform: translate(-50%, -50%);
  opacity: 0.6;
}

.cursor-ring.hover {
  width: 48px;
  height: 48px;
  border-color: var(--gold-light);
  opacity: 1;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--gold-dim);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* --- Selection --- */
::selection {
  background: var(--gold);
  color: var(--bg-primary);
}

/* --- Links --- */
a {
  color: var(--gold);
  text-decoration: none;
  position: relative;
  transition: color 0.3s ease;
}

a:hover {
  color: var(--gold-light);
}

/* Animated underline */
.link-underline {
  position: relative;
}

.link-underline::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--gold-light);
  transition: width 0.3s ease;
}

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

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
}

.font-display {
  font-family: var(--font-display);
  font-weight: 400;
}

.font-heading {
  font-family: var(--font-heading);
}

.font-handwritten {
  font-family: var(--font-handwritten);
}

.font-mono {
  font-family: var(--font-mono);
}

.text-gold {
  color: var(--gold);
}

.text-muted {
  color: var(--text-muted);
}

/* --- Navigation --- */
.site-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-lg);
  background: rgba(10, 14, 26, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-gold);
  transition: transform 0.3s ease, background 0.3s ease;
}

.site-nav.hidden {
  transform: translateY(-100%);
}

.nav-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--gold);
  letter-spacing: 0.02em;
}

.nav-title a {
  color: inherit;
}

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

.nav-links a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  transition: color 0.3s ease;
  position: relative;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--gold);
  transition: width 0.3s ease;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--gold);
}

.nav-links a:hover::after,
.nav-links a.active::after {
  width: 100%;
}

/* Mobile nav toggle */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  z-index: 1001;
}

.nav-toggle span {
  display: block;
  width: 24px;
  height: 1.5px;
  background: var(--gold);
  transition: all 0.3s ease;
  transform-origin: center;
}

.nav-toggle.open span:nth-child(1) {
  transform: rotate(45deg) translate(4px, 5px);
}

.nav-toggle.open span:nth-child(2) {
  opacity: 0;
}

.nav-toggle.open span:nth-child(3) {
  transform: rotate(-45deg) translate(4px, -5px);
}

/* Mobile nav panel */
.mobile-nav {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 26, 0.97);
  backdrop-filter: blur(20px);
  z-index: 999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-lg);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.mobile-nav.open {
  display: flex;
  opacity: 1;
}

.mobile-nav a {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--text-cream);
  transition: color 0.3s ease;
}

.mobile-nav a:hover {
  color: var(--gold);
}

/* --- Main Content --- */
main {
  position: relative;
  z-index: 1;
  padding-top: var(--nav-height);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* --- Page Header --- */
.page-header {
  padding: var(--space-3xl) 0 var(--space-2xl);
  text-align: center;
  position: relative;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  color: var(--gold);
  margin-bottom: var(--space-sm);
}

.page-header .subtitle {
  font-family: var(--font-handwritten);
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  color: var(--text-muted);
}

/* --- Cards --- */
.card {
  background: var(--bg-paper);
  color: var(--text-dark);
  border-radius: 4px;
  padding: var(--space-lg);
  position: relative;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  overflow: hidden;
}

/* Paper texture overlay */
.card::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='paper'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='5' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23paper)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  border-radius: inherit;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px var(--shadow), 0 0 0 1px var(--border-gold);
}

.card-navy {
  background: var(--lapis);
  color: var(--text-cream);
  border: 1px solid var(--border-gold);
}

.card-navy:hover {
  background: var(--lapis-light);
}

.card-dark {
  background: rgba(10, 14, 26, 0.8);
  color: var(--text-cream);
  border: 1px solid var(--border-gold);
}

/* --- Tags / Badges --- */
.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2em 0.7em;
  border-radius: 2px;
  background: var(--sage);
  color: var(--text-cream);
  transition: background 0.3s ease;
}

.tag:hover {
  background: var(--sage-light);
}

.tag-gold {
  background: var(--gold-dim);
}

.tag-gold:hover {
  background: var(--gold);
  color: var(--bg-primary);
}

.tag-navy {
  background: var(--lapis);
}

.tag-navy:hover {
  background: var(--lapis-light);
}

/* --- Decorative Elements --- */

/* Gold ornamental divider */
.divider {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin: var(--space-xl) 0;
  opacity: 0.6;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.divider-star {
  color: var(--gold);
  font-size: 0.8rem;
  flex-shrink: 0;
}

/* Scattered star decorations */
.star-decoration {
  position: absolute;
  color: var(--gold);
  opacity: 0.3;
  font-size: 1.2rem;
  pointer-events: none;
  animation: starTwinkle 4s ease-in-out infinite;
}

@keyframes starTwinkle {
  0%, 100% { opacity: 0.2; transform: scale(1) rotate(0deg); }
  50% { opacity: 0.5; transform: scale(1.1) rotate(10deg); }
}

/* Wax seal */
.wax-seal {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--crimson-light), var(--crimson));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--bg-paper);
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,0.3),
    0 4px 12px rgba(0,0,0,0.4);
  position: relative;
}

.wax-seal::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
}

/* Gold ornamental border */
.ornamental-border {
  border: 1px solid var(--border-gold);
  position: relative;
}

.ornamental-border::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid var(--border-gold);
  pointer-events: none;
}

/* Section number (editorial style) */
.section-number {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--gold-dim);
  letter-spacing: 0.1em;
}

.section-number-large {
  font-family: var(--font-heading);
  font-size: 4rem;
  font-weight: 900;
  color: transparent;
  -webkit-text-stroke: 1px var(--gold-dim);
  opacity: 0.3;
  line-height: 1;
}

/* Torn paper edge effect (top) */
.torn-edge-top {
  position: relative;
}

.torn-edge-top::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 0;
  right: 0;
  height: 8px;
  background: var(--bg-paper);
  mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,8 Q5,2 10,6 T20,5 T30,7 T40,4 T50,6 T60,3 T70,7 T80,5 T90,6 T100,4 L100,8 Z' fill='white'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0,8 Q5,2 10,6 T20,5 T30,7 T40,4 T50,6 T60,3 T70,7 T80,5 T90,6 T100,4 L100,8 Z' fill='white'/%3E%3C/svg%3E");
  mask-size: 200px 8px;
  -webkit-mask-size: 200px 8px;
}

/* --- Animations --- */

/* Fade in up (scroll reveal) */
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Stagger children */
.stagger-children .reveal:nth-child(1) { transition-delay: 0s; }
.stagger-children .reveal:nth-child(2) { transition-delay: 0.1s; }
.stagger-children .reveal:nth-child(3) { transition-delay: 0.15s; }
.stagger-children .reveal:nth-child(4) { transition-delay: 0.2s; }
.stagger-children .reveal:nth-child(5) { transition-delay: 0.25s; }
.stagger-children .reveal:nth-child(6) { transition-delay: 0.3s; }
.stagger-children .reveal:nth-child(7) { transition-delay: 0.35s; }
.stagger-children .reveal:nth-child(8) { transition-delay: 0.4s; }
.stagger-children .reveal:nth-child(9) { transition-delay: 0.45s; }
.stagger-children .reveal:nth-child(10) { transition-delay: 0.5s; }

/* Gold glow pulse */
@keyframes goldGlow {
  0%, 100% { text-shadow: 0 0 10px rgba(201, 168, 76, 0.3); }
  50% { text-shadow: 0 0 20px rgba(201, 168, 76, 0.6), 0 0 40px rgba(201, 168, 76, 0.2); }
}

.gold-glow {
  animation: goldGlow 3s ease-in-out infinite;
}

/* Shimmer effect for gold elements */
@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

.gold-shimmer {
  background: linear-gradient(90deg, var(--gold-dim), var(--gold-light), var(--gold), var(--gold-light), var(--gold-dim));
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 4s linear infinite;
}

/* Float animation for decorative elements */
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  33% { transform: translateY(-6px) rotate(1deg); }
  66% { transform: translateY(3px) rotate(-1deg); }
}

.float {
  animation: float 6s ease-in-out infinite;
}

/* --- Grid Layouts --- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-lg);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
}

.grid-asymmetric {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-lg);
}

.grid-bento {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(200px, auto);
  gap: var(--space-lg);
}

.grid-bento .span-2 {
  grid-column: span 2;
}

.grid-bento .span-row-2 {
  grid-row: span 2;
}

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mt-2xl { margin-top: var(--space-2xl); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

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

.site-footer p {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
}

.site-footer .footer-handwritten {
  font-family: var(--font-handwritten);
  font-size: 1.1rem;
  color: var(--gold-dim);
  margin-bottom: var(--space-sm);
}

/* --- Page Transition Overlay --- */
.page-transition {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.page-transition.active {
  opacity: 1;
  pointer-events: all;
}

/* --- Responsive --- */
@media (max-width: 900px) {
  .grid-2,
  .grid-3,
  .grid-asymmetric {
    grid-template-columns: 1fr;
  }

  .grid-bento {
    grid-template-columns: 1fr;
  }

  .grid-bento .span-2 {
    grid-column: span 1;
  }

  .nav-links {
    display: none;
  }

  .nav-toggle {
    display: flex;
  }

  .page-header h1 {
    font-size: clamp(2rem, 8vw, 3rem);
  }
}

@media (max-width: 600px) {
  :root {
    --space-lg: 1.25rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;
    --nav-height: 60px;
  }

  .card {
    padding: var(--space-md);
  }
}

/* Hide custom cursor on touch devices */
@media (hover: none) {
  .cursor-dot,
  .cursor-ring {
    display: none !important;
  }
}
