:root {
  --ink: #14110d;
  --ink-2: #1d1813;
  --ink-3: #2a231b;
  --cream: #faf7f1;
  --sand: #efe7da;
  --gold: #b08d57;
  --gold-soft: #d8c19a;
  --muted: #9a8c74;
  --bubble-me: #2f6e4f;
  --bubble-agent: #2a231b;
  --danger: #b3423a;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--cream);
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(176, 141, 87, 0.18), transparent 60%),
    radial-gradient(120% 80% at 0% 110%, rgba(176, 141, 87, 0.10), transparent 55%),
    var(--ink);
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login-screen { align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, rgba(42, 35, 27, 0.92), rgba(24, 20, 16, 0.96));
  border: 1px solid rgba(176, 141, 87, 0.28);
  border-radius: 24px;
  padding: 32px 26px;
  text-align: center;
  box-shadow: 0 40px 120px -60px rgba(0, 0, 0, 0.9);
}
.brand-mark {
  width: 64px; height: 64px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border: 1px solid rgba(216, 193, 154, 0.5);
  border-radius: 14px;
  color: var(--gold-soft);
  font-size: 34px;
  font-family: Georgia, serif;
}
.login-card h1 { font-family: Georgia, serif; font-weight: 500; font-size: 22px; margin: 0; letter-spacing: 0.14em; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 8px 0 24px; }
.login-card input {
  width: 100%; padding: 13px 16px; border-radius: 12px;
  border: 1px solid rgba(216, 193, 154, 0.25);
  background: rgba(10, 8, 6, 0.55); color: var(--cream);
  font-size: 15px; outline: none;
}
.login-card input:focus { border-color: var(--gold); }
.login-card button {
  width: 100%; margin-top: 12px; padding: 13px; border: 0; border-radius: 12px;
  background: var(--gold); color: #1b150e; font-weight: 600; font-size: 15px;
}
.error { color: #e58f86; font-size: 13px; min-height: 18px; margin: 12px 0 0; }

/* ---------- app ---------- */
.app-screen { height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(20, 17, 13, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(176, 141, 87, 0.18);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-family: Georgia, serif; letter-spacing: 0.12em; font-size: 15px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #8a7d68; }
.dot.online { background: #4faf73; box-shadow: 0 0 10px rgba(79, 175, 115, 0.8); }
.top-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
#logout { background: none; border: 0; color: var(--muted); font-size: 16px; padding: 4px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg .meta { font-size: 10px; color: var(--muted); margin: 4px 6px 0; }

.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .bubble { background: var(--bubble-me); color: #f2fff7; border-bottom-right-radius: 6px; }

.msg.assistant { align-self: flex-start; }
.msg.assistant .bubble {
  background: var(--bubble-agent);
  border: 1px solid rgba(176, 141, 87, 0.22);
  color: var(--cream);
  border-bottom-left-radius: 6px;
}

.msg.system { align-self: center; max-width: 92%; }
.msg.system .bubble {
  background: linear-gradient(180deg, rgba(42, 35, 27, 0.9), rgba(28, 23, 18, 0.95));
  border: 1px solid rgba(216, 193, 154, 0.3);
  border-radius: 14px;
  font-size: 13.5px;
  padding: 12px 14px;
}
.msg.system .kind {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 6px;
}

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
  background: rgba(20, 17, 13, 0.9);
  border-top: 1px solid rgba(176, 141, 87, 0.18);
  backdrop-filter: blur(12px);
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px;
  padding: 11px 14px; border-radius: 20px;
  border: 1px solid rgba(216, 193, 154, 0.22);
  background: rgba(10, 8, 6, 0.6); color: var(--cream);
  font-size: 15px; line-height: 1.4; outline: none;
}
.composer textarea:focus { border-color: rgba(216, 193, 154, 0.5); }
.composer button {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--gold); color: #1b150e; font-size: 16px;
}
.composer button:disabled { opacity: 0.4; }

.typing { color: var(--muted); font-size: 12px; padding: 0 16px 8px; }

@media (min-width: 720px) {
  .app-screen { max-width: 680px; margin: 0 auto; border-left: 1px solid rgba(176,141,87,.14); border-right: 1px solid rgba(176,141,87,.14); }
}

.hint { color: var(--muted); font-size: 11px; margin: 10px 0 0; }
