/* XEL base layer — reset, layout skeleton, shared components. */

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--violet); color: var(--bg-deep); }

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; }
a { color: var(--cyan); text-decoration: none; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--seafoam);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- fixed canvases ---------- */

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: var(--z-bg);
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: var(--z-fx);
  pointer-events: none;
}

/* ---------- nav ---------- */

#site-nav {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.25rem;
  background: rgba(10, 5, 26, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(157, 123, 255, 0.15);
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.45rem;
  color: var(--ink);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.brand-mark { filter: drop-shadow(0 0 8px rgba(125, 249, 224, 0.7)); }
.brand-dot { color: var(--ink-faint); font-weight: 400; font-size: 0.95rem; align-self: flex-end; padding-bottom: 0.2rem; }

.site-links {
  display: flex;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 1;
  min-width: 0;
  /* 5 links must never paint under the nav buttons on narrow phones:
     scroll horizontally instead, scrollbar hidden, edges fade. the gutters
     keep the first/last pill out of that fade at either scroll boundary. */
  padding-inline: 14px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 12px), transparent);
}

.site-links::-webkit-scrollbar { display: none; }

.site-links a { flex: none; }

#audio-toggle-root { flex: none; }

.site-links a {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-dim);
  padding: 0.35rem 0.9rem;
  border-radius: var(--r-pill);
  transition: color 0.2s, background 0.2s, transform 0.2s var(--ease-boing);
}

.site-links a:hover { color: var(--ink); background: rgba(157, 123, 255, 0.15); transform: translateY(-1px); }
.site-links a.active { color: var(--bg-deep); background: linear-gradient(135deg, var(--seafoam), var(--cyan)); }

/* ---------- stage ---------- */

#stage {
  position: relative;
  z-index: var(--z-stage);
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 5.25rem 1rem 2rem;
}

#speech-root {
  min-height: 92px;
  width: min(96vw, 640px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#xel-stage {
  position: relative;
  width: min(76vw, 440px);
  aspect-ratio: 1;
  /* in-flow children must never inflate the stage: flex min-content sizing vs
     aspect-ratio feeds back into the creature canvas buffer (observed 880x34825) */
  flex: none;
  min-height: 0;
}

#xel-stage > :not(canvas) { position: absolute; }

#xel-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

#hud-root { width: min(96vw, 780px); }

/* ---------- panels ---------- */

#panels-root {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: var(--z-panels);
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  position: absolute;
  top: 0; right: 0;
  height: 100%;
  width: min(92vw, 390px);
  background: var(--panel-bg);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
  border-left: 1px solid var(--panel-border);
  box-shadow: var(--shadow-pop);
  transform: translateX(106%);
  /* visibility keeps closed panels out of the tab order and the AT tree */
  visibility: hidden;
  transition: transform 0.45s var(--ease-boing), visibility 0s linear 0.45s;
  overflow-y: auto;
  padding: 1.25rem;
}

.panel.open {
  transform: none;
  visibility: visible;
  transition: transform 0.45s var(--ease-boing), visibility 0s;
}

.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: rgba(157, 123, 255, 0.35); border-radius: 4px; }

/* ---------- games modal root ---------- */

#games-root {
  position: fixed;
  inset: 0;
  z-index: var(--z-games);
  pointer-events: none;
}

/* ---------- toasts ---------- */

#toast-root {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
  width: min(94vw, 460px);
}

.toast {
  pointer-events: auto;
  background: var(--panel-bg);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
  border: 1px solid var(--panel-border);
  border-radius: var(--r-md);
  padding: 0.7rem 1.1rem;
  box-shadow: var(--shadow-pop);
  font-size: 0.95rem;
}

/* ---------- shared button ---------- */

.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: var(--r-pill);
  padding: 0.65rem 1.15rem;
  background: linear-gradient(135deg, rgba(157, 123, 255, 0.25), rgba(92, 225, 255, 0.16));
  border: 1px solid rgba(157, 123, 255, 0.4);
  transition: transform 0.18s var(--ease-boing), box-shadow 0.18s, opacity 0.2s;
}

.btn:hover { transform: translateY(-2px) scale(1.04); box-shadow: var(--glow-violet); }
.btn:active { transform: scale(0.94); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- optional analytics consent ---------- */

.analytics-consent {
  position: fixed;
  left: 0.85rem;
  bottom: 0.85rem;
  z-index: var(--z-toast);
  width: min(calc(100vw - 1.7rem), 440px);
  padding: 0.75rem 0.8rem 0.8rem;
  color: var(--ink);
  background: var(--panel-bg);
  border: 1px solid rgba(157, 123, 255, 0.38);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  backdrop-filter: blur(var(--panel-blur));
  -webkit-backdrop-filter: blur(var(--panel-blur));
}

.analytics-consent-copy {
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ink-dim);
}

.analytics-consent-copy strong {
  font-family: var(--font-display);
  font-size: 0.86rem;
  letter-spacing: 0.04em;
  color: var(--seafoam);
}

.analytics-consent-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.62rem;
}

.analytics-consent-actions a {
  margin-right: auto;
  padding: 0.4rem 0.15rem;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.analytics-consent-actions .btn {
  width: 7.25rem;
  min-width: 7rem;
  padding: 0.43rem 0.66rem;
  font-size: 0.8rem;
}

body.analytics-consent-open #toast-root { bottom: 10.5rem; }

/* ---------- index footer ---------- */

.index-footer {
  position: relative;
  z-index: var(--z-stage);
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-faint);
  padding: 0.4rem 1rem 1.1rem;
}

.index-footer a { color: var(--ink-dim); }
.index-footer a:hover { color: var(--seafoam); }

/* ---------- boot veil ---------- */

#boot-veil {
  position: fixed;
  inset: 0;
  background: var(--bg-deep);
  z-index: var(--z-boot);
  display: grid;
  place-items: center;
  transition: opacity 0.6s ease;
}

#boot-veil.gone { opacity: 0; pointer-events: none; }

.boot-shell {
  font-size: 4rem;
  animation: bootpulse 1.2s infinite var(--ease-smooth);
}

@keyframes bootpulse {
  50% { transform: scale(1.18) rotate(-8deg); filter: drop-shadow(0 0 26px rgba(125, 249, 224, 0.85)); }
}

.noscript-box {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--bg-deep);
  font-family: var(--font-display);
  font-size: 1.3rem;
  padding: 2rem;
  text-align: center;
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  #site-nav { padding: 0.5rem 0.8rem; gap: 0.5rem; }
  .brand { font-size: 1.2rem; }
  .site-links a { padding: 0.3rem 0.65rem; font-size: 0.9rem; }
  #stage { padding-top: 4.4rem; gap: 0.5rem; }
  #xel-stage { width: min(88vw, 360px); }
  .btn { font-size: 0.92rem; padding: 0.55rem 0.9rem; }
  .analytics-consent { left: 0.65rem; bottom: 0.65rem; width: calc(100vw - 1.3rem); }
  .analytics-consent-actions .btn { flex: 1 1 7rem; min-height: 44px; }
}

/* short laptops: shrink the creature before the controls fall below the fold */
@media (min-width: 641px) and (max-height: 780px) {
  #stage { padding-top: 4.2rem; gap: 0.4rem; }
  #xel-stage { width: min(52vh, 440px); }
  #speech-root { min-height: 64px; }
}

@media (max-width: 420px) {
  .analytics-consent-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .analytics-consent-actions a { grid-column: 1 / -1; margin-right: 0; padding-bottom: 0.1rem; }
  .analytics-consent-actions .btn { width: 100%; min-width: 0; }
  body.analytics-consent-open #toast-root { bottom: 14.5rem; }
}

@media (max-width: 360px) {
  .brand-dot { display: none; }
  .site-links a { padding: 0.3rem 0.5rem; font-size: 0.85rem; }
}

@media (pointer: coarse) {
  .btn { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .boot-shell { animation: none; }
  .panel { transition-duration: 0.01s; }
  .analytics-consent .btn { transition: none; }
}
