.fern-chat {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  color: var(--ink);
  font: 16px/1.55 var(--sans);
}
.fern-chat [hidden], .fern-chat[hidden] { display: none; }
.fern-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 36px));
  height: min(560px, calc(100vh - 112px));
  height: min(560px, calc(100dvh - 112px - env(safe-area-inset-bottom)));
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--paper) url('../assets/paper-grain.png');
  border: 1px solid #c8b99d;
  border-radius: 22px 22px 8px 22px;
  box-shadow: 0 12px 40px #183e5730;
}
.fern-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 15px 12px 15px 18px;
  background: var(--deep);
  color: #fff8e9;
}
.fern-chat-header h2 { margin: 0; font: 25px/1.15 var(--hand); }
.fern-chat-header p { margin: 4px 0 0; color: #fff8e9; font-size: 14px; }
.fern-chat button { cursor: pointer; border: 0; }
.fern-chat-close { flex: 0 0 44px; height: 44px; border-radius: 50%; background: #ffffff15; color: inherit; font-size: 28px; }
.fern-chat-history { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 16px; }
.fern-chat-message { width: fit-content; max-width: 100%; margin: 0 0 14px; padding: 13px; background: #f0ebdc; border-radius: 4px 16px 16px; overflow-wrap: anywhere; }
.fern-chat-message p { margin: 0 0 16px; color: inherit; font-size: 16px; line-height: 1.55; }
.fern-chat-message p:last-child { margin-bottom: 0; }
.fern-chat-message a { display: inline-block; min-height: 44px; align-content: center; text-decoration: underline; text-underline-offset: 3px; }
.fern-chat-visitor { margin-left: auto; background: var(--deep); color: #fff8e9; border-radius: 16px 4px 16px 16px; white-space: pre-wrap; }
.fern-chat-form { display: flex; flex-shrink: 0; gap: 8px; padding: 12px 12px 6px; border-top: 1px solid var(--line); }
.fern-chat-form input { min-width: 0; width: 100%; min-height: 46px; padding: 10px 12px; font: inherit; color: var(--ink); background: #fffdf8; border: 1px solid #879e9e; border-radius: 12px; }
.fern-chat-form input::placeholder { color: #586b71; opacity: 1; }
.fern-chat-form button { flex: 0 0 auto; white-space: nowrap; min-width: 62px; min-height: 46px; padding: 8px 12px; border-radius: 12px; background: var(--deep); color: #fff8e9; font-weight: 800; }
.fern-chat-note { flex-shrink: 0; margin: 0; padding: 5px 14px 12px; color: #52666b; font-size: 13px; line-height: 1.4; }
.fern-chat-bubble { display: grid; place-items: center; width: 58px; height: 58px; margin-left: auto; border-radius: 50% 50% 8px 50%; background: var(--deep); color: #fff8e9; box-shadow: 0 4px 0 #c5b38c, 0 7px 20px #183e5726; }
.fern-chat button:hover { filter: brightness(1.12); }
.fern-chat :focus-visible { outline: 3px solid #b66a34; outline-offset: 2px; }
.fern-chat-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 520px) {
  .fern-chat-header h2 { font-size: 23px; }
  .fern-chat-note { font-size: 16px; }
}
