:root {
  --cyan: #22d3ee;
  --cyan-dim: #0e7490;
  --bg: #05070d;
  --panel: rgba(34, 211, 238, 0.06);
}

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

body {
  background: radial-gradient(circle at 50% 30%, #0a1420, var(--bg));
  color: #cbeefb;
  font-family: "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}

.stage {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ---- mode toggle (fixed top-right) ---- */
.mode-toggle {
  position: fixed;
  top: 0.8rem;
  right: 0.8rem;
  z-index: 10;
  border: 1px solid var(--cyan-dim);
  background: var(--panel);
  color: var(--cyan);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
}
.mode-toggle:hover { background: var(--cyan-dim); color: #fff; }

/* ---- voice mode: only the reactor, centered, no text ---- */
.voice-hint {
  display: none;
  color: var(--cyan);
  opacity: 0.7;
  font-size: 0.85rem;
  text-align: center;
}
.stage.mode-voice {
  justify-content: center;
  min-height: 90vh;
}
.stage.mode-voice #log,
.stage.mode-voice #composer {
  display: none;
}
.stage.mode-voice .voice-hint {
  display: block;
}
.stage.mode-voice #reactor {
  transform: scale(1.5);
  margin: 2rem 0;
}

/* ---- arc reactor ---- */
.reactor {
  position: relative;
  width: 160px;
  height: 160px;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--cyan-dim);
}
.r1 { width: 160px; height: 160px; border-top-color: var(--cyan); }
.r2 { width: 115px; height: 115px; border-bottom-color: var(--cyan); }
.r3 { width: 70px; height: 70px; border-left-color: var(--cyan); }

.core-dot {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff, var(--cyan) 60%, transparent);
  box-shadow: 0 0 24px var(--cyan);
}

/* animation speeds tied to state */
.reactor { --ring-period: 8s; }
.reactor .ring { animation: spin calc(var(--ring-period) * var(--ring-rate, 1)) linear infinite; }
.reactor .r1 { --ring-rate: 0.96; }
.reactor .r2 { animation-direction: reverse; }
.reactor .r3 { --ring-rate: 1.04; }
.reactor.listening { --ring-period: 2s; }
.reactor.thinking { --ring-period: 0.8s; }
.reactor.speaking .core-dot { animation: pulse 0.5s ease-in-out infinite alternate; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { to { transform: scale(1.25); box-shadow: 0 0 40px var(--cyan); } }

.status {
  height: 1.2rem;
  color: var(--cyan);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 0.75rem;
}
/* Errors ride the status line (the chat log is hidden in voice mode). */
.status.error {
  color: #ff6b6b;
  text-transform: none;
  letter-spacing: normal;
  height: auto;
}

/* ---- chat log ---- */
.log {
  width: 100%;
  flex: 1;
  min-height: 200px;
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;

  /* scroll works, scrollbar hidden */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* old Edge/IE */
}
/* Chrome, Edge, Safari (WebKit) */
.log::-webkit-scrollbar {
  display: none;
}

.bubble {
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  max-width: 85%;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user { align-self: flex-end; background: var(--cyan-dim); color: #eaffff; }
.bubble.assistant {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--cyan-dim);
  position: relative; /* anchor for the speaker button */
  padding-right: 2rem; /* room so text doesn't sit under the button */
}
.bubble.error { align-self: center; background: #4c1d1d; color: #ffd7d7; }

/* ---- composer (single rounded bar, icons inside on the right) ---- */
.composer {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--cyan-dim);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.3rem 0.4rem 0.3rem 0.6rem;
}
.composer:focus-within { outline: 1px solid var(--cyan); }
.input {
  flex: 1;
  border: none;
  background: transparent;
  color: #eaffff;
  font-size: 1rem;
  padding: 0.45rem 0.25rem;
}
.input:focus { outline: none; }
.composer-actions {
  display: flex;
  gap: 0.15rem;
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--cyan);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.45rem 0.55rem;
  border-radius: 9px;
}
.icon-btn:hover { background: var(--cyan-dim); color: #fff; }
.icon-btn.send { font-size: 1rem; }

/* ---- per-message speaker (top-right of assistant bubble) ---- */
.speak-msg {
  position: absolute;
  top: 0.25rem;
  right: 0.3rem;
  border: none;
  background: transparent;
  color: var(--cyan);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.55;
  padding: 2px 4px;
  border-radius: 6px;
}
.speak-msg:hover { opacity: 1; background: var(--cyan-dim); color: #fff; }
/* auto-speak ON — persistent active state on every speaker button */
.speak-msg.active {
  opacity: 1;
  color: #fff;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
