/* ---------- pkla dog ai (app.js builds it; only when <body data-chat>) ---------- */
.chat-bubble {
  position: fixed; right: 20px; bottom: 20px; z-index: 30;
  display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--fg); cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
  transition: transform .2s cubic-bezier(.2, .7, .2, 1), background-color .3s ease, color .3s ease, border-color .3s ease;
}
.chat-bubble:hover { transform: scale(1.06); border-color: var(--fg); }
.chat-bubble:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
/* Open: the bubble flips to cream and its chat icon spins into an X. */
.chat-bubble > svg { grid-area: 1 / 1; transition: transform .35s cubic-bezier(.2, .7, .2, 1), opacity .25s ease; }
.chat-bubble__x { opacity: 0; transform: rotate(-90deg) scale(.5); }
.chat-bubble.is-open { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chat-bubble.is-open .chat-bubble__talk { opacity: 0; transform: rotate(90deg) scale(.5); }
.chat-bubble.is-open .chat-bubble__x { opacity: 1; transform: none; }
/* The home page's "scroll" hint moves left so the bubble has the corner. */
body[data-chat] .scroll-cue { right: auto; left: 24px; }

.chat-panel {
  color-scheme: dark;
  position: fixed; right: 20px; bottom: 88px; z-index: 30;
  display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 120px));
  border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: 0 18px 60px rgba(0, 0, 0, .7);
  overflow: hidden;
  /* Where the bubble's center is, measured from the panel's bottom-right corner: the panel grows out of it. */
  --from-x: 28px; --from-y: 40px;
  animation: none;
}
.chat-panel[hidden] { display: none; }
.chat-panel.is-closing { animation: chat-close .26s cubic-bezier(.5, 0, .75, 0) forwards; }
.chat-panel.is-instant, .chat-panel.is-instant > * { animation: none; }
@keyframes chat-open {
  from { clip-path: circle(28px at calc(100% - var(--from-x)) calc(100% + var(--from-y))); }
  to { clip-path: circle(150% at calc(100% - var(--from-x)) calc(100% + var(--from-y))); }
}
@keyframes chat-close {
  from { clip-path: circle(150% at calc(100% - var(--from-x)) calc(100% + var(--from-y))); }
  to { clip-path: circle(28px at calc(100% - var(--from-x)) calc(100% + var(--from-y))); }
}
/* The header, messages and box settle in just behind the reveal. */
.chat-panel.is-opening { animation: chat-open .5s cubic-bezier(.35, .6, .2, 1); }
.chat-panel.is-opening > * { animation: chat-settle .4s .08s cubic-bezier(.2, .7, .2, 1) both; }
.chat-panel.is-closing > * { animation: none; }
@keyframes chat-settle { from { opacity: 0; transform: translateY(10px); } }
.chat-panel__head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--line); }
.chat-panel__title { margin: 0 auto 0 4px; font-family: var(--font-serif); font-style: italic; font-size: 20px; line-height: 1.2; }
.chat-panel__clear, .chat-panel__close {
  border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 8px; padding: 6px 8px; font-size: 13px; font-weight: 600;
}
.chat-panel__close { display: grid; place-items: center; padding: 6px; }
.chat-panel__clear:hover, .chat-panel__close:hover { color: var(--fg); background: var(--surface-2); }
.chat-panel__log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg--me { align-self: flex-end; background: var(--fg); color: #000; border-bottom-right-radius: 6px; }
.chat-msg--dog { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.chat-msg code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; padding: 1px 5px; border-radius: 5px; background: rgba(243, 233, 214, .1); }
.chat-msg.is-typing::after { content: "…"; animation: chat-dots 1s steps(3, end) infinite; display: inline-block; overflow: hidden; vertical-align: bottom; width: 0; }
.chat-msg.is-typing { min-width: 44px; }
.chat-msg.is-typing::before { content: "thinking"; color: var(--muted); }
.chat-msg--dog { white-space: normal; }
.chat-msg--dog > :first-child { margin-top: 0; }
.chat-msg--dog > :last-child { margin-bottom: 0; }
.chat-msg--dog p { margin: 0 0 14px; text-wrap: wrap; }
.chat-msg--dog h1, .chat-msg--dog h2, .chat-msg--dog h3, .chat-msg--dog h4, .chat-msg--dog h5, .chat-msg--dog h6 { margin: 24px 0 10px; font: inherit; font-weight: 700; line-height: 1.3; }
.chat-msg--dog h1 { font-size: 1.5em; }
.chat-msg--dog h2 { font-size: 1.3em; }
.chat-msg--dog h3 { font-size: 1.15em; }
.chat-msg--dog ul, .chat-msg--dog ol { margin: 12px 0 18px; padding-left: 1.5em; list-style: disc; }
.chat-msg--dog ol { list-style: decimal; }
.chat-msg--dog li { padding-left: 4px; margin: 6px 0; }
.chat-msg--dog li ul, .chat-msg--dog li ol { margin: 6px 0; }
.chat-msg--dog a { color: var(--fg); text-decoration: underline; text-decoration-color: #766d5e; text-underline-offset: 3px; transition: text-decoration-color .18s; }
.chat-msg--dog a:hover { text-decoration-color: var(--fg); }
.chat-msg--dog blockquote { margin: 16px 0; padding: 2px 0 2px 16px; border-left: 3px solid #766d5e; color: #bdb4a4; }
.chat-msg--dog blockquote p:last-child { margin-bottom: 0; }
.chat-msg--dog hr { border: 0; border-top: 1px solid var(--line-strong); margin: 24px 0; }
.chat-code { margin: 16px 0; border: 1px solid #33312b; border-radius: 12px; background: #11110f; overflow: hidden; }
.chat-code__bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 14px; border-bottom: 1px solid #33312b; color: var(--muted); font-size: 12px; }
.chat-code__bar button, .chat-msg__copy { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 4px 0; }
.chat-code__bar button:hover, .chat-msg__copy:hover { color: var(--fg); }
.chat-code__bar button:focus-visible, .chat-msg__copy:focus-visible { outline: 2px solid var(--fg); outline-offset: 4px; }
.chat-code__bar button:disabled { visibility: hidden; }
.chat-code pre { overflow-x: auto; max-width: 100%; margin: 0; padding: 16px; line-height: 1.65; tab-size: 2; scrollbar-width: thin; }
.chat-code pre code { padding: 0; border-radius: 0; background: none; white-space: pre; overflow-wrap: normal; font-size: 13px; }
.chat-table { max-width: 100%; overflow-x: auto; margin: 16px 0; scrollbar-width: thin; }
.chat-table table { width: 100%; border-collapse: collapse; font-size: .9em; }
.chat-table th, .chat-table td { padding: 10px 14px; border: 1px solid #33312b; text-align: left; min-width: 100px; }
.chat-table th { background: #151513; font-weight: 600; }
.chat-msg__copy { display: block; margin-top: 10px; }
@keyframes chat-dots { to { width: 1.1em; } }
.chat-note { align-self: center; margin: 4px 0; font-size: 13px; color: var(--muted); text-align: center; }
.chat-panel__form { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-panel__input {
  flex: 1; resize: none; min-height: 42px; max-height: 140px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--field); line-height: 1.4; font-size: 15px;
}
.chat-panel__input:focus { outline: none; border-color: var(--fg); }
.chat-panel__send {
  min-height: 42px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--fg); color: #000; font-weight: 700; cursor: pointer;
}
.chat-panel__send:disabled { opacity: .5; cursor: progress; }
@media (max-width: 480px) {
  .chat-panel { right: 16px; left: 16px; width: auto; bottom: 84px; height: calc(100dvh - 104px); --from-x: 32px; --from-y: 36px; }
}
