/* The raven: a small companion that perches around the site. Behaviour lives in raven.js. */
.raven {
  --rv-body: #171b26; --rv-wing: #1f2535; --rv-sheen: #4a5b92; --rv-sheen2: #6a5796; --rv-beak: #262b36; --rv-leg: #2c303b;
  --rv-nape: var(--rv-body); /* a grey here (#6f7179) turns him into a Kerala house crow */
  --face: -1;
  position: fixed; left: 0; top: 0; z-index: 61; width: var(--rv-w, 66px); aspect-ratio: 6 / 5;
  pointer-events: none; will-change: transform; transition: opacity .7s ease;
}
.raven.is-away { opacity: 0; visibility: hidden; transition: opacity .5s ease, visibility 0s linear .5s; }
.raven.is-blink { opacity: 0; transition-duration: .2s; }
.raven.is-chatting { z-index: 63; }
.raven__tuck { position: relative; width: 100%; height: 100%; transition: transform .6s cubic-bezier(.3, .8, .3, 1); }
.raven.is-tucked .raven__tuck { transform: translateY(56%); }
.raven__btn {
  appearance: none; display: block; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; background: none;
  cursor: pointer; pointer-events: auto; transform-origin: 50% 95%; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.raven__btn:focus-visible { outline: 2px solid var(--marigold, #f2a20c); outline-offset: 3px; border-radius: 16px; }
.raven-svg {
  display: block; width: 100%; height: 100%; overflow: visible; transform: scaleX(var(--face)); transition: transform .22s ease;
  /* a thin rim of light so he never disappears into the dark rooms */
  filter: drop-shadow(0 0 1px rgba(236, 232, 220, .95)) drop-shadow(0 0 .6px rgba(236, 232, 220, .9)) drop-shadow(0 3px 5px rgba(0, 0, 0, .25));
}
.raven.is-quiet .raven-svg { filter: drop-shadow(0 0 1px rgba(236, 232, 220, .7)) drop-shadow(0 2px 4px rgba(0, 0, 0, .2)); }

/* the hover label */
.raven__tip {
  position: absolute; bottom: calc(100% + 4px); left: 0; z-index: 1; pointer-events: none; white-space: nowrap;
  font-family: var(--hand, cursive); font-size: 17px; line-height: 1.2; color: #2b2230; background: #fbfaf5;
  padding: 4px 12px 3px; border-radius: 999px; box-shadow: 0 8px 20px rgba(0, 0, 0, .2);
  opacity: 0; transform: translateY(6px) rotate(-2deg); transition: opacity .2s ease, transform .25s ease;
}
.raven[data-side="r"] .raven__tip { left: auto; right: 0; }
.raven__btn:hover + .raven__tip, .raven__btn:focus-visible + .raven__tip { opacity: 1; transform: translateY(0) rotate(-2deg); }
.raven.is-chatting .raven__tip, .raven.is-flying .raven__tip, .raven.is-tucked .raven__tip { display: none; }

/* parts that move */
.rv-all, .rv-head, .rv-jaw, .rv-lid, .rv-legs, .rv-wing-open, .rv-wing-far { transform-box: view-box; }
.rv-all { transform-origin: 60px 52px; transition: transform .35s ease; }
.rv-head { transform-origin: 70px 36px; transition: transform .45s cubic-bezier(.3, .7, .3, 1); }
.rv-jaw { transform-origin: 88px 28px; }
.rv-lid { transform-origin: 80px 24px; transform: scaleY(0); }
.rv-legs { transform-origin: 58px 76px; transition: transform .3s ease; }
.rv-wing-open, .rv-wing-far { transform-origin: 64px 40px; display: none; }

.raven.is-flying .rv-wing-open, .raven.is-flying .rv-wing-far,
.raven.is-hopping .rv-wing-open, .raven.is-hopping .rv-wing-far { display: inline; }
.raven.is-flying .rv-wing-fold, .raven.is-hopping .rv-wing-fold { display: none; }
.raven.is-flying .rv-all { transform: rotate(16deg); }
.raven.is-flying .rv-legs { transform: scaleY(.3); }
.raven.is-flying .rv-wing-open { animation: rv-flap .52s ease-in-out infinite; }
.raven.is-flying .rv-wing-far { animation: rv-flap-far .52s ease-in-out infinite; }
.raven.is-gliding .rv-wing-open { animation: none; transform: rotate(-24deg) scaleY(.82); }
.raven.is-gliding .rv-wing-far { animation: none; transform: rotate(-16deg) scaleY(.78); }
.raven.is-hopping .rv-wing-open { transform: rotate(-30deg) scaleY(.8); }
.raven.is-hopping .rv-wing-far { transform: rotate(-22deg) scaleY(.75); }
.raven.is-hopping .rv-legs { transform: scaleY(.7); }
@keyframes rv-flap { 0%, 100% { transform: rotate(10deg); } 50% { transform: rotate(-64deg) scaleY(.55); } }
@keyframes rv-flap-far { 0%, 100% { transform: rotate(16deg); } 50% { transform: rotate(-56deg) scaleY(.5); } }

.raven.is-landing .raven__btn { animation: rv-land .4s ease-out; }
@keyframes rv-land { 0% { transform: scale(1.06, .9); } 55% { transform: scale(.97, 1.04); } 100% { transform: none; } }
.raven.is-thinking .rv-head { animation: rv-think 2.6s ease-in-out infinite; }
@keyframes rv-think { 0%, 100% { transform: rotate(-13deg); } 50% { transform: rotate(-4deg); } }
.raven.is-listening .rv-head { transform: rotate(16deg) !important; }
.raven.is-speaking .rv-jaw { animation: rv-speak .9s ease-in-out; }
@keyframes rv-speak { 0%, 100% { transform: none; } 18% { transform: rotate(16deg); } 36% { transform: rotate(3deg); } 56% { transform: rotate(13deg); } 76% { transform: rotate(2deg); } }

/* ---------- the chat ---------- */
.raven-chat {
  --kb: 0px; --gap: 20px;
  position: fixed; right: var(--gap); bottom: calc(var(--gap) + var(--kb)); z-index: 62;
  width: min(384px, calc(100vw - 24px)); height: min(560px, calc(100vh - var(--tabs-h, 60px) - 120px - var(--kb)));
  display: flex; flex-direction: column; overflow: hidden;
  background: #f6f3ea; color: var(--ink, #121a2f); font-family: var(--sans, system-ui, sans-serif);
  border-radius: 22px; box-shadow: 0 30px 70px rgba(10, 12, 25, .38), 0 3px 10px rgba(10, 12, 25, .16);
  opacity: 0; transform: translateY(18px) scale(.98); transform-origin: 85% 100%;
  transition: opacity .22s ease, transform .3s cubic-bezier(.2, .9, .3, 1.1);
}
.raven-chat.is-open { opacity: 1; transform: none; }
.raven-chat__head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 14px 12px 20px; border-bottom: 1px solid rgba(18, 26, 47, .1); }
.raven-chat__name { margin: 0; font-family: var(--hand, cursive); font-weight: 700; font-size: 25px; line-height: 1.1; }
.raven-chat__sub { margin: 3px 0 0; font-family: var(--serif, Georgia, serif); font-style: italic; font-size: 14.5px; line-height: 1.35; color: rgba(18, 26, 47, .62); }
.raven-chat__close { flex: none; margin-left: auto; appearance: none; border: 0; width: 34px; height: 34px; padding: 8px; border-radius: 50%; background: rgba(18, 26, 47, .07); color: inherit; cursor: pointer; }
.raven-chat__close:hover { background: rgba(18, 26, 47, .14); }
.raven-chat__close svg { display: block; width: 100%; height: 100%; }
.raven-chat__log { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; padding: 16px 16px 10px; scrollbar-width: thin; scrollbar-color: rgba(18, 26, 47, .25) transparent; }
.rmsg { max-width: 88%; font-size: 16px; line-height: 1.5; overflow-wrap: anywhere; }
.rmsg p { margin: 0 0 .55em; }
.rmsg p:last-child { margin-bottom: 0; }
.rmsg--raven { align-self: flex-start; padding: 10px 14px; border-radius: 4px 16px 16px 16px; background: #fff; font-family: var(--serif, Georgia, serif); font-size: 17px; line-height: 1.5; box-shadow: 0 1px 2px rgba(18, 26, 47, .08); }
.rmsg--raven a { color: #7a2b10; font-weight: 400; text-underline-offset: 3px; }
.rmsg--raven strong { font-weight: 600; }
.rmsg--err { background: transparent; box-shadow: inset 0 0 0 1px rgba(18, 26, 47, .14); font-style: italic; color: rgba(18, 26, 47, .75); }
.rmsg--you { align-self: flex-end; padding: 9px 14px; border-radius: 16px 4px 16px 16px; background: var(--ink, #121a2f); color: var(--paper, #e7e8e2); white-space: pre-wrap; }
.rmsg--typing { display: inline-flex; gap: 5px; padding: 15px 16px; }
.rmsg--typing span { width: 7px; height: 7px; border-radius: 50%; background: rgba(18, 26, 47, .45); animation: rv-dot 1.2s ease-in-out infinite; }
.rmsg--typing span:nth-child(2) { animation-delay: .15s; }
.rmsg--typing span:nth-child(3) { animation-delay: .3s; }
@keyframes rv-dot { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }
.raven-chat__form { display: flex; align-items: flex-end; gap: 8px; margin: 0 12px 12px; padding: 5px 5px 5px 14px; border-radius: 20px; background: #fff; box-shadow: inset 0 0 0 1px rgba(18, 26, 47, .16); }
.raven-chat__form:focus-within { box-shadow: inset 0 0 0 2px var(--ink, #121a2f); }
.raven-chat__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.raven-chat__form textarea { flex: 1; min-width: 0; max-height: 120px; resize: none; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; font-size: 16px; line-height: 1.4; padding: 8px 0; }
.raven-chat__form textarea:focus-visible { outline: none; }
.raven-chat__form textarea::placeholder { color: rgba(18, 26, 47, .45); }
.raven-chat__send { flex: none; display: grid; place-items: center; width: 38px; height: 38px; padding: 8px; border: 0; border-radius: 50%; background: var(--marigold, #f2a20c); color: var(--ink, #121a2f); cursor: pointer; }
.raven-chat__send svg { width: 100%; height: 100%; }
.raven-chat__send:disabled { opacity: .45; cursor: default; }
.raven-chat__note { margin: -4px 18px 12px; font-size: 12.5px; line-height: 1.35; color: rgba(18, 26, 47, .55); }

@media (max-width: 560px) {
  .raven-chat { --gap: 8px; left: 8px; right: 8px; width: auto; height: min(72vh, calc(100vh - var(--kb) - 130px)); height: min(72svh, calc(100svh - var(--kb) - 130px)); border-radius: 20px; }
}
/* keep the chapter bar out from under the chat where they would overlap */
@media (max-width: 1180px) { .raven-open .pill, .raven-open .pill__menu { opacity: 0; pointer-events: none; } }
@media print { .raven, .raven-chat { display: none !important; } }
