.temoto-chat {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 130;
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", sans-serif;
  color: #1a1a1a;
}

.temoto-chat,
.temoto-chat * {
  box-sizing: border-box;
}

.temoto-chat__bubble {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: max-content;
  max-width: calc(100vw - 32px);
  white-space: nowrap;
  padding: 8px 12px;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 18px 54px rgba(0, 0, 0, .14);
  font-size: 14px;
  line-height: 1.5;
}

.temoto-chat__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 58px;
  padding: 12px 18px;
  border: 1px solid #1a1a1a;
  border-radius: 2px;
  background: #1a1a1a;
  color: #fff;
  box-shadow: 0 18px 52px rgba(0, 0, 0, .18);
  font-weight: 900;
  cursor: pointer;
}

.temoto-chat__mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #fff;
  color: #1a1a1a;
  font-size: 14px;
  line-height: 1;
}

.temoto-chat__panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto;
  width: min(380px, calc(100vw - 32px));
  max-height: min(640px, calc(100vh - 112px));
  overflow: hidden;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.temoto-chat.is-open .temoto-chat__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.temoto-chat.is-open .temoto-chat__bubble {
  display: none;
}

.temoto-chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid #cfcfcf;
}

.temoto-chat__title {
  margin: 0;
  font-family: "Shippori Mincho", "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.temoto-chat__close {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid #1a1a1a;
  border-radius: 2px;
  background: #fff;
  color: #1a1a1a;
  cursor: pointer;
}

.temoto-chat__log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.temoto-chat__msg {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 2px;
  white-space: pre-wrap;
  font-size: 16px;
  line-height: 1.8;
}

.temoto-chat__msg--model {
  align-self: flex-start;
  background: #f2f1ec;
  border: 1px solid #cfcfcf;
}

.temoto-chat__msg--user {
  align-self: flex-end;
  background: #1a1a1a;
  border: 1px solid #1a1a1a;
  color: #fff;
}

.temoto-chat__typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.temoto-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #1a1a1a;
  animation: temoto-chat-typing 900ms ease-in-out infinite;
}

.temoto-chat__typing span:nth-child(2) {
  animation-delay: 120ms;
}

.temoto-chat__typing span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes temoto-chat-typing {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.temoto-chat__form {
  padding: 12px;
  border-top: 1px solid #cfcfcf;
}

.temoto-chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.temoto-chat__chip {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #1a1a1a;
  border-radius: 2px;
  background: #fff;
  color: #1a1a1a;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.temoto-chat__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.temoto-chat__input {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid #cfcfcf;
  border-radius: 2px;
  background: #fff;
  color: #1a1a1a;
  font-size: 16px;
}

.temoto-chat__send {
  min-width: 62px;
  min-height: 44px;
  border: 0;
  border-radius: 2px;
  background: #1a1a1a;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.temoto-chat__note {
  margin: 8px 0 0;
  color: #5c5c5c;
  font-size: 16px;
  line-height: 1.8;
}

.temoto-chat__toggle:hover,
.temoto-chat__close:hover,
.temoto-chat__chip:hover,
.temoto-chat__send:hover {
  background: #3a3a3a;
  border-color: #3a3a3a;
  color: #fff;
}

@media (max-width: 560px) {
  .temoto-chat {
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    justify-content: flex-end;
    padding: 0 12px 12px;
    pointer-events: none;
  }

  .temoto-chat > * {
    pointer-events: auto;
  }

  .temoto-chat__panel {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(82vh, 680px);
    border-radius: 2px 2px 0 0;
  }

  .temoto-chat__bubble {
    right: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .temoto-chat__panel,
  .temoto-chat__typing span {
    transition: none !important;
    animation: none !important;
  }
}
