/* =========================================================================
   POST-LLM DESIGN SYSTEM (overhaul 2026-05-19, SUB-125+)
   Foundation tokens. Existing class structure preserved — only visual tokens
   updated. Backed up to Public-backup-pre-redesign-2026-05-19/.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ---- Surface (cooler, deeper, slight violet bias) ---- */
  --bg-deepest: #0a0612;       /* midnight violet, replaces #07090c hacker-black */
  --bg-surface: #16131f;       /* card/surface, violet-tinted */
  --bg-input: #11101a;         /* input field, slightly above bg-deepest */

  /* ---- Borders ---- */
  --border-faint: rgba(255, 255, 255, 0.08);
  --border-active: rgba(255, 255, 255, 0.18);
  --border-accent: rgba(168, 85, 247, 0.4);  /* violet accent border */

  /* ---- Text ---- */
  --text-primary: #e6edf3;
  --text-secondary: #b8c0cc;
  --text-dim: #8b96a3;
  --text-fainter: #5a6470;

  /* ---- Hero gradient (substrate's signature) ---- */
  --hero-gradient: linear-gradient(135deg, #a855f7 0%, #f43f5e 100%);
  --hero-gradient-soft: linear-gradient(135deg, rgba(168, 85, 247, 0.18) 0%, rgba(244, 63, 94, 0.14) 100%);
  --hero-gradient-line: linear-gradient(180deg, #a855f7 0%, #f43f5e 100%);
  --hero-violet: #a855f7;
  --hero-pink: #f43f5e;

  /* ---- Legacy accent (kept for existing animations / status colors) ---- */
  --beam-color: #ffaa44;
  --beam-glow: rgba(255, 170, 68, 0.55);
  --construct-color: #ff7a3c;
  --pass-color: #6abf69;
  --fail-color: #c44848;

  /* ---- Typography ---- */
  --font-display: 'Inter', ui-sans-serif, -apple-system, "SF Pro Text", system-ui, sans-serif;
  --font-prose: 'Inter', ui-sans-serif, -apple-system, "SF Pro Text", system-ui, sans-serif;
  --font-serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, monospace;

  /* ---- Spacing scale (8pt with finer-grain low end) ---- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 72px;

  /* ---- Radii ---- */
  --radius-chip: 4px;
  --radius-btn: 8px;
  --radius-card: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  /* ---- Motion ---- */
  --motion-hover: 150ms ease-out;
  --motion-transition: 200ms ease-in-out;
  --motion-entrance: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --motion-stream: 600ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  height: 100vh;
  width: 100vw;
  background:
    radial-gradient(ellipse at 18% 8%, rgba(168, 85, 247, 0.10), transparent 60%),
    radial-gradient(ellipse at 82% 90%, rgba(244, 63, 94, 0.08), transparent 55%),
    var(--bg-deepest);
  color: var(--text-primary);
  font-family: var(--font-prose);
  font-size: 15px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}



/* ---------- Particle field ---------- */

#particle-canvas {
  background: transparent;

  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* ---------- Beam canvas ---------- */

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

/* ---------- Brand badge ---------- */

#brand-badge {
  position: fixed;
  top: 24px;
  left: 28px;
  z-index: 2;
  padding: 12px 18px 12px 14px;
  background: rgba(22, 19, 31, 0.62);
  border: 1px solid var(--border-faint);
  border-left: 2px solid transparent;
  border-image: var(--hero-gradient-line) 1;
  border-image-slice: 1;
  border-radius: var(--radius-card);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  pointer-events: none;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  background: var(--hero-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tagline {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-fainter);
  margin-top: 2px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  min-height: 14px;
  transition: opacity 350ms ease;
}

.brand-tagline.swapping {
  opacity: 0;
}

/* ---------- Chat stage: centered always ---------- */

#chat-stage {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  height: 100vh;
  margin: 0 auto;
  padding: 0 24px;

  /* Center the form vertically. Messages spill upward from the form. */
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: stretch;
}

#chat-log {
  /* grid-row controlled later in the file per the row stack */
  overflow-y: auto;
  padding: 24px 0 16px;
  display: flex;
  flex-direction: column;
  /* SCROLLING FIX (2026-05-20): the prior `justify-content: flex-end`
     anchored messages to the bottom BUT broke scroll-up in tall chat-logs
     — once overflow kicked in, the flex algorithm fought the scrollbar.
     Replaced with the spacer-pseudo-element pattern (same as mobile):
     an auto-margin spacer pushes messages to bottom when content is
     short, allows natural top-down scrolling when content overflows. */
  gap: 22px;
  min-height: 0;
}
#chat-log::before {
  content: "";
  display: block;
  margin-top: auto;
  flex: 0 0 auto;
}

#chat-log::-webkit-scrollbar { width: 6px; }
#chat-log::-webkit-scrollbar-thumb {
  background: var(--border-active);
  border-radius: 3px;
}
#chat-log::-webkit-scrollbar-track { background: transparent; }

.msg {
  max-width: 88%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-user {
  align-self: flex-end;
  max-width: 72%;
  background: var(--bg-input);
  padding: 10px 14px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border-faint);
  font-family: var(--font-display);
  font-size: 14.5px;
  color: var(--text-secondary);
}

.msg-substrate {
  align-self: stretch;
  max-width: none;
  padding: 6px 0 6px 18px;
  position: relative;
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.62;
  color: var(--text-primary);
  letter-spacing: -0.003em;
  animation: substrate-crystallize 380ms cubic-bezier(0.4, 0, 0.2, 1);
}

.msg-substrate::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 999px;
  background: var(--hero-gradient-line);
  opacity: 0.85;
}

@keyframes substrate-crystallize {
  from { opacity: 0; transform: translateY(4px); filter: blur(3px); }
  to   { opacity: 1; transform: translateY(0);   filter: blur(0);   }
}

.msg-pending {
  align-self: flex-start;
  color: var(--text-dim);
  font-style: italic;
}

/* Calculator result: monospace + amber tint so it reads as a discrete
   computed fact rather than substrate prose. Errors get the muted-red
   variant. Plays on the same accent palette as the beam. */
.msg-calc {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 17px;
  color: #f0c98a;
  padding: 8px 14px;
  background: rgba(240, 201, 138, 0.07);
  border: 1px solid rgba(240, 201, 138, 0.18);
  border-radius: 10px;
}

/* SUB-55: markdown rendering inside substrate / pockets bubbles. Inline code
   gets a faint pill; fenced blocks get a darker mono block with horizontal
   scroll. Headers / lists / quotes / links inherit the bubble's text style
   but get tighter vertical rhythm than browser defaults. */
.msg-substrate p { margin: 4px 0; }
.msg-substrate h1, .msg-substrate h2, .msg-substrate h3,
.msg-substrate h4, .msg-substrate h5, .msg-substrate h6 {
  margin: 10px 0 4px 0;
  line-height: 1.25;
}
.msg-substrate h1 { font-size: 1.35em; }
.msg-substrate h2 { font-size: 1.2em; }
.msg-substrate h3 { font-size: 1.08em; }
.msg-substrate ul, .msg-substrate ol {
  margin: 4px 0;
  padding-left: 1.4em;
}
.msg-substrate li { margin: 2px 0; }
.msg-substrate code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 3px;
}
.msg-substrate pre {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 0.92em;
}
.msg-substrate pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}
.msg-substrate blockquote {
  margin: 6px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border-faint);
  color: var(--text-dim);
}
.msg-substrate a {
  color: #ffa044;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.msg-substrate hr {
  border: 0;
  border-top: 1px solid var(--border-faint);
  margin: 10px 0;
}

/* SUB-67: Pockets personality button bar. Sits inside #chat-stage (injected
   by app.js after init), wraps to multiple rows on narrow widths. Subtle so
   it's discoverable but doesn't compete with the form. */
.pockets-actions {
  /* Hidden by default. Reveal via .open class when user taps ✨ toggle.
     Reclaims ~3 rows of empty-state visual weight; chitchat still
     discoverable (single ✨ button), just not always-visible. */
  display: none;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin: 8px 0 4px;
  padding: 6px 2px;
  align-self: stretch;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.2s;
  overflow-anchor: none;
}
.pockets-actions.open {
  display: flex;
  animation: pockets-reveal 180ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes pockets-reveal {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* 🦒 toggle button — sits in the chat-form, leftmost. Intentionally
   smaller than mic/send so it reads as a SECONDARY affordance (chitchat
   shortcut), not a primary action like voice input or submit. */
#pockets-toggle {
  background: transparent;
  border: 1px solid var(--border-faint);
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  transition: all var(--motion-hover);
  -webkit-tap-highlight-color: transparent;
}
#pockets-toggle:hover {
  background: rgba(168, 85, 247, 0.08);
  border-color: var(--hero-violet);
  color: var(--hero-violet);
}
#pockets-toggle[aria-expanded="true"] {
  background: var(--hero-gradient);
  border-color: transparent;
  color: white;
}
.pockets-action {
  font: inherit;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px 6px 9px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(22, 19, 31, 0.6);
  color: var(--text-secondary);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-pill);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all var(--motion-hover);
}
.pockets-action {
  /* Anti-jump: prevent browser scroll-into-view nudging the button on focus */
  scroll-margin: 0;
}
.pockets-action:hover {
  background: rgba(168, 85, 247, 0.12);
  color: var(--text-primary);
  border-color: var(--border-accent);
  /* No transform — desktop kept slight lift; if it causes jumping, remove */
  transform: translateY(-1px);
}
.pockets-action:active {
  background: var(--hero-gradient);
  border-color: transparent;
  color: white;
  /* No transform on active — reflow-free press */
}
.pockets-action-emoji { font-size: 1.05em; line-height: 1; }
.pockets-action-label { white-space: nowrap; }
.msg-calc.error {
  color: #d68c8c;
  background: rgba(214, 140, 140, 0.07);
  border-color: rgba(214, 140, 140, 0.22);
}
.typing-indicator .dot {
  display: inline-block;
  margin: 0 0.05em;
  animation: typing-fade 1.4s infinite;
  animation-fill-mode: both;
  opacity: 0.3;
}
.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.18s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing-fade {
  0%, 80%, 100% { opacity: 0.3; }
  40%           { opacity: 1; }
}

#chat-form {
  /* grid-row controlled later in the file per the SUB-68 row stack */
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-card);
  /* Left padding kept tight (8px) so the 🦒 toggle hugs the left edge.
     Right padding stays 10px for mic+send breathing room. */
  padding: 10px 10px 10px 8px;
  transition: border-color var(--motion-transition), box-shadow var(--motion-transition);
}

#chat-form:focus-within {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.18), 0 8px 24px rgba(168, 85, 247, 0.05);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 15.5px;
  line-height: 1.5;
  resize: none;
  padding: 6px 0;
  max-height: 200px;
}

#chat-input::placeholder { color: var(--text-fainter); font-style: italic; }

/* Mic button (SUB-131 — audio I/O). Sits just before the send button.
   Inactive: outline matches the form. Active (recording): gradient fill. */
#chat-mic {
  background: transparent;
  border: 1px solid var(--border-active);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--motion-hover);
}
#chat-mic:hover:not(:disabled) {
  background: rgba(168, 85, 247, 0.08);
  border-color: var(--hero-violet);
  color: var(--hero-violet);
}
#chat-mic.recording {
  background: var(--hero-gradient);
  border-color: transparent;
  color: white;
  animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.4); }
  50%      { box-shadow: 0 0 0 8px rgba(168, 85, 247, 0); }
}
#chat-mic:disabled { opacity: 0.4; cursor: not-allowed; }

#chat-submit {
  background: transparent;
  border: 1px solid var(--border-active);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--motion-hover);
}

#chat-submit:hover:not(:disabled) {
  background: var(--hero-gradient);
  border-color: transparent;
  color: white;
  transform: scale(1.04);
}

#chat-submit:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---------- Per-sentence transform (SUB-75 / UI Phase 3) ----------
 *
 * Each sentence in a substrate bubble is wrapped in a clickable span.
 * Click → popover anchored near the sentence with Words sub-buttons.
 * Click an action → POST /v1/query/transform_fragment, splice response
 * in place.
 */

.msg-substrate .sentence {
  cursor: pointer;
  border-radius: 5px;
  padding: 0 2px;
  margin: 0 -2px;
  transition: background 140ms ease;
}
.msg-substrate .sentence:hover { background: rgba(255, 170, 68, 0.12); }
.msg-substrate .sentence.sentence-active { background: rgba(255, 170, 68, 0.22); }
.msg-substrate .sentence.sentence-loading {
  background: rgba(255, 170, 68, 0.14);
  opacity: 0.55;
  cursor: progress;
}
.msg-substrate .sentence.sentence-flash {
  animation: sentence-flash 600ms ease-out;
}
.msg-substrate .sentence.sentence-noop {
  animation: sentence-noop 800ms ease-out;
}
@keyframes sentence-noop {
  0%   { background: rgba(140, 140, 140, 0.35); }
  100% { background: transparent; }
}

.msg-substrate .msg-hint {
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-faint);
  font-size: 11.5px;
  font-style: italic;
  color: var(--text-secondary);
  opacity: 0.75;
}

.mini-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(8px);
  z-index: 1700;
  padding: 10px 18px;
  background: rgba(16, 20, 26, 0.96);
  border: 1px solid var(--border-faint);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.mini-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
@keyframes sentence-flash {
  0%   { background: rgba(255, 170, 68, 0.55); }
  100% { background: transparent; }
}

#sentence-popover {
  position: fixed;
  z-index: 1600;
  width: 440px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  background: rgba(16, 20, 26, 0.96);
  border: 1px solid var(--border-faint);
  border-radius: 14px;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  display: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
}
#sentence-popover.open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}
.ep-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border-faint);
}
.ep-header-title {
  flex: 1 1 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}
.ep-close {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}
.ep-close:hover { background: rgba(255, 255, 255, 0.14); }
.ep-preview {
  font-size: 12.5px;
  font-style: italic;
  color: var(--text-secondary);
  padding: 4px 6px 10px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-faint);
  max-height: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.ep-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.ep-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 11px;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--beam-color);
  color: #1a1206;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  position: relative;
  transition: background 120ms ease, transform 90ms ease, opacity 140ms ease;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 2px 5px rgba(0, 0, 0, 0.2);
}
.ep-row:not(:disabled):hover { background: #ffba66; }
.ep-row:not(:disabled):active { transform: scale(0.98); }
.ep-row:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.ep-row.ep-row-soon {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border: 1px solid var(--border-faint);
  cursor: default;
  box-shadow: none;
  font-weight: 500;
}
.ep-row-label { line-height: 1.2; }
.ep-row-soon-badge {
  position: absolute;
  top: 5px; right: 5px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.32);
  padding: 2px 4px;
  border-radius: 4px;
}

/* ---------- Primed-action chip (SUB-68 v3.1) ----------
 *
 * Shows up above the input when the user clicks a sub-button before
 * typing — declares "what will run on Send." Click × to clear.
 */

#primed-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  margin: 0 0 8px;
  background: rgba(255, 170, 68, 0.18);
  color: var(--text-primary);
  border: 1px solid rgba(255, 170, 68, 0.45);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  animation: pc-pop 180ms cubic-bezier(0.2, 0.85, 0.25, 1);
}
#primed-chip[hidden] { display: none; }
.pc-arrow { color: var(--beam-color); font-size: 14px; line-height: 1; }
.pc-label {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pc-clear {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.pc-clear:hover { background: rgba(255, 255, 255, 0.16); color: var(--text-primary); }

@keyframes pc-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ---------- Mode tabs + legend (SUB-68 May 17 spec) ---------- */

#mode-legend {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin: 4px 0 8px;
  opacity: 0.85;
}

#mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 0 0 14px;
}

/* Top-level mode tab. Inactive: brand-color text on transparent w/
 * subtle border. Active: solid brand fill, dark text. Solid only —
 * never glass (per "DO NOT" rules). */
.mode-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 8px;
  min-height: 60px;
  border: 1px solid rgba(255, 170, 68, 0.45);
  border-radius: 12px;
  background: transparent;
  color: var(--beam-color);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 140ms ease, transform 90ms ease, color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
.mode-tab:not(.active):hover {
  background: rgba(255, 170, 68, 0.1);
  border-color: var(--beam-color);
}
.mode-tab:active { transform: scale(0.98); }
.mode-tab.active {
  background: var(--beam-color);
  color: #1a1206;
  border-color: var(--beam-color);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 3px 8px rgba(0, 0, 0, 0.22);
}
.mt-icon {
  font-size: 18px;
  line-height: 1;
}
.mt-label {
  font-size: 13px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Sub-button popover (glass chrome, solid rows) ---------- */

/* SUB-68 spec: desktop sub-button popover anchored below the active
 * tab. 2-column grid of 240×60 solid-fill funny-labeled buttons. */
#sub-popover {
  position: fixed;
  z-index: 1500;
  width: 520px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  background: rgba(16, 20, 26, 0.94);
  border: 1px solid var(--border-faint);
  border-radius: 14px;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  display: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
}
#sub-popover.open {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.sp-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 4px 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-faint);
}
.sp-header-icon { font-size: 18px; line-height: 1; }
.sp-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}
.sp-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.sp-empty {
  grid-column: 1 / -1;
  padding: 14px 8px 6px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.sp-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  min-height: 60px;
  border: none;
  border-radius: 12px;
  background: var(--beam-color);
  color: #1a1206;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  position: relative;
  transition: background 120ms ease, transform 90ms ease, opacity 140ms ease;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.22);
}
.sp-row:not(:disabled):hover { background: #ffba66; }
.sp-row:not(:disabled):active { transform: scale(0.98); }
.sp-row:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}
.sp-row.sp-row-soon {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  border: 1px solid var(--border-faint);
  cursor: default;
  box-shadow: none;
  font-weight: 500;
}
.sp-row-label { line-height: 1.2; }
.sp-row-soon-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.32);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Transform chip on user bubble */
.msg-transform-chip {
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-weight: 500;
}
.msg-transform-body { white-space: pre-wrap; }

/* Beam path styles */
.beam-trail {
  fill: none;
  stroke: var(--beam-color);
  stroke-width: 2px;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--beam-glow));
  opacity: 0;
}

.construction-box {
  fill: none;
  stroke: var(--construct-color);
  stroke-width: 1.5px;
  stroke-linecap: round;
  filter: drop-shadow(0 0 5px rgba(255, 122, 60, 0.4));
}

.construction-box.passed {
  stroke: var(--pass-color);
  filter: drop-shadow(0 0 8px rgba(106, 191, 105, 0.5));
}

@media (max-width: 640px) {
  #chat-stage { padding: 0 16px; }
  #brand-badge { top: 14px; left: 14px; padding: 8px 12px; }
}


/* ---------- Apex pulse during construction ---------- */

.apex-pulse-halo {
  fill: var(--beam-color);
  opacity: 0.3;
  filter: drop-shadow(0 0 8px var(--beam-glow));
  pointer-events: none;
}

.apex-pulse-core {
  fill: var(--beam-color);
  filter: drop-shadow(0 0 4px var(--beam-glow));
  pointer-events: none;
}

/* ---------- Construction layered reveal ---------- */

.construction-ghost {
  fill: none;
  stroke: var(--construct-color);
  stroke-width: 0.8px;
  opacity: 0;
  stroke-dasharray: 2 3;
}

.construction-inner-line {
  stroke: var(--construct-color);
  stroke-width: 0.6px;
  opacity: 0.6;
  stroke-linecap: round;
}

.construction-inner.passed .construction-inner-line {
  stroke: var(--pass-color);
  opacity: 0.85;
  transition: stroke 200ms ease, opacity 200ms ease;
}

/* ---------- Chitchat ring pulse ---------- */

.chitchat-ring {
  fill: none;
  stroke: var(--beam-color);
  stroke-width: 1.2px;
  opacity: 0.5;
  filter: drop-shadow(0 0 3px var(--beam-glow));
}


/* ---------- Status line ---------- */

#status-line {
  /* grid-row controlled later in the file per the SUB-68 row stack */
  height: 22px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  opacity: 0;
  transition: opacity 280ms ease;
  pointer-events: none;
  user-select: none;
}

#status-line.visible {
  opacity: 1;
}

#status-line.celebrating {
  color: var(--pass-color);
  text-shadow: 0 0 8px rgba(106, 191, 105, 0.4);
}

/* Chat-log on top (output history scrolls), input pinned at bottom —
   the proper chat UX. Tabs + legend live just above the input so
   they're reachable without moving the eyes far from where you type. */
#chat-stage {
  grid-template-rows: 1fr auto auto auto auto auto auto;
}
#chat-log         { grid-row: 1; min-height: 0; }
#status-line      { grid-row: 2; }
#mode-legend      { grid-row: 3; }
#mode-tabs        { grid-row: 4; }
.pockets-actions  { grid-row: 5; }
#primed-chip      { grid-row: 6; }
#chat-form        { grid-row: 7; }

/* ---------- Brand badge flash ---------- */

#brand-badge.flashing {
  animation: badge-flash 800ms ease-out;
}

#brand-badge.flashing-twice {
  animation: badge-flash 1400ms ease-out;
}

@keyframes badge-flash {
  0% { box-shadow: 0 0 0 0 rgba(255, 170, 68, 0); border-color: var(--border-faint); }
  20% { box-shadow: 0 0 14px 4px rgba(255, 170, 68, 0.4); border-color: var(--beam-color); }
  60% { box-shadow: 0 0 6px 2px rgba(255, 170, 68, 0.15); border-color: var(--border-active); }
  100% { box-shadow: 0 0 0 0 rgba(255, 170, 68, 0); border-color: var(--border-faint); }
}

/* ---------- Radial burst particles ---------- */

.burst-particle {
  fill: var(--beam-color);
  filter: drop-shadow(0 0 4px var(--beam-glow));
  pointer-events: none;
}


/* ---------- Shockwave ring (sonar-like ping outward from box) ---------- */

.shockwave {
  fill: none;
  stroke: var(--beam-color);
  stroke-width: 2px;
  filter: drop-shadow(0 0 12px var(--beam-glow));
  pointer-events: none;
}

/* ---------- Construction box: locked green hold ---------- */

.construction-box.locked {
  stroke: var(--pass-color) !important;
  stroke-width: 2px !important;
  filter: drop-shadow(0 0 14px rgba(106, 191, 105, 0.6)) !important;
  fill: rgba(106, 191, 105, 0.04) !important;
  transition: fill 200ms ease, stroke 200ms ease;
}

/* ---------- Return beam pulse (post-construction) ---------- */

.beam-trail.charged {
  stroke-width: 3px;
  filter: drop-shadow(0 0 12px var(--beam-glow)) drop-shadow(0 0 4px var(--beam-color));
}

/* ---------- Markdown rendering in chat bubbles ---------- */

.msg pre {
  background: rgba(15, 18, 22, 0.85);
  border: 1px solid rgba(108, 145, 182, 0.18);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: #d8dce0;
  -webkit-overflow-scrolling: touch;
}

.msg pre code {
  background: transparent;
  padding: 0;
  font-family: inherit;
  white-space: pre;
  color: inherit;
}

.msg code:not(pre code) {
  background: rgba(108, 145, 182, 0.15);
  border: 1px solid rgba(108, 145, 182, 0.2);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  color: #f0c98a;
}

.msg ul, .msg ol {
  margin: 8px 0;
  padding-left: 22px;
}
.msg li { margin: 3px 0; }

.msg p { margin: 6px 0; }
.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }

.msg strong { color: #f0c98a; }

.msg a {
  color: var(--beam-color, #f0a85a);
  text-decoration: underline;
}

.msg blockquote {
  border-left: 3px solid rgba(108, 145, 182, 0.4);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-dim, #5a6470);
}

.msg h1, .msg h2, .msg h3, .msg h4 {
  margin: 10px 0 6px;
  font-weight: 600;
}
.msg h1 { font-size: 1.2em; }
.msg h2 { font-size: 1.1em; }
.msg h3, .msg h4 { font-size: 1.05em; }

.msg table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.msg th, .msg td {
  border: 1px solid rgba(108, 145, 182, 0.2);
  padding: 4px 8px;
  text-align: left;
}
.msg th { background: rgba(108, 145, 182, 0.1); }

/* Feedback bar — minimal. Tiny inline glyphs, near-invisible until
   hover. Discreet so they don't compete with the message content. */
.feedback-bar {
  display: inline-flex;
  gap: 2px;
  margin: 6px 0 -2px -4px;
  opacity: 0.2;
  transition: opacity 0.25s ease;
}
.feedback-bar:hover, .feedback-bar:active { opacity: 0.8; }
.feedback-bar button {
  background: none;
  border: none;
  padding: 3px 5px;
  margin: 0;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  color: inherit;
}
.feedback-bar button:disabled { cursor: default; opacity: 0.55; }
.feedback-bar .fb-selected-up { opacity: 1; color: var(--pass-color); }
.feedback-bar .fb-selected-down { opacity: 1; color: #d68c8c; }

/* =========================================================================
   POST-LLM OVERHAUL — additions (SUB-130, SUB-131)
   Appended 2026-05-19. New components only; existing classes preserved.
   ========================================================================= */

/* ---- Floating accessory links (was inline styles in index.html) ---- */

.floater {
  position: fixed;
  bottom: 18px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: rgba(22, 19, 31, 0.55);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--text-fainter);
  opacity: 0.55;
  transition: opacity var(--motion-hover), border-color var(--motion-hover);
}
.floater:hover { opacity: 0.95; border-color: var(--border-accent); }
.floater a { color: inherit; text-decoration: none; transition: color var(--motion-hover); }
.floater a:hover { color: var(--hero-violet); }
.floater .floater-sep { color: rgba(255, 255, 255, 0.25); }

#legal-footer.floater { left: 24px; }
#artifacts-link.floater { right: 24px; }

/* ---- Substrate response: TTS / audio play button (SUB-131 audio I/O) ----
   Appears at the bottom-right of every substrate response. Click → plays
   audio. If response includes audio_url field (future substrate audio
   shards), plays that. Otherwise falls back to Web Speech TTS of text. */

.msg-substrate { padding-bottom: 30px; }  /* room for audio button */

.audio-play-btn {
  position: absolute;
  bottom: 4px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  background: rgba(22, 19, 31, 0.6);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-pill);
  color: var(--text-fainter);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  cursor: pointer;
  opacity: 0;
  transition: all var(--motion-hover);
}
.msg-substrate:hover .audio-play-btn { opacity: 1; }
.audio-play-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-accent);
  background: rgba(168, 85, 247, 0.10);
}
.audio-play-btn.playing {
  color: white;
  background: var(--hero-gradient);
  border-color: transparent;
  opacity: 1;
  animation: audio-pulse 1.4s ease-in-out infinite;
}
@keyframes audio-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.35); }
  50%      { box-shadow: 0 0 0 6px rgba(168, 85, 247, 0); }
}
.audio-play-icon {
  width: 10px;
  height: 10px;
  display: inline-block;
  flex-shrink: 0;
}
.audio-play-label { font-size: 9.5px; text-transform: uppercase; }

/* ---- Mode tabs gradient refinement (active state) ---- */

.mode-tab.active {
  background: var(--hero-gradient);
  color: white;
  border-color: transparent;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

/* ---- Selection color in response area ---- */

.msg-substrate::selection,
.msg-substrate *::selection {
  background: rgba(168, 85, 247, 0.35);
  color: var(--text-primary);
}

/* ---- Read-only enforcement on substrate response (SUB-124) ---- */

.msg-substrate {
  -webkit-user-modify: read-only;
  -moz-user-modify: read-only;
}
.msg-substrate[contenteditable] { contenteditable: false; }
