:root {
  --bg: #eceae4;
  --ink: #1d1c1a;
  --body: #3a382f; /* paragraph text — slightly softer than ink */
  --muted: #6f6a62;
  --line: rgba(29, 28, 26, 0.14);
}

/* Night mode — inverted palette; the 3D scene dims in parallel via JS */
body.night {
  --bg: #11161f;
  --ink: #eceae4;
  --body: #d6d3ca; /* soft light for body text on dark */
  --muted: #9aa3b0;
  --line: rgba(236, 234, 228, 0.16);
}

/* Smooth the day/night theme flip on the UI */
body,
.panel, .panel p, .signoff, .open-gallery,
.contact input, .contact textarea, .contact button,
.dots button, .logo, .kicker,
.gallery, .detail, .detail-body p, .detail-inner,
.gallery-close, .detail-close, .detail-nav, .mode-toggle {
  transition: background-color 0.8s ease, color 0.8s ease,
              border-color 0.8s ease, box-shadow 0.6s ease;
}

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

/* visually hidden, still read by search engines & screen readers */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html { scroll-behavior: auto; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, sans-serif;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---- WebGL canvas: fixed full-screen backdrop ---- */
#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* avoids jump as mobile browser chrome shows/hides */
  display: block;
  z-index: 0;
}

/* ---- Scroll track: the thing that actually scrolls ---- */
.scroll-track {
  position: relative;
  height: 760vh; /* longer = slower orbit; tail reserved for the map reveal */
  width: 100%;
  pointer-events: none;
  z-index: 1;
}

/* ---- Loader ---- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: grid;
  place-items: center;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}
#loader span {
  font-family: "Cormorant Garamond", serif;
  font-size: clamp(2rem, 8vw, 4rem);
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--ink);
  animation: pulse 1.6s ease-in-out infinite;
}
#loader.hidden { opacity: 0; visibility: hidden; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---- Fixed chrome (header) ---- */
.chrome {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(1.2rem, 3vw, 2.2rem) clamp(1.4rem, 4vw, 3rem);
  pointer-events: none;
}
.logo {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  text-indent: 0.35em;
  font-weight: 500;
}
.logo .dot { color: var(--muted); }

/* nav dots */
.dots {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  pointer-events: auto;
}
.dots button {
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  padding: 0;
  transition: background 0.3s ease, transform 0.3s ease;
}
.dots button.active { background: var(--ink); transform: scale(1.25); }

/* ---- Right-side header cluster + day/night toggle ---- */
.chrome-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1rem;
  pointer-events: none;
}
.mode-toggle {
  pointer-events: auto;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.mode-toggle:hover { border-color: var(--ink); }
.mode-toggle svg path { transition: fill 0.6s ease; }
/* lamp "switches on" — warm glow — at night */
body.night .mode-toggle {
  color: #ffd9a3;
  border-color: rgba(255, 217, 163, 0.5);
  background: rgba(255, 217, 163, 0.08);
  box-shadow: 0 0 20px rgba(255, 200, 120, 0.45);
}
body.night .mode-toggle svg path:last-child { fill: rgba(255, 217, 163, 0.28); }

/* Darken the overlays at night (these use fixed alpha, not the vars) */
body.night .gallery { background: rgba(12, 16, 24, 0.9); }
body.night .detail { background: rgba(4, 7, 12, 0.62); }
body.night .contact input,
body.night .contact textarea { background: rgba(255, 255, 255, 0.06); }

/* ---- Hero ---- */
.hero {
  position: fixed;
  left: clamp(1.4rem, 6vw, 6rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  max-width: 38rem;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.hero h1 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2.6rem, 8vw, 6rem);
  line-height: 0.98;
  letter-spacing: -0.01em;
}
.hero h1 em { font-style: italic; color: var(--muted); }
.scroll-hint {
  margin-top: 2rem;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.scroll-hint::before {
  content: "↓";
  display: inline-block;
  margin-right: 0.6em;
  animation: bob 1.8s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(4px); } }

/* ---- Content panels ---- */
.panels { z-index: 10; }
.panel {
  position: fixed;
  right: clamp(1.4rem, 6vw, 6rem);
  top: 50%;
  width: min(30rem, 84vw);
  transform: translateY(-50%) translateX(36px);
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  will-change: opacity, transform;
}
/* The active panel is interactive (buttons/form); inactive panels stay
   transparent to input so they never block clicks or page scrolling. */
.panel.is-active { pointer-events: auto; }
.kicker {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.9rem;
}
.panel h2 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  line-height: 1;
  margin-bottom: 1.4rem;
}
.panel p { color: var(--body); line-height: 1.6; margin-bottom: 1rem; max-width: 26rem; }
.signoff { font-style: italic; color: var(--muted); }

.project-list, .service-list { list-style: none; }
.project-list li {
  display: flex;
  flex-direction: column;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}
.project-list li:last-child { border-bottom: 1px solid var(--line); }
.project-list strong { font-weight: 500; font-size: 1.05rem; }
.project-list span { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }

.service-list li {
  padding: 0.7rem 0;
  border-top: 1px solid var(--line);
  font-size: 1.1rem;
  font-weight: 300;
}
.service-list li:last-child { border-bottom: 1px solid var(--line); }

/* contact form */
.contact { display: flex; flex-direction: column; gap: 0.7rem; margin-top: 0.4rem; }
.contact input, .contact textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--line);
  padding: 0.8rem 1rem;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  resize: none;
}
.contact input:focus, .contact textarea:focus { outline: none; border-color: var(--ink); }
.contact button {
  margin-top: 0.4rem;
  padding: 0.85rem 1rem;
  background: var(--ink);
  color: var(--bg);
  border: none;
  font-family: inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  cursor: pointer;
  transition: opacity 0.25s ease;
}
.contact button:hover { opacity: 0.85; }

/* ---- Projects panel affordances ---- */
.open-gallery {
  margin-top: 0.4rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  background: var(--ink);
  color: var(--bg);
  border: none;
  padding: 0.8rem 1.3rem;
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.25s ease;
}
.open-gallery:hover { opacity: 0.85; }

/* ---- Gallery overlay ---- */
.gallery {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(236, 234, 228, 0.86);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  overflow-y: auto;
  padding: clamp(1.4rem, 4vw, 3rem);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px);
  transition: opacity 0.5s ease, transform 0.5s ease, visibility 0.5s ease;
}
.gallery.open { opacity: 1; visibility: visible; transform: none; }

.gallery-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto 2rem;
}
.gallery-head h2 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  line-height: 1;
}
.gallery-close, .detail-close {
  background: none;
  border: 1px solid var(--line);
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease;
}
.gallery-close:hover, .detail-close:hover { background: var(--ink); color: var(--bg); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr));
  gap: clamp(1rem, 2.2vw, 1.8rem);
  max-width: 1200px;
  margin: 0 auto;
}
.card {
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink);
}
.card-img {
  aspect-ratio: 4 / 3;
  width: 100%;
  position: relative;
  overflow: hidden;
  transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card-img::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(20, 20, 18, 0.35), transparent 55%);
}
.card:hover .card-img { transform: scale(1.02); }
.card-meta { padding: 0.85rem 0.2rem; }
.card-meta strong { display: block; font-weight: 500; font-size: 1.05rem; }
.card-meta span { color: var(--muted); font-size: 0.85rem; }

/* ---- Detail lightbox ---- */
.detail {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(28, 27, 25, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.detail.open { opacity: 1; visibility: visible; }
.detail-inner {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 0;
  max-width: 1000px;
  width: 100%;
  background: var(--bg);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.3);
}
.detail-img { min-height: 420px; }
.detail-body { padding: clamp(1.6rem, 3vw, 2.8rem); align-self: center; }
.detail-body h3 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1;
  margin: 0.4rem 0 1.2rem;
}
.detail-body p { color: var(--body); line-height: 1.7; }
.detail-close { position: fixed; top: 1.6rem; right: 1.6rem; background: var(--bg); }
.detail-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg);
  border: 1px solid var(--line);
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 1.8rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease;
}
.detail-nav:hover { background: var(--ink); color: var(--bg); }
.detail-nav.prev { left: 1.6rem; }
.detail-nav.next { right: 1.6rem; }

/* ---- Final location / map reveal ---- */
.location {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  padding: clamp(1.2rem, 4vw, 3rem);
  opacity: 0;
  visibility: hidden;
  background: rgba(236, 234, 228, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
}
.location.shown { visibility: visible; pointer-events: auto; }

.map-card {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  width: min(960px, 100%);
  height: min(540px, 78vh);
  background: var(--bg);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}
.sk-frame {
  display: grid;
  place-items: center;
  padding: clamp(1.4rem, 4vw, 2.6rem);
}
.sk-map { width: 100%; }
.sk-map svg {
  width: 100%;
  height: auto;
  display: block;
  color: var(--ink);
  overflow: visible;
}
.sk-shape {
  fill: currentColor;
  fill-opacity: 0.08;
  stroke: currentColor;
  stroke-opacity: 0.45;
  stroke-width: 1.4;
  stroke-linejoin: round;
}
.sk-dot { fill: #b5651d; stroke: #fff; stroke-width: 2; }
.sk-pulse {
  fill: #b5651d;
  transform-box: fill-box;
  transform-origin: center;
  animation: skping 1.9s ease-out infinite;
}
@keyframes skping {
  0% { transform: scale(0.4); opacity: 0.55; }
  100% { transform: scale(2.6); opacity: 0; }
}
.sk-label {
  fill: var(--ink);
  font-family: "Inter", sans-serif;
  font-size: 20px;
  font-weight: 400;
}
.map-info {
  padding: clamp(1.6rem, 3vw, 2.6rem);
  align-self: center;
}
.map-info h2 {
  font-family: "Cormorant Garamond", serif;
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1;
  margin: 0.4rem 0 1.2rem;
}
.map-info p { color: var(--muted); line-height: 1.7; margin-bottom: 1.4rem; }
.map-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.3rem;
}
.map-link:hover { border-color: var(--ink); }

/* darker scrim at night (the silhouette adapts via currentColor) */
body.night .location { background: rgba(12, 16, 24, 0.55); }

/* ---- Mobile ---- */
@media (max-width: 720px) {
  .chrome { padding: 1rem 1.2rem; }
  .hero {
    top: auto; bottom: 16vh; left: 1.4rem; right: 1.4rem;
    max-width: none; transform: none;
  }
  /* light halo keeps the hero legible over darker scene areas (e.g. the pool) */
  .hero h1 {
    font-size: clamp(2.4rem, 12vw, 3.6rem);
    text-shadow: 0 1px 22px rgba(236, 234, 228, 0.95), 0 0 6px rgba(236, 234, 228, 0.85);
  }
  .scroll-hint {
    margin-top: 1.2rem;
    color: var(--ink);
    text-shadow: 0 1px 14px rgba(236, 234, 228, 0.98), 0 0 4px rgba(236, 234, 228, 0.9);
  }

  .panel {
    right: 0; left: 0;
    top: auto; bottom: 0;
    width: 100%;
    max-height: 72vh;
    overflow-y: auto;
    transform: translateY(24px);
    padding: 1.4rem 1.4rem calc(1.6rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 62%, rgba(236, 234, 228, 0));
  }
  /* active panel scrolls internally if its content overflows; the scene
     area above it still scrolls the page */
  .panel.is-active { pointer-events: auto; -webkit-overflow-scrolling: touch; }
  .panel .kicker { margin-bottom: 0.55rem; }
  .panel h2 { font-size: clamp(1.9rem, 8vw, 2.6rem); margin-bottom: 0.7rem; }
  .panel p { font-size: 0.95rem; margin-bottom: 0.7rem; }
  .open-gallery { padding: 0.9rem 1.2rem; }

  /* compact contact form so it doesn't climb up the screen */
  .contact { gap: 0.5rem; margin-top: 0.2rem; }
  .contact input, .contact textarea { padding: 0.65rem 0.85rem; font-size: 0.92rem; }
  .contact textarea { height: 3.2rem; min-height: 3.2rem; }
  .contact button { margin-top: 0.2rem; padding: 0.8rem; }

  .dots { display: none; }

  .gallery { padding: 1.2rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom)); }
  .gallery-head { margin-bottom: 1.2rem; }
  .gallery-grid { gap: 1.1rem; }
  .detail { padding: 0; place-items: stretch; }
  .detail-inner {
    grid-template-columns: 1fr;
    max-height: 100dvh; height: 100dvh;
    overflow-y: auto;
  }
  .detail-img { min-height: 44vh; }
  .detail-nav { display: none; }
  .detail-close { top: 1rem; right: 1rem; }

  .location { padding: 1.1rem; }
  .map-card {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: min(82vh, 640px);
    width: 100%;
  }
  .map-info { padding: 1.3rem 1.4rem calc(1.3rem + env(safe-area-inset-bottom)); }
  .map-info h2 { margin: 0.3rem 0 0.8rem; }
  .map-info p { margin-bottom: 1rem; }
}
