/* Ask the Chonk: a chat window in the Le Chonk style. Builds on the tokens in style.css.
 * The card fills the screen below the sticky header. The log scrolls inside it and the
 * composer stays pinned to the bottom of the card. Animations use transform and opacity only. */

/* <main> holds the ambient layer, so the glow spans the full screen width, not just the container */
main#main {
  position: relative;
  isolation: isolate;
}

.ask-page {
  --nav-h: 68px; /* the sticky header: .header-row in style.css is 68px on every screen */
  --pad: 16px;
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  padding-block: var(--pad);
}

/* ---------- ambient orbs: soft orange and lime glow drifting behind the card ---------- */
.ask-ambient {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.ask-orb {
  position: absolute;
  width: 58vmax;
  height: 58vmax;
  border-radius: 50%;
  opacity: 0.6;
  will-change: transform;
}
.ask-orb--a {
  left: -24vmax;
  top: -20vmax;
  background: radial-gradient(closest-side, rgba(255, 122, 0, 0.34), rgba(255, 122, 0, 0) 72%);
  animation: ask-orb-a 26s ease-in-out infinite alternate;
}
.ask-orb--b {
  right: -26vmax;
  top: 22%;
  background: radial-gradient(closest-side, rgba(74, 222, 128, 0.2), rgba(74, 222, 128, 0) 72%);
  animation: ask-orb-b 33s ease-in-out infinite alternate;
}
.ask-orb--c {
  left: 16%;
  bottom: -36vmax;
  width: 68vmax;
  height: 68vmax;
  background: radial-gradient(closest-side, rgba(255, 154, 53, 0.22), rgba(255, 154, 53, 0) 70%);
  animation: ask-orb-c 39s ease-in-out infinite alternate;
}
@keyframes ask-orb-a { to { transform: translate3d(16vmax, 12vmax, 0) scale(1.14); } }
@keyframes ask-orb-b { to { transform: translate3d(-14vmax, 18vmax, 0) scale(0.9); } }
@keyframes ask-orb-c { to { transform: translate3d(-10vmax, -16vmax, 0) scale(1.18); } }

/* ---------- the chat card: exactly the viewport below the header ---------- */
.chat {
  position: relative;
  max-width: 820px;
  margin-inline: auto;
  height: calc(100vh - var(--nav-h) - 2 * var(--pad));
  height: calc(100dvh - var(--nav-h) - 2 * var(--pad));
  min-height: 300px;
  min-width: 0;
  padding: clamp(12px, 2.2vw, 20px);
  border-radius: var(--radius-xl);
  /* solid enough to read on, and no backdrop blur: blurring the moving orbs behind it every frame costs 60 fps */
  background: linear-gradient(180deg, rgba(24, 22, 20, 0.9), rgba(12, 11, 10, 0.95));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- slim header ---------- */
.chat-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}
.chat-id { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-avatar-wrap {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}
.chat-avatar {
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 6px 12px rgba(255, 122, 0, 0.35));
  transform-origin: 50% 80%;
  animation: ask-breathe 5.2s ease-in-out infinite;
}
@keyframes ask-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
.chat-id-text { min-width: 0; display: grid; gap: 2px; }
.chat-title {
  font-size: clamp(18px, 2.4vw, 22px);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.3s var(--ease);
}
.chat.is-busy .chat-status { color: var(--orange-hi); }
.chat.is-busy .live-dot { background: var(--orange-hi); animation-duration: 1s; }

.chat-new {
  position: relative;
  flex: none;
  overflow: hidden;
  gap: 6px;
  padding: 0 14px;
  border-color: var(--border-warm);
  background: rgba(255, 122, 0, 0.1);
  color: var(--cream);
}
.chat-new:hover { color: var(--orange-hi); background: rgba(255, 122, 0, 0.16); }
.chat-new::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.3) 50%, transparent 70%);
  transform: translateX(-120%);
  animation: ask-shimmer 4.4s var(--ease) infinite;
  pointer-events: none;
}
@keyframes ask-shimmer {
  0%, 55% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}
.chat-new-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

/* ---------- the log: the only part that scrolls ---------- */
.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 6px 12px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 122, 0, 0.4) transparent;
  /* soft edges where the log scrolls out of view */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}

/* ---------- empty state: the fat cat, a headline, four cards ---------- */
.ask-empty {
  margin: auto;
  width: 100%;
  display: grid;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding: 8px 0;
}
.ask-hero-cat {
  width: clamp(112px, 22vh, 180px);
  width: clamp(112px, 22dvh, 180px);
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 20px 24px rgba(255, 122, 0, 0.26));
  animation: ask-bob 6s ease-in-out infinite;
}
@keyframes ask-bob {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(-0.6deg); }
  50% { transform: translate3d(0, -8px, 0) rotate(0.6deg); }
}
.ask-hero-title { font-size: clamp(24px, 4vw, 34px); line-height: 1.05; }
.ask-hero-lede { color: var(--muted); font-size: 15px; max-width: 42ch; }

.ask-cards {
  width: 100%;
  max-width: 560px;
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.ask-card {
  appearance: none;
  min-width: 0;
  display: grid;
  gap: 4px;
  justify-items: start;
  text-align: left;
  min-height: 62px;
  padding: 11px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.035));
  color: var(--cream);
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: transform 0.3s var(--ease), border-color 0.3s, background 0.3s, box-shadow 0.3s;
  animation: ask-card-in 0.8s var(--spring) backwards;
  animation-delay: calc(var(--i, 0) * 90ms + 260ms);
}
.ask-cards .ask-card:nth-child(1) { --i: 0; }
.ask-cards .ask-card:nth-child(2) { --i: 1; }
.ask-cards .ask-card:nth-child(3) { --i: 2; }
.ask-cards .ask-card:nth-child(4) { --i: 3; }
.ask-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-warm);
  background: linear-gradient(180deg, rgba(255, 122, 0, 0.16), rgba(255, 122, 0, 0.05));
  box-shadow: 0 14px 30px rgba(255, 122, 0, 0.14);
}
.ask-card:focus-visible { border-radius: 18px; }
.chat-new:focus-visible { border-radius: 999px; }
.ask-card-kicker {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--orange-hi);
}
@keyframes ask-card-in {
  from { opacity: 0; transform: translate3d(0, 16px, 0) scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* ---------- messages ---------- */
.msg {
  min-width: 0;
  max-width: 90%;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.msg.me { margin-left: auto; }
.msg.is-new { animation: ask-msg-in 0.75s var(--spring) backwards; }
.msg.me.is-new { animation-name: ask-msg-in-me; }
@keyframes ask-msg-in {
  from { opacity: 0; transform: translate3d(0, 18px, 0) scale(0.92); }
  to { opacity: 1; transform: none; }
}
@keyframes ask-msg-in-me {
  from { opacity: 0; transform: translate3d(24px, 10px, 0) scale(0.92); }
  to { opacity: 1; transform: none; }
}

.msg-body {
  min-width: 0;
  padding: 11px 15px;
  border-radius: 20px;
  font-size: 15.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.bot .msg-body {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg.me .msg-body {
  background: linear-gradient(180deg, var(--orange-hi), var(--orange));
  color: var(--orange-ink);
  font-weight: 600;
  border-bottom-right-radius: 6px;
  box-shadow: 0 10px 26px rgba(255, 122, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.msg.is-error .msg-body {
  border-color: rgba(255, 107, 107, 0.55);
  background: rgba(255, 107, 107, 0.09);
  color: var(--cream);
}

.msg-avatar-wrap {
  position: relative;
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
}
.msg-avatar {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 50%;
  background: #120d08;
  border: 1px solid var(--border-warm);
}
.msg-avatar-wrap::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid var(--orange-hi);
  opacity: 0;
  pointer-events: none;
}
/* the chonk pulse: when a reply finishes, the avatar bumps and a ring ripples out once */
.msg.is-pulse .msg-avatar { animation: ask-avatar-pulse 0.9s var(--spring) 1; }
.msg.is-pulse .msg-avatar-wrap::after { animation: ask-ring 1s var(--ease) 1; }
@keyframes ask-avatar-pulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes ask-ring {
  0% { opacity: 0.85; transform: scale(0.8); }
  100% { opacity: 0; transform: scale(1.8); }
}

/* thinking: three bouncing dots */
.dots { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 2px; }
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange-hi);
  animation: ask-dot 1s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ask-dot {
  0%, 80%, 100% { transform: translate3d(0, 0, 0); opacity: 0.35; }
  40% { transform: translate3d(0, -6px, 0); opacity: 1; }
}

/* streaming: a blinking caret at the end of the text, removed when the reply is done */
.caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: -0.16em;
  border-radius: 2px;
  background: var(--orange-hi);
  animation: ask-caret 1s steps(1, end) infinite;
}
@keyframes ask-caret {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

/* ---------- composer: one pill, text on the left, round send or stop on the right ---------- */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 6px 6px 6px 16px;
  border-radius: 26px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.42);
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.composer:focus-within {
  border-color: var(--border-warm);
  box-shadow: 0 0 0 4px rgba(255, 122, 0, 0.14);
}
.chat.is-busy .composer { border-color: rgba(255, 122, 0, 0.3); }

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 48px;
  max-height: calc(1.45em * 5 + 24px);
  padding: 12px 0;
  resize: none;
  overflow-y: hidden;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--cream);
  font: inherit;
  font-size: 16px; /* 16 px stops iOS from zooming in */
  line-height: 1.45;
}
.composer textarea::placeholder { color: var(--faint); opacity: 1; }
/* the pill shows focus, so the textarea itself draws no ring */
.composer textarea:focus,
.composer textarea:focus-visible { outline: 0; box-shadow: none; border-radius: 0; }

.send-btn {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--orange-hi), var(--orange));
  color: var(--orange-ink);
  box-shadow: var(--shadow-glow);
  cursor: pointer;
  transition: transform 0.25s var(--ease), background 0.3s, box-shadow 0.3s, opacity 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.send-btn:hover:not(:disabled) { transform: translateY(-1px) scale(1.05); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.send-btn svg {
  grid-area: 1 / 1;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.25s, transform 0.35s var(--spring);
}
.send-btn:focus-visible { border-radius: 50%; }
.send-btn .icon-stop {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: none;
  opacity: 0;
  transform: scale(0.5);
}
.send-btn.is-stop .icon-send { opacity: 0; transform: translateY(-8px) scale(0.6); }
.send-btn.is-stop .icon-stop { opacity: 1; transform: none; }
.send-btn svg { position: relative; }
/* while the chonk talks, Stop breathes: a halo that scales and fades (transform and opacity only) */
.send-btn::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 122, 0, 0.5), rgba(255, 122, 0, 0) 72%);
  opacity: 0;
  pointer-events: none;
}
.send-btn.is-stop { background: linear-gradient(180deg, #ffd3a6, var(--orange-hi)); }
.send-btn.is-stop::before { animation: ask-halo 1.6s ease-in-out infinite; }
@keyframes ask-halo {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.12); }
}

.composer-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding-inline: 6px;
}
.chat-note { font-size: 12px; line-height: 1.4; color: var(--faint); min-width: 0; }
.chat-count {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}
.chat-count.is-warn { color: var(--orange-hi); }
.chat-count.is-max { color: var(--danger); }

/* the floating companion stays out of the chat */
body:has(#chat-form) .pet-dock,
body:has(#chat-form) .pet-panel { display: none !important; }

/* short screens (small phones, landscape): the empty state keeps its four cards in view */
@media (max-height: 720px) {
  .ask-hero-lede,
  .ask-card-kicker { display: none; }
  .ask-hero-cat {
    width: clamp(88px, 15vh, 120px);
    width: clamp(88px, 15dvh, 120px);
  }
  .ask-empty { gap: 8px; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .ask-page { --pad: 10px; }
  .chat { gap: 10px; }
  .chat-title { font-size: 18px; }
  .chat-avatar-wrap { width: 40px; height: 40px; }
  .chat-avatar { width: 40px; height: 40px; }
  .msg { max-width: 94%; }
  .msg-body { font-size: 15px; padding: 10px 14px; }
  .ask-card { min-height: 62px; padding: 10px 12px; font-size: 13.5px; }
}

@media (max-width: 380px) {
  .ask-card { padding: 10px 10px; font-size: 13px; }
  .chat-note { font-size: 11.5px; }
}

/* very narrow phones: the New chat label becomes an icon with a screen-reader name */
@media (max-width: 359px) {
  .chat-new { width: 40px; height: 40px; padding: 0; justify-content: center; }
  .chat-new-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .ask-orb,
  .chat-avatar,
  .ask-hero-cat,
  .ask-card,
  .msg.is-new,
  .msg.is-pulse .msg-avatar,
  .msg.is-pulse .msg-avatar-wrap::after,
  .chat-new::after,
  .send-btn.is-stop::before,
  .dots i,
  .caret { animation: none !important; }
  .ask-card,
  .msg.is-new { opacity: 1; transform: none; }
  .caret { opacity: 1; }
  .ask-card:hover { transform: none; }
}
