*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface-2: #222230;
  --border: #2e2e3e;
  --gold: #c9a84c;
  --gold-dim: #8a6e2f;
  --text: #e8e8f0;
  --text-dim: #888899;
  --user-bg: #1e3a5f;
  --user-border: #2a5a9f;
  --assistant-bg: #1a1a22;
  --assistant-border: #c9a84c33;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
}

/* ── Header ── */
header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, #8a5e1c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  color: #0f0f13;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.header-text { flex: 1; min-width: 0; }
.header-text h1 { font-size: 18px; font-weight: 700; color: var(--gold); letter-spacing: 0.3px; }
.subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

#model-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 0 10px;
  height: 36px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, color 0.15s;
  max-width: 180px;
}
#model-select:focus, #model-select:hover { border-color: var(--gold-dim); color: var(--text); }

#clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
#clear-btn:hover { border-color: var(--gold-dim); color: var(--gold); }

/* ── Messages ── */
main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

main::-webkit-scrollbar { width: 6px; }
main::-webkit-scrollbar-track { background: transparent; }
main::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fadeUp 0.2s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  align-self: flex-end;
}

.message.assistant .msg-avatar {
  background: linear-gradient(135deg, var(--gold) 0%, #8a5e1c 100%);
  color: #0f0f13;
}

.message.user .msg-avatar {
  background: var(--user-border);
  color: var(--text);
}

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  font-size: 15px;
  max-width: calc(100% - 60px);
  word-break: break-word;
}

.message.assistant .msg-bubble {
  background: var(--assistant-bg);
  border: 1px solid var(--assistant-border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.message.user .msg-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 4px;
  color: var(--text);
}

/* stage directions e.g. *(Leans back)* */
.stage-dir {
  color: #4caf82;
  font-style: italic;
  opacity: 0.85;
}

/* streaming cursor */
.cursor::after {
  content: '▋';
  display: inline-block;
  animation: blink 0.7s step-end infinite;
  color: var(--gold);
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* error state */
.message.error .msg-bubble {
  background: #2a1010;
  border-color: #6b2020;
  color: #e07070;
}

/* empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  color: var(--text-dim);
  pointer-events: none;
}
#empty-state .big-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, #8a5e1c 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 26px;
  color: #0f0f13;
  margin-bottom: 4px;
}
#empty-state h2 { font-size: 20px; color: var(--gold); }
#empty-state p { font-size: 14px; max-width: 340px; line-height: 1.5; }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 14px 20px;
  flex-shrink: 0;
}

#chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 11px 14px;
  resize: none;
  max-height: 180px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s;
  overflow-y: auto;
}
#input::placeholder { color: var(--text-dim); }
#input:focus { border-color: var(--gold-dim); }

#send-btn {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--gold);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
#send-btn svg { width: 18px; height: 18px; color: #0f0f13; }
#send-btn:hover { background: #d4b05a; }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 600px) {
  main { padding: 16px 12px; }
  footer { padding: 10px 12px; }
  .header-inner { padding: 10px 12px; }
}
