/*
 * Coral Editorial + Lattice System
 *
 * Design vocabulary:
 * - Grid of nodes (100px spacing)
 * - Coral accent for interactive elements
 * - L-shaped Manhattan connections in hero/contact
 * - Subtle grid background elsewhere
 */

:root {
  /* Core palette */
  --bg: #FDFBF7;
  --bg-alt: #F5F0E8;
  --text: #1A1714;
  --text-dim: #6B635A;
  --accent: #E85A4F;
  --accent-hover: #D14940;
  --border: #E8E2D9;

  /* Lattice system - single source of truth */
  --grid-size: 100;
  --grid-size-px: 100px;
  --node-radius: 2px;
  --node-color: rgba(26, 23, 20, 0.12);
  --node-color-solid: #1A1714;
  --line-color: rgba(232, 90, 79, 0.5);
  --connection-radius: 250;
}

/* System preference (no flash) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1A1714;
    --bg-alt: #252220;
    --text: #FDFBF7;
    --text-dim: #A09A93;
    --border: #3D3835;
    --node-color: rgba(253, 251, 247, 0.15);
    --node-color-solid: #FDFBF7;
    --line-color: rgba(232, 90, 79, 0.7);
  }
}

/* Explicit user override */
[data-theme="light"] {
  --bg: #FDFBF7;
  --bg-alt: #F5F0E8;
  --text: #1A1714;
  --text-dim: #6B635A;
  --border: #E8E2D9;
  --node-color: rgba(26, 23, 20, 0.12);
  --node-color-solid: #1A1714;
  --line-color: rgba(232, 90, 79, 0.5);
}

[data-theme="dark"] {
  --bg: #1A1714;
  --bg-alt: #252220;
  --text: #FDFBF7;
  --text-dim: #A09A93;
  --border: #3D3835;
  --node-color: rgba(253, 251, 247, 0.15);
  --node-color-solid: #FDFBF7;
  --line-color: rgba(232, 90, 79, 0.7);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Crimson Pro', Georgia, serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Lattice Canvas - shared by hero and contact
   ========================================================================== */

.lattice-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

/* ==========================================================================
   Grid Background - CSS-only for content sections
   Single radial gradient repeated, matches canvas grid exactly
   ========================================================================== */

.grid-bg {
  background-image: radial-gradient(circle at center, var(--node-color) var(--node-radius), transparent var(--node-radius));
  background-size: var(--grid-size-px) var(--grid-size-px);
  background-position: calc(var(--grid-size-px) / 2) calc(var(--grid-size-px) / 2);
}

/* ==========================================================================
   Scroll Progress
   ========================================================================== */

.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  width: 0%;
  z-index: 1000;
}

/* ==========================================================================
   Header
   ========================================================================== */

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

nav {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.25rem 3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.375rem;
  font-style: italic;
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 2.5rem;
  align-items: center;
}

.nav-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.9375rem;
  position: relative;
  transition: color 0.3s ease;
}

.nav-links a::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

/* Theme toggle */
.theme-toggle {
  background: var(--text);
  color: var(--bg);
  border: none;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.theme-toggle:hover {
  opacity: 0.8;
}

/* ==========================================================================
   Hero - Full lattice effect
   ========================================================================== */

.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  padding: 8rem 3rem;
  overflow: hidden;
}

.hero-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3rem;
  width: 100%;
}

.hero-main h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(4rem, 10vw, 9rem);
  font-weight: 400;
  font-style: italic;
  line-height: 1.15;
  letter-spacing: -0.03em;
  margin-bottom: 0;
}

.hero-main h1 .line {
  display: inline;
}

.hero-main h1 .char {
  display: inline-block;
  opacity: 0;
  animation: charReveal 0.6s ease forwards;
}

@keyframes charReveal {
  to { opacity: 1; }
}

.hero-main h1 em {
  color: var(--accent);
  font-style: italic;
}

.hero-main h1::after {
  content: '';
  display: block;
  width: 120px;
  height: 2px;
  background: var(--accent);
  margin-top: 1.5rem;
  transform: scaleX(0);
  transform-origin: left;
  animation: lineExpand 1s cubic-bezier(0.16, 1, 0.3, 1) 0.8s forwards;
}

@keyframes lineExpand {
  to { transform: scaleX(1); }
}

.hero-side {
  display: flex;
  align-items: center;
  gap: 3rem;
}

.hero-sub {
  font-size: 1.125rem;
  color: var(--text-dim);
  margin-bottom: 0;
  max-width: 420px;
  line-height: 1.7;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-block;
  padding: 1rem 2.5rem;
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9375rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
  transition: color 0.4s ease;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: -1;
}

.btn:hover {
  color: var(--bg);
}

.btn:hover::before {
  transform: scaleX(1);
}

/* ==========================================================================
   Sections - Base styles
   ========================================================================== */

section {
  padding: 8rem 3rem;
  max-width: 1400px;
  margin: 0 auto;
  scroll-margin-top: 80px;
}

.section-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.5rem;
  font-weight: 400;
  font-style: italic;
  margin-bottom: 4rem;
  position: relative;
}

.section-title::after {
  content: '';
  display: block;
  width: 60px;
  height: 1px;
  background: var(--accent);
  margin-top: 1rem;
}

/* ==========================================================================
   Projects Section - Grid background
   ========================================================================== */

#projects {
  position: relative;
  background: var(--bg-alt);
  max-width: none;
  padding-left: 0;
  padding-right: 0;
}

#projects .section-inner {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 3rem;
}

/* Featured project */
.featured {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4rem;
  margin-bottom: 4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4rem;
  align-items: center;
  transition: all 0.5s ease;
  position: relative;
  text-decoration: none;
  color: inherit;
}

.featured::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at center, var(--node-color) 1px, transparent 1px);
  background-size: 50px 50px;
  background-position: 25px 25px;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.featured:hover::before {
  opacity: 1;
}

.featured:hover {
  border-color: var(--accent);
  box-shadow: 0 30px 60px rgba(0,0,0,0.08);
}

.featured-content {
  position: relative;
  z-index: 1;
}

.featured-content h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.5rem;
  font-style: italic;
  margin-bottom: 1rem;
}

.featured-content p {
  color: var(--text-dim);
  font-size: 1.125rem;
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

/* Misty Step logo - subtle watermark in corner */
.featured-logo {
  position: absolute;
  bottom: 2rem;
  right: 2rem;
  width: 140px;
  height: auto;
  color: var(--accent);
  opacity: 0.7;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.featured:hover .featured-logo {
  opacity: 1;
  transform: translateX(4px);
}

.link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9375rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: gap 0.3s ease;
}

.link:hover {
  gap: 16px;
}

/* Project grid - consistent card sizes */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.project {
  display: block;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2rem;
  transition: all 0.4s ease;
  position: relative;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
}

/* Dotted background on hover - same as featured */
.project::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at center, var(--node-color) 1px, transparent 1px);
  background-size: 30px 30px;
  background-position: 15px 15px;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.project:hover::before {
  opacity: 1;
}

/* Pulse node on hover - grid vocabulary */
.project::after {
  content: '';
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0);
  transition: all 0.4s ease;
}

.project:hover::after {
  opacity: 1;
  transform: scale(1);
  animation: nodePulse 2s ease-in-out infinite;
}

@keyframes nodePulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.5); opacity: 1; }
}

.project:hover {
  border-color: var(--accent);
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(0,0,0,0.06);
}


.project h4 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.375rem;
  font-style: italic;
  margin-bottom: 0.5rem;
  transition: color 0.3s ease;
  position: relative;
  z-index: 1;
}

.project:hover h4 {
  color: var(--accent);
}

.project p {
  color: var(--text-dim);
  font-size: 0.9375rem;
  position: relative;
  z-index: 1;
}

/* ==========================================================================
   Services Section - Grid background
   ========================================================================== */

#services {
  position: relative;
}

#services::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at center, var(--node-color) var(--node-radius), transparent var(--node-radius));
  background-size: var(--grid-size-px) var(--grid-size-px);
  background-position: calc(var(--grid-size-px) / 2) calc(var(--grid-size-px) / 2);
  opacity: 0.5;
  pointer-events: none;
}

.services-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3rem;
}

.service {
  border-left: 2px solid var(--border);
  padding-left: 2rem;
  transition: all 0.4s ease;
  position: relative;
}

/* Node marker at top of border */
.service::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0;
  width: 8px;
  height: 8px;
  background: var(--border);
  border-radius: 50%;
  transition: all 0.4s ease;
}

.service:hover::before {
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.service:hover {
  border-color: var(--accent);
  transform: translateX(10px);
}

.service h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.5rem;
  font-style: italic;
  margin-bottom: 1rem;
  transition: color 0.3s ease;
}

.service:hover h3 {
  color: var(--accent);
}

.service p {
  color: var(--text-dim);
  font-size: 1rem;
}

/* ==========================================================================
   Contact Section - Full lattice effect (bookend)
   ========================================================================== */

#contact {
  position: relative;
  background: var(--bg-alt);
  max-width: none;
  text-align: center;
  overflow: hidden;
}

#contact .section-inner {
  position: relative;
  z-index: 1;
  max-width: 700px;
  margin: 0 auto;
}

#contact .section-title::after {
  margin-left: auto;
  margin-right: auto;
}

.contact-intro {
  color: var(--text-dim);
  font-size: 1.0625rem;
  margin-bottom: 2rem;
  line-height: 1.7;
}

/* ==========================================================================
   Footer
   ========================================================================== */

footer {
  padding: 3rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  color: var(--text-dim);
  font-size: 0.8125rem;
}

footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.3s ease;
}

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

/* ==========================================================================
   Reveal Animations
   ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(40px);
  transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1024px) {
  .featured { grid-template-columns: 1fr; }
  .projects-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .projects-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  nav { padding: 1rem 1.5rem; }
  .nav-links { gap: 1.5rem; }
  section { padding: 5rem 1.5rem; }
  .services-grid { grid-template-columns: 1fr; }
  .featured { padding: 2rem; }
  .hero-side { flex-direction: column; align-items: flex-start; gap: 2rem; }
}
