/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0f1e;
  --surface: #1a2744;
  --surface2: #243156;
  --accent: #3b82f6;
  --accent-dim: #2563eb;
  --text: #e8dcc8;
  --text-dim: #9aa3b8;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  overflow: hidden;
}

/* ---- Screens ---- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ---- Settings Screen ---- */
.settings-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.settings-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.settings-subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
}
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.settings-label { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.settings-input {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 14px 16px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}
.settings-input:focus { border-color: var(--accent); }
.settings-input::placeholder { color: var(--text-dim); }

/* ---- Loading Screen ---- */
.loading-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.loading-pulse {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}
.loading-text { color: var(--text-dim); font-size: 16px; }

/* ---- Chat Screen ---- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--surface);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }

.ready-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 20px;
  padding: 3px 10px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  line-height: 1;
  transition: color 0.2s;
}
.icon-btn:hover { color: var(--text); }

/* ---- Messages ---- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.message.thinking {
  align-self: flex-start;
  background: var(--surface);
  color: var(--text-dim);
  font-style: italic;
}

/* ---- Input Bar ---- */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--surface);
  flex-shrink: 0;
}
.input-field {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  padding: 12px 16px;
  outline: none;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
  font-family: inherit;
}
.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text-dim); }

.mic-btn, .send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}
.mic-btn {
  background: var(--surface);
  color: var(--text-dim);
}
.mic-btn:hover, .mic-btn.active { background: var(--amber); color: #fff; }
.send-btn {
  background: var(--accent);
  color: #fff;
}
.send-btn:hover { background: var(--accent-dim); }
.send-btn:active { transform: scale(0.92); }

/* ---- Buttons ---- */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 24px;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}
.btn-primary:hover { background: var(--accent-dim); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 24px;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}
.btn-secondary:hover { background: #2e3d60; }

/* ---- Preview Panel ---- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.preview-panel {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  width: 100%;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.preview-header { display: flex; flex-direction: column; gap: 4px; }
.preview-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.preview-summary { font-size: 17px; font-weight: 600; color: var(--text); }
.preview-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 14px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--green);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
}
.preview-actions { display: flex; gap: 10px; }
.preview-actions .btn-secondary { flex: 1; }
.preview-actions .btn-primary { flex: 2; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 15px;
  z-index: 200;
  animation: fadeIn 0.2s ease;
  white-space: nowrap;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ---- Conversation Mode Button (header) ---- */
.conv-btn-header {
  background: var(--surface);
  border: 1px solid var(--surface2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  padding: 7px 12px;
  border-radius: 20px;
  line-height: 1;
  transition: background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.conv-btn-header::after { content: "Talk"; font-size: 13px; color: var(--text-dim); }
.conv-btn-header:hover { background: var(--surface2); transform: scale(1.03); }

/* ---- Conversation Mode Overlay ---- */
.conv-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
}
.conv-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* Orb */
.conv-orb {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--surface2);
  cursor: pointer;
  transition: background 0.3s, border-color 0.3s, transform 0.2s;
  position: relative;
}
.conv-orb::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color 0.3s;
}

/* States */
.conv-orb.idle {
  background: var(--surface);
  border-color: var(--surface2);
}
.conv-orb.listening {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent);
  animation: orbListen 1.2s ease-in-out infinite;
}
.conv-orb.listening::after { border-color: rgba(59, 130, 246, 0.3); animation: orbRing 1.2s ease-in-out infinite; }
.conv-orb.thinking {
  background: rgba(245, 158, 11, 0.15);
  border-color: var(--amber);
  animation: orbSpin 1s linear infinite;
}
.conv-orb.speaking {
  background: rgba(34, 197, 94, 0.15);
  border-color: var(--green);
  animation: orbSpeak 0.6s ease-in-out infinite alternate;
}

@keyframes orbListen {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes orbRing {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.2); opacity: 0; }
}
@keyframes orbSpin {
  from { box-shadow: 0 0 0 0 rgba(245,158,11,0.4); }
  to { box-shadow: 0 0 24px 8px rgba(245,158,11,0); }
}
@keyframes orbSpeak {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.conv-label {
  font-size: 18px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  min-height: 28px;
  text-align: center;
}
.conv-exit {
  background: var(--surface);
  border: 1px solid var(--surface2);
  color: var(--text-dim);
  font-size: 15px;
  padding: 10px 24px;
  border-radius: 24px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.conv-exit:hover { color: var(--text); border-color: var(--text-dim); }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 2px; }
