/* Berea — minimal, readable, monastic-leaning. */

:root {
  --bg: #0f0d0a;
  --bg-alt: #1a1612;
  --bg-card: #221d18;
  --line: #2e2820;
  --ink: #e9e1d4;
  --ink-soft: #b9ad97;
  --ink-mute: #7a7060;
  --accent: #c9a25a;        /* old-gold */
  --accent-soft: #8a6e3a;
  --user: #b8d4d4;
  --error: #e08577;
  --radius: 10px;
  --maxw: 760px;
  --safeb: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }

body {
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg-alt);
  z-index: 5;
}
.brand {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
}
.iconbtn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  width: 2.2rem;
  height: 2.2rem;
  border-radius: var(--radius);
  font-size: 1.2rem;
  cursor: pointer;
}
.iconbtn:hover { color: var(--ink); border-color: var(--accent-soft); }

main#chat {
  overflow-y: auto;
  padding: 1.25rem 1rem 1rem;
  scroll-behavior: smooth;
}

#messages {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.welcome {
  max-width: var(--maxw);
  margin: 4rem auto 1rem;
  text-align: center;
  color: var(--ink-soft);
}
.welcome .lead {
  font-size: 1.6rem;
  color: var(--accent);
  font-style: italic;
  margin: 0 0 0.4rem;
}
.welcome .sub { margin: 0 auto 2rem; max-width: 36em; }
.suggested { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.chip {
  font-family: inherit;
  font-size: 0.92rem;
  background: var(--bg-card);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--accent-soft); }

.msg { display: flex; flex-direction: column; gap: 0.4rem; }
.msg.user .bubble {
  background: transparent;
  border-left: 3px solid var(--user);
  color: var(--user);
  padding: 0.2rem 0 0.2rem 0.9rem;
  font-style: italic;
}
.msg.assistant .bubble {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.assistant .bubble h3 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 1.2rem 0 0.2rem;
}

.cites {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.cite {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s;
}
.cite:hover { border-color: var(--accent-soft); }
.cite .cite-ref {
  display: block;
  color: var(--accent);
  font-style: italic;
  margin-bottom: 0.2rem;
}
.cite .cite-snip { display: block; }
.cite-full {
  display: none;
  margin-top: 0.5rem;
  white-space: pre-wrap;
  color: var(--ink);
}
.cite.open .cite-full { display: block; }
.cite.open .cite-snip { display: none; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem calc(0.75rem + var(--safeb));
  background: var(--bg-alt);
  border-top: 1px solid var(--line);
}
#input {
  flex: 1;
  resize: none;
  font-family: inherit;
  font-size: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  max-height: 40vh;
}
#input:focus { outline: none; border-color: var(--accent-soft); }
#sendBtn {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: var(--radius);
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}
#sendBtn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Drawers */
.drawer {
  position: fixed;
  top: 0; bottom: 0;
  width: min(360px, 85vw);
  background: var(--bg-alt);
  border-right: 1px solid var(--line);
  padding: 1rem;
  z-index: 10;
  transform: translateX(-105%);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.drawer.right {
  left: auto; right: 0;
  border-right: 0;
  border-left: 1px solid var(--line);
  transform: translateX(105%);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}
.drawer ul { list-style: none; padding: 0; margin: 0; overflow-y: auto; }
.drawer li {
  padding: 0.6rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.drawer li:hover { color: var(--ink); }
.drawer li.active { color: var(--accent); }

#journalDraft {
  flex: 0 0 auto;
  height: 8rem;
  resize: vertical;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: var(--radius);
  font-family: inherit;
  padding: 0.6rem;
}
.primary {
  background: var(--accent);
  color: var(--bg);
  border: 0;
  border-radius: var(--radius);
  padding: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}
.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: var(--radius);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  font-family: inherit;
}
.ghost:hover { color: var(--ink); }

#journalList li {
  cursor: default;
  white-space: pre-wrap;
  font-size: 0.85rem;
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 9;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.scrim.show { opacity: 1; pointer-events: auto; }

/* small screens */
@media (max-width: 640px) {
  body { font-size: 16px; }
  main#chat { padding: 1rem 0.7rem; }
}
