:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #f0b90b;
  --accent-dim: #7a5f07;
  --user-bubble: #1f3a5f;
  --ai-bubble: #1c2128;
  --error: #f85149;
  --ok: #3fb950;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
}
.hidden { display: none !important; }
.screen { height: 100vh; display: flex; flex-direction: column; }

/* ── auth screen ── */
#auth-screen { align-items: center; justify-content: center; }
.auth-card {
  width: min(400px, 92vw);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  text-align: center;
}
.auth-card h1 { font-size: 28px; margin-bottom: 4px; }
.tagline { color: var(--muted); margin-bottom: 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 9px; background: var(--bg3); color: var(--muted);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab.active { color: var(--accent); border-color: var(--accent-dim); background: #1a1a10; }
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; justify-content: center; }
.subtab {
  padding: 5px 14px; background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent;
}
.subtab.active { color: var(--text); border-bottom-color: var(--accent); }
form { display: flex; flex-direction: column; gap: 10px; }
input, textarea, select {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); padding: 10px 12px; font-size: 14px; font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-dim); }
button { font-family: inherit; }
.primary {
  background: var(--accent); color: #111; border: none; border-radius: 8px;
  padding: 10px 16px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.primary:hover { filter: brightness(1.1); }
.primary:disabled { opacity: 0.5; cursor: default; }
.ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.ghost:hover { color: var(--text); border-color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; margin-top: 12px; line-height: 1.5; }
.hint.warn { color: var(--error); }
.error { color: var(--error); font-size: 13px; margin-top: 10px; }

/* ── chat screen ── */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg2); border-bottom: 1px solid var(--border);
  gap: 10px; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; }
.header-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#model-picker { max-width: 220px; }
.badge {
  font-size: 12px; padding: 4px 9px; border-radius: 999px;
  background: var(--bg3); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap;
}
.badge.premium { color: var(--accent); border-color: var(--accent-dim); }
.badge.user { color: var(--text); }
.badge.exhausted { color: var(--error); border-color: var(--error); }

main {
  flex: 1; overflow-y: auto; padding: 20px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.msg { max-width: min(760px, 92%); display: flex; flex-direction: column; gap: 4px; }
.msg .who { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.msg .bubble {
  padding: 10px 14px; border-radius: 12px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; }
.msg.ai .bubble { background: var(--ai-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.ai .bubble.error { border-color: var(--error); color: var(--error); }
.cursor::after { content: "▋"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

footer {
  display: flex; gap: 10px; padding: 12px 16px;
  background: var(--bg2); border-top: 1px solid var(--border);
}
#input { flex: 1; resize: none; max-height: 160px; }

@media (max-width: 640px) {
  .badge.user { display: none; }
  #model-picker { max-width: 140px; }
}
