/* ==========================================================================
   Kodex Hero Companions — shared structural shell + theme system
   One stylesheet for all hero pages. Per-hero colour comes from the
   [data-hero] tokens block only; structure never forks per character.
   ========================================================================== */

/* ---------- 1. Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
}

body,
h1, h2, h3, p, ul, ol, figure, dl, dd { margin: 0; }

ul[class] { list-style: none; padding: 0; }

img { display: block; max-width: 100%; height: auto; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- 2. Global tokens ---------- */
:root {
  --font-display: "Cabinet Grotesk", "General Sans", system-ui, sans-serif;
  --font-body: "General Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --step-0: 1rem;          /* 16px body */
  --step--1: 0.8125rem;    /* 13px labels */
  --step--2: 0.75rem;      /* 12px floor */
  --step-1: clamp(1.0625rem, 0.99rem + 0.32vw, 1.1875rem);
  --step-2: clamp(1.25rem, 1.15rem + 0.45vw, 1.5rem);
  --step-3: clamp(1.75rem, 1.45rem + 1.4vw, 2.5rem);
  --step-4: clamp(2.25rem, 1.7rem + 2.4vw, 3.75rem);

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;

  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;

  --shell-max: 1360px;
  --tap: 44px;

  /* Fallback theme (overridden per hero) */
  --bg: #101014;
  --bg-deep: #08080b;
  --surface: #17171d;
  --surface-2: #1e1e26;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --ink: #f2f1ef;
  --ink-muted: #a9a7a3;
  --accent: #b8d90a;
  --accent-2: #8b9457;
  --accent-ink: #0b0b0d;
  --glow: rgba(184, 217, 10, 0.22);
  --texture: rgba(255, 255, 255, 0.04);
}

/* ---------- 3. Per-hero theme tokens ---------- */
[data-hero="axel"] {
  --bg: #16120f;
  --bg-deep: #0b0908;
  --surface: #1f1a15;
  --surface-2: #29221b;
  --line: rgba(228, 133, 63, 0.18);
  --line-strong: rgba(228, 133, 63, 0.42);
  --ink: #f6efe6;
  --ink-muted: #b5a897;
  --accent: #f08a3c;
  --accent-2: #a8b06a;
  --accent-ink: #1a1109;
  --glow: rgba(240, 118, 44, 0.28);
  --texture: rgba(168, 176, 106, 0.07);
}

[data-hero="zane"] {
  --bg: #0b1215;
  --bg-deep: #05090b;
  --surface: #10191d;
  --surface-2: #172329;
  --line: rgba(80, 208, 224, 0.18);
  --line-strong: rgba(80, 208, 224, 0.42);
  --ink: #eaf3f5;
  --ink-muted: #9ab0b6;
  --accent: #4fd3e4;
  --accent-2: #f0b552;
  --accent-ink: #05171c;
  --glow: rgba(63, 200, 219, 0.24);
  --texture: rgba(240, 181, 82, 0.06);
}

[data-hero="fiona"] {
  --bg: #150c17;
  --bg-deep: #0a050c;
  --surface: #1e1122;
  --surface-2: #29182e;
  --line: rgba(240, 118, 175, 0.18);
  --line-strong: rgba(240, 118, 175, 0.44);
  --ink: #f8ecf4;
  --ink-muted: #bda3b6;
  --accent: #f272ac;
  --accent-2: #f0c268;
  --accent-ink: #1c0a14;
  --glow: rgba(233, 84, 155, 0.26);
  --texture: rgba(240, 194, 104, 0.06);
}

[data-hero="luna"] {
  --bg: #0a0810;
  --bg-deep: #050409;
  --surface: #120e1c;
  --surface-2: #1a1428;
  --line: rgba(168, 132, 244, 0.2);
  --line-strong: rgba(168, 132, 244, 0.46);
  --ink: #eee9f8;
  --ink-muted: #a79dbd;
  --accent: #b28cf7;
  --accent-2: #7ceeb0;
  --accent-ink: #100a1c;
  --glow: rgba(140, 96, 230, 0.28);
  --texture: rgba(231, 155, 192, 0.07);
}

/* ---------- 3b. Per-hero motif textures (identity panel only) ---------- */
[data-hero="axel"] {
  --motif-pattern: repeating-linear-gradient(135deg, var(--texture) 0 2px, transparent 2px 11px);
}
[data-hero="zane"] {
  --motif-pattern:
    linear-gradient(var(--texture) 1px, transparent 1px),
    linear-gradient(90deg, var(--texture) 1px, transparent 1px);
  --motif-size: 26px 26px;
}
[data-hero="fiona"] {
  --motif-pattern: radial-gradient(var(--texture) 1.2px, transparent 1.4px);
  --motif-size: 20px 20px;
}
[data-hero="luna"] {
  --motif-pattern: repeating-linear-gradient(0deg, var(--texture) 0 1px, transparent 1px 7px);
}

/* ---------- 4. Base ---------- */
body {
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(120% 80% at 50% -10%, var(--glow) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.015em;
}

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

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: absolute;
  left: var(--sp-4);
  top: var(--sp-2);
  z-index: 100;
  transform: translateY(-200%);
  padding: 0.75rem 1.25rem;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: transform 140ms ease;
}
.skip-link:focus { transform: translateY(0); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.shell {
  width: 100%;
  max-width: var(--shell-max);
  margin-inline: auto;
  padding-inline: clamp(1rem, 3vw, 2.5rem);
}

/* ==========================================================================
   5. TEMPORARY HERO SWITCHER
   Remove the marked block in each hero page's HTML to retire the testing bar;
   this CSS block can then be deleted too. See README.
   ========================================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: clamp(0.75rem, 2vw, 1.5rem);
  min-height: 64px;
  padding-block: var(--sp-2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: none;
  text-decoration: none;
  color: var(--ink);
  min-height: var(--tap);
  padding-right: clamp(0.5rem, 2vw, 1rem);
  border-right: 1px solid var(--line);
}
.brand img { width: 34px; height: 22px; object-fit: contain; }
.brand__word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step--1);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.switcher {
  flex: 1 1 auto;
  min-width: 0;
}

.switcher__list {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  padding-block: 4px;
  -webkit-overflow-scrolling: touch;
}
.switcher__list::-webkit-scrollbar { height: 4px; }
.switcher__list::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 4px;
}

.switcher__item { flex: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.25rem 0.875rem 0.25rem 0.3125rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 600;
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}
.chip img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}
.chip:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-2); }
.chip[aria-current="page"] {
  color: var(--ink);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}
.chip[aria-current="page"] .chip__dot { background: var(--accent); }
.chip__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  flex: none;
}

.topbar__tag {
  flex: none;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
}
@media (max-width: 899px) { .topbar__tag { display: none; } }

@media (max-width: 599px) {
  .brand { padding-right: 0.5rem; }
  .brand__word { display: none; }
  .chip { padding: 0.25rem 0.7rem 0.25rem 0.25rem; font-size: var(--step--2); gap: 0.4rem; }
  .chip img { width: 30px; height: 30px; }
  .topbar__inner { min-height: 58px; gap: 0.5rem; }
}
/* ===================== END TEMPORARY HERO SWITCHER ======================= */

/* ---------- 6. Console layout ---------- */
.console { padding-block: clamp(1rem, 2.5vw, 2rem) clamp(2rem, 5vw, 3.5rem); }

.console__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(1.25rem, 3vw, 2rem);
  align-items: start;
}

@media (min-width: 1000px) {
  .console__grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.85fr);
    gap: clamp(1.5rem, 3vw, 2.5rem);
  }
}

/* ---------- 7. The live avatar stage (dominant surface) ---------- */
.stage-wrap { position: relative; }

.stage {
  position: relative;
  isolation: isolate;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(90% 65% at 50% 8%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 65%),
    linear-gradient(175deg, var(--surface-2) 0%, var(--bg-deep) 90%);
  overflow: hidden;
  aspect-ratio: 4 / 5;
  min-height: 380px;
  max-height: calc(100dvh - 190px);
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, 0.9);
}

@media (min-width: 700px) { .stage { aspect-ratio: 1 / 1; } }

@media (min-width: 1000px) {
  .stage {
    aspect-ratio: 4 / 3;
    min-height: 460px;
    max-height: calc(100dvh - 200px);
  }
}

/* Corner ticks — console framing, purely decorative */
.stage::before,
.stage::after {
  content: "";
  position: absolute;
  width: 34px; height: 34px;
  border: 2px solid var(--accent);
  opacity: 0.55;
  z-index: 3;
  pointer-events: none;
}
.stage::before { top: 10px; left: 10px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.stage::after { bottom: 10px; right: 10px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }

/* D-ID injects its full-mode UI here. It must own the full box. */
.stage__target {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
}

/* Loading / fallback layer sits BEHIND the widget and never covers it. */
.stage__state {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  text-align: center;
  transition: opacity 400ms ease;
}
.stage.is-live .stage__state { opacity: 0; }

.stage__pulse {
  width: 74px; height: 74px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: grid;
  place-items: center;
  position: relative;
}
.stage__pulse::after {
  content: "";
  position: absolute;
  inset: -12px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0.35;
  animation: kodex-pulse 3.2s ease-out infinite;
}
.stage__pulse span {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
@keyframes kodex-pulse {
  0%   { transform: scale(0.82); opacity: 0.5; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

.stage__state-title {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 700;
}
.stage__state-text {
  font-size: var(--step--1);
  color: var(--ink-muted);
  max-width: 34ch;
}

/* Zane's newer D-ID embed uses Fabio mode, which owns a floating panel rather
   than mounting inside the stage. Keep the shared stage footprint useful and
   point clearly to the only interaction surface without imitating its UI. */
.stage--fabio {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
}
.stage__fabio-art {
  position: absolute;
  inset: var(--sp-4) var(--sp-4) 0 auto;
  width: min(68%, 420px);
  height: calc(100% - var(--sp-4));
  object-fit: contain;
  object-position: right bottom;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5));
}
.stage__fabio-copy {
  position: relative;
  z-index: 2;
  width: min(58%, 29rem);
  margin: var(--sp-5);
  padding: var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg-deep) 88%, transparent);
  backdrop-filter: blur(10px);
}
.stage__fabio-copy .stage__state-text { margin-top: var(--sp-2); }
.stage__offline { display: none; }
.stage.is-offline .stage__pulse,
.stage.is-offline .stage__loading { display: none; }
.stage.is-offline .stage__offline { display: grid; gap: var(--sp-2); justify-items: center; }

.stage-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  margin-top: var(--sp-3);
  font-size: var(--step--1);
  color: var(--ink-muted);
}
.stage-note strong { color: var(--ink); font-weight: 600; }
.stage-note__item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.stage-note__item svg { flex: none; color: var(--accent); }
.stage-note__disclosure {
  flex-basis: 100%;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--line);
}

@media (max-width: 599px) {
  .stage__fabio-art {
    inset: var(--sp-3) 0 0 auto;
    width: 82%;
  }
  .stage__fabio-copy {
    width: calc(100% - (2 * var(--sp-3)));
    margin: var(--sp-3);
  }
}

/* ---------- 8. Identity rail ---------- */
.identity {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, var(--surface) 0%, color-mix(in srgb, var(--bg) 92%, transparent) 100%);
  padding: clamp(1.25rem, 3vw, 1.75rem);
  overflow: hidden;
}
.identity::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--motif-pattern, none);
  background-size: var(--motif-size, auto);
  opacity: 0.5;
  pointer-events: none;
}
.identity > * { position: relative; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.eyebrow svg { flex: none; }

.identity__head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-4);
  margin-top: var(--sp-3);
}
.identity__portrait {
  width: 84px;
  height: 84px;
  flex: none;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
}
h1 {
  font-size: var(--step-3);
  text-transform: uppercase;
  letter-spacing: -0.01em;
}
.identity__role {
  margin-top: 0.35rem;
  font-size: var(--step--1);
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}

.tagline {
  margin-top: var(--sp-4);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step-2);
  line-height: 1.25;
  color: var(--ink);
  border-left: 3px solid var(--accent);
  padding-left: var(--sp-4);
}

.summary { margin-top: var(--sp-4); color: var(--ink-muted); }
.summary strong { color: var(--ink); font-weight: 600; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}
.tags li {
  font-size: var(--step--2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
}

.asks { margin-top: var(--sp-5); }
.asks__label {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.asks__list {
  margin-top: var(--sp-3);
  display: grid;
  gap: var(--sp-2);
}
.asks__list li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  font-size: var(--step--1);
  line-height: 1.5;
}
.asks__list li::before {
  content: "\201C";
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 0.9;
  color: var(--accent);
  flex: none;
}

/* ---------- 9. Detail section ---------- */
.details {
  padding-block: clamp(2rem, 5vw, 3.5rem);
  border-top: 1px solid var(--line);
}
.details__head { max-width: 62ch; }
h2 { font-size: var(--step-2); text-transform: uppercase; letter-spacing: 0.01em; }
.details__head p { margin-top: var(--sp-3); color: var(--ink-muted); }

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  margin-top: var(--sp-5);
}
@media (min-width: 700px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: var(--sp-5);
}
.card h3 { font-size: var(--step-1); }
.card p { margin-top: var(--sp-2); color: var(--ink-muted); font-size: var(--step--1); }

.rail-art {
  margin-top: var(--sp-6);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-5);
  align-items: center;
}
@media (min-width: 800px) { .rail-art { grid-template-columns: 220px minmax(0, 1fr); } }
.rail-art img {
  width: 100%;
  max-width: 220px;
  height: auto;
  justify-self: center;
  filter: drop-shadow(0 18px 32px rgba(0, 0, 0, 0.55));
}
.rail-art__body { max-width: 62ch; }
.rail-art__body h2 { margin-bottom: var(--sp-3); }
.rail-art__body p + p { margin-top: var(--sp-3); }
.rail-art__body p { color: var(--ink-muted); }

/* ---------- 10. Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding-block: var(--sp-6) var(--sp-7);
  background: color-mix(in srgb, var(--bg-deep) 70%, transparent);
}
.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4) var(--sp-6);
  align-items: center;
  justify-content: space-between;
}
.site-footer img { width: 46px; height: 30px; object-fit: contain; }
.site-footer p {
  font-size: var(--step--2);
  color: var(--ink-muted);
  max-width: 74ch;
  line-height: 1.55;
}

/* ---------- 11. Ambient motion (CSS only) ---------- */
.stage-wrap::before {
  content: "";
  position: absolute;
  inset: -8% 0 auto 0;
  height: 70%;
  z-index: -1;
  background: radial-gradient(60% 60% at 50% 40%, var(--glow) 0%, transparent 70%);
  filter: blur(34px);
  animation: kodex-drift 18s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes kodex-drift {
  from { transform: translate3d(-2%, 0, 0) scale(1); opacity: 0.75; }
  to   { transform: translate3d(2%, 2%, 0) scale(1.06); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .stage-wrap::before { animation: none; }
}

/* ---------- 12. Root landing (index.html) ---------- */
.landing {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  gap: var(--sp-4);
  padding: var(--sp-6);
}
.landing img { width: 120px; height: auto; }
.landing__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  justify-content: center;
  margin-top: var(--sp-2);
}

/* ---------- 13. Non-obscuring connection notice (sits below the stage) ---- */
.stage-alert {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin-top: var(--sp-3);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--accent-2);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-2) 80%, transparent);
  font-size: var(--step--1);
  color: var(--ink);
  line-height: 1.5;
}
.stage-alert[hidden] { display: none; }
.stage-alert svg { flex: none; margin-top: 2px; color: var(--accent-2); }
