:root {
  color-scheme: light;
  --paper: #f7f1e8;
  --paper-deep: #eee3d3;
  --card: rgba(255, 252, 247, 0.92);
  --ink: #2c2523;
  --muted: #716764;
  --wine: #8d3f5d;
  --wine-dark: #6f2e47;
  --coral: #cf765f;
  --peach: #f3d7c3;
  --sage: #5d7668;
  --line: rgba(69, 48, 42, 0.14);
  --shadow: 0 18px 60px rgba(84, 52, 42, 0.13);
  font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 17px;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; margin: 0; }

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 5%, rgba(207, 118, 95, 0.14), transparent 31rem),
    radial-gradient(circle at 92% 88%, rgba(141, 63, 93, 0.11), transparent 30rem),
    var(--paper);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(141, 63, 93, 0.35);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.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;
}

.unlock-shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}

.unlock-card {
  width: min(100%, 440px);
  padding: 38px 28px 32px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 30px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  text-align: center;
}

.brand-mark { border-radius: 24px; box-shadow: 0 12px 28px rgba(111, 46, 71, 0.22); }
.eyebrow {
  margin: 22px 0 8px;
  color: var(--wine);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.unlock-card h1 { margin: 0; font-size: clamp(1.8rem, 8vw, 2.4rem); letter-spacing: -0.04em; }
.welcome-copy { margin: 14px auto 28px; max-width: 31ch; color: var(--muted); line-height: 1.55; }
.login-form { text-align: left; }
.login-form label { display: block; margin: 0 0 8px 4px; font-size: 0.88rem; font-weight: 750; }
.password-row { position: relative; }
.password-row input {
  width: 100%;
  min-height: 54px;
  padding: 12px 72px 12px 16px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fffdfa;
  color: var(--ink);
  font-size: 1rem;
}
.text-button {
  position: absolute;
  right: 8px;
  top: 7px;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--wine);
  font-size: 0.83rem;
  font-weight: 750;
}
.primary-button, .secondary-button, .danger-button {
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: 15px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button {
  width: 100%;
  margin-top: 14px;
  background: linear-gradient(135deg, var(--wine), var(--coral));
  color: #fff;
  box-shadow: 0 8px 20px rgba(141, 63, 93, 0.2);
}
.primary-button:disabled { opacity: 0.6; cursor: wait; }
.form-error { min-height: 1.35rem; margin: 12px 4px 0; color: #a33030; font-size: 0.85rem; text-align: center; }

.app-shell {
  height: 100dvh;
  max-width: 880px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(247, 241, 232, 0.52);
}

.app-header {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(247, 241, 232, 0.88);
  backdrop-filter: blur(22px);
}
.brand-row { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-row img { flex: 0 0 auto; border-radius: 11px; box-shadow: 0 5px 14px rgba(111, 46, 71, 0.16); }
.brand-row h1 { margin: 0; font-size: 1.15rem; letter-spacing: -0.03em; }
.connection-status { margin: 3px 0 0; color: var(--muted); font-size: 0.72rem; white-space: nowrap; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #c29648; }
.connection-status.online .status-dot { background: #4d896c; box-shadow: 0 0 0 4px rgba(77, 137, 108, 0.11); }
.connection-status.offline .status-dot { background: #b4524f; }
.header-actions { display: flex; gap: 5px; }
.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--wine);
  cursor: pointer;
}
.icon-button:active { background: rgba(141, 63, 93, 0.09); }
.icon-button svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.message-scroller {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 28px max(16px, env(safe-area-inset-right)) 18px max(16px, env(safe-area-inset-left));
  scroll-behavior: smooth;
}
.empty-state { min-height: 100%; display: grid; place-content: center; justify-items: center; padding: 28px 0 60px; text-align: center; }
.hello-orb {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #f7ddc9, #e9b5ae);
  color: var(--wine);
  box-shadow: 0 14px 32px rgba(111, 46, 71, 0.13);
  font-size: 1.7rem;
}
.empty-state h2 { margin: 22px 0 8px; font-size: clamp(1.45rem, 6vw, 2rem); letter-spacing: -0.035em; }
.empty-state > p { max-width: 38ch; margin: 0; color: var(--muted); line-height: 1.55; }
.suggestions { width: min(100%, 570px); display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 28px; }
.suggestions button {
  min-height: 52px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 252, 247, 0.7);
  color: var(--wine-dark);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.suggestions button:active { transform: scale(0.98); }

.messages { width: min(100%, 720px); margin: 0 auto; display: grid; gap: 24px; }
.message { display: grid; grid-template-columns: minmax(0, auto); justify-items: start; }
.message.user { justify-items: end; }
.message-label { margin: 0 7px 6px; color: var(--muted); font-size: 0.72rem; font-weight: 750; }
.bubble {
  max-width: min(88%, 620px);
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 7px 19px 19px 19px;
  background: rgba(255, 253, 249, 0.94);
  box-shadow: 0 5px 18px rgba(76, 52, 44, 0.06);
  line-height: 1.58;
}
.message.user .bubble {
  border-color: transparent;
  border-radius: 19px 7px 19px 19px;
  background: linear-gradient(135deg, var(--wine), #a95065);
  color: #fff;
  box-shadow: 0 7px 20px rgba(111, 46, 71, 0.16);
}
.message.error .bubble { border-color: rgba(163, 48, 48, 0.3); background: #fff1ef; color: #7a2929; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.typing-dots { display: inline-flex; align-items: center; gap: 5px; min-width: 50px; padding: 3px 2px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--wine); animation: bounce 1.15s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: 0.14s; }
.typing-dots i:nth-child(3) { animation-delay: 0.28s; }
.message:not(.pending) .typing-dots { display: none; }
.message.pending .message-text:not(:empty) + .typing-dots { display: none; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.35; } 30% { transform: translateY(-5px); opacity: 1; } }
.speak-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 36px;
  margin: 5px 6px 0;
  padding: 0 7px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}
.speak-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.message.user .speak-button, .message.pending .speak-button, .message.error .speak-button { display: none; }

.composer-wrap {
  z-index: 5;
  padding: 7px max(14px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(247, 241, 232, 0.9);
  backdrop-filter: blur(22px);
}
.chat-notice { min-height: 0; margin: 0 auto 5px; max-width: 720px; color: #8b3939; font-size: 0.78rem; text-align: center; }
.chat-notice:empty { display: none; }
.composer {
  width: min(100%, 720px);
  min-height: 54px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 7px 7px 7px 16px;
  border: 1px solid rgba(69, 48, 42, 0.18);
  border-radius: 22px;
  background: rgba(255, 253, 249, 0.96);
  box-shadow: 0 8px 28px rgba(76, 52, 44, 0.08);
}
.composer:focus-within { border-color: rgba(141, 63, 93, 0.48); box-shadow: 0 0 0 3px rgba(141, 63, 93, 0.08); }
.composer textarea {
  flex: 1;
  max-height: 132px;
  min-height: 38px;
  resize: none;
  padding: 8px 0 5px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.35;
}
.composer textarea::placeholder { color: #968b87; }
.send-button {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--wine);
  color: #fff;
  cursor: pointer;
}
.send-button:disabled { opacity: 0.35; cursor: default; }
.send-button svg { grid-area: 1 / 1; width: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stop-icon { display: none; }
.sending .send-icon { display: none; }
.sending .stop-icon { display: block; }
.privacy-note { margin: 6px 0 0; color: #8d817c; font-size: 0.64rem; text-align: center; }

.sheet {
  width: min(calc(100% - 28px), 470px);
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: #fffcf7;
  color: var(--ink);
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(43, 32, 31, 0.46); backdrop-filter: blur(4px); }
.sheet form { position: relative; padding: 30px 26px 26px; text-align: center; }
.sheet img { border-radius: 16px; }
.sheet h2 { margin: 16px 0 12px; font-size: 1.4rem; letter-spacing: -0.03em; }
.sheet ol { margin: 22px 0; padding-left: 1.4rem; text-align: left; line-height: 1.5; }
.sheet li { margin: 11px 0; padding-left: 5px; }
.sheet-close { position: absolute; top: 12px; right: 14px; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; }
.confirm-sheet p { color: var(--muted); }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.secondary-button { border: 1px solid var(--line); background: #f8f2e9; color: var(--ink); }
.danger-button { background: #a13e42; color: #fff; }

@media (max-width: 580px) {
  :root { font-size: 16px; }
  .suggestions { grid-template-columns: 1fr; width: min(100%, 320px); }
  .suggestions button { min-height: 48px; }
  .message-scroller { padding-top: 20px; }
  .bubble { max-width: 91%; }
}

@media (min-width: 881px) {
  .app-shell { border-inline: 1px solid var(--line); box-shadow: 0 0 70px rgba(76, 52, 44, 0.08); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #211c1b;
    --paper-deep: #2d2523;
    --card: rgba(49, 41, 39, 0.94);
    --ink: #f8eee8;
    --muted: #c1b4ad;
    --wine: #d4839d;
    --wine-dark: #efa8bb;
    --coral: #db8773;
    --line: rgba(255, 235, 224, 0.14);
  }
  .password-row input, .bubble, .composer, .suggestions button, .sheet { background: #312927; }
  .app-header, .composer-wrap { background: rgba(33, 28, 27, 0.9); }
  .app-shell { background: rgba(33, 28, 27, 0.5); }
  .message.error .bubble { background: #4a2928; color: #ffd7d2; }
  .secondary-button { background: #3b312e; color: var(--ink); }
}
