* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #071c1a;
  color: #f5f7f6;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.page {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #08211f;
}

#avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

#avatarVideo {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #04101d;
}

#avatarVideo[hidden],
#avatar[hidden],
#answerVideo[hidden] {
  display: none !important;
}

#answerVideo {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: #000000;
}

#avatar:active {
  cursor: grabbing;
}

.incoming-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(76px, 15vh, 140px);
  padding: calc(28px + env(safe-area-inset-top)) 32px calc(28px + env(safe-area-inset-bottom));
  background: #000000;
}

.incoming-layer[hidden] {
  display: none !important;
}

.page.voice-call {
  background: #000000;
}

.page.voice-call #avatar,
.page.voice-call #avatarVideo,
.page.voice-call #answerVideo {
  display: none !important;
}

.page.intro-playing .message-layer,
.page.intro-playing .bottom-layer {
  display: none !important;
}

.page.clean-call .message-layer,
.page.clean-call .toast {
  display: none !important;
}

.page.clean-call .top-bar {
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.page.clean-call .signal-dot,
.page.clean-call .identity p {
  display: none !important;
}

.page.clean-call .identity {
  flex: 0 0 auto;
}

.page.clean-call .identity h1 {
  color: #ffffff;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.72);
}

.incoming-layer.answering .incoming-avatar,
.incoming-layer.answering .incoming-button.accept {
  animation: incoming-pulse 1s ease-in-out infinite;
}

.incoming-layer.answering .incoming-button:disabled {
  opacity: 0.78;
}

@keyframes incoming-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.035);
  }
}

.incoming-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.incoming-avatar {
  position: relative;
  width: min(132px, 31vw);
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(155deg, #123f3a, #071c1a);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 24px 58px rgba(0, 0, 0, 0.65);
}

.incoming-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.incoming-avatar span {
  color: #f5f7f6;
  font-size: clamp(46px, 12vw, 60px);
  font-weight: 600;
}

.incoming-profile h2 {
  margin: 28px 0 0;
  color: #ffffff;
  font-size: clamp(24px, 6vw, 31px);
  line-height: 1.2;
  letter-spacing: 0;
}

.incoming-profile p {
  margin: 9px 0 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: 14px;
  line-height: 1.3;
}

.incoming-actions {
  width: min(340px, 84vw);
  display: flex;
  justify-content: space-between;
}

.incoming-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.incoming-action > span {
  color: #ffffff;
  font-size: 13px;
  line-height: 1;
}

.incoming-button {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  transition: transform 140ms ease, filter 140ms ease;
}

.incoming-button:active {
  transform: scale(0.94);
}

.incoming-button svg {
  width: 30px;
  height: 30px;
  stroke-width: 2.1;
}

.incoming-button.decline {
  background: linear-gradient(180deg, #ff5b52 0%, #e4322b 100%);
  box-shadow: 0 14px 34px rgba(228, 50, 43, 0.42);
}

.incoming-button.accept {
  background: linear-gradient(180deg, #46d877 0%, #28a84c 100%);
  box-shadow: 0 14px 34px rgba(40, 168, 76, 0.38);
}

.voice-answer-button {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: calc(30px + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 4px;
  color: rgba(255, 255, 255, 0.76);
  background: transparent;
  font-size: 13px;
  line-height: 1;
}

.voice-answer-button:active {
  color: #ffffff;
}

.voice-answer-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.top-bar {
  position: absolute;
  z-index: 2;
  top: calc(20px + env(safe-area-inset-top));
  left: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.signal-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f76f68;
  box-shadow: 0 0 12px rgba(247, 111, 104, 0.75);
}

.signal-dot.online {
  background: #59d9a9;
  box-shadow: 0 0 12px rgba(89, 217, 169, 0.75);
}

.identity {
  min-width: 0;
  flex: 1;
}

.identity h1 {
  margin: 0;
  font-size: clamp(21px, 4vw, 30px);
  line-height: 1.2;
  letter-spacing: 0;
}

.identity p {
  margin: 4px 0 0;
  color: rgba(245, 247, 246, 0.74);
  font-size: 13px;
  line-height: 1.3;
}

.role-switch {
  flex: 0 1 auto;
  display: flex;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(4, 18, 18, 0.66);
  overflow: hidden;
}

.role-option {
  min-width: 54px;
  padding: 8px 10px;
  border-radius: 6px;
  color: rgba(245, 247, 246, 0.7);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  transition: background 160ms ease, color 160ms ease;
}

.role-option.active {
  background: rgba(89, 217, 169, 0.24);
  color: #ffffff;
}

.message-layer {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(184px + env(safe-area-inset-bottom));
  width: min(720px, calc(100% - 36px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.transcript,
.subtitle {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(4, 18, 18, 0.7);
  backdrop-filter: blur(14px);
}

.transcript span {
  display: block;
  color: rgba(245, 247, 246, 0.55);
  font-size: 11px;
  line-height: 1.2;
}

.transcript p,
.subtitle p {
  margin: 5px 0 0;
  font-size: 16px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.bottom-layer {
  position: absolute;
  z-index: 2;
  left: 22px;
  right: 22px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
  flex-direction: column-reverse;
}

.call-controls {
  position: relative;
  width: min(430px, 100%);
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
}

.round-button {
  width: 64px;
  height: 64px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.13);
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}

.round-button:active {
  transform: scale(0.94);
}

.round-button svg {
  width: 25px;
  height: 25px;
  stroke-width: 2;
}

.mic-button {
  justify-self: center;
}

.icon-pair {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-pair > svg + svg {
  display: none;
}

.icon-pair.show-alternative > svg:first-child {
  display: none;
}

.icon-pair.show-alternative > svg + svg {
  display: block;
}

.end-button {
  justify-self: center;
  width: 78px;
  height: 78px;
  border-color: transparent;
  background: linear-gradient(180deg, #ff5b52 0%, #e4322b 100%);
  box-shadow: 0 12px 32px rgba(228, 50, 43, 0.42);
}

.end-button svg {
  width: 30px;
  height: 30px;
  stroke-width: 2.2;
}

#muteButton {
  justify-self: center;
}

.mic-button.listening {
  border-color: #ffb2ac;
  background: #f76f68;
  box-shadow: 0 0 26px rgba(247, 111, 104, 0.35);
}

.toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: calc(174px + env(safe-area-inset-bottom));
  max-width: calc(100% - 36px);
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(18, 25, 31, 0.92);
  color: #ffffff;
  font-size: 13px;
  line-height: 1.4;
  transform: translateX(-50%);
}

.page.role-ultraman,
.page.role-ultraman .transcript,
.page.role-ultraman .subtitle {
  border-color: rgba(105, 201, 255, 0.22);
  background: #071b33;
}

.page.role-ultraman .transcript,
.page.role-ultraman .subtitle,
.page.role-ultraman .role-switch {
  background: rgba(5, 16, 31, 0.72);
}

.page.role-ultraman .signal-dot.online {
  background: #69c9ff;
  box-shadow: 0 0 12px rgba(105, 201, 255, 0.75);
}

.page.role-ultraman .identity h1 {
  text-shadow: 0 0 18px rgba(105, 201, 255, 0.45);
}

.page.role-ultraman .role-option.active {
  background: rgba(105, 201, 255, 0.24);
}

.page.role-ultraman .mic-button.listening {
  border-color: #ff98a2;
  background: #ff5364;
  box-shadow: 0 0 26px rgba(255, 83, 100, 0.35);
}

@media (max-width: 520px) {
  .call-controls {
    grid-template-columns: 60px 1fr 60px;
  }

  .round-button {
    width: 60px;
    height: 60px;
  }

  .end-button {
    width: 72px;
    height: 72px;
  }
}

@media (max-width: 520px) {
  .role-option {
    min-width: 50px;
    padding: 7px 8px;
  }

  .message-layer {
    bottom: calc(194px + env(safe-area-inset-bottom));
  }

  .transcript p,
  .subtitle p {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}
