/* Hermes Voice — Modern mobile-first design (v2) */

:root {
  --bg: #0d0d0f;
  --bg-grad-1: #15131f;
  --bg-grad-2: #0d0d0f;
  --bg-elevated: #18181b;
  --bg-card: #1e1e22;
  --border: #2a2a30;
  --border-active: #3a3a42;
  --text: #f0f0f2;
  --text-dim: #888892;
  --text-faint: #55555a;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.5);
  --accent-grad: linear-gradient(135deg, #6366f1, #4f46e5);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.5);
  --danger-grad: linear-gradient(135deg, #ef4444, #dc2626);
  --success: #22c55e;
  --success-glow: rgba(34, 197, 94, 0.4);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(900px 600px at 50% -10%, var(--bg-grad-1), transparent 70%),
    var(--bg-grad-2);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.hidden { display: none !important; }

/* ============ TOAST ============ */
.toast {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(24, 24, 27, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  animation: toastIn 0.3s ease;
  max-width: 90%;
  text-align: center;
}
.toast.error { border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.toast.success { border-color: rgba(34, 197, 94, 0.4); color: #86efac; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ TOKEN GATE ============ */
.token-gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.4s ease;
}
.token-gate-inner {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.logo-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  border-radius: 20px;
  background: var(--accent-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 8px 32px var(--accent-glow);
  animation: logoFloat 3s ease-in-out infinite;
}
.token-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}
.token-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 28px;
}
.token-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.token-input-wrap input {
  width: 100%;
  font-size: 16px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.token-input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.token-submit-btn {
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}
.token-submit-btn:active { transform: scale(0.97); }
.token-submit-btn:disabled { opacity: 0.5; }
.token-error {
  margin-top: 12px;
  font-size: 13px;
  color: var(--danger);
  padding: 8px 12px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-xs);
}

/* ============ MAIN INTERFACE ============ */
.main-interface {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  animation: fadeIn 0.3s ease;
}

/* ============ TOP BAR ============ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  flex-shrink: 0;
}
.top-bar-left { display: flex; align-items: center; gap: 8px; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s, box-shadow 0.3s;
}
.status-dot.ready { background: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.status-dot.recording { background: var(--danger); box-shadow: 0 0 8px var(--danger-glow); animation: dotPulse 1s ease-in-out infinite; }
.status-dot.thinking { background: #f59e0b; box-shadow: 0 0 8px rgba(245, 158, 11, 0.5); animation: dotPulse 0.8s ease-in-out infinite; }
.status-dot.speaking { background: var(--success); box-shadow: 0 0 8px var(--success-glow); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 8px var(--danger-glow); }
.top-bar-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.icon-btn:active { background: var(--bg-card); color: var(--text); }

.top-bar-right { display: flex; align-items: center; gap: 8px; }
.voice-picker-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px 0 8px;
  height: 32px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-dim);
}
.voice-picker-btn:active { background: var(--bg-card); }
.voice-label-text { font-weight: 500; letter-spacing: 0.2px; }

/* ============ CONVERSATION ============ */
.conversation {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  animation: msgIn 0.3s ease;
  word-wrap: break-word;
  cursor: default;
}
.msg-user {
  align-self: flex-end;
  background: var(--accent-grad);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg-hermes {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 6px;
  cursor: pointer;
  position: relative;
}
.msg-hermes::after {
  content: "↻ replay";
  position: absolute;
  bottom: -18px;
  left: 4px;
  font-size: 10px;
  color: var(--text-faint);
  opacity: 0;
  transition: opacity 0.2s;
}
.msg-hermes:active::after { opacity: 1; }
.msg-thinking {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}
.msg-thinking .thinking-dots {
  display: inline-flex;
  gap: 4px;
}
.msg-thinking .thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim);
  animation: thinkDot 1.4s ease-in-out infinite;
}
.msg-thinking .thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.msg-thinking .thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
.msg-error {
  align-self: center;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}
.msg-error .retry-btn {
  display: block;
  margin-top: 8px;
  width: 100%;
  padding: 8px;
  background: rgba(239, 68, 68, 0.2);
  border: none;
  border-radius: var(--radius-xs);
  color: #fca5a5;
  font-size: 13px;
  cursor: pointer;
}

/* ============ WELCOME STATE ============ */
.welcome-state {
  margin: auto;
  text-align: center;
  padding: 24px;
  animation: fadeIn 0.5s ease;
}
.welcome-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
.welcome-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
}
.welcome-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* ============ MIC AREA ============ */
.mic-area {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 24px;
  background: linear-gradient(to top, rgba(13, 13, 15, 0.95) 55%, transparent);
  position: relative;
}
.mic-ring-container {
  position: relative;
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mic-glow-ring {
  position: absolute;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.3s;
}
.mic-ring, .mic-ring-2 {
  position: absolute;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: all 0.3s;
}
.mic-ring { border-color: var(--border-active); }
.mic-btn {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-active);
  color: var(--text-dim);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}
.mic-btn.idle { color: var(--text-dim); }
.mic-btn.idle:active { transform: scale(0.92); background: var(--bg-card); }
.mic-btn.ready {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 24px var(--accent-glow);
}
.mic-btn.ready:active { transform: scale(0.92); }
.mic-btn.recording {
  background: var(--danger-grad);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 24px var(--danger-glow);
  transform: scale(1.08);
}
.mic-btn.recording ~ .mic-ring,
.mic-btn.recording ~ .mic-ring-2 {
  border-color: var(--danger);
  animation: ringExpand 1.5s ease-out infinite;
}
.mic-btn.recording ~ .mic-ring-2 { animation-delay: 0.5s; }
.mic-btn.thinking {
  background: var(--bg-elevated);
  border-color: #f59e0b;
  color: #f59e0b;
  pointer-events: none;
}
.mic-btn.thinking .mic-loader { display: block; }
.mic-btn.speaking {
  background: var(--bg-elevated);
  border-color: var(--success);
  color: var(--success);
  box-shadow: 0 4px 16px var(--success-glow);
}
.mic-btn.speaking .mic-icon-idle { animation: speakWave 0.8s ease-in-out infinite alternate; }
.mic-btn.error {
  border-color: var(--danger);
  color: var(--danger);
  animation: shake 0.4s ease;
}
.mic-loader {
  display: none;
  position: absolute;
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--border-active);
  border-top-color: #f59e0b;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Level meter */
.level-meter {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 22px;
  margin-top: 14px;
}
.level-meter span {
  width: 4px;
  height: 20%;
  background: var(--danger);
  border-radius: 2px;
  transition: height 0.08s ease;
}

.status-text {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  min-height: 18px;
  transition: color 0.2s;
}
.status-text.recording { color: var(--danger); font-weight: 500; }
.status-text.thinking { color: #f59e0b; }
.status-text.speaking { color: var(--success); }
.status-text.error { color: var(--danger); }
.rec-timer {
  margin-top: 4px;
  font-size: 12px;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ============ VOICE DROPDOWN ============ */
.voice-dropdown {
  position: absolute;
  top: 52px;
  right: 12px;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
.voice-dropdown-inner {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 16px;
  min-width: 200px;
}
.voice-dropdown-inner h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 10px;
  padding-left: 4px;
}
.voice-list { display: flex; flex-direction: column; gap: 4px; }
.voice-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.voice-option:active { background: var(--bg-card); }
.voice-option.selected {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.3);
}
.voice-option-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.voice-option-icon.male { background: rgba(99, 102, 241, 0.15); color: var(--accent); }
.voice-option-icon.female { background: rgba(236, 72, 153, 0.15); color: #ec4899; }
.voice-option-info { flex: 1; }
.voice-option-name { font-size: 14px; font-weight: 500; color: var(--text); }
.voice-option-gender { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
.voice-option-check {
  width: 18px; height: 18px;
  color: var(--accent);
  opacity: 0; flex-shrink: 0;
}
.voice-option.selected .voice-option-check { opacity: 1; }

/* ============ SETTINGS PANEL ============ */
.settings-panel {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
  animation: fadeIn 0.2s ease;
}
.settings-panel-inner {
  width: 90%;
  max-width: 340px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.settings-panel-inner h2 { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.setting-row { margin-bottom: 12px; }
.setting-row label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.setting-row input {
  width: 100%;
  font-size: 14px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  outline: none;
}
.setting-row input:focus { border-color: var(--accent); }
.settings-btn {
  padding: 10px 16px;
  font-size: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text);
  cursor: pointer;
  margin-right: 8px;
  transition: background 0.2s;
}
.settings-btn:active { background: var(--border); }
.settings-btn.danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes logoFloat { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes dotPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes ringExpand { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(1.8); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes speakWave { 0% { transform: scaleY(0.9); } 100% { transform: scaleY(1.1); } }
@keyframes thinkDot { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* ============ SCROLLBAR ============ */
.conversation::-webkit-scrollbar { width: 4px; }
.conversation::-webkit-scrollbar-track { background: transparent; }
.conversation::-webkit-scrollbar-thumb { background: var(--border-active); border-radius: 2px; }

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
  .mic-btn { width: 68px; height: 68px; }
  .mic-ring-container { width: 88px; height: 88px; }
  .msg { font-size: 14px; }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
