:root {
  --bg: #faf7f4;
  --surface: #ffffff;
  --text: #2a211c;
  --muted: #7a6c63;
  --border: #e6ddd6;
  --accent: #8a4b2a;
  --accent-text: #ffffff;
  --mine: #8a4b2a;
  --mine-text: #ffffff;
  --theirs: #efe7e1;
  --error: #b3261e;
  --ok: #2e7d32;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181412;
    --surface: #221c19;
    --text: #efe7e1;
    --muted: #a8988d;
    --border: #3a302b;
    --accent: #d08a5c;
    --accent-text: #181412;
    --mine: #a35c35;
    --mine-text: #ffffff;
    --theirs: #2c2420;
    --error: #f28b82;
    --ok: #81c995;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
nav a[aria-current="page"] { color: var(--text); background: var(--theirs); }
nav .brand { color: var(--text); font-weight: 600; margin-right: auto; padding-left: 0; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
main.chat { padding-bottom: 96px; }

h1 { font-size: 1.4rem; margin: 8px 0 12px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.card h2 { margin-top: 0; }
.hint, small, .empty { color: var(--muted); }
small { font-size: 0.8rem; margin-left: 4px; }
.error { color: var(--error); }
.ok { color: var(--ok); }
code { font-size: 0.9em; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; }

button, .button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.secondary { background: var(--theirs); color: var(--text); }
button.link { background: none; color: var(--muted); padding: 4px 8px; }
button:disabled { opacity: 0.5; }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}

.login { max-width: 340px; margin: 15vh auto 0; display: grid; gap: 12px; }
.login h1 { text-align: center; }

/* chat */
.msg { display: flex; margin: 8px 0; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--theirs);
  overflow-wrap: anywhere;
}
.msg.user .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { border-bottom-left-radius: 4px; }
.msg.pending .bubble { opacity: 0.6; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.user .bubble a { color: inherit; }

#thinking { display: none; }
#thinking.htmx-request { display: flex; }
#thinking .bubble { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

#composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
#composer textarea { resize: none; field-sizing: content; max-height: 40vh; }

/* profile + log */
.profile-editor { min-height: 50vh; font-family: ui-monospace, Menlo, monospace; font-size: 14px; margin-bottom: 8px; }
.items { list-style: none; padding: 0; margin: 0; }
.items li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.items form { flex-shrink: 0; }
.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--theirs);
  margin-right: 4px;
}
