:root {
  color-scheme: light;
  --bg: #fdf6ee;
  --bg-soft: #f8ecde;
  --surface: #fffaf3;
  --ink: #2a1f2d;
  --ink-soft: #4a3d4d;
  --muted: #685460;
  --line: #ecdcc9;
  --accent: #c4421a;
  --accent-strong: #a33513;
  --accent-ink: #ffffff;
  --accent-soft: #ffe3d6;
  --sun: #f6b756;
  --plum: #7a4a8c;
  --plum-soft: #efe3f5;
  --radius-sm: 0.6rem;
  --radius: 1.1rem;
  --radius-lg: 1.75rem;
  --radius-pill: 999px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --shadow: 0 1px 2px rgba(42, 31, 45, 0.04), 0 8px 24px rgba(42, 31, 45, 0.06);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 1.02rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

[dir="rtl"] body { font-family: "Vazirmatn", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, system-ui, sans-serif; }

main { max-width: 42rem; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; }

#login {
  margin: auto;
  padding: 2rem 1.5rem;
  text-align: start;
  width: 100%;
}

#login h1 {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.7rem, 1.4rem + 1.2vw, 2.2rem);
  letter-spacing: -0.01em;
}

#login p { color: var(--muted); margin: 0.25rem 0 1.6rem; }

#login-form { display: flex; flex-direction: column; gap: 0.7rem; }

label { font-size: 0.9rem; font-weight: 600; color: var(--ink-soft); }

input, textarea, button { font: inherit; color: inherit; }

input, textarea {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
}

input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

button {
  padding: 0.8rem 1.2rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: var(--accent-strong); }
button:disabled { opacity: 0.6; cursor: default; }

#login-msg { display: block; margin-block-start: 0.9rem; color: var(--muted); font-size: 0.92rem; }

#login-msg.ok {
  margin-block-start: 1.1rem;
  padding: 0.75rem 1rem;
  background: #eaf4e7;
  border: 1px solid #cfe6c9;
  border-radius: var(--radius-sm);
  color: #2f6b3a;
  font-size: 0.95rem;
}

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

#chat header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1.1rem;
  background: var(--surface);
  border-block-end: 1px solid var(--line);
  font-weight: 600;
}

#chat header .name { font-family: var(--serif); font-weight: 400; font-size: 1.15rem; }

.spacer { flex: 1; }

#notify {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
}

#notify:hover { background: var(--accent-soft); }

#notify.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

#logout {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-pill);
}

#logout:hover { background: var(--bg-soft); color: var(--ink); }

#messages {
  list-style: none;
  margin: 0;
  padding: 1.2rem 1.1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

#messages li {
  animation: message-in 200ms ease-out both;
  max-width: 85%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow);
}

#messages li.user {
  align-self: flex-end;
  background: var(--accent-soft);
  color: var(--ink);
  border-end-end-radius: var(--radius-sm);
}

#messages li.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-end-start-radius: var(--radius-sm);
}

#messages li a { color: var(--accent); }

#messages.initial li { animation: none; }

@media (prefers-reduced-motion: reduce) {
  #messages li { animation: none; }
}

#typing {
  padding: 0 1.2rem 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

#composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.8rem 1.1rem calc(0.8rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-block-start: 1px solid var(--line);
}

#composer textarea { flex: 1; resize: none; max-height: 8rem; }

a { color: var(--accent); }

@media (max-width: 480px) {
  #messages { padding: 0.9rem 0.8rem; }
  #messages li { max-width: 92%; }
  #login { padding: 1.5rem 1.1rem; }
}
