:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6d675f;
  --line: #e3ddd3;
  --accent: #d9622b;
  --accent-text: #ffffff;
  --mine: #d9622b;
  --mine-text: #ffffff;
  --error: #b3261e;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a19;
    --surface: #262422;
    --text: #f1ede7;
    --muted: #a39c92;
    --line: #3a3733;
    --accent: #ec7a43;
    --mine: #b9531f;
    --error: #ff8a80;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--error); min-height: 1.2em; margin: 0; font-size: 15px; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

#login { align-items: center; justify-content: center; padding: 16px; }
.card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; display: flex; flex-direction: column; gap: 12px;
}
.card img { align-self: center; }
.card h1 { margin: 0; text-align: center; font-size: 26px; }
.card > p { margin: 0 0 8px; text-align: center; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--muted); }
input {
  font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
button[type=submit] {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px;
  padding: 13px; font-weight: 600; cursor: pointer;
}

header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.spacer { flex: 1; }
.ghost {
  background: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font-size: 14px; color: var(--muted); cursor: pointer;
}

#chat { position: relative; }
#messages {
  position: relative;
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.error { background: none; border: 1px dashed var(--error); color: var(--error); }
.msg.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

.empty { margin: auto 0; text-align: center; padding: 0 8px; }
.empty p { margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chips button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; cursor: pointer;
}

#composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--line); background: var(--surface);
}
textarea {
  flex: 1; resize: none; max-height: 140px; padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg); font-size: 17px; line-height: 1.35;
}
#send {
  width: 44px; height: 44px; border-radius: 50%; padding: 0;
  display: grid; place-items: center; flex-shrink: 0;
}
#send:disabled { opacity: .5; }

#down {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 80px);
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); display: grid; place-items: center;
  box-shadow: 0 2px 8px rgb(0 0 0 / .15); cursor: pointer;
}
.status { display: block; color: var(--muted); font-size: 15px; font-style: italic; }
