:root {
  --bg: #080b12;
  --surface: #0f1319;
  --surface2: #151a24;
  --text: #d0d8e4;
  --text-bright: #e6edf3;
  --muted: #6e7681;
  --lexi-purple: #a78bfa;
  --cyan: #39d4e0;
  --lexi-pink: #e879a8;
  --green: #3fb950;
  --red: #f85149;
  --border: #1e2a3a;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 500px;
  margin: 0 auto;
}
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 8px; align-items: baseline; }
.brand .mark { color: var(--lexi-purple); font-size: 20px; }
.brand .name {
  font-weight: 800;
  background: linear-gradient(135deg, var(--lexi-purple), var(--cyan), var(--lexi-pink));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.badge { font-size: 12px; padding: 4px 10px; border-radius: 999px; }
.badge.ok { background: rgba(63,185,80,0.12); color: var(--green); }
.badge.warn { background: rgba(248,81,73,0.12); color: var(--red); }
main#view-root { flex: 1; padding: 16px; }
.view.hidden { display: none; }
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--lexi-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 40px auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#bottom-nav {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
#bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  padding: 14px 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.nav-btn.active { color: var(--lexi-purple); }
#error-region { position: fixed; bottom: 60px; left: 0; right: 0; padding: 0 16px; pointer-events: none; }

/* ─── Pairing screen ─── */
.pair-wrap { padding: 24px 8px; display: flex; flex-direction: column; gap: 16px; }
.pair-hero { text-align: center; padding: 24px 0; }
.pair-hero .pair-mark {
  display: inline-block;
  font-size: 48px;
  color: var(--lexi-purple);
  filter: drop-shadow(0 0 16px rgba(167,139,250,0.4));
  margin-bottom: 12px;
}
.pair-hero h1 { font-size: 22px; font-weight: 800; color: var(--text-bright); margin-bottom: 8px; }
.pair-hero p { color: var(--muted); font-size: 14px; line-height: 1.5; }
.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary {
  background: linear-gradient(135deg, var(--lexi-purple), var(--cyan));
  color: var(--bg);
}
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.pair-code-input {
  width: 100%;
  padding: 20px;
  font-size: 32px;
  font-family: "JetBrains Mono", monospace;
  text-align: center;
  letter-spacing: 16px;
  background: var(--surface2);
  color: var(--text-bright);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.pair-code-input:focus { outline: 2px solid var(--lexi-purple); }
.pair-status { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 4px; }
.pair-error { color: var(--red); font-size: 14px; text-align: center; padding: 8px; }
.hidden { display: none !important; }

/* ─── Chat view ─── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 110px); margin: -16px; }
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.staleness-banner {
  background: rgba(210,153,34,0.12);
  color: #d29922;
  font-size: 12px;
  padding: 8px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bubble.me {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--lexi-purple), var(--cyan));
  color: var(--bg);
  border-bottom-right-radius: 4px;
}
.bubble.lexi {
  align-self: flex-start;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble-time {
  font-size: 10px;
  opacity: 0.6;
  align-self: flex-end;
}
.bubble-image { max-width: 100%; border-radius: 8px; display: block; }
.bubble-voice-marker { margin-right: 6px; }
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 160px;
  line-height: 1.4;
}
.chat-input:focus { outline: 2px solid var(--lexi-purple); }
.chat-send {
  background: linear-gradient(135deg, var(--lexi-purple), var(--cyan));
  color: var(--bg);
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Voice view ─── */
.voice-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 16px;
}
.voice-status {
  color: var(--muted);
  font-size: 14px;
  min-height: 20px;
  text-align: center;
}
.voice-orb {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--lexi-purple), var(--cyan));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px rgba(167,139,250,0.3);
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, box-shadow 200ms ease;
}
.voice-orb .orb-mark {
  font-size: 56px;
  color: var(--bg);
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.5));
}
.voice-orb .orb-ring {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--lexi-purple);
  opacity: 0;
}
.voice-orb.active .orb-ring {
  opacity: 0.6;
  animation: pulse 1.6s ease-in-out infinite;
}
.voice-orb.holding { transform: scale(1.08); box-shadow: 0 0 60px rgba(167,139,250,0.5); }
.voice-orb.ptt { cursor: grab; }
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.25); opacity: 0; }
}
.voice-live-transcript {
  min-height: 48px;
  color: var(--text-bright);
  font-size: 16px;
  text-align: center;
  line-height: 1.4;
  padding: 0 16px;
}
.voice-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}
.ptt-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  justify-content: center;
}
.ptt-toggle input[type="checkbox"] { accent-color: var(--lexi-purple); width: 18px; height: 18px; }
.placeholder { color: var(--muted); text-align: center; padding: 40px; }

/* ─── Vision view ─── */
.vision-wrap { display: flex; flex-direction: column; gap: 16px; padding: 8px; }
.vision-title { font-size: 20px; font-weight: 800; color: var(--text-bright); }
.vision-hint { color: var(--muted); font-size: 14px; line-height: 1.4; }
.vision-actions { display: flex; flex-direction: column; gap: 8px; }
.vision-prompt {
  width: 100%;
  padding: 12px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
}
.vision-prompt:focus { outline: 2px solid var(--lexi-purple); }
.vision-preview img { width: 100%; max-height: 280px; object-fit: contain; border-radius: 12px; background: var(--surface2); }
.vision-reply {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
}
.vision-reply .reply-text { color: var(--text); font-size: 15px; line-height: 1.5; }
.vision-reply .capture-path {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  margin-top: 8px;
  word-break: break-all;
}
.vision-result .error { color: var(--red); padding: 12px; }
.vision-result .muted { color: var(--muted); padding: 8px; }
.btn label { cursor: pointer; display: block; }

/* ─── Error reporter ─── */
#error-region { position: fixed; bottom: 60px; left: 0; right: 0; padding: 8px 16px; pointer-events: none; z-index: 1000; }
.error-banner {
  background: var(--surface2);
  border: 1px solid rgba(248,81,73,0.6);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
  pointer-events: auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.error-plain { color: var(--text-bright); font-size: 14px; margin-bottom: 8px; }
.error-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-small {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
}
.btn-small.primary { background: var(--lexi-purple); color: var(--bg); }
.btn-small.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.error-technical {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.error-sent {
  font-size: 12px;
  color: var(--green);
  margin-top: 8px;
  font-family: "JetBrains Mono", monospace;
  word-break: break-all;
}
.report-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(8,11,18,0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 16px;
}
.report-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 480px;
  width: 100%;
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
  max-height: 90vh;
  overflow-y: auto;
}
.report-modal h3 { color: var(--text-bright); }
.report-modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.report-modal textarea {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.report-modal pre {
  background: var(--bg); padding: 8px; border-radius: 6px;
  font-size: 11px; color: var(--muted);
  max-height: 160px; overflow: auto; white-space: pre-wrap;
}
.modal-hint { color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.report-status { font-size: 13px; color: var(--muted); }
.report-sent-ok { color: var(--green); font-family: "JetBrains Mono", monospace; font-size: 12px; word-break: break-all; }

/* ─── Safe-area insets (notched phones) ─── */
@supports (padding: env(safe-area-inset-top)) {
  #top-bar { padding-top: calc(12px + env(safe-area-inset-top)); }
  #bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
  #error-region { bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* ─── Thumb-reach: primary actions live in the bottom half ─── */
.chat-form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

/* ─── Tablet: wider container, same structure ─── */
@media (min-width: 600px) {
  #app { max-width: 640px; }
  .voice-orb { width: 240px; height: 240px; }
  .voice-orb .orb-mark { font-size: 64px; }
}

/* ─── Desktop responsive (best-effort, not polished per spec) ─── */
@media (min-width: 1024px) {
  #app { max-width: 720px; }
  body { background: #05070c; }
  #app { box-shadow: 0 0 40px rgba(167,139,250,0.08); min-height: 100vh; }
}

/* ─── Prefer system font hinting on Samsung Galaxy ─── */
@media (max-width: 500px) {
  body { font-size: 15px; }
  .bubble { font-size: 15px; }
  .chat-input { font-size: 16px; } /* 16px prevents iOS zoom on focus */
  .vision-prompt { font-size: 16px; }
}

/* ─── Reduced motion ─── */
@media (prefers-reduced-motion: reduce) {
  .spinner, .voice-orb.active .orb-ring { animation: none; }
  .voice-orb { transition: none; }
}

/* ─── Dark-theme-only (no light mode in v1) ─── */
@media (prefers-color-scheme: light) {
  /* Intentionally ignored — Lexi's identity is dark. */
}
