:root {
  color-scheme: light;
  --ink: #253027;
  --muted: #6d756d;
  --paper: #f5efe3;
  --card: #fffdf7;
  --green: #2f4935;
  --green-light: #e5ecdf;
  --rust: #9c4f34;
  --line: #d9d0bf;
  --shadow: 0 18px 50px rgba(56, 47, 36, .11);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 8%, rgba(216, 159, 93, .2), transparent 28rem),
    linear-gradient(155deg, #f7f1e6, #eee6d7);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
.shell { width: min(760px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 44px; }
.porch-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; }
.eyebrow { color: var(--rust); font-size: .72rem; font-weight: 800; letter-spacing: .16em; margin: 0 0 2px; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; letter-spacing: -.025em; }
h1 { font-size: clamp(2rem, 7vw, 3.5rem); line-height: .95; margin: 0; }
h2 { font-size: 2rem; margin: 0 0 8px; }
.card { background: rgba(255, 253, 247, .92); border: 1px solid rgba(145, 128, 102, .25); border-radius: 20px; box-shadow: var(--shadow); }
.gate { margin: 8vh auto 0; max-width: 620px; padding: clamp(24px, 6vw, 48px); }
.gate > p { color: var(--muted); }
.gate .kicker { color: var(--green); font-weight: 750; margin: 0 0 4px; }
label { display: block; font-size: .82rem; font-weight: 750; margin-bottom: 7px; }
.key-row { display: flex; gap: 10px; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); padding: 12px 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(47, 73, 53, .13); }
button { border: 0; border-radius: 999px; background: var(--green); color: white; font-weight: 750; padding: 12px 20px; white-space: nowrap; }
button:hover { filter: brightness(1.08); }
button:disabled { cursor: wait; opacity: .6; }
.quiet { background: transparent; border: 1px solid var(--line); color: var(--ink); padding: 8px 15px; }
.error { min-height: 1.5em; color: #a22f28 !important; margin-bottom: 0; }
.presence { display: flex; align-items: center; gap: 12px; padding: 13px 18px; box-shadow: none; }
.presence strong, .presence small { display: block; }
.presence small { color: var(--muted); }
.lamp { width: 11px; height: 11px; border-radius: 50%; background: #d39c52; box-shadow: 0 0 0 5px rgba(211, 156, 82, .16); }
.lamp.connected { background: #4f825b; box-shadow: 0 0 0 5px rgba(79, 130, 91, .14); }
.messages { min-height: 42vh; padding: 30px 0 16px; display: flex; flex-direction: column; gap: 16px; }
.empty { margin: auto; max-width: 480px; text-align: center; color: var(--muted); padding: 48px 20px; }
.message { max-width: 82%; }
.message.mine { align-self: flex-end; }
.message.wiz { align-self: flex-start; }
.message.other { align-self: flex-start; }
.message-meta { color: var(--muted); font-size: .75rem; margin: 0 10px 5px; }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 18px 18px 18px 5px; padding: 13px 16px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 7px 20px rgba(62, 49, 33, .06); }
.mine .bubble { background: var(--green); border-color: var(--green); color: white; border-radius: 18px 18px 5px 18px; }
.wiz .bubble { background: var(--green-light); border-color: #cad6c3; }
.needs-reply { color: var(--rust); font-size: .75rem; margin: 5px 10px 0; }
.composer { position: sticky; bottom: 12px; padding: 15px; }
textarea { display: block; resize: vertical; min-height: 80px; max-height: 220px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 10px; }
.status { color: var(--muted); font-size: .82rem; }
.privacy-note { color: var(--muted); font-size: .74rem; text-align: center; margin: 18px 4px 0; }

@media (max-width: 560px) {
  .shell { width: min(100% - 20px, 760px); padding-top: 18px; }
  .key-row { flex-direction: column; }
  .key-row button { width: 100%; }
  .message { max-width: 92%; }
  .composer { bottom: 5px; }
  .composer-row { align-items: flex-end; }
}

@media (prefers-reduced-motion: no-preference) {
  .bubble { animation: arrive .22s ease-out; }
  @keyframes arrive { from { opacity: 0; transform: translateY(5px); } }
}
