/* JAI'S PHONE in-thread keyboard: no native input and no viewport resize on iOS Safari. */
.line-thread {
  --jai-keyboard-size: 300px;
  --jai-kbd-height: 0px;
}
.line-thread.jai-virtual-keyboard-open {
  --jai-kbd-height: var(--jai-keyboard-size);
}
.line-thread .compose-field {
  position: relative;
}
.line-thread .compose-field [data-chat-draft] {
  pointer-events: none !important;
  caret-color: transparent !important;
}
.line-thread .jai-virtual-composer {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  cursor: text;
  background: transparent;
  border: 0;
  touch-action: manipulation;
  width: 100%;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}
.line-thread .thread-compose-zone {
  transition: bottom 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
.line-thread .thread-messages {
  transition: bottom 0.38s cubic-bezier(0.32, 0.72, 0, 1);
  overscroll-behavior: contain;
}
#jai-fake-keyboard {
  position: absolute;
  z-index: 7;
  bottom: 0;
  left: 0;
  right: 0;
  height: 300px;
  box-sizing: border-box;
  color: #000;
  overflow: visible;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  animation: jai-source-kbd-open 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
#jai-fake-keyboard .jai-kin {
  height: 300px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 8px 3px 12px;
  box-sizing: border-box;
}
#jai-fake-keyboard .jai-kr {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 3px;
  min-width: 0;
}
#jai-fake-keyboard .jai-key {
  display: grid;
  place-items: center;
  position: relative;
  flex: 1;
  min-width: 0;
  max-width: 36px;
  height: 43px;
  background: #fff;
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.33);
  font-size: 19px;
  line-height: 1;
  transition:
    background 0.08s,
    transform 0.08s;
}
#jai-fake-keyboard .jai-key.sp {
  background: #abb0bb;
  max-width: 45px;
  font-size: 17px;
}
#jai-fake-keyboard .jai-key.wide {
  max-width: none;
  flex: 5;
  font-size: 15px;
}
#jai-fake-keyboard .jai-key.ret {
  max-width: none;
  flex: 2.2;
  background: #abb0bb;
  font-size: 15px;
}
#jai-fake-keyboard .jai-key-pressed {
  background: #abb0bb;
  transform: translateY(1px);
}
#jai-fake-keyboard .jai-key-label {
  display: grid;
  place-items: center;
  line-height: 1;
}
#jai-fake-keyboard .jai-key-preview {
  display: none;
  position: absolute;
  bottom: calc(100% - 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 49px;
  height: 58px;
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 2px 6px #0004;
  font-size: 32px;
  line-height: 1;
  place-items: center;
  pointer-events: none;
}
#jai-fake-keyboard .jai-key-preview::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 9px;
  background: #fff;
  border-radius: 0 0 5px 5px;
}
#jai-fake-keyboard .jai-key-pressed {
  z-index: 2;
}
#jai-fake-keyboard .jai-key-pressed .jai-key-preview {
  display: grid;
}
#jai-fake-keyboard .jai-kr > .jai-key:first-child .jai-key-preview {
  left: 0;
  transform: none;
}
#jai-fake-keyboard .jai-kr > .jai-key:last-child .jai-key-preview {
  left: auto;
  right: 0;
  transform: none;
}
#jai-fake-keyboard .jai-kbot {
  display: flex;
  justify-content: space-between;
  font-size: 20px;
}
@keyframes jai-source-kbd-open {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}
.jai-bubble-pop {
  animation: jai-bubble-enter 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes jai-bubble-enter {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}
.jai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  width: max-content;
  padding: 11px 14px;
  margin: 9px 0;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 15px;
}
.jai-typing-indicator span {
  height: 7px;
  width: 7px;
  background: #a2a6ac;
  border-radius: 50%;
  animation: jai-typing-dot 1.2s infinite;
}
.jai-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}
.jai-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes jai-typing-dot {
  0%,
  60%,
  100% {
    opacity: 0.45;
    transform: none;
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}
@media (prefers-reduced-motion: reduce) {
  #jai-fake-keyboard,
  .jai-bubble-pop,
  .jai-typing-indicator span {
    animation: none;
  }
  .line-thread .thread-compose-zone,
  .line-thread .thread-messages {
    transition: none;
  }
}

/* Decorative keys are noninteractive. The composer overlay is the sole trigger. */
#jai-fake-keyboard,
#jai-fake-keyboard * {
  pointer-events: none !important;
}

/* Safari-safe layout: the messages, composer and visual keyboard are sequential
   flex children. Neither the composer nor the message scroller is absolutely
   positioned over the keyboard. */
.line-thread.jai-virtual-keyboard-open {
  display: flex !important;
  flex-direction: column !important;
}
.line-thread .thread-messages {
  bottom: auto !important;
  min-height: 0;
  flex: 1 1 auto !important;
}
.line-thread .thread-compose-zone {
  bottom: auto !important;
  position: relative !important;
  flex: 0 0 auto !important;
  z-index: 8;
}
.line-thread #jai-fake-keyboard {
  position: relative !important;
  inset: auto !important;
  flex: 0 0 var(--jai-keyboard-size) !important;
  height: var(--jai-keyboard-size) !important;
  min-height: var(--jai-keyboard-size);
  order: 3;
  z-index: 9;
}
.line-thread.jai-virtual-keyboard-open .thread-compose-zone {
  order: 2;
}
.line-thread.jai-virtual-keyboard-open .thread-messages {
  order: 1;
  padding-bottom: 16px !important;
}
.line-thread.jai-virtual-keyboard-open .thread-compose-zone .compose-send {
  z-index: 9;
  position: relative;
  pointer-events: auto;
}

/* Once the Episode is finished, keys can be tapped for haptic-like visual feedback. */
.line-thread.jai-keyboard-toy #jai-fake-keyboard,
.line-thread.jai-keyboard-toy #jai-fake-keyboard .jai-key {
  pointer-events: auto !important;
  touch-action: manipulation;
  cursor: pointer;
}
.line-thread.jai-keyboard-toy #jai-fake-keyboard .jai-kin {
  pointer-events: auto !important;
}

/* The keyboard owns the Home-indicator area when open. Keep the composer
   immediately above it rather than reserving a second bottom safe area. */
.line-thread.jai-virtual-keyboard-open .thread-compose-zone {
  padding-bottom: 10px;
}
.line-thread #jai-fake-keyboard .jai-kin {
  height: 100%;
}
@media (max-height: 640px) {
  .line-thread {
    --jai-keyboard-size: 236px;
  }
  .line-thread .thread-toolbar {
    height: 99px;
    min-height: 99px;
    padding-top: 50px;
  }
  .line-thread #jai-fake-keyboard .jai-kin {
    gap: 7px;
    padding-top: 7px;
  }
  .line-thread #jai-fake-keyboard .jai-key {
    height: 36px;
  }
  .line-thread #jai-fake-keyboard .jai-kbot {
    padding-top: 0;
    font-size: 18px;
  }
}

/* Monochrome keyboard controls rather than colored emoji. */
#jai-fake-keyboard {
  background: #dfe0e5;
}
#jai-fake-keyboard .jai-key.sp,
#jai-fake-keyboard .jai-key.ret {
  background: #fff;
  color: #000;
}
#jai-fake-keyboard .jai-key-label svg {
  width: 24px;
  height: 24px;
}
#jai-fake-keyboard .jai-key.ret svg {
  width: 29px;
  height: 29px;
}
#jai-fake-keyboard .jai-kbot {
  color: #000;
  padding: 6px 20px 0;
}
#jai-fake-keyboard .jai-kbot svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

/* Render Thai as native HTML text, matching the reference keyboard approach. */
#jai-fake-keyboard .jai-key-label {
  overflow: visible;
  line-height: 1.6;
  white-space: pre;
}
#jai-fake-keyboard {
  contain: layout style;
  isolation: isolate;
}
body:not(:has(.line-thread.jai-virtual-keyboard-open)) #jai-fake-keyboard {
  display: none;
}
