/* ── Core Tokens & Reset ─────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-dark: #000000;

  --orb-base: transparent;
  --orb-listen: #ef4444;
  /* 红色：聆听中 */
  --orb-think: #8b5cf6;
  /* 紫色：思考中 */
  --orb-speak: #3b82f6;
  /* 蓝色：播放中 */

  --text-main: rgba(255, 255, 255, 0.9);
  --text-muted: rgba(255, 255, 255, 0.5);
  --success: #10b981;
  --error: #ef4444;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  position: relative;
}

/* ── Header ─────────────────────────────────────── */
.header {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  z-index: 30;
}

/* ── Session Button ────────────────────────────── */
.session-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease;
  padding: 0;
}

.session-btn:hover {
  color: var(--text-main);
}

/* ── Session Panel ─────────────────────────────── */
.session-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  height: 100vh;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Session Backdrop ──────────────────────────── */
.session-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.session-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.session-panel.open {
  transform: translateX(0);
}

.session-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
}

.session-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.session-new-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.08);
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: default;
  transition: background 0.15s ease;
}

.session-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.session-item.active {
  background: rgba(255, 255, 255, 0.08);
}

.session-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-item-id {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.session-item-time {
  font-size: 11px;
  color: var(--text-muted);
}

.session-item-actions {
  display: flex;
  gap: 4px;
}

/* 桌面端：hover 时才显示操作按钮 */
@media (hover: hover) {
  .session-item-actions {
    opacity: 0;
    transition: opacity 0.15s ease;
  }

  .session-item:hover .session-item-actions {
    opacity: 1;
  }
}

.session-switch-btn,
.session-delete-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.session-switch-btn:hover {
  background: rgba(59, 130, 246, 0.2);
  color: #7dd3fc;
  border-color: rgba(59, 130, 246, 0.3);
}

.session-delete-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

/* ── Settings Button ───────────────────────────── */
.settings-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease;
  padding: 0;
}

.settings-btn:hover {
  color: var(--text-main);
}

/* ── Settings Backdrop ─────────────────────────── */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Settings Panel ────────────────────────────── */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 300px;
  height: 100vh;
  background: rgba(10, 10, 15, 0.92);
  backdrop-filter: blur(20px);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-panel-header {
  display: flex;
  align-items: center;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
}

.settings-body {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 8px;
  border-radius: 8px;
}

.settings-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.settings-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-item-label {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-main);
}

.settings-item-desc {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Toggle Switch ─────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  transition: background 0.25s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  transition: transform 0.25s ease, background 0.25s ease;
}

.toggle input:checked+.toggle-slider {
  background: rgba(59, 130, 246, 0.6);
}

.toggle input:checked+.toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* connection-status hidden — disconnect shown in orb center */
.connection-status {
  display: none;
}

/* ── Interaction Area (Central UI) ──────────────── */
.interaction-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  gap: 60px;
}

.status-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 18px;
  /* Slightly larger for center visibility */
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 500;
  height: 24px;
  transition: opacity 0.3s ease;
  z-index: 10;
}

/* ── The Orb & Ripples ──────────────────────────── */
.orb-container {
  position: relative;
  width: 600px;
  height: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb {
  position: relative;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}

.orb:hover {
  transform: scale(1.05);
}

.orb:active {
  transform: scale(0.95);
}

.orb-icon {
  display: none;
}

.orb-icon.hidden {
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}

/* ── State: Listening (Recording) ───────────────── */
/* WebGL shader handles the listening state visuals */

/* ── State: Thinking (API Processing) ───────────── */
.orb-container.state-thinking .orb {
  transform: scale(0.95);
}

/* ── State: Speaking (TTS Playback) ─────────────── */
.orb-container.state-speaking .orb {
  /* Simulate audio waveform with scale */
  animation: orbSpeakPulse 0.8s ease-in-out infinite alternate;
}

@keyframes orbSpeakPulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1.02);
  }
}

/* ── Message Layer (above animation) ───────────── */
.message-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 45%;
  max-width: 560px;
  height: 100vh;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: none;
  overflow: hidden;
}

.subtitle-text {
  width: 100%;
  max-height: 100vh;
  overflow-y: auto;
  pointer-events: auto;
  direction: rtl;
  /* 滚动条左对齐 */
  padding: 80px 16px 32px 8px;
  font-size: 15px;
  line-height: 1.7;
  font-weight: 300;
  color: var(--text-main);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  text-align: left;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  word-wrap: break-word;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* 内容恢复正常文字方向 */
.subtitle-text>* {
  direction: ltr;
}

.subtitle-text::-webkit-scrollbar {
  width: 4px;
}

.subtitle-text::-webkit-scrollbar-track {
  background: transparent;
}

.subtitle-text::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

.subtitle-text.visible {
  opacity: 1;
  transform: translateY(0);
}

.subtitle-text.usercode {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Message Blocks ────────────────────────────── */
.msg {
  margin-bottom: 16px;
  padding: 0;
  border-radius: 0;
}

.msg-user {
  color: rgba(255, 255, 255, 0.5);
  font-style: italic;
  font-size: 0.9em;
  padding-left: 4px;
  border-left: 2px solid rgba(255, 255, 255, 0.15);
}

.msg-ai {
  color: var(--text-main);
  font-weight: 300;
}

/* ── Markdown Styles inside subtitle ─────────────── */
.subtitle-text h1,
.subtitle-text h2,
.subtitle-text h3 {
  margin: 0.4em 0 0.2em;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.95);
}

.subtitle-text h1 {
  font-size: 1.3em;
}

.subtitle-text h2 {
  font-size: 1.15em;
}

.subtitle-text h3 {
  font-size: 1.05em;
}

.subtitle-text p {
  margin: 0.3em 0;
}

.subtitle-text ul,
.subtitle-text ol {
  margin: 0.3em 0;
  padding-left: 1.4em;
}

.subtitle-text li {
  margin: 0.15em 0;
}

.subtitle-text code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: 'Cascadia Code', 'Fira Code', monospace;
}

.subtitle-text pre {
  background: rgba(255, 255, 255, 0.06);
  padding: 0.6em 0.8em;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.4em 0;
}

.subtitle-text pre code {
  background: none;
  padding: 0;
}

.subtitle-text strong {
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
}

.subtitle-text em {
  color: rgba(255, 255, 255, 0.8);
}

.subtitle-text a {
  color: #7dd3fc;
  text-decoration: underline;
}

.subtitle-text blockquote {
  border-left: 3px solid rgba(255, 255, 255, 0.2);
  margin: 0.4em 0;
  padding: 0.2em 0.8em;
  color: rgba(255, 255, 255, 0.7);
}

.subtitle-text hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 0.6em 0;
}