:root {
  --bg: #070b14;
  --panel: #0d1526;
  --line: #1c2a45;
  --accent: #ff4655;
  --gold: #ffb347;
  --cyan: #53c1ff;
  --text: #e9effd;
  --muted: #8396b8;
}

* { box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 560px at 50% -12%, #14233f 0%, var(--bg) 58%),
    var(--bg);
}

/* ---- 舞台：居中放一台“手机” ---- */
.stage {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--app-height, 100dvh);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.phone {
  position: relative;
  width: min(400px, 100%);
  height: min(820px, 92vh);
  background: linear-gradient(160deg, #2b303c, #0a0c12);
  border-radius: 44px;
  border: 1px solid #3a4152;
  box-shadow:
    0 0 0 9px #05070c,
    0 0 0 10px #2a3142,
    0 30px 60px rgba(0, 0, 0, .6);
  padding: 10px;
}

.notch {
  position: absolute;
  top: 17px;
  left: 50%;
  transform: translateX(-50%);
  width: 118px;
  height: 20px;
  background: #05070c;
  border-radius: 12px;
  z-index: 3;
}

.screen {
  width: 100%;
  height: 100%;
  border-radius: 34px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 12px 6px;
  background:
    radial-gradient(700px 360px at 50% -8%, #14233f 0%, var(--bg) 58%),
    var(--bg);
}
.screen.bg-iron {
  background:
    radial-gradient(820px 420px at 50% -10%, #3a0d12 0%, #15060a 58%),
    #0d0507;
}
.screen.bg-black {
  background: #05070c;
}
.screen.bg-space {
  background:
    radial-gradient(900px 500px at 50% -10%, #0a1a3a 0%, #040810 60%),
    #040810;
}
.screen.bg-iron .hud {
  background: linear-gradient(135deg, rgba(255, 70, 85, .2), rgba(60, 18, 24, .75));
  border-color: rgba(255, 179, 71, .32);
}
.screen.bg-black .hud {
  background: linear-gradient(135deg, rgba(45, 52, 62, .55), rgba(18, 22, 28, .85));
  border-color: rgba(255, 255, 255, .14);
}
.screen.bg-space .hud {
  background: linear-gradient(135deg, rgba(18, 45, 95, .6), rgba(8, 16, 36, .85));
  border-color: rgba(83, 193, 255, .24);
}

/* ---- 顶部 HUD ---- */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(35, 52, 90, .6), rgba(18, 28, 50, .85));
  border: 1px solid rgba(83, 193, 255, .22);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
.hud-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  border: 2px solid var(--gold);
  box-shadow: 0 0 12px rgba(255, 179, 71, .35);
}
.hud-avatar img,
.hud-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}
.hud-avatar img { object-fit: cover; }
body.speaking .hud-avatar {
  animation: avatarPulse 1s ease-in-out infinite;
}
@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 179, 71, .3); }
  50% { box-shadow: 0 0 20px rgba(255, 179, 71, .8); }
}
#personaBtn { margin-left: auto; }
#emojiBtn,
#micBtn {
  width: 34px;
  height: 34px;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#emojiBtn { font-size: 22px; }
#micBtn { font-size: 18px; }
#micBtn.recording {
  color: #ff6b6b;
  border-color: #ff6b6b;
  animation: micPulse 1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.arc {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  box-shadow: 0 0 18px rgba(255, 179, 71, .55), inset 0 0 10px rgba(255, 179, 71, .25);
  flex: 0 0 auto;
  animation: breathe 3s ease-in-out infinite;
}
.core {
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff7d9, var(--cyan) 45%, #0a4f80 100%);
  box-shadow: 0 0 14px var(--cyan);
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 14px rgba(255, 179, 71, .4), inset 0 0 8px rgba(255, 179, 71, .2); }
  50% { box-shadow: 0 0 30px rgba(255, 179, 71, .8), inset 0 0 16px rgba(255, 179, 71, .4); }
}

.title {
  flex: 1;
  min-width: 0;
}
.title h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--gold), #fff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
@font-face {
  font-family: 'SegoeScript';
  src: url('/fonts/segoe-script.ttf') format('truetype');
  font-display: swap;
}
.sub {
  margin: 2px 0 0;
  font-size: 15px;
  color: #ffd98a;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .4);
  letter-spacing: .5px;
  font-family: 'SegoeScript', "Segoe Script", "Savoye LET", cursive;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  cursor: pointer;
  transition: color .2s, text-shadow .2s;
}
.sub:hover {
  color: #ffe9b0;
  text-shadow: 0 1px 8px rgba(255, 200, 80, .55);
}
.sub:active {
  transform: scale(.98);
}

/* 说话时的声波指示 */
.voice {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 22px;
  padding-right: 4px;
}
.voice .bar {
  width: 4px;
  height: 5px;
  background: var(--cyan);
  border-radius: 2px;
  opacity: .3;
  transition: opacity .2s;
}
body.speaking .voice .bar { opacity: 1; animation: wave .9s ease-in-out infinite; }
body.speaking .voice .bar:nth-child(2) { animation-delay: .12s; }
body.speaking .voice .bar:nth-child(3) { animation-delay: .24s; }
body.speaking .voice .bar:nth-child(4) { animation-delay: .36s; }
@keyframes wave { 0%, 100% { height: 5px; } 50% { height: 18px; } }

.status {
  font-size: 12px;
  color: var(--cyan);
  border: 1px solid rgba(83, 193, 255, .35);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 1px;
  white-space: nowrap;
}
.status[data-state="thinking"] { color: var(--gold); border-color: rgba(255, 179, 71, .5); }
.status[data-state="speaking"] { color: var(--accent); border-color: rgba(255, 70, 85, .55); animation: blink 1s step-start infinite; }
@keyframes blink { 50% { opacity: .45; } }

/* ---- 消息区 ---- */
.log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 2px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.msg { display: flex; align-items: flex-start; gap: 8px; }
.msg.user { justify-content: flex-end; }
.msg.assistant { justify-content: flex-start; }

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  border: 0;
  box-shadow: none;
}
.avatar img,
.avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}
.avatar img { object-fit: cover; }

.msg-stack {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  min-width: 0;
}
.msg.user .msg-stack { align-items: flex-end; }
.msg.assistant .msg-stack { align-items: flex-start; }
.bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid transparent;
  color: rgb(var(--bubble-text-rgb, 242, 243, 245));
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.msg.user .bubble {
  background: rgba(var(--bubble-rgb, 13, 21, 38), var(--bubble-alpha, 0.55));
  border-color: rgba(140, 210, 255, .30);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: rgba(var(--bubble-rgb, 13, 21, 38), var(--bubble-alpha, 0.55));
  border-color: rgba(255, 255, 255, .16);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .25);
}

.bubble.streaming::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s step-start infinite;
  margin-left: 1px;
}

.play-btn {
  margin-top: 8px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  opacity: .65;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.play-btn svg {
  display: block;
}
.play-btn:hover {
  opacity: 1;
  border-color: var(--cyan);
  color: var(--cyan);
}
.play-btn.playing {
  opacity: 1;
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 10px rgba(83, 193, 255, .5);
}
.bubble-img {
  display: block;
  max-width: 100%;
  margin-top: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .12);
}
.msg.user .bubble-img { margin-left: auto; }
.sticker-panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 45vh;
  overflow-y: auto;
  background: #0d1526;
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  padding: 10px 10px 16px;
  z-index: 40;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .5);
}
.sticker-panel.hidden { display: none; }
.sticker-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.sticker-tabs button {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 6px;
  font-size: 13px;
  cursor: pointer;
}
.sticker-tabs button.active {
  border-color: var(--cyan);
  color: var(--cyan);
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.emoji-grid button {
  border: 0;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  padding: 2px;
  border-radius: 6px;
}
.emoji-grid button:hover { background: rgba(255, 255, 255, .08); }
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.sticker-grid.hidden { display: none; }
.sticker-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--line);
}
.ai-notice {
  flex: 0 0 auto;
  text-align: center;
  font-size: 10.5px;
  color: rgba(150, 185, 215, .5);
  padding: 0;
  margin: -6px 0 -6px;
  letter-spacing: .5px;
  line-height: 1.2;
}
.agree-text {
  max-height: 45vh;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agree-text p { margin: 0; }
.msg-time {
  width: 100%;
  margin-top: 4px;
  padding: 0 6px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  letter-spacing: .5px;
  user-select: none;
  box-sizing: border-box;
}

/* ---- 语速/音调调节 ---- */
.tune {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  background: rgba(13, 21, 38, .7);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
}
.tune-item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text);
}
.tune-item input[type="range"] {
  flex: 1;
  accent-color: var(--cyan);
  height: 18px;
}
.tune-item span {
  min-width: 36px;
  text-align: right;
  color: var(--text);
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  flex: 0 0 auto;
}
.icon-btn:hover { color: var(--gold); }

/* ---- 设置弹层 ---- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.settings-overlay.hidden { display: none; }
.settings-panel {
  width: min(340px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(135deg, rgba(35, 52, 90, .5), rgba(18, 28, 50, .72));
  border: 1px solid rgba(83, 193, 255, .22);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-title { font-size: 15px; letter-spacing: 1px; color: var(--text); }

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.settings-label {
  font-size: 13px;
  color: var(--text);
  letter-spacing: 1px;
}
.field {
  display: flex;
  align-items: center;
  gap: 10px;
}
.field span {
  min-width: 96px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
}
.field input {
  flex: 1;
  background: rgba(7, 11, 20, .6);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: 0;
  min-width: 0;
}
.field input:focus { border-color: var(--cyan); }
.field input[type="color"] {
  flex: 0 0 auto;
  width: 46px;
  height: 30px;
  padding: 2px;
  cursor: pointer;
}
.field select {
  flex: 1;
  background: rgba(7, 11, 20, .6);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: 0;
  min-width: 0;
}
textarea {
  width: 100%;
  background: rgba(7, 11, 20, .6);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: 0;
  resize: vertical;
  min-height: 64px;
}
textarea:focus { border-color: var(--cyan); }
.persona-actions {
  display: flex;
  gap: 8px;
}
.persona-actions .secondary,
.persona-actions .primary {
  flex: 1;
  align-self: auto;
}
.primary {
  border: 0;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #c22c3a);
  align-self: flex-start;
}
.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.bg-options {
  display: flex;
  gap: 10px;
}
.bg-swatch {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  cursor: pointer;
  border: 2px solid var(--line);
  padding: 0;
}
.bg-swatch.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 179, 71, .3);
}
.bg-swatch.bg-default { background: radial-gradient(circle at 30% 30%, #1d3557, #0a1120); }
.bg-swatch.bg-iron { background: radial-gradient(circle at 30% 30%, #ff4655, #3a0d12); }
.bg-swatch.bg-black { background: #05070c; }
.bg-swatch.bg-space { background: radial-gradient(circle at 30% 30%, #0a1a3a, #040810); }
.bg-upload {
  display: flex;
  gap: 10px;
}
.secondary {
  flex: 1;
  border: 1px solid var(--line);
  background: rgba(7, 11, 20, .6);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.secondary:hover { border-color: var(--cyan); }
.avatar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar-label {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
}

/* ---- 头像裁剪弹窗 ---- */
.crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 10, .8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.crop-overlay.hidden { display: none; }
.crop-box {
  width: min(320px, 100%);
  background: linear-gradient(180deg, #14233f, #0d1526);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.crop-title { font-size: 14px; color: var(--text); }
.crop-viewport {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 0 auto;
  border-radius: 50%;
  overflow: hidden;
  background: #05070c;
  border: 2px solid rgba(255, 255, 255, .25);
  touch-action: none;
  cursor: grab;
}
.crop-viewport:active { cursor: grabbing; }
.crop-viewport img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}
.crop-actions { display: flex; gap: 10px; }
.crop-actions button { flex: 1; }

/* ---- 输入区 ---- */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  padding: 10px;
  background: rgba(13, 21, 38, .9);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.composer input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 16px;
  padding: 8px 6px;
}
.composer input::placeholder { color: var(--muted); }
.composer button {
  border: 0;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #c22c3a);
  box-shadow: 0 4px 16px rgba(255, 70, 85, .35);
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }
.composer button:active { transform: translateY(1px); }

/* 手机窄屏时去掉边框，直接满屏 */
@media (max-width: 600px) {
  .stage { padding: 0; }
  .phone {
    width: 100%;
    height: 100vh;
    height: var(--app-height, 100dvh);
    border-radius: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
  }
  .screen {
    border-radius: 0;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(6px + env(safe-area-inset-left, 0px));
    padding-right: calc(6px + env(safe-area-inset-right, 0px));
  }
  /* iOS：输入框字号必须 ≥16px，否则点击会自动放大页面 */
  .field input,
  .field select,
  textarea {
    font-size: 16px;
  }
  .notch { display: none; }
}
