:root {
  --paper: #fbf6ec;
  --paper-2: #f5edde;
  --surface: #ffffff;
  --ink: #1c1611;
  --ink-2: #3a2f25;
  --muted: #79695b;
  --line: #ece2cf;
  --line-strong: #d9caae;
  --accent: #b9532e;
  --accent-deep: #8a3c1f;
  --accent-soft: #f4dbcb;
  --shadow-sm: 0 1px 2px rgba(28, 22, 17, 0.04);
  --shadow-md: 0 8px 24px -10px rgba(28, 22, 17, 0.18);
  --shadow-lg: 0 30px 60px -20px rgba(28, 22, 17, 0.25);
  --radius: 14px;
  --radius-lg: 20px;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(185, 83, 46, 0.06), transparent 60%),
    radial-gradient(900px 500px at -10% 100%, rgba(138, 60, 31, 0.05), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

#app { display: flex; flex-direction: column; height: 100vh; position: relative; z-index: 1; }
.hidden { display: none !important; }

/* Top bar */
#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  background: transparent;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  flex: 0 0 auto;
}
.brand-mark {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-deep);
}
.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.meter-wrap { flex: 1; display: flex; justify-content: center; }
.meter {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
}
.meter strong { color: var(--ink); font-weight: 600; }
.meter:empty { display: none; }

.actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* Buttons */
button {
  font: inherit;
  cursor: pointer;
  border: 0;
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
button:hover { background: #000; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
  padding: 9px 14px;
}
button.ghost:hover { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
button.link {
  background: transparent; color: var(--muted);
  padding: 8px; font-size: 13px;
}
button.link:hover { color: var(--ink); background: transparent; }
button.primary {
  background: var(--accent); color: #fff;
  border-radius: 10px; padding: 12px;
  font-weight: 600;
}
button.primary:hover { background: var(--accent-deep); }

/* Main */
#main { flex: 1; overflow: hidden; position: relative; display: flex; }

/* Chat */
#chatScreen { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#messages {
  flex: 1; overflow-y: auto;
  padding: 24px 24px 8px;
  display: flex; flex-direction: column; gap: 14px;
  max-width: 760px; width: 100%; margin: 0 auto;
}

.bubble {
  max-width: 78%;
  padding: 13px 16px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 15.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: bubblein 0.25s ease-out;
}
@keyframes bubblein {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.bubble.user {
  background: var(--ink);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 6px;
}
.bubble.assistant {
  background: var(--surface);
  border: 1px solid var(--line);
  align-self: flex-start;
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}
.bubble.typing { color: var(--muted); font-style: italic; }
.bubble.typing::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  margin-left: 6px; vertical-align: middle;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* Empty state */
.empty {
  text-align: center;
  padding: 64px 20px 40px;
  max-width: 640px;
  margin: 0 auto;
}
.empty .kicker {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-deep);
  font-weight: 600;
  margin-bottom: 14px;
}
.empty h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0 0 14px;
}
.empty h2 em {
  font-style: italic;
  color: var(--accent-deep);
  font-weight: 500;
}
.empty p {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15.5px;
  line-height: 1.55;
}
.suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
}
.suggestion {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-2);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}
.suggestion:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

/* Composer */
#composer {
  padding: 16px 20px 22px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}
.composer-shell {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-shell:focus-within {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md), 0 0 0 4px rgba(185, 83, 46, 0.08);
}
#composerInput {
  flex: 1;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 15.5px;
  color: var(--ink);
  padding: 10px 0;
  max-height: 180px;
  line-height: 1.5;
}
#composerInput::placeholder { color: var(--muted); }
#sendBtn {
  width: 40px; height: 40px;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}
#sendBtn:hover { background: var(--accent-deep); }
#sendBtn:disabled { background: var(--line-strong); color: var(--muted); }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(28, 22, 17, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadein 0.2s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 28px 22px;
  width: 100%;
  max-width: 400px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-lg);
  animation: cardin 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes cardin {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-card h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.modal-card p.muted {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.5;
}

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 12px;
  font-weight: 500;
  font-size: 14.5px;
}
.google-btn:hover { background: #fcfaf6; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 12px;
  margin: 6px 0 2px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; color: var(--muted);
  border: 0; border-bottom: 2px solid transparent;
  padding: 10px 14px;
  border-radius: 0;
  font-weight: 500;
  font-size: 14px;
  margin-bottom: -1px;
}
.tab:hover { background: transparent; color: var(--ink-2); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.auth-form { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.auth-form input {
  font: inherit; font-size: 14.5px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.auth-form input:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(185, 83, 46, 0.08);
}
.auth-form input::placeholder { color: var(--muted); }
.auth-form button { margin-top: 4px; }
.form-error { color: #b3261e; font-size: 13px; min-height: 18px; }

#authClose { align-self: center; margin-top: 4px; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: toastin 0.25s ease-out;
}
@keyframes toastin {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Scrollbar */
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Responsive */
@media (max-width: 640px) {
  #topbar { padding: 14px 16px; gap: 10px; }
  .meter-wrap { display: none; }
  .empty { padding: 48px 16px 32px; }
  .empty h2 { font-size: 32px; }
  #messages { padding: 16px 16px 8px; }
  #composer { padding: 12px 14px 18px; }
  .bubble { max-width: 88%; }
  .modal-card { padding: 26px 22px 18px; }
}
