:root {
  color-scheme: light;
  --ink: #103c50;
  --ink-soft: #54727d;
  --sea: #1ca9c1;
  --sea-deep: #087b9d;
  --foam: #fffef9;
  --glass: rgba(232, 252, 248, 0.94);
  --coral: #ff825f;
  font-family: Inter, ui-rounded, "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: transparent;
}

body {
  position: relative;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(255, 130, 95, 0.48);
  outline-offset: 3px;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.agent-widget {
  position: fixed;
  z-index: 20;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 286px;
  height: 390px;
  user-select: none;
  -webkit-user-select: none;
}

html[data-shell-tide-embedded="true"] .agent-widget {
  width: 228.8px;
  height: 312px;
}

html[data-shell-tide-embedded="true"] .agent-expanded {
  width: 286px;
  height: 390px;
  transform: scale(0.8);
  transform-origin: left top;
}

html[data-shell-tide-embedded="true"] .agent-widget.is-collapsed {
  width: 46.4px;
  height: 46.4px;
}

html[data-shell-tide-embedded="true"] .collapsed-avatar {
  width: 46.4px;
  height: 46.4px;
}

html[data-shell-tide-embedded="true"] .chat-dialog {
  zoom: 0.8;
}

.agent-expanded {
  position: relative;
  width: 100%;
  height: 100%;
}

.collapse-button {
  position: absolute;
  z-index: 8;
  top: 72px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1.5px solid rgba(16, 60, 80, 0.24);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 12px rgba(8, 79, 99, 0.14);
}

.collapse-button svg,
.agent-icon-button svg,
.chat-close svg,
.send-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.collapse-button svg {
  width: 15px;
  height: 15px;
}

.manga-bubble {
  position: absolute;
  z-index: 6;
  isolation: isolate;
  top: 4px;
  left: 8px;
  width: 248px;
  min-height: 64px;
  padding: 13px 17px;
  border: 2px solid var(--ink);
  border-radius: 22px 22px 22px 8px;
  color: var(--ink);
  background: rgba(255, 254, 249, 0.97);
  box-shadow: 4px 5px 0 rgba(16, 60, 80, 0.13);
}

.manga-bubble::after {
  position: absolute;
  pointer-events: none;
  content: "";
  z-index: -1;
  bottom: -13px;
  left: 42px;
  width: 24px;
  height: 24px;
  border-bottom: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
  background: rgba(255, 254, 249, 0.97);
  transform: rotate(-45deg) skew(-8deg, -8deg);
  transform-origin: center;
}

.manga-bubble p {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.91rem;
  font-weight: 720;
  line-height: 1.35;
}

.avatar-stage {
  position: absolute;
  z-index: 2;
  top: 76px;
  left: 23px;
  width: 240px;
  height: 270px;
  cursor: grab;
  touch-action: none;
}

.agent-widget.is-dragging .avatar-stage,
.agent-widget.is-dragging .collapsed-avatar {
  cursor: grabbing;
}

.avatar-stage::after {
  position: absolute;
  z-index: -1;
  right: 23px;
  bottom: 15px;
  left: 23px;
  height: 18px;
  border: 2px solid rgba(32, 183, 198, 0.32);
  border-radius: 50%;
  content: "";
}

.avatar-fallback,
.avatar-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.avatar-fallback[hidden] {
  display: none;
}

.agent-controls {
  position: absolute;
  z-index: 7;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.agent-icon-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #28bdd0, #0785aa);
  box-shadow: 0 6px 16px rgba(7, 87, 109, 0.24), inset 0 0 0 1px rgba(5, 92, 118, 0.38);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.agent-icon-button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.04);
}

.agent-icon-button:active:not(:disabled) {
  transform: translateY(1px) scale(0.97);
}

.mic-button {
  background: linear-gradient(145deg, #ff9a72, var(--coral));
  box-shadow: 0 6px 16px rgba(163, 68, 43, 0.22), inset 0 0 0 1px rgba(156, 66, 42, 0.32);
}

.realtime-voice-button {
  color: #f8fffd;
  background: linear-gradient(145deg, #7fcfd0, #3b9cb4);
  box-shadow: 0 6px 16px rgba(7, 87, 109, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.realtime-voice-button::after {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 8px;
  height: 8px;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  background: #7f98a2;
  content: "";
}

.realtime-voice-button.is-on {
  background: linear-gradient(145deg, #34d6b9, #0799b9);
  box-shadow: 0 0 0 5px rgba(42, 212, 191, 0.14), 0 6px 16px rgba(7, 87, 109, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.realtime-voice-button.is-on::after {
  background: #ffcf58;
  animation: realtime-dot-blink 900ms ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(255, 207, 88, 0.52);
}

.mic-button.is-recording {
  animation: mic-pulse 1s ease-in-out infinite;
}

.agent-icon-button:disabled {
  cursor: not-allowed;
  filter: grayscale(0.55);
  opacity: 0.58;
}

.agent-icon-button[hidden] {
  display: none;
}

.recording-timer {
  position: absolute;
  top: -25px;
  left: 50%;
  min-width: 54px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #8d3825;
  background: #fff1eb;
  font-size: 0.72rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
}

.agent-widget.is-collapsed {
  width: 58px;
  height: 58px;
}

.agent-widget.is-collapsed .agent-expanded {
  display: none;
}

.collapsed-avatar {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  padding: 3px;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.98);
  border-radius: 50%;
  background: linear-gradient(145deg, #e8fbf7, #9ce3df);
  box-shadow: 0 7px 20px rgba(7, 86, 108, 0.28), inset 0 0 0 1px rgba(8, 123, 157, 0.24);
  cursor: grab;
  touch-action: none;
}

.collapsed-avatar[hidden] {
  display: none;
}

.collapsed-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  pointer-events: none;
}

.chat-dialog {
  position: fixed;
  inset: auto max(18px, env(safe-area-inset-right)) max(82px, calc(env(safe-area-inset-bottom) + 76px)) auto;
  width: min(372px, calc(100vw - 24px));
  max-height: min(520px, calc(100dvh - 100px));
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  color: var(--ink);
  background: transparent;
}

.chat-dialog::backdrop {
  background: transparent;
}

.chat-card {
  display: grid;
  grid-template-rows: auto minmax(120px, 1fr) auto;
  max-height: inherit;
  overflow: hidden;
  border: 2px solid rgba(16, 60, 80, 0.75);
  border-radius: 22px 22px 8px 22px;
  background: var(--glass);
  box-shadow: 0 16px 45px rgba(7, 66, 83, 0.25), 4px 5px 0 rgba(16, 60, 80, 0.12);
  backdrop-filter: blur(14px);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 8px 10px 8px 12px;
  border-bottom: 1px solid rgba(16, 60, 80, 0.12);
  background: rgba(255, 255, 255, 0.56);
}

.chat-identity {
  display: flex;
  align-items: center;
  gap: 9px;
}

.chat-identity img {
  width: 42px;
  height: 42px;
  padding: 2px;
  border-radius: 50%;
  background: #c9f1ed;
  object-fit: contain;
}

.chat-identity span {
  display: grid;
}

.chat-identity strong {
  font-size: 0.93rem;
}

.chat-identity small {
  color: var(--ink-soft);
  font-size: 0.7rem;
}

.chat-close,
.send-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
}

.chat-close {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.75);
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-height: 180px;
  padding: 14px;
  overflow: auto;
  overscroll-behavior: contain;
  background: rgba(232, 252, 248, 0.84);
}

.message {
  display: grid;
  max-width: 84%;
}

.message p {
  margin: 0;
  padding: 9px 12px;
  border-radius: 15px;
  font-size: 0.85rem;
  line-height: 1.42;
}

.message > span {
  margin: 3px 7px 0;
  color: var(--ink-soft);
  font-size: 0.62rem;
}

.message-agent {
  align-self: flex-start;
}

.message-agent p {
  border: 1px solid rgba(8, 123, 157, 0.2);
  border-radius: 15px 15px 15px 5px;
  background: rgba(255, 255, 255, 0.92);
}

.message-player {
  align-self: flex-end;
}

.message-player p {
  border-radius: 15px 15px 5px 15px;
  color: #fff;
  background: linear-gradient(145deg, #20aec3, #087f9f);
}

.message-player > span {
  text-align: right;
}

.chat-composer {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(16, 60, 80, 0.12);
  background: rgba(255, 255, 255, 0.66);
}

.chat-composer textarea {
  width: 100%;
  max-height: 110px;
  min-height: 42px;
  padding: 10px 12px;
  resize: none;
  border: 1.5px solid rgba(16, 60, 80, 0.22);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.96);
  line-height: 1.35;
}

.chat-composer textarea::placeholder {
  color: #718b94;
}

.send-button {
  color: #fff;
  background: linear-gradient(145deg, #24b7c9, #087f9f);
}

.send-button:disabled,
.chat-composer textarea:disabled {
  cursor: wait;
  opacity: 0.6;
}

@keyframes mic-pulse {
  50% {
    box-shadow: 0 0 0 8px rgba(255, 130, 95, 0.16), 0 6px 16px rgba(163, 68, 43, 0.24);
    transform: scale(1.05);
  }
}

@keyframes realtime-dot-blink {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 207, 88, 0.5);
  }

  50% {
    opacity: 0.35;
    transform: scale(0.72);
    box-shadow: 0 0 0 5px rgba(255, 207, 88, 0.16);
  }
}

@media (max-width: 520px) {
  .agent-widget {
    right: 10px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .chat-dialog {
    inset: auto 8px max(78px, calc(env(safe-area-inset-bottom) + 70px)) 8px;
    width: auto;
    max-height: min(480px, calc(100dvh - 94px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .manga-bubble,
  .agent-icon-button,
  .collapsed-avatar,
  .chat-card {
    border: 2px solid CanvasText;
  }
}
