:root:has(.chat-panel[open]) { overflow: hidden; }

.chat-launcher,
.chat-panel {
  --chat-ink: #382439;
  --chat-paper: #fff8ef;
  --chat-gold: #ffcf86;
  --chat-line: #e6d7cc;
  font-family: var(--body, system-ui, sans-serif);
  color: var(--chat-ink);
}

.chat-launcher {
  position: fixed;
  inset: auto max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) auto;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 15px 8px 9px;
  border: 1px solid #fff2da;
  border-radius: 999px;
  background: var(--chat-ink);
  color: #fff8ef;
  box-shadow: 0 5px 20px #38243940;
  font-weight: 900;
  font-size: 14px;
  cursor: pointer;
}

.chat-launcher span, .chat-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: var(--chat-gold);
  color: var(--chat-ink);
  border-radius: 10px;
  font-size: 19px;
}

.chat-launcher:hover { background: #64425b; }
.chat-panel[open] { display: grid; }
.chat-panel {
  position: fixed;
  inset: auto max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) auto;
  width: min(414px, calc(100% - 28px));
  max-width: none;
  height: min(595px, calc(100dvh - 28px));
  max-height: none;
  grid-template-rows: auto minmax(0, 1fr) auto;
  margin: 0;
  padding: 0;
  border: 1px solid var(--chat-line);
  border-radius: 24px;
  background: var(--chat-paper);
  box-shadow: 0 24px 90px #28172e65;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.48;
}

.chat-panel::backdrop { background: #25172745; }
.chat-panel [hidden] { display: none; }
.chat-panel button { font: inherit; cursor: pointer; }
.chat-panel button:disabled { cursor: wait; opacity: .58; }
.chat-launcher:focus-visible, .chat-panel :focus-visible { outline: 2px solid #875076; outline-offset: 2px; }
.chat-panel .chat-close:focus-visible { outline-color: var(--chat-gold); }

.chat-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 17px 16px;
  background: radial-gradient(ellipse at top right, #6e415d, transparent 65%), var(--chat-ink);
  color: var(--chat-paper);
}

.chat-mark { width: 42px; height: 42px; transform: rotate(-7deg); font-size: 24px; }
.chat-head p { margin: 0 0 3px; color: var(--chat-gold); font-size: 10px; letter-spacing: .13em; text-transform: uppercase; font-weight: 900; }
.chat-head h2 { margin: 0; color: inherit; font: 900 25px/1.1 var(--body, system-ui, sans-serif); }
.chat-panel .chat-close { min-width: 44px; min-height: 44px; padding: 0; border: 1px solid #ffffff58; border-radius: 50%; background: transparent; color: inherit; font-size: 24px; }
.chat-close:hover { background: #ffffff24; }

.chat-scroll { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px; }
.chat-conversation { display: grid; gap: 12px; }
.chat-entry { min-width: 0; max-width: 95%; }
.chat-entry p { width: fit-content; margin: 0; padding: 10px 13px; border: 1px solid var(--chat-line); border-radius: 4px 15px 15px 15px; background: white; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-entry-user { justify-self: end; }
.chat-entry-user p { border-color: #f1d4ae; border-radius: 15px 4px 15px 15px; background: #ffe4bb; }
.chat-shortcuts, .chat-starters, .chat-fallback { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.chat-starters { margin-top: 17px; }
.chat-shortcuts a, .chat-starters button, .chat-fallback a, .chat-retry {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid #ccb1bd;
  border-radius: 999px;
  padding: 6px 10px;
  background: #fffdf8;
  color: var(--chat-ink);
  font: 800 13px/1.35 var(--body, system-ui, sans-serif);
  text-decoration: none;
  text-align: left;
}
.chat-panel .chat-starters button, .chat-panel .chat-retry { font-size: 13px; font-weight: 800; }
.chat-shortcuts a:hover, .chat-starters button:hover, .chat-fallback a:hover, .chat-retry:hover { border-color: #64425b; background: #f5e6ed; }
.chat-status { margin: 9px 0 0; color: #67465a; font-size: 13px; }
.chat-status:empty { margin: 0; }
.chat-compose { padding: 12px; border-top: 1px solid var(--chat-line); background: #fffaf5; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) 44px; align-items: center; gap: 7px; }
.chat-form input { width: 100%; min-height: 44px; padding: 9px 12px; border: 1px solid #b99eae; border-radius: 13px; background: #fff; color: var(--chat-ink); font: inherit; font-size: 16px; }
.chat-form button { min-height: 44px; border: 0; border-radius: 13px; background: var(--chat-ink); color: white; font-size: 23px; }
.chat-form button:hover:not(:disabled) { background: #64425b; }
.chat-foot { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.chat-foot p, .chat-foot button { margin: 0; color: #64465a; font-size: 12px; }
.chat-foot button { padding: 3px 0; border: 0; background: transparent; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.chat-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 480px) {
  .chat-panel { right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 16px); height: min(580px, calc(100dvh - 16px)); border-radius: 20px; }
}

.chat-typing p { color: transparent; position: relative; min-width: 54px; min-height: 40px; }
.chat-typing p::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 30px;
  height: 8px;
  background: radial-gradient(circle closest-side, #875076 90%, transparent) 0 50% / 10px 8px repeat-x;
  -webkit-mask: linear-gradient(90deg, #000 30%, #0004 50%, #000 70%) 0 0 / 300% 100%;
  mask: linear-gradient(90deg, #000 30%, #0004 50%, #000 70%) 0 0 / 300% 100%;
  animation: chat-dots 1.1s linear infinite;
}
@keyframes chat-dots { to { -webkit-mask-position: -300% 0; mask-position: -300% 0; } }
@media (prefers-reduced-motion: reduce) { .chat-typing p::after { animation: none; } }
