:root {
  --bg: #14110f;
  --bg-2: #1c1815;
  --panel: #241f1b;
  --panel-2: #2e2722;
  --line: #3a312a;
  --text: #ece4d8;
  --muted: #a3978a;
  --accent: #e0b25b;
  --accent-ink: #1a1408;
  --mine: #3b4a3a;
  --danger: #e07a6b;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #2a221c 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
a { color: var(--accent); }

/* --- login --- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; text-align: center;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px;
  padding: 36px 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.brand-mark { font-size: 44px; line-height: 1; }
.brand h1 { font: 700 34px/1.1 var(--serif); letter-spacing: .04em; margin: 10px 0 4px; }
.brand h1 span, .topbar-brand span { color: var(--accent); }
.tagline { color: var(--muted); font-family: var(--serif); font-style: italic; margin: 0; }
.login-intro { margin: 22px 0 22px; color: var(--text); }
.login-error { color: var(--danger); margin: -8px 0 16px; }
.providers { display: grid; gap: 10px; }
.provider {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); text-decoration: none; color: var(--text); font-weight: 600;
  transition: background .15s, border-color .15s;
}
.provider:hover { background: var(--panel-2); border-color: #554739; }
.provider svg { width: 20px; height: 20px; flex: none; }
.provider.google { background: #fff; color: #1f1f1f; border-color: #fff; }
.provider.google:hover { background: #f1f1f1; }
.provider.facebook { background: #1877f2; color: #fff; border-color: #1877f2; }
.provider.facebook:hover { background: #166fe0; }
.muted { color: var(--muted); }
.lang-switch { display: flex; justify-content: center; gap: 6px; margin-top: 22px; }
.lang-switch button { background: none; border: 1px solid transparent; border-radius: 8px; padding: 4px 10px; color: var(--muted); }
.lang-switch button.active { border-color: var(--line); color: var(--text); }
.legal { margin: 18px 0 0; font-size: 13px; }

/* --- app --- */
.app { height: 100%; display: flex; flex-direction: column; max-width: 820px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: rgba(20,17,15,.85); backdrop-filter: blur(8px);
}
.topbar-brand { font: 700 18px var(--serif); letter-spacing: .04em; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; white-space: nowrap;
}
.chip:hover { border-color: #554739; }
.user { display: flex; align-items: center; gap: 6px; min-width: 0; margin: 0 4px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }
.user-name { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 16px 8px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.feed > * { flex-shrink: 0; }

.msg { max-width: 82%; border-radius: var(--radius); padding: 10px 14px; overflow-wrap: anywhere; animation: rise .2s ease-out; }
.msg p { margin: 0 0 .6em; }
.msg p:last-child { margin-bottom: 0; }
.msg.char { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg .who { font-weight: 700; color: var(--accent); font-size: 14px; margin-bottom: 2px; }

.note {
  align-self: stretch; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; animation: rise .2s ease-out;
}
.note .body { padding: 14px 16px; white-space: pre-wrap; }
.note .body:first-line { font-family: var(--serif); }
.note img { display: block; width: 100%; max-height: 420px; object-fit: cover; background: #000; }
.note.portrait { align-self: flex-start; max-width: 340px; }
.note.portrait img { aspect-ratio: 1 / 1; max-height: none; }
.note.portrait .body { font-style: italic; color: var(--muted); }
.note.error .body { color: var(--danger); }

.dock { border-top: 1px solid var(--line); padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); background: rgba(20,17,15,.92); }
.keyboard { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; max-height: 40vh; overflow-y: auto; }
.keyboard:empty { display: none; }
.kb-row { display: contents; }
.kb-row button {
  flex: 1 1 auto; min-width: 0; max-width: 100%; padding: 8px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kb-row button:hover:not(:disabled) { background: var(--panel-2); border-color: #554739; }
.kb-row button.active { border-color: var(--accent); }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 11px 14px; border-radius: 12px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); font: inherit; outline: none;
}
.composer textarea:focus { border-color: #6b5a47; }
.send {
  width: 46px; height: 46px; border-radius: 12px; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 18px; flex: none;
}

.typing { display: flex; gap: 4px; padding: 0 2px 8px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }

@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (max-width: 560px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  .topbar-brand { font-size: 16px; }
  .user-name { display: none; }
  .feed { padding: 14px 12px 6px; }
  .msg { max-width: 90%; }
  .dock { padding-left: 12px; padding-right: 12px; }
}

/* --- privacy page --- */
.doc { max-width: 720px; margin: 0 auto; padding: 40px 16px 64px; }
.doc h1 { font: 700 30px var(--serif); }
.doc h2 { font: 700 20px var(--serif); margin-top: 32px; }
.doc p, .doc li { color: #d8cfc3; }
