:root {
  --bg: #0d0c10;
  --panel: #141218;
  --panel-2: #191620;
  --line: rgba(255, 255, 255, 0.08);
  --text: #ece7e4;
  --muted: #9b939b;
  --accent: #e0485e;
  --accent-2: #d9a964;
  --sage: #8fae9b;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

button,
textarea {
  font-family: inherit;
}

.live {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  width: 100%;
  height: 100%;
}

/* 3D 舞台 */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.01) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #16131a 0%, #100e14 70%, #0c0b0f 100%);
}

#stage3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: none;
}

.portrait-fallback {
  display: block;
  position: absolute;
  left: 50%;
  bottom: 4%;
  transform: translateX(-50%);
  max-width: 88%;
  max-height: 88%;
  object-fit: contain;
  z-index: 1;
  filter: saturate(0.95) contrast(1.03);
  animation: idleFloat 5.2s ease-in-out infinite;
}

.no-webgl #stage3d {
  display: none;
}

.model-ready .portrait-fallback {
  display: none;
}

.no-webgl .stage.speaking .portrait-fallback {
  animation: speakFloat 0.85s ease-in-out infinite;
}

@keyframes idleFloat {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-8px);
  }
}

@keyframes speakFloat {
  0%,
  100% {
    transform: translateX(-50%) translateY(-2px);
  }
  50% {
    transform: translateX(-50%) translateY(-11px);
  }
}

.stage-info {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 0 24px 24px;
  pointer-events: none;
  background: linear-gradient(0deg, rgba(13, 12, 16, 0.78), transparent 70%);
}

.stage-corner {
  position: absolute;
  top: 18px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 118px;
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(13, 12, 16, 0.58);
  backdrop-filter: blur(8px);
  pointer-events: none;
}

.stage-corner span {
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--muted);
  white-space: nowrap;
}

.stage-corner strong {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.stage-corner--left {
  left: 18px;
  border-left: 2px solid var(--accent);
}

.stage-corner--right {
  right: 18px;
  text-align: right;
  border-right: 2px solid var(--sage);
}

.kicker {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--accent);
}

.name-plate h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
}

.epithet {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.live-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

.wave {
  display: none;
  gap: 3px;
  align-items: center;
  height: 16px;
}

.stage.speaking .wave {
  display: inline-flex;
}

.wave i {
  width: 3px;
  height: 6px;
  border-radius: 2px;
  background: var(--accent);
  animation: waveBar 0.7s ease-in-out infinite;
}

.wave i:nth-child(2) {
  animation-delay: 0.1s;
}

.wave i:nth-child(3) {
  animation-delay: 0.2s;
}

.wave i:nth-child(4) {
  animation-delay: 0.3s;
}

.wave i:nth-child(5) {
  animation-delay: 0.4s;
}

@keyframes waveBar {
  0%,
  100% {
    height: 5px;
  }
  50% {
    height: 15px;
  }
}

/* 侧边聊天 */
.side {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.008) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #131117 0%, #0e0d12 100%);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.head-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.head-title h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.head-title p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 3px rgba(143, 174, 155, 0.14);
}

.status-dot.offline {
  background: #c96b62;
  box-shadow: 0 0 0 3px rgba(201, 107, 98, 0.14);
}

.head-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.icon-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.04);
}

.icon-btn.active {
  color: #fff;
  border-color: var(--accent);
  background: rgba(224, 72, 94, 0.16);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 8px;
}

.bubble {
  position: relative;
  max-width: 100%;
  padding: 10px 13px 11px;
  border-radius: 8px;
  line-height: 1.68;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise 0.24s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.bubble.user {
  align-self: flex-end;
  background: #2a161d;
  border: 1px solid rgba(224, 72, 94, 0.24);
  border-top-right-radius: 2px;
}

.bubble.bot {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-left: 2px solid var(--accent);
  border-top-left-radius: 2px;
}

.bubble.error {
  border-left-color: #c96b62;
  color: #d8b8b2;
}

.who-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

.who {
  font-size: 12px;
  color: var(--muted);
}

.bubble.user .who {
  color: #d9949e;
}

.mini-play {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.mini-play:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.22);
}

.mini-play.speaking {
  color: #fff;
  border-color: var(--accent);
  background: rgba(224, 72, 94, 0.16);
}

.content {
  min-height: 1em;
}

.wait-hint {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  animation: pulse 1.6s ease-in-out infinite;
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 7px 0 3px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite both;
}

.typing i:nth-child(2) {
  animation-delay: 0.18s;
}

.typing i:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes blink {
  0%,
  70%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  background: #17141a;
  color: var(--text);
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 14px;
  line-height: 1.5;
  min-height: 46px;
  max-height: 130px;
  outline: none;
  transition: border-color 0.15s ease;
}

.composer textarea:focus {
  border-color: rgba(224, 72, 94, 0.55);
}

.composer textarea::placeholder {
  color: #6f6870;
}

.send-btn {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.send-btn:hover {
  background: #f05a70;
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(10, 9, 13, 0.66);
}

.modal-mask[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(300px, 86vw);
  background: #17141a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px 20px 20px;
  text-align: center;
}

.modal-wide {
  width: min(680px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  text-align: left;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
}

.modal-wide::-webkit-scrollbar {
  width: 8px;
}

.modal-wide::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 8px;
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
}

.modal img {
  display: block;
  width: 210px;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 6px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.22);
}

.share-hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--muted);
  word-break: break-all;
}

.share-copy {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
}

.share-copy:hover {
  border-color: rgba(224, 72, 94, 0.5);
}

.share-qr {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.profile-modal {
  padding: 24px 24px 22px;
}

.profile-header {
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.profile-header h2 {
  margin: 0;
  font-size: 20px;
}

.profile-sub {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0 16px;
}

.profile-item {
  min-width: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.profile-item span {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--muted);
}

.profile-item strong {
  display: block;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  word-break: break-word;
}

.profile-sections {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.profile-lore {
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.profile-lore h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

.profile-lore p {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.profile-lore p:last-child {
  margin-bottom: 0;
}

.lore-line {
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.lore-line:last-child {
  border-bottom: 0;
}

.lore-line b {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
  color: var(--sage);
}

.lore-line p {
  margin: 0;
}

.fight-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.fight-row:last-of-type {
  border-bottom: 0;
}

.fight-row span {
  flex: none;
  font-size: 12px;
  color: var(--muted);
}

.fight-row strong {
  min-width: 0;
  font-size: 12px;
  text-align: right;
  color: var(--text);
  word-break: break-word;
}

.fight-note {
  margin: 9px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.profile-quote {
  margin: 16px 0 10px;
  padding: 0 10px;
  text-align: center;
  font-size: 16px;
  color: var(--text);
  border: 0;
}

.profile-note {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.mode-2d #stage3d {
  display: none;
}

.mode-2d .portrait-fallback {
  display: block;
  translate: var(--px, 0px) var(--py, 0px);
}

.share-qr canvas,
.share-qr img {
  border-radius: 6px;
}

@media (max-width: 860px) {
  .live {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh minmax(0, 1fr);
  }

  .stage {
    border-bottom: 1px solid var(--line);
  }

  .stage-info {
    padding: 0 16px 12px;
  }

  .stage-corner {
    top: 10px;
    min-width: 0;
    padding: 7px 9px;
  }

  .stage-corner--left {
    left: 10px;
  }

  .stage-corner--right {
    right: 10px;
  }

  .stage-corner span,
  .stage-corner strong {
    font-size: 10px;
    letter-spacing: 0.08em;
  }

  .name-plate h1 {
    font-size: 26px;
  }

  .side {
    border-left: none;
  }

  .chat-head {
    padding: 10px 14px;
  }

  .messages {
    padding: 14px 12px 18px;
  }

  .composer {
    padding: 10px 12px 12px;
  }

  .profile-modal {
    padding: 18px 14px 16px;
  }

  .profile-header h2 {
    font-size: 17px;
  }

  .profile-grid {
    grid-template-columns: 1fr;
  }
}

/* 流畅度优化 */
html {
  scroll-behavior: smooth;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.bubble {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.bubble:hover {
  transform: translateY(-1px);
}

.messages {
  scroll-behavior: smooth;
}

.modal-mask:not([hidden]) {
  animation: fadeIn 0.18s ease;
}

.modal {
  animation: modalIn 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.icon-btn,
.share-copy {
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.icon-btn:hover,
.share-copy:hover {
  transform: translateY(-1px);
}

.send-btn {
  transition: background 0.18s ease, opacity 0.18s ease, transform 0.18s ease;
}

.send-btn:hover {
  transform: translateY(-1px);
}

.stage::before {
  transition: background 0.6s ease;
}

.portrait-fallback {
  opacity: 1;
  transition: opacity 0.6s ease;
}
