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

/* ── Design tokens — field-terminal system (see docs/DESIGN.md) ─────────────── */
:root {
  /* Palette — keep in sync with js/core/theme.js (one palette, two consumers) */
  --color-obsidian-loam: #13140e;   /* page canvas — near-black, olive cast    */
  --color-bone-vellum:   #f4f3e8;   /* primary text — warm paper, not LCD white */
  --color-iron-filings:  #404040;   /* hairline borders, dividers              */
  --color-drift-ash:     #84837b;   /* muted secondary text                    */
  --color-lime-surveyor: #ebfc72;   /* THE accent — survey marker              */
  --color-marsh-olive:   #bacd31;   /* deeper lime stop for fades              */
  --color-trail-sand:    #8a7d63;   /* survey-line trail (theme.js trail); 3D only */

  /* White studio room — the environment the globe floats in. A soft cyclorama,
     not a flat fill: brightest right behind the sphere, faintly cool overhead,
     a touch warmer toward the floor. Kept warm/organic, never clinical #fff. */
  --room-light: #f6f6f3;   /* luminous near-white core (behind the globe)   */
  --room-top:   #e8eaec;   /* faintly cool upper air — gives the cove depth  */
  --room-floor: #e4e0d8;   /* soft warm floor the globe hovers above         */
  --room-bloom: rgba(255, 255, 255, 0.9);  /* radial light halo behind globe */
  --room-line:  rgba(34, 35, 27, 0.16);    /* hairline for controls on white */

  /* Control chrome on the white room — translucent chips built from
     --room-light (246,246,243), never clinical pure white. */
  --ctrl-bg:       rgba(246, 246, 243, 0.78);
  --ctrl-bg-hover: rgba(246, 246, 243, 0.98);
  /* Modal backdrop — near-opaque loam behind the lightbox photo. */
  --backdrop:      rgba(19, 20, 14, 0.97);

  /* Bloom position — JS overwrites each frame via syncBloom() so the radial
     gradient tracks the projected globe center exactly across all viewports. */
  --bloom-x: 50%;
  --bloom-y: 42%;

  /* Ink — dark text for elements that sit DIRECTLY on the white room (the
     floating HUD and controls). Distinct from --text, which stays light for
     the dark panel/tooltip/lightbox surfaces. Warm near-black, olive cast,
     never pure #000 — the room stays organic. */
  --ink:        #23241c;   /* primary text on the white room                 */
  --ink-dim:    #585a4e;   /* muted secondary (sub, coords) on the white room*/

  /* Semantic aliases (names required by verify/checks/env.js) */
  --bg:         var(--color-obsidian-loam);
  --bg-raise:   #1c1e15;
  --panel-bg:   rgba(19, 20, 14, 0.96);
  --text:       var(--color-bone-vellum);
  --text-dim:   rgba(244, 243, 232, 0.72);
  --text-faint: var(--color-drift-ash);
  --line:       var(--color-iron-filings);
  --accent:     var(--color-lime-surveyor);
  --accent-2:   var(--color-marsh-olive);

  /* Region accents — naturalistic earth family, muted so the lime stays the
     loudest note. Must match THEME.regions in theme.js and manifest colors. */
  --region-climbing:     #e26b34;
  --region-landscape:    #47b862;
  --region-music:        #9a5fdb;
  --region-portrait:     #e6a028;
  --region-professional: #3aa2cf;

  /* Semantic */
  --warn:   #ffb84d;
  --error:  #ff5d5d;

  /* Type — Inter carries the editorial voice; JetBrains Mono carries every
     UI label and tag: quiet and instrument-like, sentence case, never
     uppercase shouting. */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-hero:  clamp(2.6rem, 7vw, 4.5rem);  /* display — tight lh 0.9 block   */
  --fs-h2:    1.8rem;                       /* subheading ~29px               */
  --fs-body:  1rem;
  --fs-label: 0.8125rem;                    /* 13px mono labels               */
  --fs-meta:  0.8125rem;

  --track-display: -0.03em;                 /* editorial tracking, all sans   */

  /* Spacing */
  --sp-1: 5px;
  --sp-2: 7px;
  --sp-3: 14px;
  --sp-4: 18px;
  --sp-5: 21px;
  --sp-6: 29px;
  --sp-8: 59px;
  --sp-10: 86px;

  /* Radius — instrument panel: 3.6px on controls, square cards/images */
  --r-sm:   3.6px;
  --r-md:   0px;
  --r-pill: 3.6px;

  /* Z-index ladder */
  --z-canvas:  0;
  --z-intro:   10;
  --z-hud:     15;
  --z-tooltip: 20;
  --z-panel:   30;
  --z-modal:   40;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
html {
  /* Prevent iOS Safari from exposing a bright browser background when a touch
     drag offsets the viewport. The studio floor color fills any gap. */
  background: var(--room-floor);
  overscroll-behavior: none;
}

body {
  /* White studio room — the renderer uses alpha:true so the canvas is
     transparent and this shows through everywhere Three.js hasn't drawn
     geometry. The globe floats inside a soft cyclorama: a radial light-bloom
     sits behind the sphere, layered over a gentle vertical cove that fades to
     a faintly warmer floor — implying air and a surface the globe hovers above,
     never a hard horizon. Airy and near-white, but three-dimensional.
     UI panels use --panel-bg (near-opaque loam) so chrome never bleeds. */
  background:
    radial-gradient(
      circle at var(--bloom-x) var(--bloom-y),
      var(--room-bloom) 0%,
      rgba(255, 255, 255, 0) 46%
    ),
    linear-gradient(
      to bottom,
      var(--room-top)   0%,    /* faintly cool upper air */
      var(--room-light) 38%,   /* luminous near-white core */
      var(--room-light) 60%,
      var(--room-floor) 100%   /* soft warm floor the globe floats above */
    );
  color: var(--text);
  font-family: var(--font-sans);
  letter-spacing: var(--track-display);
  overflow: hidden;
  overscroll-behavior: none;
  height: 100dvh;
  width: 100dvw;
}

/* Soft elliptical shadow that anchors the globe to the implied floor.
   JS (syncContactShadow) writes left/top/width/height each frame so it stays
   centred under the globe across all viewport sizes and camera distances.
   z-index: -1 puts it behind the transparent canvas but above the body gradient. */
#contact-shadow {
  position: fixed;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    rgba(60, 50, 35, 0.16) 0%,
    rgba(60, 50, 35, 0.05) 55%,
    transparent 100%
  );
  pointer-events: none;
  z-index: -1;
  /* Hidden until the globe's first rendered frame — see canvas#globe.ready —
     so it never sits alone under an invisible canvas. */
  opacity: 0;
  transition: opacity 0.7s ease-out;
}
#contact-shadow.ready { opacity: 1; }

canvas#globe {
  display: block;
  position: fixed;
  inset: 0;
  z-index: var(--z-canvas);
  cursor: grab;
  touch-action: none;  /* hand all touch events to JS; prevents iOS page pan */
  /* Arrival choreography (js/ui/entrance.js): hidden and slightly scaled
     down until the scene's first rendered frame flips .ready, so the globe
     eases into the white room instead of popping in whole. */
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.7s ease-out, transform 0.7s ease-out;
}
canvas#globe.ready { opacity: 1; transform: scale(1); }
canvas#globe:active { cursor: grabbing; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Controls that sit on the white room need an ink ring — lime is invisible
   on near-white. The dark-panel controls keep the lime ring above. */
.region-jump:focus-visible,
#orbit-btn:focus-visible {
  outline-color: var(--ink);
}

/* ── Top bar — wordmark + live coordinates ──────────────────────────────────── */
#topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  /* Horizontal padding tighter than the body gutter (--sp-6): the wordmark and
     location label hug the screen corners, clear of the globe. */
  padding: var(--sp-5) var(--sp-3);
  z-index: var(--z-hud);
  pointer-events: none;   /* nothing here is clickable — it floats on the scene */
}

.brand-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  pointer-events: auto;   /* re-enable events for this subtree within the pointer-events:none nav */
}

.brand {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink);
}

.about-trigger {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--ink-dim);
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}
.about-trigger:hover { color: var(--accent); }
.about-trigger:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Location label — quietly names the region in view; hidden over open ground */
#coords {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  font-weight: 400;
  letter-spacing: normal;
  color: var(--ink-dim);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.4s ease;
}
#coords.visible { opacity: 1; }
#coords::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-right: var(--sp-2);
  background: var(--accent);
  vertical-align: 12%;
}

/* ── Intro — editorial hero, bottom-left over the scene ─────────────────────── */
#intro {
  position: fixed;
  left: var(--sp-6);
  bottom: var(--sp-10);
  text-align: left;
  pointer-events: none;
  transition: opacity 0.8s ease;
  z-index: var(--z-intro);
}
#intro.faded { opacity: 0; }

.intro-name {
  font-size: var(--fs-hero);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: var(--track-display);
  color: var(--ink);
  /* 8ch forces the two-word name to stack ("Jeffrey" / "Morales") so the hero
     stays in the room's left margin and never runs onto the dark globe —
     ink on the moss terrain is illegible. */
  max-width: 8ch;
}

.intro-sub {
  margin-top: var(--sp-4);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--ink-dim);
}

/* Quiet loading status — visible while tiles stream in, faded once they land
   (js/ui/entrance.js calls tilesReady()). */
.intro-status {
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--ink-dim);
  transition: opacity 0.5s ease;
}
.intro-status.faded { opacity: 0; }

/* Portrait: the globe intentionally overfills the width (see sceneSetup
   updateCamera), so the intro sits ON the dark terrain, not the white room —
   flip it to the light text tokens or it disappears into the ground. */
@media (orientation: portrait) {
  .intro-name   { color: var(--text); }
  .intro-sub    { color: var(--text-dim); }
  .intro-status { color: var(--text-dim); }
}

/* ── Region jump bar — bottom-right ─────────────────────────────────────────── */
#region-bar {
  position: fixed;
  right: var(--sp-6);
  bottom: var(--sp-6);
  z-index: var(--z-hud);
}

/* One unified instrument strip: a single hairline container with internal
   dividers, instead of loose floating pills — quieter and more deliberate. */
#region-nav {
  display: flex;
  background: var(--ctrl-bg);
  border: 1px solid var(--room-line);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.region-jump {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  background: transparent;
  border: none;
  border-left: 1px solid var(--room-line);
  border-radius: 0;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}
.region-jump:first-child { border-left: none; }
.region-jump::before {
  /* The region's color, as a small round marker. */
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--swatch, var(--text-faint));
  flex-shrink: 0;
}
.region-jump:hover {
  background: var(--ctrl-bg-hover);
}
.region-jump.active {
  background: var(--accent);
  color: var(--bg);
  border-left-color: transparent;
}
/* Hide the divider on the segment following the active one too, so the lime
   fill has clean edges instead of hairlines butted against it. */
.region-jump.active + .region-jump { border-left-color: transparent; }

/* ── Zoom back out — floats bottom-left, independent of the region bar ──────── */
#orbit-btn {
  position: fixed;
  bottom: var(--sp-6);
  left: var(--sp-6);
  z-index: var(--z-hud);
  background: var(--ctrl-bg);
  border: 1px solid var(--room-line);
  border-radius: var(--r-pill);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
#orbit-btn:hover {
  background: var(--ctrl-bg-hover);
  color: var(--ink);
}
body.at-surface #orbit-btn {
  opacity: 1;
  pointer-events: auto;
}

/* ── Tooltip ────────────────────────────────────────────────────────────────── */
#tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--panel-bg);
  color: var(--text);
  padding: var(--sp-1) var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: var(--z-tooltip);
  white-space: nowrap;
}
#tooltip.visible { opacity: 1; }

/* ── Panel ──────────────────────────────────────────────────────────────────── */
#panel {
  position: fixed;
  top: 50%;
  right: var(--sp-6);
  transform: translateY(-50%) translateX(0);
  width: min(380px, 90vw);
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-6);
  z-index: var(--z-panel);
  transition: opacity 0.35s cubic-bezier(.22,1,.36,1),
              transform 0.35s cubic-bezier(.22,1,.36,1);
}
#panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) translateX(var(--sp-6));
}

#panel-close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}
#panel-close:hover { color: var(--accent); }

#panel-icon {
  font-size: 2rem;
  margin-bottom: var(--sp-3);
}

#panel-title {
  font-size: var(--fs-h2);
  font-weight: 400;
  line-height: 1.06;
  letter-spacing: var(--track-display);
  color: var(--text);
  margin-bottom: var(--sp-3);
}

#panel-body {
  font-size: var(--fs-body);
  line-height: 1.62;
  color: var(--text-dim);
}

/* ── Lightbox (full-screen photo view) ──────────────────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-6);
  background: var(--backdrop);
  opacity: 1;
  transition: opacity 0.35s cubic-bezier(.22,1,.36,1);
  cursor: zoom-out;
}
#lightbox.hidden {
  opacity: 0;
  pointer-events: none;
}

#lightbox-img {
  /* Full-bleed spirit: the photo is the surface — no radius, no border, no shadow. */
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  cursor: default;
  /* Eases up into place as the backdrop fades in. */
  transform: translateY(0) scale(1);
  transition: transform 0.45s cubic-bezier(.22,1,.36,1), opacity 0.45s cubic-bezier(.22,1,.36,1);
}
#lightbox.hidden #lightbox-img {
  transform: translateY(14px) scale(0.985);
  opacity: 0;
}

#lightbox-caption {
  max-width: 92vw;
  text-align: left;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--text-faint);
  line-height: 1.5;
  transition: opacity 0.45s cubic-bezier(.22,1,.36,1) 0.08s;
}
#lightbox.hidden #lightbox-caption { opacity: 0; }
#lightbox-caption strong {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  letter-spacing: var(--track-display);
  color: var(--text);
  font-weight: 400;
  margin-bottom: var(--sp-1);
}

#lightbox-close {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-6);
  background: none;
  border: none;
  color: var(--text);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}
#lightbox-close:hover { opacity: 1; }

/* ── About overlay ──────────────────────────────────────────────────────────── */
#about {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--panel-bg);
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Closed: collapsed to top-left corner (where the trigger button lives) */
  clip-path: inset(0 100% 100% 0);
  opacity: 0;
  pointer-events: none;
  transition: clip-path 0.45s cubic-bezier(.22,1,.36,1),
              opacity   0.35s ease;
}
#about.open {
  clip-path: inset(0 0% 0% 0);
  opacity: 1;
  pointer-events: auto;
}

#about-close {
  position: fixed;
  top: var(--sp-4);
  right: var(--sp-6);
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s, color 0.2s;
  z-index: 1;
}
#about-close:hover { color: var(--text); opacity: 1; }

#about-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--sp-10) var(--sp-8);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
  min-height: 100dvh;
}

#about-location {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
/* Lime dot — mirrors the coords indicator in #topnav */
#about-location::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

#about-name {
  font-size: var(--fs-hero);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: var(--track-display);
  color: var(--text);
}

#about-tagline {
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--accent);
}

#about-bio p {
  font-size: var(--fs-body);
  line-height: 1.62;
  color: var(--text-dim);
}
#about-bio p + p { margin-top: var(--sp-4); }

#about-craft {
  list-style: none;
  border-top: 1px solid var(--line);
}
.about-craft-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sp-4);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
}
.about-craft-label  { color: var(--text); }
.about-craft-detail { color: var(--text-faint); text-align: right; }

#about-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: auto;   /* pushes links to the bottom of the flex column */
  padding-bottom: var(--sp-10);
}
.about-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  letter-spacing: normal;
  color: var(--text-dim);
  text-decoration: none;
  transition: border-color 0.2s, color 0.2s;
}
.about-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Reduced motion ─────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #intro, #panel, #tooltip, #lightbox, #lightbox-img, #lightbox-caption,
  #orbit-btn, .region-jump, #about,
  canvas#globe, #contact-shadow, .intro-status { transition: none; }
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #intro {
    left: var(--sp-4);
    right: var(--sp-4);
    bottom: 100px;   /* clear the region bar */
  }

  #region-bar {
    left: 0;
    right: 0;
    bottom: 0;
    /* No left padding here — .region-jump's own sp-3 padding already insets
       the first dot, matching the header's left edge above. Stacking the
       bar's padding on top of the button's padding doubled the gap. */
    padding: var(--sp-2) var(--sp-4) var(--sp-2) 0;
    background: var(--ctrl-bg);
    border-top: 1px solid var(--room-line);
  }
  #region-nav {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* The full-width bar provides the backing on mobile — drop the strip's
       own chrome so we don't stack a bordered chip inside a translucent bar. */
    background: transparent;
    border: none;
    border-radius: 0;
  }
  #region-nav::-webkit-scrollbar { display: none; }
  .region-jump { flex: 0 0 auto; }

  /* Orbit button floats above the left side of the nav bar on mobile */
  #orbit-btn {
    bottom: calc(52px + var(--sp-3));
    left: var(--sp-4);
  }

  #panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    transform: translateY(0);
    border-left: none;
    border-right: none;
    border-bottom: none;
  }
  #panel.hidden {
    transform: translateY(100%);
  }

  #about-inner {
    padding: var(--sp-10) var(--sp-4) var(--sp-6);
  }
}
