:root {
  --bg: #0d1b2a;
  --bg-elevated: #1b263b;
  --accent: #7bdff2;
  --accent-strong: #a5f3fc;
  --accent-purple: #8b5cf6;
  --text: #f0f4f8;
  --text-muted: #9fb3c8;
  --danger: #ef4444;
  --divider: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Roboto", Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
}
input, textarea { user-select: text; }

#root {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen { display: flex; flex-direction: column; flex: 1; min-height: 100dvh; }
.screen.hidden { display: none; }

/* ── Setup screen ─────────────────────────────────────── */
#setup-screen {
  padding: calc(var(--safe-top) + 32px) 24px 32px;
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg-elevated) 100%);
  justify-content: center;
  align-items: center;
  text-align: center;
}
#setup-screen h1 {
  font-size: 48px;
  margin: 0 0 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
#setup-screen .subtitle {
  color: var(--text-muted);
  margin: 0 0 40px;
  font-size: 16px;
}
#setup-screen label { align-self: flex-start; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
#setup-screen input {
  width: 100%;
  padding: 16px 18px;
  font-size: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  color: var(--text);
  margin-bottom: 24px;
}
#setup-screen .hint { color: var(--text-muted); font-size: 12px; margin-top: 16px; }

button.primary {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
  color: #0d1b2a;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
button.primary:active { opacity: 0.8; transform: scale(0.98); }

button.secondary {
  padding: 14px;
  font-size: 15px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  cursor: pointer;
}
button.secondary:active { opacity: 0.8; }

button.danger {
  padding: 14px;
  font-size: 15px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  cursor: pointer;
  margin-top: 32px;
}

/* ── Main screen header ───────────────────────────────── */
#main-screen header,
#settings-screen header {
  padding: calc(var(--safe-top) + 16px) 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--divider);
  background: var(--bg);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}
.brand .name {
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 14px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 10px;
}
.icon-btn:active { background: var(--bg-elevated); }

/* ── Thread ─────────────────────────────────────────── */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 140px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.msg {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: slide-in 0.25s ease-out;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent) 100%);
  color: #0d1b2a;
  border-bottom-right-radius: 4px;
}
.msg.brian {
  align-self: flex-start;
  background: var(--bg-elevated);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--divider);
}
.msg.brian.typing { opacity: 0.7; font-style: italic; }
.msg .meta { display: block; font-size: 10px; margin-top: 6px; opacity: 0.6; letter-spacing: 0.5px; }
.msg .thumb {
  display: block;
  max-width: 200px;
  border-radius: 10px;
  margin-bottom: 8px;
}

/* ── Composer ─────────────────────────────────────── */
#composer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 12px calc(var(--safe-bottom) + 12px);
  background: var(--bg);
  border-top: 1px solid var(--divider);
  z-index: 10;
}
#composer input {
  width: 100%;
  padding: 14px 18px;
  font-size: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: 24px;
  color: var(--text);
  outline: none;
}
#composer input:focus { border-color: var(--accent); }
.action-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.action-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  color: var(--text);
  padding: 12px 0;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  cursor: pointer;
}
.action-btn:active { transform: scale(0.95); background: rgba(123, 223, 242, 0.1); }
.action-btn .icon { font-size: 22px; }
.action-btn.primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
  color: #0d1b2a;
  border: none;
  font-weight: 700;
}

.status-bar {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 170px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 27, 42, 0.95);
  border: 1px solid var(--divider);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-muted);
  z-index: 9;
  pointer-events: none;
  transition: opacity 0.3s;
}
.status-bar.hidden { opacity: 0; }

/* ── Settings ─────────────────────────────────────── */
.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.setting { display: flex; flex-direction: column; gap: 6px; }
.setting label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.setting input[type="text"],
.setting input[type="password"] {
  padding: 14px 16px;
  font-size: 15px;
  background: var(--bg-elevated);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  color: var(--text);
}
.setting.toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--divider);
}
.setting.toggle label { text-transform: none; letter-spacing: normal; font-size: 15px; color: var(--text); }
.setting.toggle input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); }

/* ── Overlays ─────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 27, 42, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 32px;
}
.overlay.hidden { display: none; }
.record-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #0d1b2a;
  font-size: 32px;
  font-weight: 700;
  position: relative;
  cursor: pointer;
}
.record-circle .pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--accent);
  animation: record-pulse 1.5s ease-out infinite;
}
@keyframes record-pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}
.record-hint { margin-top: 24px; color: var(--text-muted); }

#photo-overlay video { width: 100%; max-width: 480px; border-radius: var(--radius); }
.photo-controls {
  margin-top: 24px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  align-items: center;
}
#photo-shoot {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  font-size: 32px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-purple) 100%);
  border: none;
  color: #0d1b2a;
  cursor: pointer;
  justify-self: center;
}
