/*
 * Living UI — the shared living design layer for codexofreality.org.
 *
 * Wired into every top-level content page (body.living-ui) except the
 * R1.7-protected Living Time Sphere page and utility/redirect pages.
 * The homepage loads it alongside living-entry.css, which carries the
 * entry overlay and the guided path.
 *
 * The layer is ambience and surface, never structure:
 *   - a dark-stone ambient field with slow breathing teal/gold glows
 *   - gold seams on rules and dividers
 *   - stone-tinted panel/card surfaces with a soft gold hairline
 *   - living links: a gold underline draws in on hover, with a faint glow
 *   - gold selection, gold focus-visible rings
 *   - smooth in-page anchor travel (motion-safe only)
 *   - staged reveal-on-enter for top-level sections (armed by
 *     living-ui.js; everything is fully visible without JS)
 *   - the living motion wave: cards rising softly into view, hover
 *     and press answers on doors and buttons, surfaces easing their
 *     colours when the theme variables change, and two quiet
 *     homepage moments (the day line, the Sphere frame's glow)
 *   - the page opening (.lpo-*): one quiet arrival moment, once per
 *     session — the mark, the page's name, today's line, and a quiet
 *     way-forward line late in the hold — injected by
 *     living-ui.js only, standing apart on the same opaque deep-stone
 *     ground as the homepage entry while it plays (the page beneath
 *     is neither visible nor interactive), gone in ~4.2s or at the
 *     visitor's first gesture, and removed from the DOM; it adds
 *     nothing the visitor must read, dismiss, or decide about, and
 *     nothing at all without JS
 *   - the unified site navigation (.living-nav) — deliberately NOT
 *     gated on body.living-ui: every content page that loads this
 *     stylesheet carries the same persistent wayfinding home, whether
 *     or not its body opts into the ambience above.
 *
 * Motion uses transform/opacity only. Under prefers-reduced-motion the
 * layer is present but still: no breathing, no reveals, no gliding.
 */

body.living-ui {
  --lui-gold: var(--gold, #f3c97a);
  --lui-gold-deep: var(--gold-deep, #d99545);
  --lui-teal: #7af3ff;
  --lui-beige: #f4f0de;
  --lui-hairline: rgba(243, 201, 122, 0.22);
}

/* ------------------------------------------------------------------ */
/* Ambient stone field                                                 */
/* ------------------------------------------------------------------ */

body.living-ui::before {
  content: "";
  position: fixed;
  inset: -6%;
  z-index: -1;
  background:
    radial-gradient(ellipse 52% 38% at 16% 6%, rgba(45, 212, 191, 0.075), transparent 62%),
    radial-gradient(ellipse 44% 34% at 86% 12%, rgba(243, 201, 122, 0.06), transparent 65%),
    radial-gradient(ellipse 60% 42% at 50% 108%, rgba(45, 212, 191, 0.05), transparent 66%);
  animation: lui-breathe 13s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes lui-breathe {
  from { opacity: 0.6; transform: scale(1); }
  to { opacity: 1; transform: scale(1.05); }
}

/* ------------------------------------------------------------------ */
/* Gold seams                                                          */
/* ------------------------------------------------------------------ */

body.living-ui hr {
  border: 0;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--lui-gold-deep) 22%, var(--lui-gold) 50%, var(--lui-gold-deep) 78%, transparent);
  opacity: 0.75;
}

body.living-ui blockquote {
  border-left: 3px solid var(--lui-gold-deep);
}

/* ------------------------------------------------------------------ */
/* Panel / card surfaces                                               */
/* ------------------------------------------------------------------ */

body.living-ui :is(
  .card,
  .feature-card,
  .what-card,
  .signal-card,
  .front-door-card,
  .moon-panel,
  .caravan-card,
  .exercise-card,
  .witness-card,
  .artifact-card-mini,
  .participation-chapter,
  .participation-outcome,
  .codex-seal
) {
  border-color: var(--lui-hairline);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(244, 240, 222, 0.05);
}

/* ------------------------------------------------------------------ */
/* Living links                                                        */
/* ------------------------------------------------------------------ */

body.living-ui main a:not(.btn):not([class*="card"]):not(.le-door):not(.le-lead-link) {
  background-image: linear-gradient(90deg, var(--lui-gold-deep), var(--lui-gold));
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 0 100%;
  transition: background-size 0.35s ease, text-shadow 0.35s ease;
}

body.living-ui main a:not(.btn):not([class*="card"]):not(.le-door):not(.le-lead-link):hover,
body.living-ui main a:not(.btn):not([class*="card"]):not(.le-door):not(.le-lead-link):focus-visible {
  background-size: 100% 1px;
  text-shadow: 0 0 14px rgba(243, 201, 122, 0.35);
}

/* ------------------------------------------------------------------ */
/* Selection + focus                                                   */
/* ------------------------------------------------------------------ */

body.living-ui ::selection {
  background: rgba(243, 201, 122, 0.85);
  color: #05070d;
}

body.living-ui :focus-visible {
  outline: 2px solid var(--lui-gold);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ */
/* Smooth anchor travel (motion-safe only)                             */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
  html:has(> body.living-ui) {
    scroll-behavior: smooth;
  }
}

/* ------------------------------------------------------------------ */
/* Staged reveals — visible by default; living-ui.js arms the rest     */
/* ------------------------------------------------------------------ */

body.living-ui main > section {
  transition: opacity 0.85s ease, transform 0.85s cubic-bezier(0.22, 0.61, 0.21, 1);
}

body.living-ui main > section.lui-reveal-pending {
  opacity: 0;
  transform: translateY(26px);
}

/* ------------------------------------------------------------------ */
/* Unified site navigation — one persistent bar on every content page  */
/*                                                                     */
/* Inserted by scripts/apply-living-nav.mjs right after each page's    */
/* skip link. Sticky, so Home is one tap away from anywhere on the     */
/* page — including deep inside the Scroll Library, whose own          */
/* mastheads scroll away. Styles stand alone (own variables, no        */
/* body.living-ui gate) so pages that load this stylesheet only for    */
/* the nav still render it fully. The R1.7 sphere page is excluded     */
/* and keeps its own chrome.                                           */
/* ------------------------------------------------------------------ */

/* The rendered height of the bar below (one slim link row: the links'
 * 44px tap target, plus its bottom border). The legacy mobile menu
 * panel in navigation.css subtracts this so the panel ends at the
 * visible viewport bottom on pages that carry both bars, instead of
 * overshooting it by the height of this one. */
:root {
  --living-nav-h: 45px;
}

.living-nav {
  --lnav-gold: #f3c97a;
  --lnav-gold-deep: #d99545;
  --lnav-beige: #f4f0de;
  --lnav-hairline: rgba(243, 201, 122, 0.28);
  position: sticky;
  top: 0;
  z-index: 800;
  background: rgba(7, 10, 17, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--lnav-hairline);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: inherit;
}

.living-nav-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
}

.living-nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.25rem;
  color: var(--lnav-beige);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  white-space: nowrap;
  flex: none;
}

.living-nav-mark {
  color: var(--lnav-gold);
  font-size: 1.15em;
  line-height: 1;
}

.living-nav-links {
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
  display: flex;
  align-items: stretch;
  gap: 0.1rem;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.living-nav-links::-webkit-scrollbar {
  display: none;
}

.living-nav-links li {
  display: flex;
  margin: 0;
  padding: 0;
}

.living-nav-links a {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 0.78rem;
  min-height: 44px;
  color: rgba(244, 240, 222, 0.82);
  font-size: 0.94rem;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: inset 0 -2px 0 transparent;
  transition: color 0.3s ease, box-shadow 0.3s ease, text-shadow 0.3s ease;
}

.living-nav-links a:hover,
.living-nav-links a:focus-visible {
  color: var(--lnav-gold);
  text-shadow: 0 0 14px rgba(243, 201, 122, 0.35);
}

.living-nav-links a.is-current {
  color: var(--lnav-gold);
  box-shadow: inset 0 -2px 0 var(--lnav-gold-deep);
}

/* The Support door: external, always last, quietly gold — same size
 * and tap target as every other link in the bar. */
.living-nav-links a.living-nav-support {
  color: var(--lnav-gold);
}

.living-nav a:focus-visible {
  outline: 2px solid var(--lnav-gold);
  outline-offset: -2px;
}

@media (max-width: 620px) {
  .living-nav-inner {
    padding: 0 0.6rem;
    gap: 0.4rem;
    flex-wrap: nowrap;
  }

  /* On a phone the brand rests as its mark alone (the name stays in
   * the markup and in the link's home target) so the rooms and the
   * Share button keep the row. */
  .living-nav-brand {
    font-size: 0;
    padding: 0.45rem 0.1rem;
    gap: 0;
  }

  .living-nav-brand .living-nav-mark {
    font-size: 1.3rem;
  }

  .living-nav-links a {
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
  }
}

/* The one travel bar: a single slim row, sticky at the top, that
 * never wraps into a second row and never covers the page — content
 * flows beneath it in normal order, and the room links scroll
 * sideways inside the bar on a narrow screen. */
.travel-bar .living-nav-inner {
  flex-wrap: nowrap;
  align-items: center;
}

.travel-bar .living-nav-links {
  flex: 1 1 auto;
  min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  .living-nav-links a {
    transition: none;
  }
}

/* ------------------------------------------------------------------ */
/* The page opening — one quiet moment, then out of the way            */
/*                                                                     */
/* Injected by living-ui.js on arrival (never in markup, so a no-JS    */
/* page is untouched). Lighter than the homepage entry only in what   */
/* it says — no status cycle, just the page's name, today's line, and */
/* one quiet way-forward line late in the hold — never in how it      */
/* stands: it uses the entry's own opaque deep-stone ground (the      */
/* same recipe as .le-overlay in living-entry.css), covers the full   */
/* viewport above everything, and takes every tap while it plays, so  */
/* the page beneath is neither visible nor interactive until the      */
/* dismissed. The first gesture dismisses it in the same instant      */
/* (living-ui.js), and the page is scroll-locked meanwhile            */
/* (body.lpo-opening below — the entry's le-lock behaviour). One      */
/* system, two weights.                                               */
/* ------------------------------------------------------------------ */

.lpo-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 50% 38%, rgba(45, 212, 191, 0.07), transparent 55%),
    radial-gradient(circle at 50% 62%, rgba(243, 201, 122, 0.05), transparent 60%),
    linear-gradient(170deg, #0a0e18 0%, #05070d 70%);
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.75s ease-in-out;
  cursor: pointer;
}

.lpo-overlay.lpo-leaving {
  opacity: 0;
  pointer-events: none;
}

.lpo-emblem-wrap {
  position: relative;
  width: min(34vw, 128px);
  aspect-ratio: 1 / 1;
  animation: lpo-settle 0.8s cubic-bezier(0.22, 0.61, 0.21, 1) both;
}

.lpo-emblem-wrap::before {
  content: "";
  position: absolute;
  inset: -45%;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(122, 243, 255, 0.14) 0%, rgba(122, 243, 255, 0.05) 45%, transparent 68%);
  animation: lpo-breathe 4.6s ease-in-out infinite alternate;
  pointer-events: none;
}

.lpo-emblem {
  width: 100%;
  height: 100%;
  display: block;
}

.lpo-eye {
  transform-box: fill-box;
  transform-origin: center;
  animation: lpo-eye-open 1.3s cubic-bezier(0.22, 0.61, 0.21, 1) 0.25s both;
}

.lpo-name {
  margin: 0.85rem 0 0;
  max-width: 86vw;
  overflow: hidden;
  color: var(--lui-beige, #f4f0de);
  font-size: clamp(0.95rem, 2.6vw, 1.12rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  text-overflow: ellipsis;
  animation: lpo-settle 0.8s cubic-bezier(0.22, 0.61, 0.21, 1) 0.15s both;
}

.lpo-line {
  margin: 0.35rem 0 0;
  max-width: 86vw;
  color: rgba(243, 201, 122, 0.85);
  font-size: clamp(0.82rem, 2.2vw, 0.95rem);
  letter-spacing: 0.04em;
  text-align: center;
  animation: lpo-settle 0.8s cubic-bezier(0.22, 0.61, 0.21, 1) 0.3s both;
}

/* The way-forward line: settles in at 1.8s, late in the hold, small
 * and quiet — present before the fade so a first-time visitor is
 * never left wondering how to get through, gone with the overlay. */
.lpo-hint {
  margin: 1.15rem 0 0;
  max-width: 86vw;
  color: rgba(244, 240, 222, 0.62);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  animation: lpo-settle 0.8s cubic-bezier(0.22, 0.61, 0.21, 1) 1.8s both;
}

@keyframes lpo-settle {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes lpo-breathe {
  from { opacity: 0.35; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1.04); }
}

@keyframes lpo-eye-open {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* While the opening plays, the page is scroll-locked beneath it — the
 * homepage entry's le-lock behaviour under this layer's own class.
 * The class is only ever added by living-ui.js, so without JS nothing
 * here applies. */
body.lpo-opening {
  overflow: hidden;
}

/* The page rises once beneath the opening — behind the opaque ground,
 * where it settles long before the fade, so the page is still when
 * the veil lifts. The hidden-from state is an animation start, not a
 * resting style, and the class that arms it (body.lpo-opening) is
 * only ever added by living-ui.js — without JS nothing here applies
 * and content renders exactly as authored. */
body.lpo-opening main {
  animation: lpo-rise 0.9s cubic-bezier(0.22, 0.61, 0.21, 1) both;
}

@keyframes lpo-rise {
  from { opacity: 0.45; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ */
/* Living motion — the animation wave                                  */
/*                                                                     */
/* Shared, tasteful motion for the whole house, riding this layer:     */
/*   - cards rise softly into view, once, as they arrive — armed by    */
/*     living-ui.js only, so nothing is ever hidden without JS         */
/*   - cards and doors answer a hover and a press                      */
/*   - surfaces ease their colours when the site's theme variables     */
/*     change: whatever sets the variables (a moon theme, a daypart),  */
/*     the surfaces crossfade instead of snapping — this layer is      */
/*     theme-agnostic and names no theme of its own                    */
/*   - two homepage moments: the day line settles in as it is          */
/*     written, and the homepage Sphere's frame breathes a slow        */
/*     gold glow (the Sphere page itself is never touched)             */
/*                                                                     */
/* Discipline: transform/opacity only, plus the independent            */
/* translate/scale properties, which compose with — never override —   */
/* a page's own transforms and transitions. No infinite animation      */
/* here runs while the tab is hidden (living-ui.js adds .lui-paused).  */
/* Everything in this section rests under reduced motion and under     */
/* the site's motion-off attribute (data-codex-motion="off").          */
/* ------------------------------------------------------------------ */

/* Colour ease — surfaces crossfade when theme variables change */
body.living-ui {
  transition: background-color 0.8s ease;
}

body.living-ui main :is(
  .card,
  .feature-card,
  .what-card,
  .signal-card,
  .front-door-card,
  .moon-panel,
  .caravan-card,
  .exercise-card,
  .witness-card,
  .artifact-card-mini,
  .participation-chapter,
  .participation-outcome,
  .codex-seal
) {
  transition:
    translate 0.3s ease,
    scale 0.2s ease,
    background-color 0.8s ease,
    border-color 0.8s ease;
}

/* Card reveals — the armed state is applied by living-ui.js at
 * runtime, only to cards still below the fold; the pending state
 * never appears in markup and never applies without JS. */
body.living-ui main :is(
  .card,
  .feature-card,
  .what-card,
  .signal-card,
  .front-door-card,
  .moon-panel,
  .caravan-card,
  .exercise-card,
  .witness-card,
  .artifact-card-mini,
  .participation-chapter,
  .participation-outcome,
  .codex-seal
).lui-card-armed {
  transition:
    opacity 0.7s ease,
    transform 0.7s cubic-bezier(0.22, 0.61, 0.21, 1),
    translate 0.3s ease,
    scale 0.2s ease,
    background-color 0.8s ease,
    border-color 0.8s ease;
}

body.living-ui main :is(
  .card,
  .feature-card,
  .what-card,
  .signal-card,
  .front-door-card,
  .moon-panel,
  .caravan-card,
  .exercise-card,
  .witness-card,
  .artifact-card-mini,
  .participation-chapter,
  .participation-outcome,
  .codex-seal
).lui-card-pending {
  opacity: 0;
  transform: translateY(14px);
}

@keyframes lui-soft-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes lui-frame-breathe {
  from { opacity: 0.22; }
  to { opacity: 0.5; }
}

@media (prefers-reduced-motion: no-preference) {
  /* Hover lift + press answer on the house's cards and doors.
   * The independent translate/scale properties carry these, so a
   * page's own transform animations keep composing underneath. */
  body.living-ui main :is(
    .card,
    .feature-card,
    .what-card,
    .signal-card,
    .front-door-card,
    .moon-panel,
    .caravan-card,
    .exercise-card,
    .witness-card,
    .artifact-card-mini,
    .participation-chapter,
    .participation-outcome,
    .codex-seal
  ):hover {
    translate: 0 -2px;
  }

  body.living-ui main :is(
    .card,
    .feature-card,
    .what-card,
    .signal-card,
    .front-door-card,
    .moon-panel,
    .caravan-card,
    .exercise-card,
    .witness-card,
    .artifact-card-mini,
    .participation-chapter,
    .participation-outcome,
    .codex-seal
  ):active {
    scale: 0.99;
  }

  /* Buttons and entry doors dip a breath when pressed. No transition
   * is declared here on purpose: the press lands crisply and each
   * page's own button transitions stay exactly as authored. */
  body.living-ui :is(.btn, .le-door):active {
    scale: 0.98;
  }

  .living-nav a:active {
    background: rgba(243, 201, 122, 0.12);
  }

  /* The day line settles in each time it is written — on arrival,
   * and again when the living day panel rewrites it. */
  body.living-ui .ld-moon-line {
    animation: lui-soft-in 0.9s ease both;
  }

  /* The homepage Sphere's frame breathes a slow gold glow. This is
   * the hero card's frame on the homepage only — an overlay of
   * light, pointer-transparent, above the stage and beneath the
   * card's own inset glow. The Sphere page is untouched. */
  .homepage-sphere-frame::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    background: radial-gradient(circle at 50% 42%, rgba(243, 201, 122, 0.16), transparent 62%);
    opacity: 0.35;
    pointer-events: none;
    animation: lui-frame-breathe 9s ease-in-out infinite alternate;
  }
}

/* Hidden tab: the layer's ambient animations rest instead of
 * breathing unseen (.lui-paused is toggled by living-ui.js). */
body.living-ui.lui-paused::before,
body.lui-paused .homepage-sphere-frame::before {
  animation-play-state: paused;
}

/* The site's motion-off attribute stills this wave too (set on the
 * homepage root by living-codex.js when motion is not allowed). */
html[data-codex-motion="off"] body.living-ui .ld-moon-line,
html[data-codex-motion="off"] .homepage-sphere-frame::before {
  animation: none;
}

html[data-codex-motion="off"] body.living-ui main :is(
  .card,
  .feature-card,
  .what-card,
  .signal-card,
  .front-door-card,
  .moon-panel,
  .caravan-card,
  .exercise-card,
  .witness-card,
  .artifact-card-mini,
  .participation-chapter,
  .participation-outcome,
  .codex-seal
) {
  translate: none;
  scale: none;
}

/* ------------------------------------------------------------------ */
/* Reduced motion: the layer rests                                     */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .lpo-overlay {
    display: none !important;
  }

  body.lpo-opening main {
    animation: none;
  }

  body.living-ui::before {
    animation: none !important;
  }

  body.living-ui main a:not(.btn):not([class*="card"]):not(.le-door):not(.le-lead-link),
  body.living-ui main > section {
    transition: none;
  }

  body.living-ui main > section.lui-reveal-pending {
    opacity: 1;
    transform: none;
  }

  /* The animation wave rests completely: no card is ever left
   * pending, no hover or press offset applies, the day line and
   * the Sphere frame's glow stand still. */
  body.living-ui main :is(
    .card,
    .feature-card,
    .what-card,
    .signal-card,
    .front-door-card,
    .moon-panel,
    .caravan-card,
    .exercise-card,
    .witness-card,
    .artifact-card-mini,
    .participation-chapter,
    .participation-outcome,
    .codex-seal
  ),
  body.living-ui :is(.btn, .le-door) {
    transition: none;
    translate: none;
    scale: none;
  }

  body.living-ui main :is(
    .card,
    .feature-card,
    .what-card,
    .signal-card,
    .front-door-card,
    .moon-panel,
    .caravan-card,
    .exercise-card,
    .witness-card,
    .artifact-card-mini,
    .participation-chapter,
    .participation-outcome,
    .codex-seal
  ).lui-card-pending {
    opacity: 1;
    transform: none;
  }

  body.living-ui .ld-moon-line,
  .homepage-sphere-frame::before {
    animation: none;
  }
}
