/* Блум — персонаж-помічник унизу сторінки (js/bloom.js). Кольори беруться зі змінних теми, тож працює і в темній, і в світлій. */
.bl-root {
    --bl-ink: var(--ink, #eef2ff); --bl-muted: var(--muted, #8f9cc6); --bl-panel: var(--panel, #0c1630);
    --bl-panel2: var(--panel-2, #13214a); --bl-line: var(--line, #1d2f63); --bl-accent: var(--accent, #2461f2);
    --bl-soft: var(--accent-soft, rgba(36, 97, 242, .16));
    position: fixed; z-index: 90; right: 20px; bottom: 20px; bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right)); font-family: var(--font, system-ui, sans-serif); color: var(--bl-ink);
    display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none;
}
.bl-root > * { pointer-events: auto; }
.bl-root [hidden] { display: none !important; }
.bl-root button, .bl-root a { font-family: inherit; }
.bl-root :focus-visible { outline: 2px solid var(--bl-accent); outline-offset: 2px; }

/* Сторінки з полем введення внизу */
.bl-root.bl-lift { bottom: 96px; bottom: calc(96px + env(safe-area-inset-bottom)); }

/* Персонаж */
.bl-launcher, .bl-tab {
    position: relative; display: grid; place-items: center; padding: 0; cursor: pointer; color: inherit;
    background: var(--bl-panel); border: 1px solid var(--bl-line); border-radius: 50%;
    box-shadow: 0 8px 24px rgba(5, 12, 40, .28); transition: transform .2s, box-shadow .2s, border-color .2s;
}
.bl-launcher { width: 64px; height: 64px; }
.bl-launcher:hover { transform: translateY(-2px); border-color: var(--bl-accent); box-shadow: 0 12px 28px rgba(36, 97, 242, .32); }
.bl-launcher .bl-svg { width: 46px; height: 46px; overflow: visible; }
.bl-tab { display: none; width: 36px; height: 36px; opacity: .7; }
.bl-tab:hover { opacity: 1; }
.bl-tab .bl-svg { width: 24px; height: 24px; overflow: visible; }
.bl-root.is-hidden .bl-launcher, .bl-root.is-hidden .bl-panel, .bl-root.is-hidden .bl-bubble { display: none !important; }
.bl-root.is-hidden .bl-tab { display: grid; }

/* Анімація: легке дихання, погойдування листків, кліпання */
.bl-body { transform-origin: 50% 95%; animation: bl-breathe 4.2s ease-in-out infinite; }
.bl-leaves { transform-origin: 54px 50px; animation: bl-sway 5.6s ease-in-out infinite; }
.bl-eye { transform-box: fill-box; transform-origin: center; animation: bl-blink 5.5s infinite; }
.bl-pupil { transition: transform .12s ease-out; }
.bl-tab .bl-body, .bl-tab .bl-leaves, .bl-tab .bl-eye { animation: none; }
.bl-root.is-thinking .bl-body { animation-duration: 1.4s; }
@keyframes bl-breathe { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, 1.045); } }
@keyframes bl-sway { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(3deg); } }
@keyframes bl-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.08); } }

/* Бульбашка-привітання */
.bl-bubble { position: relative; max-width: 250px; margin-right: 6px; animation: bl-pop .35s cubic-bezier(.22, 1, .36, 1); }
.bl-bubble-text {
    display: block; width: 100%; text-align: left; padding: 11px 32px 11px 14px; font-size: 14px; line-height: 1.4; color: var(--bl-ink);
    background: var(--bl-panel); border: 1px solid var(--bl-line); border-radius: 16px 16px 4px 16px; cursor: pointer;
    box-shadow: 0 10px 28px rgba(5, 12, 40, .25);
}
.bl-bubble-text b { font-weight: 600; }
.bl-bubble-x {
    position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0;
    color: var(--bl-muted); background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.bl-bubble-x:hover { color: var(--bl-ink); background: var(--bl-soft); }
.bl-bubble-x svg { width: 12px; height: 12px; }
@keyframes bl-pop { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }

/* Вікно */
.bl-panel {
    display: flex; flex-direction: column; width: min(380px, calc(100vw - 32px)); height: min(540px, calc(100vh - 130px)); height: min(540px, calc(100dvh - 130px));
    background: var(--bl-panel); border: 1px solid var(--bl-line); border-radius: 18px; overflow: hidden;
    box-shadow: 0 24px 60px rgba(3, 8, 30, .45); opacity: 0; transform: translateY(10px) scale(.98); transform-origin: 100% 100%;
    transition: opacity .2s, transform .2s;
}
.bl-root.is-open .bl-panel { opacity: 1; transform: none; }
.bl-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 12px; border-bottom: 1px solid var(--bl-line); background: var(--bl-panel2); }
.bl-avatar { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%; background: var(--bl-panel); border: 1px solid var(--bl-line); }
.bl-avatar .bl-svg { width: 26px; height: 26px; overflow: visible; }
.bl-avatar .bl-body, .bl-avatar .bl-leaves, .bl-avatar .bl-eye { animation: none; }
.bl-titles { flex: 1; min-width: 0; margin-left: 4px; }
.bl-title { font-weight: 700; font-size: 15px; line-height: 1.2; }
.bl-status { font-size: 12px; color: var(--bl-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bl-hbtn {
    display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; color: var(--bl-muted);
    background: none; border: 0; border-radius: 9px; cursor: pointer; text-decoration: none;
}
.bl-hbtn:hover { color: var(--bl-ink); background: var(--bl-soft); }
.bl-hbtn svg { width: 17px; height: 17px; }

.bl-log { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.bl-msg { max-width: 92%; font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.bl-user { align-self: flex-end; padding: 9px 13px; color: #fff; background: var(--bl-accent); border-radius: 16px 16px 4px 16px; white-space: pre-wrap; }
.bl-bot { align-self: flex-start; padding: 9px 13px; background: var(--bl-panel2); border: 1px solid var(--bl-line); border-radius: 16px 16px 16px 4px; }
.bl-error { border-color: #c0443f; }
.bl-note { margin-top: 6px; font-size: 12px; color: var(--bl-muted); }
.bl-md > :first-child { margin-top: 0; } .bl-md > :last-child { margin-bottom: 0; }
.bl-md p, .bl-md ul, .bl-md ol { margin: 0 0 8px; } .bl-md ul, .bl-md ol { padding-left: 20px; }
.bl-md a { color: var(--accent-fg, var(--bl-accent)); }
.bl-md code { font-family: var(--mono, ui-monospace, monospace); font-size: 12.5px; padding: 1px 5px; border-radius: 5px; background: var(--bl-soft); }
.bl-code { position: relative; margin: 6px 0; }
.bl-code pre { margin: 0; padding: 26px 10px 10px; overflow-x: auto; background: #070d22; color: #dfe7ff; border-radius: 10px; }
.bl-code pre code { padding: 0; background: none; color: inherit; font-size: 12.5px; }
.bl-copy { position: absolute; top: 4px; right: 4px; padding: 2px 8px; font-size: 11px; color: #9fb0e6; background: none; border: 1px solid #243566; border-radius: 6px; cursor: pointer; }
.bl-copy:hover { color: #fff; border-color: var(--bl-accent); }
.bl-copy-all { margin-top: 6px; padding: 0; font-size: 12px; color: var(--bl-muted); background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.bl-copy-all:hover { color: var(--bl-ink); }

.bl-welcome { margin: auto 0; text-align: center; padding: 8px 6px; }
.bl-big { display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 10px; }
.bl-big .bl-svg { width: 72px; height: 72px; overflow: visible; }
.bl-welcome h3 { margin: 0 0 6px; font-size: 18px; }
.bl-welcome p { margin: 0 0 14px; font-size: 14px; line-height: 1.5; color: var(--bl-muted); }
.bl-welcome a { color: var(--accent-fg, var(--bl-accent)); }
.bl-suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.bl-suggest button {
    padding: 7px 12px; font-size: 13px; color: var(--bl-ink); background: none; border: 1px solid var(--bl-line); border-radius: 999px; cursor: pointer;
}
.bl-suggest button:hover { border-color: var(--bl-accent); background: var(--bl-soft); }

.bl-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.bl-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--bl-muted); animation: bl-dot 1.2s infinite; }
.bl-typing i:nth-child(2) { animation-delay: .15s; } .bl-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bl-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.bl-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px; border-top: 1px solid var(--bl-line); }
.bl-input {
    flex: 1; min-width: 0; max-height: 110px; padding: 9px 12px; font: inherit; font-size: 14px; line-height: 1.4; resize: none;
    color: var(--bl-ink); background: var(--bl-panel2); border: 1px solid var(--bl-line); border-radius: 12px;
}
.bl-input::placeholder { color: var(--bl-muted); }
.bl-input:focus { outline: none; border-color: var(--bl-accent); }
.bl-send {
    display: grid; place-items: center; flex: none; width: 38px; height: 38px; padding: 0; color: #fff; background: var(--bl-accent);
    border: 0; border-radius: 50%; cursor: pointer;
}
.bl-send:hover:not(:disabled) { filter: brightness(1.12); }
.bl-send:disabled, .bl-input:disabled { opacity: .5; cursor: not-allowed; }
.bl-send svg { width: 18px; height: 18px; }

/* Телефон: персонаж менший, вікно майже на всю ширину; iOS не зумить поле введення (16px) */
@media (max-width: 640px) {
    .bl-root.bl-lift { bottom: 92px; bottom: calc(92px + env(safe-area-inset-bottom)); }
    .bl-root { right: 12px; right: max(12px, env(safe-area-inset-right)); bottom: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
    .bl-launcher { width: 54px; height: 54px; }
    .bl-launcher .bl-svg { width: 39px; height: 39px; }
    .bl-bubble { max-width: min(250px, calc(100vw - 90px)); }
    .bl-panel { width: calc(100vw - 24px); height: min(560px, calc(100dvh - 90px)); }
    .bl-input { font-size: 16px; }
    /* Відкрите вікно саме закриває персонажа, щоб не дублювати */
    .bl-root.is-open .bl-launcher { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .bl-body, .bl-leaves, .bl-eye, .bl-typing i { animation: none !important; }
    .bl-panel, .bl-launcher, .bl-bubble { transition: none; animation: none; }
}
