/* 小芽 · 样式
   设计原则：柔和、留白、大按钮、不抢孩子的注意力 */

:root {
  --bg-1: #f8f2ff;
  --bg-2: #ece0ff;
  --bg-3: #fdf7ff;
  --ink: #4b3f5e;
  --ink-soft: #8b7fa3;
  --purple: #a98ee0;
  --purple-deep: #8b6bc9;
  --lilac: #f0e6ff;
  --white: #ffffff;
  --danger: #ef7d8e;
  --shadow: 0 10px 30px rgba(122, 92, 170, 0.12);
  --shadow-soft: 0 4px 14px rgba(122, 92, 170, 0.08);
  --r-lg: 26px;
  --r-md: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --dock-h: 104px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 600px at 12% 8%, #fff6fb 0%, transparent 60%),
    radial-gradient(800px 700px at 88% 92%, #e6d8ff 0%, transparent 62%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

img { -webkit-user-drag: none; }

/* ================= 布局 ================= */
.app {
  position: relative;
  height: 100dvh;
  display: grid;
  grid-template-areas:
    "top  top"
    "stage chat"
    "dock dock";
  grid-template-columns: minmax(300px, 37%) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

/* 竖屏 / 窄屏：上下排 */
@media (max-width: 900px), (orientation: portrait) {
  .app {
    grid-template-areas:
      "top"
      "stage"
      "chat"
      "dock";
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(140px, 30vh) minmax(0, 1fr) auto;
  }
}

/* ================= 顶栏 ================= */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(16px, 2.4vw, 32px);
  z-index: 5;
}

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

.avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.who { min-width: 0; }
.who h1 {
  margin: 0;
  font-size: clamp(20px, 2vw, 26px);
  letter-spacing: 2px;
  font-weight: 700;
}
.status {
  margin: 3px 0 0;
  display: flex; align-items: center; gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #7ed6a8;
  box-shadow: 0 0 0 0 rgba(126, 214, 168, .6);
  animation: breathe 2.4s ease-in-out infinite;
}
.status.thinking .dot { background: #f2c063; }
.status.speaking .dot { background: var(--purple); }

.tools { display: flex; gap: 10px; flex-shrink: 0; }

.tool {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .72);
  color: var(--ink-soft);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform .18s, background .18s, color .18s;
}
.tool:active { transform: scale(.92); }
.tool svg {
  width: 24px; height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool svg path:first-child { fill: currentColor; stroke: none; }
.tool[aria-pressed="false"] { color: #c3b8d6; }
.tool[aria-pressed="false"] .wave { opacity: .25; }
.tool.confirming { background: var(--danger); color: #fff; }

/* ================= 舞台 ================= */
.stage {
  grid-area: stage;
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  padding: 6px 10px 10px;
  overflow: hidden;
}

/* 背景星星，透明度很低，不抢戏 */
.stars { position: absolute; inset: 0; pointer-events: none; }
.stars i {
  position: absolute;
  width: 12px; height: 12px;
  background: #fff;
  opacity: .5;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  animation: twinkle 5s ease-in-out infinite;
}
.stars i:nth-child(1) { left: 8%;  top: 12%; transform: scale(.7); animation-delay: 0s;   background: #ffe08a; }
.stars i:nth-child(2) { left: 82%; top: 8%;  transform: scale(.55); animation-delay: 1.1s; background: #b8d4ff; }
.stars i:nth-child(3) { left: 16%; top: 74%; transform: scale(.5);  animation-delay: 2.2s; background: #fff; }
.stars i:nth-child(4) { left: 88%; top: 62%; transform: scale(.75); animation-delay: .7s;  background: #ffe08a; }
.stars i:nth-child(5) { left: 34%; top: 6%;  transform: scale(.45); animation-delay: 3.1s; background: #ffc6d9; }
.stars i:nth-child(6) { left: 70%; top: 86%; transform: scale(.6);  animation-delay: 1.8s; background: #b8d4ff; }
.stars i:nth-child(7) { left: 5%;  top: 46%; transform: scale(.4);  animation-delay: 2.6s; background: #fff; }
.stars i:nth-child(8) { left: 92%; top: 34%; transform: scale(.45); animation-delay: 3.6s; background: #ffc6d9; }

/* 形象背后的柔光 */
.halo {
  position: absolute;
  width: min(74%, 460px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.95) 0%, rgba(255,255,255,.35) 52%, transparent 70%);
  filter: blur(6px);
  transition: transform .5s ease, opacity .5s ease;
}

.spirit-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: float 4.2s ease-in-out infinite;
  will-change: transform;
}

.spirit {
  display: block;
  width: auto;
  height: auto;
  max-width: 94%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 18px 26px rgba(126, 96, 178, .18));
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.spirit-wrap:active .spirit { transform: scale(.97); }

/* 思考时头顶的三个点 */
.think {
  position: absolute;
  top: 4%;
  right: 6%;
  display: flex;
  gap: 5px;
  padding: 10px 12px;
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(6px) scale(.9);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.think i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--purple);
  animation: bounce 1.1s ease-in-out infinite;
}
.think i:nth-child(2) { animation-delay: .15s; }
.think i:nth-child(3) { animation-delay: .3s; }

/* 状态：思考 / 说话 / 倾听 */
.is-thinking .think { opacity: 1; transform: translateY(0) scale(1); }
.is-thinking .spirit { animation: thinkTilt 1.8s ease-in-out infinite; }

.is-speaking .spirit-wrap { animation: float 1.1s ease-in-out infinite; }
.is-speaking .spirit { filter: drop-shadow(0 16px 34px rgba(169, 142, 224, .42)); }
.is-speaking .halo { transform: scale(1.08); opacity: 1; }

.is-listening .halo {
  animation: haloPulse 1.6s ease-out infinite;
}

.stage-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
  font-size: 12.5px;
  color: var(--ink-soft);
  max-width: 92%;
  text-align: center;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}
.stage-hint.show { opacity: 1; }

/* 没有麦克风权限时，给底部提示留出位置，别压到脚上 */
.no-mic .stage { padding-bottom: 42px; }

/* ================= 对话区 ================= */
.chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px clamp(16px, 2.2vw, 30px) 6px clamp(8px, 1.4vw, 20px);
  overflow: hidden;
}
@media (max-width: 900px), (orientation: portrait) {
  .chat { padding: 2px 14px 4px; }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 2px;
  transition: opacity .35s, max-height .35s;
}
.chips.hide { opacity: 0; max-height: 0; padding: 0; overflow: hidden; pointer-events: none; }

.chip {
  border: 0;
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .82);
  color: var(--purple-deep);
  font-size: 14px;
  font-family: inherit;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform .16s, background .16s;
}
.chip:active { transform: scale(.95); background: #fff; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 2px 4px 8px 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(169, 142, 224, .28) transparent;
}
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(169, 142, 224, .26); border-radius: 99px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.bubble {
  max-width: 78%;
  padding: 13px 17px;
  border-radius: 20px;
  font-size: clamp(16.5px, 1.55vw, 19px);
  line-height: 1.72;
  letter-spacing: .2px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: rise .32s cubic-bezier(.22, 1, .36, 1) both;
  position: relative;
}

.bubble.bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, .96);
  border-bottom-left-radius: 7px;
  box-shadow: var(--shadow);
}
.bubble.me {
  align-self: flex-end;
  background: linear-gradient(135deg, #b79ee4, #a184d8);
  color: #fff;
  border-bottom-right-radius: 7px;
  box-shadow: 0 8px 22px rgba(139, 107, 201, .26);
}

/* 流式输出时末尾的光标 */
.bubble.streaming::after {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--purple);
  vertical-align: middle;
  animation: blink 1s steps(1) infinite;
}
.bubble.streaming { min-height: 1.4em; }

/* 等模型开口时的三个点 */
.bubble.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 54px;
  min-height: 1.5em;
}
.bubble.thinking-dots i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--purple);
  animation: bounce 1.1s ease-in-out infinite;
}
.bubble.thinking-dots i:nth-child(2) { animation-delay: .15s; }
.bubble.thinking-dots i:nth-child(3) { animation-delay: .3s; }

.sys-note {
  align-self: center;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, .6);
  padding: 5px 12px;
  border-radius: 999px;
  animation: rise .3s ease both;
}

/* ================= 底部输入坞 ================= */
.dock {
  grid-area: dock;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px clamp(14px, 2.4vw, 32px) calc(14px + var(--safe-b));
  background: linear-gradient(to top, rgba(248, 242, 255, .96) 55%, rgba(248, 242, 255, 0));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 6;
}

.mic {
  position: relative;
  flex: 0 0 auto;
  width: 68px; height: 68px;
  border: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #fff, #f2e9ff);
  color: var(--purple-deep);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .18s, background .25s, color .25s;
}
.mic svg {
  width: 30px; height: 30px;
  fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round;
}
.mic:active { transform: scale(.94); }
.mic-ring {
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--purple);
  opacity: 0;
  pointer-events: none;
}

.mic.rec {
  background: linear-gradient(145deg, #ff9aa8, #ef7285);
  color: #fff;
}
.mic.rec .mic-ring { animation: micPulse 1.5s ease-out infinite; }

/* 设备不支持网页录音时按钮还在，点了给提示，不假装功能消失 */
.no-mic .mic { opacity: .55; }

.composer {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: 60px;
  padding: 4px 10px 4px 16px;
  border-radius: 24px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  transition: box-shadow .25s;
}
.composer:focus-within { box-shadow: 0 10px 30px rgba(122, 92, 170, .2), 0 0 0 2px rgba(169, 142, 224, .35); }

#input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: clamp(16.5px, 1.5vw, 18.5px);
  line-height: 1.55;
  color: var(--ink);
  max-height: 4.7em;
  padding: 10px 0;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}
#input::placeholder { color: #b6abc8; }

.rec-hint {
  position: absolute;
  left: 14px;
  bottom: calc(100% + 10px);
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(75, 63, 94, .9);
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.rec-hint.show { opacity: 1; transform: translateY(0); }
.rec-hint b { color: #ffd9df; font-weight: 600; }

.send {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  border: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #bda7ea, #9c7fd8);
  color: #fff;
  box-shadow: 0 8px 20px rgba(139, 107, 201, .32);
  cursor: pointer;
  transition: transform .18s, opacity .2s, background .2s;
}
.send svg { width: 26px; height: 26px; fill: currentColor; }
.send:active:not(:disabled) { transform: scale(.92); }
.send:disabled {
  background: #ded4ee;
  box-shadow: none;
  cursor: default;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 132px;
  transform: translate(-50%, 12px);
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(75, 63, 94, .92);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 50;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= 动效 ================= */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-10px); }
}
@keyframes thinkTilt {
  0%, 100% { transform: translateY(0) rotate(-1.2deg); }
  50%      { transform: translateY(-4px) rotate(1.2deg); }
}
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30%           { transform: translateY(-5px); opacity: 1; }
}
@keyframes twinkle {
  0%, 100% { opacity: .18; }
  50%      { opacity: .62; }
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(126, 214, 168, .55); }
  50%      { box-shadow: 0 0 0 5px rgba(126, 214, 168, 0); }
}
@keyframes haloPulse {
  0%   { transform: scale(.94); opacity: .95; }
  100% { transform: scale(1.16); opacity: .3; }
}
@keyframes micPulse {
  0%   { opacity: .75; transform: scale(.96); }
  100% { opacity: 0;   transform: scale(1.28); }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
  50% { opacity: 0; }
}

/* 大屏（一体机）再放大一档，最后一排也看得清 */
@media (min-width: 1600px) {
  .bubble { max-width: 72%; font-size: 21px; }
  #input { font-size: 20px; }
  .mic { width: 76px; height: 76px; }
  .send { width: 62px; height: 62px; }
  .topbar { padding-top: 20px; }
  .avatar { width: 60px; height: 60px; }
}

/* 低年级平板横屏高度不足时，把空间让给对话 */
@media (max-height: 620px) and (orientation: landscape) {
  .bubble { font-size: 16.5px; }
  .chips { padding-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ================= 设置面板 ================= */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 16px;
}
.sheet[hidden] { display: none; }

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(58, 46, 80, .34);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.sheet-card {
  position: relative;
  width: min(92vw, 420px);
  max-height: 88vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 24px;
  padding: 22px 22px 18px;
  box-shadow: 0 24px 60px rgba(60, 40, 90, .28);
  animation: rise .24s cubic-bezier(.22, 1, .36, 1) both;
}
.sheet-card h2 {
  margin: 0 0 16px;
  font-size: 19px;
  letter-spacing: 1.5px;
}

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field input,
.field select {
  width: 100%;
  height: 46px;
  border: 1px solid #e4dcf2;
  border-radius: 12px;
  padding: 0 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: #fbf8ff;
  outline: none;
}
.field input:focus,
.field select:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(169, 142, 224, .18);
}

.field-note {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 2px 0 16px;
  line-height: 1.6;
}

.sheet-actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  height: 48px;
  border: 0;
  border-radius: 14px;
  font-size: 15px;
  font-family: inherit;
  background: #f2ecfb;
  color: var(--purple-deep);
  cursor: pointer;
  transition: transform .16s;
}
.btn.primary {
  background: linear-gradient(145deg, #bda7ea, #9c7fd8);
  color: #fff;
}
.btn:active { transform: scale(.97); }
/* 名字旁边的配置状态 */
.meta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  font-size: 11.5px;
  letter-spacing: 0;
  color: var(--ink-soft);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
}
.meta:active { background: #fff; }
.meta i { font-style: normal; opacity: .45; }
.meta .ok { color: #3f9d6b; }
.meta .bad { color: #d4677a; }
.meta .pending { color: #b0954e; }

.status { flex-wrap: wrap; }

/* 配置详情里的行 */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid #f2edfa;
  font-size: 14px;
}
.info-row span { color: var(--ink-soft); flex-shrink: 0; }
.info-row b {
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}
.info-row:last-of-type { border-bottom: 0; }