:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #2b2f2c;
  --muted: #6d746f;
  --accent: #5b8a72;
  --accent-text: #ffffff;
  --bubble-user: #5b8a72;
  --bubble-user-text: #ffffff;
  --bubble-bot: #ffffff;
  --border: #e3ded6;
  --notice: #fbf3e4;
  --danger: #b5523b;
  --radius: 18px;
  --shadow: 0 8px 30px rgba(43, 47, 44, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a18;
    --surface: #1f2421;
    --text: #e6e9e7;
    --muted: #98a19c;
    --accent: #7fb196;
    --accent-text: #10140f;
    --bubble-user: #3f6b55;
    --bubble-user-text: #f1f5f2;
    --bubble-bot: #242a26;
    --border: #2e3531;
    --notice: #2a2619;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.screen { min-height: 100dvh; }

/* Welcome / end */
.welcome { display: grid; place-items: center; padding: 24px 16px; }
.card {
  width: 100%; max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
  text-align: center;
}
.logo { align-self: center; }
h1 { margin: 0; font-size: 28px; font-weight: 600; }
.lead { margin: 0; color: var(--muted); }
.facts { list-style: none; padding: 0; margin: 0; text-align: left; display: grid; gap: 6px; }
.facts li::before { content: "·"; color: var(--accent); font-weight: 700; margin-right: 8px; }
.notice {
  background: var(--notice);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  text-align: left;
}
.consent { display: flex; gap: 10px; align-items: center; text-align: left; cursor: pointer; }
.consent input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Buttons */
.btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 20px;
  cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 14px; font-size: 14px; }

/* Session */
.session { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { flex: none; }
.name { font-weight: 600; }
.status { font-size: 13px; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn .short { display: none; }
.timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }
.timer.warn { color: var(--danger); }

.demo-banner {
  text-align: center; font-size: 13px; padding: 6px 16px;
  background: var(--notice); color: var(--muted);
}

.messages {
  flex: 1; overflow-y: auto;
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 10px;
  max-width: 760px; width: 100%; margin: 0 auto;
}
.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bubble-bot);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 6px;
}
.msg.error { align-self: center; background: transparent; color: var(--danger); font-size: 14px; }
.typing::after {
  content: "…";
  display: inline-block;
  animation: blink 1.2s infinite;
}
@keyframes blink { 50% { opacity: .2; } }

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1;
  font: inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 14px;
  resize: none;
  max-height: 160px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send { width: 44px; height: 44px; padding: 0; flex: none; }

/* Help dialog */
dialog {
  border: none; border-radius: 20px;
  padding: 24px; max-width: 420px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin-top: 0; font-size: 20px; }
.hotlines { padding-left: 18px; display: grid; gap: 6px; }

@media (max-width: 520px) {
  .btn .long { display: none; }
  .btn .short { display: inline; }
  .topbar { padding: 10px 12px; }
  .actions { gap: 6px; }
  .msg { max-width: 90%; }
  .card { padding: 24px 18px; }
}
