/* ─────────────────────────────────────────────────────────────────────────
   JomTanya — dark, full-bleed 3D stage.
   The WebGL scene (js/tanya-scene.js) paints the fixed canvas; everything in
   this file is the DOM layer on top of it. The page turns dark while the stage
   is showing — the home hero or JomTanya (body.is-stage, set by js/stage.js);
   body.is-tanya scopes the chat view itself.
   ───────────────────────────────────────────────────────────────────────── */

@property --tanya-spin {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

.tanya-stage {
  --t-bg: #040a15;
  --t-ink: #e7f4fc;
  --t-ink-soft: #bfd2e3;
  --t-muted: #8198b1;
  --t-cyan: #00a3e0;
  --t-cyan-hot: #4dd0ff;
  --t-orange: #e86a3a;
  --t-amber: #f2a33a;
  --t-red: #ff6b6b;
  --t-live: #3ee0a1;
  --t-line: rgba(125, 205, 255, 0.16);
  --t-line-strong: rgba(125, 205, 255, 0.34);
  --t-panel: rgba(7, 18, 35, 0.66);
  --t-card: rgba(13, 31, 56, 0.55);

  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  color: var(--t-ink);
}

/* ── Page chrome ───────────────────────────────────────────────────────
   The whole app is one dark theme now (see styles.css's :root and
   quiz-dark.css), so the header/footer/nav no longer need an is-stage
   condition — they're just always styled for dark. What IS still
   stage-conditional below is the WebGL canvas itself and the pointer-event
   passthrough it needs. */

.site-header {
  background: rgba(4, 10, 21, 0.55);
  border-bottom-color: rgba(125, 205, 255, 0.12);
  backdrop-filter: blur(14px) saturate(1.3);
}

.brand:hover,
.brand:focus-visible {
  background: rgba(0, 163, 224, 0.16);
}

.site-nav a {
  color: #9db3c9;
}

.site-nav a:hover,
.site-nav a.is-active {
  color: #ffffff;
  background: rgba(0, 163, 224, 0.2);
}

.nav-toggle span {
  background: #e7f4fc;
}

.site-footer {
  position: relative;
  z-index: 2;
  background: rgba(4, 10, 21, 0.65);
  border-top-color: rgba(125, 205, 255, 0.1);
  backdrop-filter: blur(10px);
}

body.is-stage .site-footer {
  padding-block: 0.6rem 0.75rem;
}

.footer-inner {
  color: #7f97b0;
}

.footer-link {
  color: #cfe7f7;
}

.footer-link:hover,
.footer-link:focus-visible {
  color: #4dd0ff;
  background: rgba(0, 163, 224, 0.14);
}

/* The shared view entrance animates transform, which would briefly re-anchor the
   view's fixed scrim to the view. Tanya fades instead. */
#view-tanya.is-active {
  animation: tanya-view-in 0.6s ease both;
}

@keyframes tanya-view-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Canvas, fallback and scrim ───────────────────────────────────────── */

/* The canvas sits behind <main>, so empty layout boxes must let pointer events
   through to it (orb hover/click, memory stars); only real controls catch them. */
body.is-stage > main,
body.is-stage #view-tanya,
body.is-stage .tanya-stage,
body.is-home-stage #view-trivia,
body.is-home-stage .home {
  pointer-events: none;
}

body.is-stage .tanya-hud,
body.is-home-stage .home-copy {
  pointer-events: auto;
}

/* Quiz mode has no orb or memory stars to click through to — the whole view (cards,
   options, buttons) just needs its normal interactivity back after the blanket
   `main { pointer-events: none }` above. */
body.is-quiz-stage #view-trivia {
  pointer-events: auto;
}

body:not(.is-stage) .tanya-canvas {
  display: none;
}

.tanya-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: block;
  touch-action: manipulation;
  /* Painted until the first WebGL frame, and permanently if WebGL is unavailable. */
  background:
    radial-gradient(ellipse 60% 45% at 50% 38%, rgba(0, 163, 224, 0.2), transparent 70%),
    radial-gradient(ellipse 90% 40% at 50% 100%, rgba(232, 106, 58, 0.1), transparent 70%),
    linear-gradient(180deg, #040a15 0%, #07203a 62%, #040a15 100%);
}

/* One shared scrim (#stage-scrim, a body-level sibling of the canvas — see
   index.html) darkens the city under whichever view is active. It used to live
   inside #view-tanya and only ever painted there; now it's a real global layer,
   gated off entirely when no stage mode is running. */
body:not(.is-stage) .tanya-scrim {
  display: none;
}

.tanya-scrim {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(4, 10, 21, 0.35) 0%, transparent 18%, transparent 55%, rgba(4, 10, 21, 0.72) 100%);
}

/* Tanya's intro copy and the quiz's briefing/question text both sit over the open
   city — pool a little extra darkness behind the centred column for contrast. */
body.is-tanya .tanya-scrim,
body.is-quiz-stage .tanya-scrim {
  background:
    radial-gradient(ellipse 52% 60% at 50% 46%, rgba(4, 10, 21, 0.6), rgba(4, 10, 21, 0.25) 55%, transparent 80%),
    linear-gradient(180deg, rgba(4, 10, 21, 0.35) 0%, transparent 18%, transparent 55%, rgba(4, 10, 21, 0.72) 100%);
}

body.tanya-no-3d .tanya-scrim {
  background:
    linear-gradient(180deg, rgba(4, 10, 21, 0.35) 0%, transparent 18%, transparent 55%, rgba(4, 10, 21, 0.72) 100%),
    linear-gradient(rgba(0, 163, 224, 0.06) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(0, 163, 224, 0.06) 1px, transparent 1px) 0 0 / 48px 48px;
}

/* ── HUD ──────────────────────────────────────────────────────────────── */

.tanya-hud {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  padding: 0.8rem 0 0.35rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--t-muted);
}

.tanya-hud p {
  margin: 0;
}

.hud-status {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.38rem 0.75rem 0.38rem 0.6rem;
  border: 1px solid var(--t-line);
  border-radius: 999px;
  background: rgba(4, 12, 24, 0.55);
  color: var(--t-ink-soft);
}

.hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--t-muted);
  box-shadow: 0 0 0 0 currentColor;
}

.hud-status[data-level="pending"] .hud-dot {
  animation: hud-blink 1s ease-in-out infinite;
}

.hud-status[data-level="live"] .hud-dot {
  background: var(--t-live);
  color: rgba(62, 224, 161, 0.55);
  animation: hud-ping 2.4s ease-out infinite;
}

.hud-status[data-level="demo"] .hud-dot {
  background: var(--t-amber);
}

@keyframes hud-blink {
  50% { opacity: 0.25; }
}

@keyframes hud-ping {
  0% { box-shadow: 0 0 0 0 currentColor; }
  70%, 100% { box-shadow: 0 0 0 8px transparent; }
}

.hud-meta {
  display: inline-flex;
  gap: 1rem;
  align-items: center;
}

.hud-mem b {
  color: var(--t-cyan-hot);
  font-weight: 700;
  margin-left: 0.25rem;
}

.hud-quota {
  color: var(--t-amber);
}

.hud-btn {
  margin-left: auto;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--t-ink-soft);
  background: rgba(4, 12, 24, 0.55);
  border: 1px solid var(--t-line);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.hud-btn:hover,
.hud-btn:focus-visible {
  outline: none;
  color: #fff;
  border-color: var(--t-line-strong);
  background: rgba(0, 163, 224, 0.14);
}

.hud-btn.is-armed {
  color: #fff;
  border-color: rgba(232, 106, 58, 0.7);
  background: rgba(232, 106, 58, 0.22);
}

/* ── Layout grid ──────────────────────────────────────────────────────── */

.tanya-grid {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  /* Empty space falls through to the canvas, so the orb and memory stars stay clickable. */
  pointer-events: none;
}

.tanya-grid > * {
  pointer-events: auto;
}

.tanya-grid > .tanya-orb-zone {
  pointer-events: none;
}

.tanya-orb-zone {
  grid-area: orb;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.tanya-orb-anchor {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  container-type: size;
  display: grid;
  place-items: center;
}

.tanya-fallback-orb {
  width: 46cqmin;
  height: 46cqmin;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.55), transparent 32%),
    conic-gradient(from 200deg, #00a3e0 0deg, #00a3e0 140deg, #0b1c33 200deg, #e86a3a 245deg, #00a3e0 295deg, #00a3e0 360deg);
  box-shadow:
    0 0 40px 6px rgba(0, 163, 224, 0.45),
    0 0 0 14px rgba(0, 163, 224, 0.08),
    0 0 0 30px rgba(0, 163, 224, 0.04);
  animation: fallback-breathe 4s ease-in-out infinite;
  transition: opacity 0.9s ease, transform 0.9s ease;
}

body.tanya-3d .tanya-fallback-orb {
  opacity: 0;
  transform: scale(0.6);
}

@keyframes fallback-breathe {
  50% { transform: scale(1.05); box-shadow: 0 0 60px 10px rgba(0, 163, 224, 0.55), 0 0 0 18px rgba(0, 163, 224, 0.08), 0 0 0 36px rgba(0, 163, 224, 0.03); }
}

/* Intro mode: centred hero, starter questions, then the question box. */
.tanya-stage[data-mode="intro"] .tanya-grid {
  width: min(100%, 780px);
  margin-inline: auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(150px, 1fr) auto auto auto;
  grid-template-areas: "orb" "intro" "starters" "chat";
  row-gap: 1.1rem;
  padding-bottom: 1.4rem;
}

.tanya-stage[data-mode="intro"] .chat-log,
.tanya-stage[data-mode="intro"] .chips {
  display: none;
}

.tanya-stage[data-mode="chat"] .tanya-intro,
.tanya-stage[data-mode="chat"] .tanya-starters {
  display: none;
}

/* Chat mode, desktop: Tanya holds the left of the stage, the conversation the right. */
.tanya-stage[data-mode="chat"] .tanya-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 620px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "orb chat";
  column-gap: clamp(1rem, 3vw, 2.5rem);
  padding-bottom: 1rem;
}

.tanya-stage[data-mode="chat"] .tanya-orb-anchor {
  height: min(100%, 560px);
}

/* ── Intro copy ───────────────────────────────────────────────────────── */

.tanya-intro {
  grid-area: intro;
  text-align: center;
  animation: tanya-rise 0.8s 0.15s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.tanya-kicker {
  margin: 0 0 0.4rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--t-cyan-hot);
}

.tanya-title {
  margin: 0 0 0.55rem;
  font-size: clamp(2rem, 4.6vw, 3.25rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: #fff;
}

.tanya-title span {
  background: linear-gradient(100deg, #4dd0ff 0%, #ffffff 45%, #4dd0ff 60%, #00a3e0 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: title-shimmer 6s ease-in-out infinite;
}

@keyframes title-shimmer {
  0%, 100% { background-position: 100% 0; }
  50% { background-position: 0% 0; }
}

.tanya-lede {
  margin: 0 auto;
  max-width: 54ch;
  color: var(--t-ink-soft);
  font-size: 1rem;
  line-height: 1.6;
}

/* ── Starter questions ────────────────────────────────────────────────── */

.tanya-starters {
  grid-area: starters;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.tanya-starters li {
  animation: tanya-rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.tanya-starters li:nth-child(1) { animation-delay: 0.25s; }
.tanya-starters li:nth-child(2) { animation-delay: 0.32s; }
.tanya-starters li:nth-child(3) { animation-delay: 0.39s; }
.tanya-starters li:nth-child(4) { animation-delay: 0.46s; }

.starter {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.8rem 2.4rem 0.85rem 1rem;
  text-align: left;
  font: inherit;
  color: var(--t-ink);
  background: linear-gradient(160deg, rgba(14, 36, 64, 0.72), rgba(7, 18, 35, 0.72));
  border: 1px solid var(--t-line);
  border-radius: 16px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.starter::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  width: 9px;
  height: 9px;
  border-top: 2px solid var(--t-cyan-hot);
  border-right: 2px solid var(--t-cyan-hot);
  transform: translateY(-50%) rotate(45deg);
  opacity: 0.5;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.starter:hover,
.starter:focus-visible {
  outline: none;
  transform: translateY(-2px);
  border-color: rgba(77, 208, 255, 0.55);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(77, 208, 255, 0.2), 0 0 28px rgba(0, 163, 224, 0.2);
}

.starter:hover::after,
.starter:focus-visible::after {
  opacity: 1;
  transform: translate(3px, -50%) rotate(45deg);
}

.starter:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.starter-tag {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t-cyan-hot);
}

.starter-q {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.35;
}

/* ── Chat panel ───────────────────────────────────────────────────────── */

.tanya-chat {
  grid-area: chat;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tanya-stage[data-mode="intro"] .tanya-chat {
  animation: tanya-rise 0.7s 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.tanya-stage[data-mode="chat"] .tanya-chat {
  margin-top: 0.35rem;
  background: linear-gradient(180deg, rgba(8, 20, 38, 0.6), rgba(5, 13, 27, 0.82));
  border: 1px solid var(--t-line);
  border-radius: 22px;
  backdrop-filter: blur(16px) saturate(1.25);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  overflow: hidden;
  animation: panel-in 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: none; }
}

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.25rem 1.2rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(125, 205, 255, 0.25) transparent;
  mask-image: linear-gradient(180deg, transparent 0, #000 22px);
}

/* ── Messages ─────────────────────────────────────────────────────────── */

.msg {
  max-width: 100%;
}

.msg-user {
  align-self: flex-end;
  max-width: 86%;
  animation: tanya-rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.msg-user .bubble {
  padding: 0.65rem 1rem;
  border-radius: 16px 16px 4px 16px;
  background: linear-gradient(135deg, rgba(232, 106, 58, 0.28), rgba(232, 106, 58, 0.12));
  border: 1px solid rgba(232, 106, 58, 0.38);
  color: #fff3ec;
  font-size: 0.97rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.msg-ai {
  position: relative;
  padding: 0.8rem 1rem 0.85rem 1.15rem;
  border-radius: 14px;
  background: var(--t-card);
  border: 1px solid var(--t-line);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.msg-ai::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--t-cyan-hot), rgba(0, 163, 224, 0.1));
  box-shadow: 0 0 10px rgba(77, 208, 255, 0.6);
}

.msg-ai[data-turn]:hover {
  border-color: var(--t-line-strong);
}

.msg-ai.is-refusal::before {
  background: linear-gradient(180deg, var(--t-amber), rgba(242, 163, 58, 0.1));
  box-shadow: 0 0 10px rgba(242, 163, 58, 0.55);
}

.msg-ai.is-error::before {
  background: linear-gradient(180deg, var(--t-red), rgba(255, 107, 107, 0.1));
  box-shadow: 0 0 10px rgba(255, 107, 107, 0.55);
}

.msg-ai.is-flash {
  animation: msg-flash 1.4s ease;
}

@keyframes msg-flash {
  0% { box-shadow: 0 0 0 0 rgba(77, 208, 255, 0.7); border-color: rgba(77, 208, 255, 0.9); }
  100% { box-shadow: 0 0 0 14px rgba(77, 208, 255, 0); }
}

.msg-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
  margin-bottom: 0.4rem;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t-muted);
}

.msg-who {
  color: var(--t-cyan-hot);
}

.msg-tag {
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid currentColor;
  color: var(--t-amber);
  letter-spacing: 0.06em;
}

.is-error .msg-tag {
  color: var(--t-red);
}

.msg-ai .bubble {
  color: #dcecf7;
  font-size: 0.98rem;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

/* Answers are rendered from a small markdown subset (bold, bullets, links) — see
   renderAnswer() in js/tanya.js. Tight spacing keeps short answers chat-like. */
.msg-ai .bubble p {
  margin: 0 0 0.55rem;
}

.msg-ai .bubble p:last-child,
.msg-ai .bubble ul:last-child {
  margin-bottom: 0;
}

.msg-ai .bubble ul {
  margin: 0 0 0.55rem;
  padding-left: 1.15rem;
}

.msg-ai .bubble li {
  margin-bottom: 0.2rem;
}

.msg-ai .bubble li::marker {
  color: var(--t-cyan-hot);
}

/* Bold figures glow — they're the same text that floats as holograms in the scene. */
.msg-ai .bubble strong {
  color: #ffffff;
  font-weight: 650;
  text-shadow: 0 0 14px rgba(77, 208, 255, 0.55);
}

.msg-ai .bubble a,
.bubble-sources a {
  color: var(--t-cyan-hot);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-ai.is-new .bubble > * {
  animation: tanya-materialise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(var(--i, 0) * 90ms);
}

@keyframes tanya-materialise {
  from { opacity: 0; transform: translateY(6px); filter: blur(5px); }
  to { opacity: 1; transform: none; filter: none; }
}

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

/* Attribution footer — quieter than the answer, but always visible, so it's clear
   which figures came from MRC and which came from the web. */
.bubble-sources {
  margin-top: 0.7rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--t-line);
  font-size: 0.8rem;
  color: var(--t-ink-soft);
}

.bubble-sources-title {
  display: block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--t-muted);
  margin-bottom: 0.28rem;
}

.bubble-sources ul {
  margin: 0;
  padding-left: 1.05rem;
}

.bubble-sources li {
  margin-bottom: 0.18rem;
}

.bubble-source-unverified {
  opacity: 0.7;
  font-style: italic;
}

.msg-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.msg-action {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--t-ink-soft);
  background: transparent;
  border: 1px solid var(--t-line);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.msg-action:hover,
.msg-action:focus-visible {
  outline: none;
  color: #fff;
  border-color: var(--t-line-strong);
  background: rgba(0, 163, 224, 0.14);
}

/* Pending answer: equaliser bars + honest progress copy + a running timer. */
.msg-ai.is-pending {
  border-style: dashed;
  border-color: rgba(125, 205, 255, 0.28);
}

.msg-timer {
  color: var(--t-ink-soft);
  font-variant-numeric: tabular-nums;
}

.pending-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--t-ink-soft);
  font-size: 0.92rem;
}

.pending-wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
  flex-shrink: 0;
}

.pending-wave i {
  width: 3px;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--t-cyan-hot), var(--t-cyan));
  box-shadow: 0 0 8px rgba(77, 208, 255, 0.6);
  transform-origin: bottom;
  animation: eq 1s ease-in-out infinite;
}

.pending-wave i:nth-child(2) { animation-delay: -0.2s; }
.pending-wave i:nth-child(3) { animation-delay: -0.4s; }
.pending-wave i:nth-child(4) { animation-delay: -0.6s; }
.pending-wave i:nth-child(5) { animation-delay: -0.8s; }

@keyframes eq {
  0%, 100% { transform: scaleY(0.25); }
  50% { transform: scaleY(1); }
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.chat-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tanya-stage[data-mode="chat"] .chat-footer {
  padding: 0.7rem 1rem 1rem;
  border-top: 1px solid rgba(125, 205, 255, 0.08);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chips:empty {
  display: none;
}

.chip {
  border: 1px solid rgba(77, 208, 255, 0.28);
  background: rgba(0, 163, 224, 0.08);
  color: #cfefff;
  border-radius: 999px;
  padding: 0.42rem 0.9rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.chip:hover,
.chip:focus-visible {
  outline: none;
  background: rgba(0, 163, 224, 0.18);
  border-color: rgba(77, 208, 255, 0.6);
  box-shadow: 0 0 18px rgba(0, 163, 224, 0.25);
  transform: translateY(-1px);
}

.chip:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.tanya-form {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.4rem 0.4rem 0.9rem;
  border-radius: 999px;
  background: rgba(3, 10, 21, 0.78);
  border: 1px solid var(--t-line-strong);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  transition: border-color 0.2s, box-shadow 0.2s;
  isolation: isolate;
}

/* Animated brand-coloured edge: a slow sweep on focus, a fast one while Tanya works. */
.tanya-form::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: -1;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from var(--tanya-spin), transparent 0deg, #4dd0ff 60deg, transparent 120deg, transparent 200deg, #e86a3a 250deg, transparent 300deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s;
  animation: tanya-spin 4s linear infinite;
}

.tanya-form:focus-within {
  border-color: rgba(77, 208, 255, 0.5);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4), 0 0 0 4px rgba(0, 163, 224, 0.12);
}

.tanya-form:focus-within::before,
.tanya-form.is-busy::before {
  opacity: 1;
}

.tanya-form.is-busy::before {
  animation-duration: 1.2s;
}

@keyframes tanya-spin {
  to { --tanya-spin: 360deg; }
}

.form-glyph {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border-radius: 50%;
  background: conic-gradient(from 200deg, #00a3e0 0deg, #00a3e0 145deg, #0b1c33 200deg, #e86a3a 250deg, #00a3e0 360deg);
  box-shadow: 0 0 10px rgba(0, 163, 224, 0.6);
}

.tanya-form.is-busy .form-glyph {
  animation: tanya-glyph-spin 1s linear infinite;
}

@keyframes tanya-glyph-spin {
  to { transform: rotate(360deg); }
}

.tanya-form input {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  padding: 0.6rem 0;
  font: inherit;
  font-size: 1rem;
  color: var(--t-ink);
  caret-color: var(--t-cyan-hot);
}

.tanya-form input::placeholder {
  color: var(--t-muted);
}

.tanya-form input:focus {
  outline: none;
}

.form-kbd {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--t-muted);
  border: 1px solid var(--t-line);
  border-radius: 6px;
  padding: 0.05rem 0.4rem;
}

.tanya-form:focus-within .form-kbd {
  display: none;
}

@media (hover: none) {
  .form-kbd { display: none; }
}

.btn-send {
  position: relative;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, #ff8a5b, #e86a3a 55%, #c9532a);
  box-shadow: 0 6px 18px rgba(232, 106, 58, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn-send:hover {
  filter: brightness(1.08);
  box-shadow: 0 8px 24px rgba(232, 106, 58, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-send:active {
  transform: scale(0.93);
}

.btn-send:focus-visible {
  outline: 2px solid var(--t-cyan-hot);
  outline-offset: 3px;
}

.btn-send:disabled {
  cursor: default;
  filter: grayscale(0.7) brightness(0.7);
  box-shadow: none;
}

.btn-send-count {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
}

.tanya-form.is-cooling .btn-send svg {
  display: none;
}

.tanya-form.is-cooling .btn-send-count {
  display: grid;
}

/* ── Memory-star tooltip (positioned by the scene) ────────────────────── */

.node-tip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  translate: -50% calc(-100% - 16px);
  max-width: 260px;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  background: rgba(4, 12, 24, 0.9);
  border: 1px solid var(--t-line-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 163, 224, 0.2);
  color: #e7f4fc;
  font-size: 0.82rem;
  line-height: 1.4;
  pointer-events: none;
}

.node-tip strong {
  display: block;
  margin-bottom: 0.15rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--t-cyan-hot);
}

.node-tip span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Responsive ───────────────────────────────────────────────────────── */

/* Tablet and phone: Tanya shrinks to a band above the conversation. */
@media (max-width: 1024px) {
  .tanya-stage[data-mode="chat"] .tanya-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: clamp(92px, 17vh, 170px) minmax(0, 1fr);
    grid-template-areas: "orb" "chat";
    padding-bottom: 0.75rem;
  }

  .tanya-stage[data-mode="chat"] .tanya-chat {
    width: min(100%, 720px);
    margin-inline: auto;
    animation-name: tanya-rise;
  }
}

@media (max-width: 720px) {
  /* Every pixel of height goes to the conversation on phones. */
  body.is-tanya .site-footer {
    display: none;
  }

  .tanya-hud {
    padding-top: 0.6rem;
    gap: 0.45rem 0.8rem;
    font-size: 0.64rem;
  }

  .hud-status {
    padding: 0.32rem 0.6rem 0.32rem 0.5rem;
  }

  .tanya-starters {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
  }

  .tanya-starters li:nth-child(n + 4) {
    display: none;
  }

  .starter {
    padding-block: 0.65rem;
  }

  .tanya-lede {
    font-size: 0.93rem;
  }

  .tanya-stage[data-mode="chat"] .tanya-chat {
    border-radius: 18px;
  }

  .chat-log {
    padding: 1rem 0.85rem 0.6rem;
  }

  .tanya-stage[data-mode="chat"] .chat-footer {
    padding: 0.6rem 0.7rem 0.75rem;
  }

  /* Follow-ups scroll sideways instead of stacking into a wall of buttons. */
  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-inline: -0.2rem;
    padding-inline: 0.2rem;
  }

  .chips::-webkit-scrollbar {
    display: none;
  }

  .chip {
    white-space: nowrap;
  }
}

@media (max-height: 720px) {
  .tanya-stage[data-mode="intro"] .tanya-grid {
    grid-template-rows: minmax(110px, 1fr) auto auto auto;
    row-gap: 0.75rem;
  }

  .tanya-lede {
    display: none;
  }
}

/* ── Home hero on the 3D stage ────────────────────────────────────────── */

.home-visual,
.home-scrim,
.home-kicker {
  display: none;
}

body.is-home-stage .home {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  align-items: center;
  gap: 1.5rem 3rem;
}

body.is-home-stage .home-scrim {
  display: block;
  position: absolute;
  /* Root cause of the visible seam: percentage-sized radial-gradients (e.g.
     "ellipse 60% ... at 20% 50%") size themselves against THIS BOX's own
     dimensions — so the fade only fully completes at last-stop% * radius% of
     the box's width from its centre. With the centre at 20% and any radius
     worth having, that distance is always bigger than the 20%-of-width of
     room actually available before the box's own left edge — the fade gets
     cut off mid-fade, and the box boundary (still-opaque color -> nothing)
     *is* the hard seam. Reducing peak opacity earlier made the jump smaller
     but never removed it. Fixed instead: every position/radius below is in
     rem, not %, so the geometry can't reference (and be limited by) the
     box's own size at all — only the fixed overflow this box is given has
     to stay ≥ each radius, which is just arithmetic, not proportional. */
  top: -3rem;
  right: -2rem;
  bottom: -3rem;
  left: -30rem;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(22rem 20rem at 32rem 50%, rgba(4, 10, 21, 0.42), rgba(4, 10, 21, 0.18) 55%, transparent 100%),
    radial-gradient(30rem 24rem at right 0 top 40%, rgba(4, 10, 21, 0.16), transparent 100%);
}

body.is-home-stage .home-copy {
  position: relative;
  animation: tanya-rise 0.8s 0.1s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

body.is-home-stage .home-kicker {
  display: block;
  margin: 0 0 0.9rem;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #4dd0ff;
}

body.is-home-stage .home h1 {
  color: #ffffff;
  text-shadow: 0 2px 30px rgba(4, 10, 21, 0.6);
}

body.is-home-stage .home .subtitle {
  color: #bfd2e3;
  max-width: 46ch;
}

body.is-home-stage .home .btn-secondary {
  background: rgba(7, 18, 35, 0.6);
  color: #e7f4fc;
  border-color: rgba(125, 205, 255, 0.34);
  backdrop-filter: blur(10px);
}

body.is-home-stage .home .btn-secondary:hover:not(:disabled) {
  background: rgba(0, 163, 224, 0.2);
  border-color: rgba(77, 208, 255, 0.7);
}

body.is-home-stage .home-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
  animation: tanya-rise 0.9s 0.2s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.home-orb-anchor {
  width: 100%;
  max-width: 360px;
  max-height: 36vh;
  aspect-ratio: 1;
  container-type: size;
  display: grid;
  place-items: center;
  margin-inline: auto;
}

.home-orb-caption {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.95rem 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  color: #cfe7f7;
  background: rgba(4, 12, 24, 0.6);
  border: 1px solid rgba(125, 205, 255, 0.28);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.home-orb-caption:hover,
.home-orb-caption:focus-visible {
  outline: none;
  color: #ffffff;
  border-color: rgba(77, 208, 255, 0.7);
  background: rgba(0, 163, 224, 0.18);
}

.home-orb-caption-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4dd0ff;
  color: rgba(77, 208, 255, 0.55);
  animation: hud-ping 2.4s ease-out infinite;
}

@media (max-width: 860px) {
  body.is-home-stage .home {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    padding-top: 1rem;
  }

  body.is-home-stage .home-visual {
    order: -1;
  }

  .home-orb-anchor {
    width: auto;
    max-width: 260px;
    height: min(26vh, 230px);
  }

  body.is-home-stage .home-scrim {
    /* Narrower box at this width, so it gets its own overflow (not the desktop
       rule's -30rem, sized for a very different, wider layout) and its own
       fixed-unit gradient sized to safely fit — see the desktop rule above for
       why these must be rem, not %, of the box. */
    left: -4rem;
    right: -4rem;
    background: radial-gradient(10rem 9rem at 50% 70%, rgba(4, 10, 21, 0.4), rgba(4, 10, 21, 0.16) 55%, transparent 100%);
  }
}

/* ── Phone and tablet fixes (device audit 2026-10-08) ─────────────────────
   Checked at 320x568, 390x844, 844x390 (landscape phone), 768x1024, 1024x768
   and 1024x1366: no sideways page scroll anywhere, the layout was sound. These
   fix what the audit did find. */

/* iOS Safari counts the area behind its toolbar in 100vh, which pushed the
   composer under the toolbar. 100dvh is the visible height. */
@supports (height: 100dvh) {
  body { min-height: 100dvh; }
}

/* Touch targets: at least 44px, and the long follow-up row signals that it scrolls. */
@media (hover: none) and (pointer: coarse) {
  .chip { min-height: 44px; padding-block: 0.5rem; }
  .btn-send { width: 44px; height: 44px; }
  .hud-btn { min-height: 44px; }
}

@media (max-width: 720px) {
  .chips {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
}

/* Small phones: the status pill and "New chat" share one line instead of
   "New chat" wrapping underneath and costing a row of height. */
@media (max-width: 400px) {
  .tanya-hud { flex-wrap: nowrap; gap: 0.4rem; }
  .hud-status { min-width: 0; flex: 0 1 auto; }
  .hud-status #tanya-status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hud-btn { flex-shrink: 0; }
  .hud-meta { display: none; }
}

/* Landscape phones: only ~390px of height. The orb band, the page footer and
   three rows of wrapped follow-ups left no room for the input at all. */
@media (max-height: 500px) and (orientation: landscape) {
  body.is-tanya .site-footer { display: none; }

  .tanya-hud { padding-top: 0.3rem; padding-bottom: 0.2rem; }

  .tanya-stage[data-mode="chat"] .tanya-grid {
    grid-template-rows: 0 minmax(0, 1fr);
    padding-bottom: 0.4rem;
  }
  .tanya-stage[data-mode="chat"] .tanya-orb-zone { display: none; }

  .chat-log { padding: 0.6rem 0.85rem 0.3rem; }

  .tanya-stage[data-mode="chat"] .chat-footer { padding: 0.4rem 0.7rem 0.5rem; gap: 0.35rem; }

  .chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent);
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; }
}
