/* ============================================================
   TERMINAL THEME — loaded after app.css, overrides only.
   CRT/phosphor look. Mobile behavior untouched.
   ============================================================ */

:root {
  --bg: #060907;
  --panel: rgba(0, 255, 140, 0.045);
  --panel2: rgba(0, 255, 140, 0.08);
  --panel3: rgba(0, 255, 140, 0.13);
  --line: rgba(51, 255, 102, 0.22);
  --acc1: #33ff66;
  --acc2: #19b356;
  --grad: linear-gradient(135deg, #2fe97a, #17a94f);
  --good: #39ff88;
  --warn: #ffb000;
  --bad: #ff5555;
  --tx: #c9f7d4;
  --dim: #5f8a68;
}

html, body, button, input, textarea, select {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco,
    "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}
body { background: var(--bg); color: var(--tx); }

/* ── CRT overlays (non-interactive) ── */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 9998; pointer-events: none;
  background: radial-gradient(120% 100% at 50% 40%, transparent 60%, rgba(0, 0, 0, 0.38) 100%);
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.16) 2px 3px);
  opacity: 0.5;
}

/* power-on flicker */
@keyframes crtOn {
  0% { opacity: 0; transform: scaleY(0.004); filter: brightness(6); }
  35% { opacity: 1; transform: scaleY(0.7); filter: brightness(2.4); }
  55% { transform: scaleY(1); filter: brightness(1.4); }
  70% { opacity: 0.65; }
  82% { opacity: 1; }
  90% { opacity: 0.85; }
  100% { opacity: 1; transform: none; filter: none; }
}
body { animation: crtOn 420ms ease-out 1 both; transform-origin: 50% 45%; }

::selection { background: rgba(51, 255, 102, 0.32); color: #eaffef; }
#input, textarea, input { caret-color: var(--acc1); }

/* ── square off the world ── */
#composer, .msg, .sheet, .drawer, .modal, .toast, .tab, .tool-chip, .codeblock,
.qcard, .overlay-card, .filechip, .chip, .achip, .mrow, .srow, .diffbox,
.grad-btn, .ghost-btn, .mini-btn, .danger-btn, .icon-btn, #micBtn, #sendBtn,
#newChat, #jumpPill, .badge, .tb-chip, .eff-chip, #interimOverlay, #hfBar,
.speak-chip, #speakChip, .orb, .errbox, .warn-t, .card-err, #healthBar,
#offlineBar, #todoChip, #unreadCt, #ttsBtn, #modelSearch, #sessSearch {
  border-radius: 4px;
}

/* glow accents */
.dot, .tdot, .tdot2 { box-shadow: 0 0 10px rgba(51, 255, 102, 0.55); }
.grad-btn, #sendBtn {
  box-shadow: 0 0 14px rgba(51, 255, 102, 0.22), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  color: #04120a;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.grad-btn:active, #sendBtn:active { box-shadow: 0 0 22px rgba(51, 255, 102, 0.4); }

/* top bar + titles */
#topbar, #tabStrip { border-bottom: 1px solid var(--line); background: rgba(4, 8, 6, 0.86); }
#sessTitle, .splash-name, .dr-title, .sheet-head h3 {
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px rgba(51, 255, 102, 0.35);
}
.tb-chip { border: 1px dashed var(--line); background: rgba(0, 255, 140, 0.05); }

/* messages */
.msg { border: 1px solid var(--line); background: var(--panel); }
.md code { background: rgba(0, 255, 140, 0.09); border: 1px solid rgba(51, 255, 102, 0.18); }
.codeblock { background: #010403; border: 1px solid var(--line); }
.codeblock .cb-head { background: rgba(0, 255, 140, 0.06); color: var(--dim); letter-spacing: 0.06em; }
.md a { color: var(--acc1); text-decoration-color: rgba(51, 255, 102, 0.5); }
.diffbox .dl.add { color: #7dffb0; }
.typing i { background: var(--acc1); border-radius: 1px; box-shadow: 0 0 8px rgba(51, 255, 102, 0.6); }

/* tool chips → bracketed terminal tags */
.tool-chip {
  font-size: 12px; letter-spacing: 0.03em;
  background: rgba(0, 255, 140, 0.05); border: 1px solid var(--line);
}
.tp-pre, .tp-out { color: #a8e8b6; }

/* composer: shell prompt line */
#composerWrap { padding-bottom: calc(env(safe-area-inset-bottom, 0px)); }
#composer { position: relative; border: 1px solid var(--line); background: rgba(1, 5, 3, 0.72); }
#composer::before {
  content: "❯";
  position: absolute;
  left: calc(44px + 12px + 10px);
  top: 15px;
  color: var(--acc1);
  font-weight: 700;
  text-shadow: 0 0 8px rgba(51, 255, 102, 0.6);
  pointer-events: none;
}
#input { padding-left: 34px; font-size: 16px; min-height: 44px; }

/* mic orb → terminal button glow */
#micBtn { border: 1px solid var(--line); background: rgba(0, 255, 140, 0.06); }
.mic-rings::before, .mic-rings::after { border-color: rgba(51, 255, 102, 0.5); }

/* sheets / drawers / modals: darker glass, green hairlines */
.sheet, .drawer, .modal, .sheet-backdrop, .modal-backdrop, #scrim {
  backdrop-filter: blur(10px);
}
.sheet-head h3::before { content: "## "; color: var(--dim); }

/* toasts */
.toast { border-left: 3px solid var(--acc1); font-size: 13px; }
.toast.warn { border-left-color: var(--warn); }
.toast.danger { border-left-color: var(--bad); }

/* badges */
.bfree { background: rgba(57, 255, 136, 0.14); color: var(--good); border: 1px solid rgba(57, 255, 136, 0.4); }
.bdef { background: linear-gradient(135deg, rgba(47, 233, 122, 0.25), rgba(23, 169, 79, 0.25)); color: var(--acc1); border: 1px solid rgba(51, 255, 102, 0.5); }
.bctx { color: var(--dim); }

/* effort selector row */
#effortRow {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 8px;
  overflow-x: auto; scrollbar-width: none;
}
#effortRow::-webkit-scrollbar { display: none; }
#effortRow[hidden] { display: none; }

/* plan/build mode switcher */
#modeRow {
  display: flex; gap: 8px;
  padding: 0 4px 8px;
}
.mode-chip {
  min-height: 32px; padding: 0 14px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em;
  color: var(--dim);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 4px;
  touch-action: manipulation;
}
.mode-chip.on {
  color: #04120a;
  background: var(--grad);
  border-style: solid; border-color: transparent;
  box-shadow: 0 0 12px rgba(51, 255, 102, 0.35);
}

/* inline todo strip */
#todoPanel { padding: 6px 8px 0; }
#todoPanel button {
  width: 100%; text-align: left;
  min-height: 34px; padding: 6px 10px;
  font-size: 12px; color: var(--tx);
  background: rgba(0, 255, 140, 0.05);
  border: 1px dashed var(--line);
  border-radius: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  touch-action: manipulation;
}
.eff-tag { color: var(--dim); font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; }
.eff-chip {
  min-height: 30px; padding: 0 12px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--tx);
  background: rgba(0, 255, 140, 0.05);
  border: 1px dashed var(--line);
  border-radius: 4px;
  touch-action: manipulation;
}
.eff-chip.on {
  background: var(--grad); color: #04120a; border-style: solid; border-color: transparent;
  box-shadow: 0 0 12px rgba(51, 255, 102, 0.35);
  animation: effPop 180ms var(--spring, ease-out);
}
@keyframes effPop { from { transform: scale(0.92); } to { transform: scale(1); } }

/* reduced motion: kill flicker + pops */
@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
  .eff-chip.on { animation: none; }
}

/* ============================================================
   ── voice HUD ──
   CRT status panel pinned above the composer.
   ============================================================ */

#voiceHud {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  width: min(94vw, 480px);
  /* above composer (≤40) · below sheets (80) / modals (90) / toasts (120) */
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 12px 12px;
  background: rgba(1, 5, 3, 0.92);
  border: 1px solid var(--line);
  border-radius: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 18px rgba(51, 255, 102, 0.07);
  animation: vhIn 240ms cubic-bezier(0.32, 0.72, 0.24, 1) both;
}
#voiceHud[hidden] { display: none; }

@keyframes vhIn {
  from { opacity: 0; transform: translateX(-50%) translateY(14px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── phase: listening — phosphor breathing ── */
#voiceHud.ph-listen {
  border-color: rgba(51, 255, 102, 0.45);
  animation:
    vhIn 240ms cubic-bezier(0.32, 0.72, 0.24, 1) both,
    vhBreathe 2s ease-in-out infinite;
}
@keyframes vhBreathe {
  0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 6px rgba(51, 255, 102, 0.12); }
  50%      { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 22px rgba(51, 255, 102, 0.38); }
}

/* ── phase: transcribing / sending — amber + braille spinner ── */
#voiceHud.ph-trans,
#voiceHud.ph-send { border-color: rgba(255, 176, 0, 0.45); }
#voiceHud.ph-trans #vhPhase,
#voiceHud.ph-send #vhPhase { color: var(--warn); text-shadow: 0 0 8px rgba(255, 176, 0, 0.4); }
#voiceHud.ph-trans #vhPhase::after,
#voiceHud.ph-send #vhPhase::after {
  content: "⠋";
  margin-left: 6px;
  animation: vhSpin 1s step-end infinite;
}
@keyframes vhSpin {
  0%        { content: "⠋"; }
  10%       { content: "⠙"; }
  20%       { content: "⠹"; }
  30%       { content: "⠸"; }
  40%       { content: "⠼"; }
  50%       { content: "⠴"; }
  60%       { content: "⠦"; }
  70%       { content: "⠧"; }
  80%       { content: "⠇"; }
  90%, 100% { content: "⠏"; }
}

/* ── phase: waiting — dim green shimmer ── */
#voiceHud.ph-wait { border-color: rgba(51, 255, 102, 0.28); }
#voiceHud.ph-wait #vhPhase {
  background: linear-gradient(
    90deg,
    var(--dim) 0%, var(--dim) 35%,
    var(--acc1) 50%,
    var(--dim) 65%, var(--dim) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--acc1);
  text-shadow: none;
  animation: vhShimmer 1.6s linear infinite;
}
@keyframes vhShimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

/* ── phase: generating — pulsing amber + indeterminate sweep ── */
#voiceHud.ph-gen {
  border-color: rgba(255, 176, 0, 0.55);
  animation:
    vhIn 240ms cubic-bezier(0.32, 0.72, 0.24, 1) both,
    vhGenGlow 1.4s ease-in-out infinite;
}
@keyframes vhGenGlow {
  0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 6px rgba(255, 176, 0, 0.1); }
  50%      { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 24px rgba(255, 176, 0, 0.32); }
}
#voiceHud.ph-gen #vhPhase { color: var(--warn); text-shadow: 0 0 8px rgba(255, 176, 0, 0.4); }
#voiceHud.ph-gen #vhHead { position: relative; overflow: hidden; }
#voiceHud.ph-gen #vhHead::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 34%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--warn), transparent);
  animation: vhSweep 1.1s linear infinite;
}
@keyframes vhSweep {
  from { transform: translateX(-105%); }
  to   { transform: translateX(400%); }
}

/* ── phase: speaking — strong green glow ── */
#voiceHud.ph-speak {
  border-color: rgba(51, 255, 102, 0.55);
  animation:
    vhIn 240ms cubic-bezier(0.32, 0.72, 0.24, 1) both,
    vhSpeakGlow 1.6s ease-in-out infinite;
}
@keyframes vhSpeakGlow {
  0%, 100% { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 10px rgba(51, 255, 102, 0.2); }
  50%      { box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55), 0 0 28px rgba(51, 255, 102, 0.45); }
}

/* ── head row ── */
#vhHead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 8px;
  border-bottom: 1px solid rgba(51, 255, 102, 0.14);
}
#vhPhase {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--acc1);
  text-shadow: 0 0 8px rgba(51, 255, 102, 0.45);
}
#vhTimer {
  margin-left: auto;
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}
#vhClose {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin: -8px -6px -8px 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
  color: var(--dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#vhClose:hover { color: var(--acc1); }
#vhClose:active {
  color: var(--acc1);
  border-color: var(--line);
  background: rgba(51, 255, 102, 0.08);
}

/* ── level meter ── */
#vhMeter {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: rgba(0, 255, 140, 0.08);
}
#vhLevel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, #17a94f, #33ff66 70%, #7dffb0);
  box-shadow: 0 0 8px rgba(51, 255, 102, 0.45);
  transition: width 80ms linear;
}
#vhFloor {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 62%;               /* JS overrides */
  width: 2px;
  border-radius: 1px;
  background: repeating-linear-gradient(
    to bottom,
    var(--warn) 0 3px,
    transparent 3px 5px
  );
  filter: drop-shadow(0 0 3px rgba(255, 176, 0, 0.6));
}

/* ── waveform bars (scaleY driven by JS; bobbed when idle) ── */
#vhWave {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 30px;
}
#vhWave i {
  width: 5px;
  min-height: 6px;
  background: var(--acc1);
  border-radius: 1px;
  box-shadow: 0 0 6px rgba(51, 255, 102, 0.55);
  transform-origin: bottom;
  transform: scaleY(0.4);
  transition: transform 60ms linear;
}
#voiceHud:not(.has-live) #vhWave i { animation: vhBob 1.15s ease-in-out infinite; }
#voiceHud:not(.has-live) #vhWave i:nth-child(1) { animation-delay: 0s; }
#voiceHud:not(.has-live) #vhWave i:nth-child(2) { animation-delay: 0.12s; }
#voiceHud:not(.has-live) #vhWave i:nth-child(3) { animation-delay: 0.24s; }
#voiceHud:not(.has-live) #vhWave i:nth-child(4) { animation-delay: 0.36s; }
#voiceHud:not(.has-live) #vhWave i:nth-child(5) { animation-delay: 0.48s; }
@keyframes vhBob {
  0%, 100% { transform: scaleY(0.25); }
  50%      { transform: scaleY(1); }
}
/* speaking: faster, hotter idle dance */
#voiceHud.ph-speak:not(.has-live) #vhWave i {
  animation-duration: 0.7s;
  box-shadow: 0 0 10px rgba(51, 255, 102, 0.85);
}

/* ── hint line ── */
#vhHint {
  min-height: 16px;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.03em;
}

/* ── audio result chip ── */
#vhAudioSlot { display: flex; flex-wrap: wrap; gap: 6px; }
#vhAudioSlot:empty { display: none; }
.audio-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 4px 8px;
  background: #010403;
  border: 1px dashed var(--line);
  border-radius: 4px;
}
.audio-chip audio {
  display: block;
  height: 32px;
  max-width: 70vw;
  accent-color: var(--acc1);
}
.ac-name {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--dim);
  white-space: nowrap;
}

/* ── timing badges: [stt 0.9s] ── */
#vhTiming {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#vhTiming span,
.timing-badge {
  display: inline-block;
  padding: 1px 4px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--dim);
  background: rgba(0, 255, 140, 0.05);
  border-radius: 2px;
  border-bottom: none;
}

/* ── send-now ghost button ── */
#vhSendNow {
  align-self: stretch;
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--acc1);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 4px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
#vhSendNow:active {
  background: var(--acc1);
  border-style: solid;
  border-color: var(--acc1);
  color: #04120a;
}
#vhSendNow[hidden] { display: none; }

/* ── message timestamps ── */
.msg-time {
  display: block;
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.05em;
  margin-top: 2px;
  align-self: flex-start;          /* assistant/system → left */
}
.msg.user .msg-time {
  align-self: flex-end;            /* user bubbles → right */
  text-align: right;
}

/* ── reduced motion: HUD animations off ── */
@media (prefers-reduced-motion: reduce) {
  #voiceHud,
  #voiceHud.ph-listen,
  #voiceHud.ph-gen,
  #voiceHud.ph-speak,
  #voiceHud.ph-trans #vhPhase::after,
  #voiceHud.ph-send #vhPhase::after,
  #voiceHud.ph-wait #vhPhase,
  #voiceHud:not(.has-live) #vhWave i {
    animation: none !important;
  }
}
