:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-input: #1f232c;
  --border: #2a2f3a;
  --text: #f2f4f8;
  --text-muted: #9aa3b2;
  --primary: #6366f1;
  --primary-hover: #4f52d6;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.screen {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
}

.screen.active {
  display: flex;
}

/* Landing */
#screen-landing {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(circle at 50% 0%, #1c2030 0%, var(--bg) 60%);
}

.landing-card {
  max-width: 420px;
  width: 100%;
}

.brand {
  font-size: 2.4rem;
  margin: 0 0 8px;
  background: linear-gradient(90deg, #818cf8, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 1.05rem;
}

.age-notice {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.fine-print {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 18px;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  color: var(--text);
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }

.btn-lg {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Card (user info / finding / stranger-left / error) */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  max-width: 460px;
  width: 100%;
  margin: auto;
  position: relative;
}

.card.centered {
  text-align: center;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 1.3rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-back {
  position: absolute;
  top: 16px;
  left: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* Form fields */
#form-userinfo { margin-top: 20px; }

.field {
  display: block;
  margin-bottom: 18px;
  border: none;
  padding: 0;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.field input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
}

.field input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.field-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}

.chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.checkbox-row input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -8px 0 14px;
}

/* Finding screen */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#screen-finding .btn, #screen-stranger-left .btn, #screen-error .btn {
  margin-top: 14px;
}

.centered-toggle {
  justify-content: center;
  margin: 6px 0 4px;
}

/* Chat screen */
#screen-chat {
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.stranger-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.stranger-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.status-pill.reconnecting .status-dot { background: #f59e0b; }
.status-pill.offline .status-dot { background: var(--danger); }

.chat-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.auto-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.auto-toggle input {
  width: 16px;
  height: 16px;
}

.safety-tip {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 16px;
  background: var(--bg-elevated);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.me {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.stranger {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-align: center;
  max-width: 90%;
}

.message-form {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.message-form input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font-size: 1rem;
  min-width: 0;
}

.message-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.message-form .btn {
  padding: 12px 20px;
  flex-shrink: 0;
}

/* Small screens fine-tuning */
@media (max-width: 380px) {
  .brand { font-size: 2rem; }
  .chip { padding: 9px 12px; font-size: 0.85rem; }
}
