:root {
  --bg: #0f1115;
  --panel: #171a21;
  --accent: #e8a87c;
  --text: #eae6e0;
  --muted: #8b8fa3;
  --user-bubble: #2a2f3a;
  --border: #232733;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled, input:disabled, textarea:disabled { opacity: .6; cursor: wait; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
header {
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
header .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}
header .title { flex: 1; }
header #logout {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
  padding: 4px 8px;
}
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--panel);
  border-bottom-left-radius: 4px;
}
.msg.typing { color: var(--muted); font-style: italic; }
#chat-form {
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}
#input {
  flex: 1;
  resize: none;
  border: 1px solid #2a2f3a;
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  padding: 11px 14px;
  font-size: 15px;
  font-family: inherit;
  max-height: 120px;
}
#send {
  border: none;
  border-radius: 20px;
  background: var(--accent);
  color: #1a1410;
  font-weight: 700;
  font-size: 15px;
  min-width: 72px;
  min-height: 44px;
  padding: 0 20px;
  cursor: pointer;
}
#gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  z-index: 10;
}
#gate h1 { font-size: 22px; margin: 0; }
#gate .subtitle { color: var(--muted); margin: 0 0 6px; font-size: 14px; }
.tabs { display: flex; gap: 8px; margin-bottom: 4px; }
.tab {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}
.tab.active {
  background: var(--accent);
  color: #1a1410;
  font-weight: 700;
  border-color: var(--accent);
}
.auth-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #2a2f3a;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
}
.auth-form button {
  width: 100%;
  min-height: 44px;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #1a1410;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
#gate-error {
  color: #e69a9a;
  font-size: 13px;
  margin: 0;
  min-height: 18px;
  text-align: center;
}
