:root {
  color-scheme: light;
  --ink: #4c3869;
  --muted: #8b78a4;
  --line: rgba(176, 137, 224, 0.24);
  --purple: #9a60dc;
  --pink: #ef96bf;
  --mint: #b9eee3;
  --card: rgba(255, 255, 255, 0.76);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(247, 239, 255, 0.94), rgba(255, 247, 236, 0.92) 48%, rgba(232, 251, 246, 0.94)),
    #fff;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid rgba(218, 192, 242, 0.76);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  min-width: 0;
  box-shadow: 0 8px 20px rgba(128, 82, 194, 0.11);
}

button:active { transform: translateY(1px) scale(0.99); }
button.primary {
  border: 0;
  background: linear-gradient(90deg, #a670e5, #ef96bf);
  color: #fff;
}
button.wide { width: 100%; }
button.is-active {
  border: 0;
  background: linear-gradient(90deg, #a670e5, #76d3ca);
  color: #fff;
}

input,
select {
  min-height: 42px;
  border: 1px solid rgba(218, 192, 242, 0.76);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh; /* iOS 地址栏动态高度，避免被遮挡 */
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid rgba(214, 190, 242, 0.72);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 24px 64px rgba(128, 82, 194, 0.16);
  backdrop-filter: blur(18px);
}

.auth-brand {
  margin-bottom: 18px;
}

.auth-card h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 44px);
  line-height: 1.05;
}

.auth-card p {
  color: var(--muted);
  font-weight: 800;
}

.auth-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin: 22px 0 12px;
}

.auth-form input {
  min-height: 48px;
  font-weight: 900;
  letter-spacing: 0;
}

.auth-form button {
  min-height: 48px;
  padding: 0 18px;
}

.auth-status {
  min-height: 22px;
  margin: 0;
}

.auth-status.ok { color: #3a8f80; }
.auth-status.bad { color: #b84d75; }

.install-id {
  margin: 12px 0 0;
  word-break: break-all;
  font-size: 12px;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh; /* iOS 地址栏动态高度 */
}

.mobile-tabbar {
  display: none;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  height: 100dvh; /* iOS 地址栏动态高度 */
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.46);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #a670e5, #76d3ca);
  color: #fff;
  font-weight: 1000;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.topbar p,
.card p {
  color: var(--muted);
}

.nav-btn {
  width: 100%;
  justify-content: flex-start;
}

.workspace {
  display: grid;
  gap: 18px;
  align-content: start;
  padding: 24px;
}

.topbar,
.hero-grid,
.panel-grid {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.1;
}

.topbar p {
  margin: 8px 0 0;
  display: none; /* 2.2.1：去掉左上角状态小字 */
}

.top-actions,
.actions-line,
.seg-row,
.task-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.notice {
  padding: 12px 14px;
  border: 1px solid rgba(239, 150, 191, 0.38);
  border-radius: 16px;
  background: rgba(255, 244, 250, 0.86);
  color: #8d4f84;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(128, 82, 194, 0.11);
}

.hero-grid {
  grid-template-columns: minmax(300px, 1fr) 300px;
}

.pet-stage {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border: 1px solid rgba(214, 190, 242, 0.82);
  border-radius: 30px;
  background:
    linear-gradient(145deg, rgba(255, 251, 255, 0.82), rgba(255, 247, 235, 0.78) 52%, rgba(232, 251, 246, 0.84));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.62), 0 18px 42px rgba(128,82,194,0.14);
}

.pet-stage::before {
  content: "";
  position: absolute;
  inset: 22px;
  border: 1px solid rgba(218, 192, 242, 0.62);
  border-radius: 24px;
  background-image:
    linear-gradient(90deg, rgba(255, 220, 232, 0.18) 25%, transparent 25%),
    linear-gradient(rgba(255, 220, 232, 0.18) 25%, transparent 25%);
  background-size: 58px 58px;
}

.pet-stage.has-background::before {
  opacity: 0.18;
}

#stageBackground {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.95;
}

#petFrame {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

.card,
.progress-card {
  border: 1px solid rgba(214, 190, 242, 0.72);
  border-radius: 24px;
  background: var(--card);
  box-shadow: 0 18px 42px rgba(128, 82, 194, 0.12);
  backdrop-filter: blur(14px);
}

.card {
  padding: 18px;
}

.card.is-attention {
  outline: 3px solid rgba(239, 150, 191, 0.46);
  box-shadow: 0 20px 46px rgba(128, 82, 194, 0.18);
}

.card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.progress-card {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 18px;
}

.app-shell:not([data-active-tab="pet"]) .progress-card {
  display: none;
}

.app-shell:not([data-active-tab="pet"]) .hero-grid {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell[data-active-tab="shop"] .hero-grid {
  display: none;
}

.level-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.level-row span {
  color: var(--muted);
  font-size: 24px;
  font-weight: 900;
}

.level-row strong {
  color: var(--purple);
  font-size: 58px;
  line-height: 0.95;
}

.coin-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-weight: 900;
}

.coin-row strong { color: var(--ink); }

.exp-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(232, 218, 249, 0.82);
}

.exp-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a670e5, #ef96bf, #76d3ca);
  transition: width 180ms ease;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.panel-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dance-list,
.task-list,
.shop-list {
  display: grid;
  gap: 10px;
}

.dance-list {
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  margin-bottom: 12px;
}

.slider-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  color: var(--muted);
  font-weight: 900;
}

.slider-row input,
.slider-row select {
  width: 100%;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.task-row {
  margin-bottom: 12px;
}

.task-row input {
  flex: 1;
}

.task-item {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(218, 192, 242, 0.58);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  font-weight: 900;
}

.task-item.done {
  color: var(--muted);
  text-decoration: line-through;
}

.focus-card {
  display: grid;
  gap: 14px;
  text-align: center;
}

.timer-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
}

#timerStartBtn {
  min-width: 0;
  min-height: 48px;
}

#timerText {
  color: var(--purple);
  font-size: clamp(48px, 8vw, 72px);
  line-height: 1;
}

.shop-list {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

.shop-item {
  display: grid;
  gap: 10px;
}

/* ===== 聊天 ===== */
.chat-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  max-width: 900px;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-persona-name {
  flex: 1 1 auto;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  color: var(--purple);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.chat-head-btns button {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: none;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  overflow-y: auto;
  padding: 14px;
  border: 1px solid rgba(218, 192, 242, 0.4);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.5);
  overscroll-behavior: contain;
}

.chat-msg {
  display: flex;
  align-items: flex-start;
  max-width: 82%;
}

.chat-msg.is-user {
  align-self: flex-end;
  justify-content: flex-end;
}

.chat-msg.is-ai {
  align-self: flex-start;
}

.chat-avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin-right: 8px;
  border: 1px solid rgba(218, 192, 242, 0.5);
  border-radius: 50%;
  object-fit: cover;
  background: linear-gradient(135deg, #ffe9c7, #ffd6e4);
}

.chat-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chat-msg.is-user .chat-bubble {
  border-bottom-right-radius: 6px;
  background: linear-gradient(90deg, #a670e5, #ef96bf);
  color: #fff;
}

.chat-msg.is-ai .chat-bubble {
  border: 1px solid rgba(218, 192, 242, 0.58);
  border-bottom-left-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 54px;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--purple);
  animation: chatBlink 1.1s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.chat-typing span:nth-child(3) { animation-delay: 0.36s; }

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

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat-input-row textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  resize: none;
  padding: 10px 12px;
  line-height: 1.45;
  border-radius: 16px;
}

.chat-input-row button {
  min-width: 76px;
  min-height: 44px;
}

/* ===== 聊天页布局：模型保持可见，聊天卡片撑满剩余高度 ===== */
.app-shell[data-active-tab="chat"] .chat-messages {
  min-height: 0;
  max-height: none;
}

/* 2.2.1：聊天页顶栏只保留“导入模型”按钮 */
.app-shell[data-active-tab="chat"] .top-actions button:not(#importModelBtn) {
  display: none;
}

/* 2.3：舞台页顶栏只保留“导入背景 + 切换模型（多选）” */
.app-shell[data-active-tab="stage"] .top-actions button:not(#importBgBtn):not(#switchModelBtn) {
  display: none;
}

/* 2.3：舞台页不显示顶部主舞台，舞台模块就是下面的多开网格 */
.app-shell[data-active-tab="stage"] .hero-grid {
  display: none;
}

/* ===== 舞台：模型多开（同一个大框，最多 4 个并排站位，可齐舞） ===== */
.stage-grid {
  position: relative;
  height: min(62svh, 560px);
  min-height: 380px;
  overflow: hidden;
  border: 1px solid rgba(214, 190, 242, 0.82);
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 251, 255, 0.82), rgba(255, 247, 235, 0.78) 52%, rgba(232, 251, 246, 0.84));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.62), 0 18px 42px rgba(128, 82, 194, 0.14);
  margin-bottom: 8px;
}

.stage-grid::before {
  content: "";
  position: absolute;
  inset: 13px;
  z-index: 0;
  border: 1px solid rgba(218, 192, 242, 0.62);
  border-radius: 18px;
  background-image:
    linear-gradient(90deg, rgba(255, 220, 232, 0.18) 25%, transparent 25%),
    linear-gradient(rgba(255, 220, 232, 0.18) 25%, transparent 25%);
  background-size: 42px 42px;
}

.stage-slot {
  position: absolute;
  z-index: 1;
  width: min(46%, 230px);
  height: 66%;
  transform: translate(-50%, -50%);
  touch-action: none;
}

.stage-slot.is-dragging {
  z-index: 3;
  transform: translate(-50%, -50%) scale(1.03);
  filter: drop-shadow(0 12px 18px rgba(128, 82, 194, 0.28));
}

.stage-grid iframe.stage-mini-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

.stage-grab-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.stage-slot.is-dragging .stage-grab-layer {
  cursor: grabbing;
}

.stage-grid-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  line-height: 1.9;
}

.stage-grid-legend {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.model-row-del {
  flex: 0 0 auto;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(244, 112, 139, 0.12);
  color: #e0527a;
  box-shadow: none;
  font-size: 12px;
  font-weight: 900;
}

.stage-dance-row {
  margin-bottom: 10px;
}

.stage-dance-row select {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  font-weight: 800;
}

.stage-scale-row {
  margin-bottom: 10px;
}

.stage-scale-row label {
  flex: 0 0 auto;
  font-weight: 900;
  color: var(--muted);
}

.stage-scale-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.stage-scale-row span {
  flex: 0 0 auto;
  min-width: 46px;
  font-weight: 900;
  color: var(--muted);
  text-align: right;
}


/* ===== 选择模型弹窗（图三样式） ===== */
.model-picker-window {
  display: grid;
  gap: 12px;
  width: min(440px, 100%);
  max-height: min(760px, 100%);
  padding: 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 24px 60px rgba(48, 30, 72, 0.24);
}

.model-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.model-picker-head h2 {
  margin: 0;
  font-size: 20px;
}

.model-picker-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
  box-shadow: none;
  font-size: 18px;
  line-height: 1;
}

.model-picker-list {
  display: grid;
  gap: 8px;
  max-height: 46vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: none;
  text-align: left;
}

.model-row.is-checked {
  outline: 2px solid rgba(166, 112, 229, 0.55);
  background: rgba(246, 238, 255, 0.9);
}

.model-row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-row-status {
  flex: 0 0 auto;
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(218, 192, 242, 0.25);
  font-size: 14px;
  font-weight: 900;
}

.model-row-status.is-active {
  color: #fff;
  background: linear-gradient(90deg, #a670e5, #76d3ca);
}

.model-picker-import {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(90deg, #f2a35e, #ef96bf);
  color: #fff;
  font-weight: 900;
}

.model-picker-empty {
  margin: 6px 0;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  line-height: 1.8;
}

@media (min-width: 901px) {
  .app-shell[data-active-tab="chat"] .workspace {
    height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr);
    align-content: stretch;
  }

  .app-shell[data-active-tab="chat"] .hero-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-shell[data-active-tab="chat"] .pet-stage {
    min-height: 0;
    height: 260px;
  }

  .app-shell[data-active-tab="chat"] .chat-card {
    height: 100%;
    min-height: 0;
  }
}

/* ===== 人设编辑弹窗 ===== */
.persona-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px 18px 110px;
  background: rgba(48, 30, 72, 0.38);
  backdrop-filter: blur(8px);
}

.persona-window {
  display: grid;
  gap: 10px;
  width: min(480px, 100%);
  max-height: min(680px, 100%);
  overflow-y: auto;
  padding: 18px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 60px rgba(48, 30, 72, 0.24);
}

.persona-window h2 {
  margin: 0;
  font-size: 18px;
}

.persona-tip {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.persona-field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 900;
  font-size: 14px;
}

.persona-field input,
.persona-field textarea {
  width: 100%;
  padding: 8px 10px;
  font-weight: 700;
  line-height: 1.4;
}

.persona-field textarea {
  resize: vertical;
  min-height: 42px;
}

.persona-actions {
  position: sticky;
  bottom: 0;
  justify-content: flex-end;
  padding: 6px 0 0;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 0 0 24px 24px;
}

#bgmBtn.is-active {
  border: 0;
  background: linear-gradient(90deg, #a670e5, #76d3ca);
  color: #fff;
}

.game-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(48, 30, 72, 0.38);
  backdrop-filter: blur(8px);
}

.game-window {
  position: relative;
  width: min(460px, 100%);
  height: min(820px, 100%);
  overflow: hidden;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(48, 30, 72, 0.24);
}

.game-window iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

@media (max-width: 900px) {
  html,
  body {
    min-height: 100svh;
    overflow-x: hidden;
  }

  .auth-form {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: block;
    min-height: 100svh;
  }

  .sidebar {
    display: none;
  }

  .mobile-tabbar {
    position: fixed;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    z-index: 90;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
    padding: 7px;
    border: 1px solid rgba(218, 192, 242, 0.72);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 16px 38px rgba(128, 82, 194, 0.18);
    backdrop-filter: blur(16px);
  }

  .mobile-tabbar button {
    min-height: 40px;
    border-radius: 14px;
    padding: 0 4px;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: none;
  }

  .mobile-tabbar button.is-active {
    border: 0;
    background: linear-gradient(135deg, #a670e5, #ef96bf);
    color: #fff;
  }

  .brand {
    min-width: 180px;
    margin: 0 8px 0 0;
  }

  .nav-btn {
    min-width: 110px;
  }

  .workspace {
    gap: 12px;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    padding: max(10px, env(safe-area-inset-top)) 10px 96px;
  }

  .topbar,
  .hero-grid,
  .panel-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
    gap: 8px;
    min-width: 0;
    padding: 2px 0 0;
  }

  .topbar h1 {
    font-size: clamp(20px, 6vw, 24px);
    line-height: 1.08;
    overflow-wrap: anywhere;
  }

  .topbar p {
    margin-top: 5px;
    font-size: 13px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 100%;
    min-width: 0;
    width: 100%;
    gap: 7px;
  }

  .top-actions button {
    width: 100%;
    min-height: 38px;
    border-radius: 14px;
    padding: 0 6px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pet-stage {
    min-height: 330px;
    height: min(53svh, 500px);
    border-radius: 22px;
  }

  .app-shell[data-active-tab="focus"] .pet-stage,
  .app-shell[data-active-tab="games"] .pet-stage {
    min-height: 230px;
    height: min(34svh, 330px);
  }

  .pet-stage::before {
    inset: 13px;
    border-radius: 18px;
    background-size: 42px 42px;
  }

  .progress-card {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px 12px;
    padding: 12px;
  }

  .progress-card .level-row {
    grid-row: span 2;
  }

  .level-row strong {
    font-size: 42px;
  }

  .level-row span {
    font-size: 18px;
  }

  #expText,
  .coin-row {
    margin: 0;
    font-size: 13px;
  }

  #dailyBtn {
    grid-column: 1 / -1;
    min-height: 40px;
  }

  .card,
  .progress-card {
    border-radius: 18px;
  }

  .card {
    padding: 14px;
  }

  .card h2 {
    margin-bottom: 10px;
    font-size: 16px;
  }

  .dance-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .seg-row,
  .actions-line,
  .task-row {
    gap: 8px;
  }

  .focus-card {
    padding: 18px 14px;
  }

  .timer-actions {
    grid-template-columns: minmax(0, 1fr) 88px;
  }

  #timerStartBtn {
    width: 100%;
    min-height: 50px;
  }

  .slider-row {
    margin-top: 10px;
  }

  .game-modal {
    padding: 0;
  }

  .game-window {
    width: 100vw;
    height: 100svh;
    border-radius: 0;
  }

  .chat-card {
    min-height: 0;
  }

  .chat-messages {
    max-height: 42svh;
    min-height: 220px;
  }

  /* 聊天页：顶栏只留“导入模型”（标题 + 单按钮单行），模型舞台缩矮，把空间让给对话框 */
  .app-shell[data-active-tab="chat"] .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .app-shell[data-active-tab="chat"] .top-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    width: auto;
    max-width: none;
  }

  .app-shell[data-active-tab="chat"] .top-actions button {
    width: auto;
  }

  .app-shell[data-active-tab="chat"] .workspace {
    height: 100dvh;
    grid-template-rows: auto auto minmax(0, 1fr);
    align-content: stretch;
  }

  .app-shell[data-active-tab="chat"] .pet-stage {
    min-height: 0;
    height: 170px;
  }

  .app-shell[data-active-tab="chat"] .chat-card {
    height: 100%;
    min-height: 0;
  }

  .app-shell[data-active-tab="chat"] .chat-messages {
    min-height: 0;
    max-height: none;
  }

  /* 打字时隐藏底部导航，输入框不会被遮挡 */
  body.chat-typing-mode .mobile-tabbar {
    display: none;
  }

  body.chat-typing-mode .workspace {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  /* 舞台多开：手机同一个大框 */
  .stage-grid {
    height: min(58svh, 500px);
    min-height: 320px;
  }

  .stage-grid-empty {
    font-size: 13px;
  }

  .stage-dance-row {
    flex-wrap: nowrap;
  }

  .stage-dance-row span {
    flex: 0 0 auto;
    font-weight: 900;
  }

  .stage-dance-row select {
    min-width: 0;
  }

  .model-picker-window {
    width: min(420px, 100%);
    padding: 16px;
  }
}

@media (max-width: 420px) {
  .topbar h1 {
    font-size: 20px;
  }

  .pet-stage {
    min-height: 310px;
    height: min(50svh, 440px);
  }

  .app-shell[data-active-tab="chat"] .pet-stage {
    min-height: 0;
    height: 170px;
  }

  .app-shell[data-active-tab="focus"] .pet-stage,
  .app-shell[data-active-tab="games"] .pet-stage {
    min-height: 220px;
    height: min(32svh, 300px);
  }
}

/* ===== AR 拍照（参考版排版：全屏摄像头 + 半透明操作条 + 方向键） ===== */
body.ar-mode { overflow: hidden; overscroll-behavior: none; }
body.ar-mode #petStage {
  position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh;
  z-index: 9000; margin: 0; border-radius: 0; background: #000;
}
body.ar-mode #petStage > #petFrame { border-radius: 0; width: 100%; height: 100%; }
body.ar-mode #stageBackground { display: none !important; }

.ar-bar { position: fixed; inset: 0; z-index: 9100; pointer-events: none; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.ar-topbar { position: fixed; top: max(10px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; align-items: flex-start; gap: 10px; }
.ar-bar .ar-icon {
  flex: 0 0 auto; width: 40px; height: 40px; border: 0;
  border-radius: 50%; background: rgba(0,0,0,.5); color: #fff; font-size: 24px; font-weight: 900;
  pointer-events: auto; touch-action: manipulation;
}
.ar-hint {
  flex: 1 1 auto; min-width: 0; padding: 8px 12px; border-radius: 10px; background: rgba(0,0,0,.18);
  color: #fff; font-size: 12px; line-height: 1.35; text-shadow: 0 2px 6px #000; pointer-events: none;
  text-wrap: balance;
}
.ar-control-dock {
  position: fixed; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom)); max-width: 400px; margin: 0 auto; padding: 6px; gap: 4px;
  display: grid; border: 1px solid rgba(255,255,255,.34); border-radius: 14px;
  background: rgba(10,10,16,.18); box-shadow: none; backdrop-filter: blur(5px); pointer-events: none;
}
.ar-control-dock > * { pointer-events: auto; }
.ar-slider-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.ar-slider-control { display: grid; gap: 3px; min-width: 0; color: rgba(255,255,255,.92); font-size: 10px; font-weight: 800; }
.ar-slider-control span { display: flex; justify-content: space-between; gap: 4px; white-space: nowrap; }
.ar-slider-control output { color: rgba(255,255,255,.68); font-variant-numeric: tabular-nums; }
.ar-slider-control input { width: 100%; min-width: 0; accent-color: #f4b4d7; touch-action: manipulation; }
.ar-shutter-row { display: flex; justify-content: center; }
.ar-capture-row { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 34px; }
.ar-record {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 92px; height: 34px;
  padding: 0 12px; border: 1px solid rgba(255,255,255,.38); border-radius: 10px;
  background: rgba(118, 32, 44, .72); color: #fff; font-size: 12px; font-weight: 850; white-space: nowrap; touch-action: manipulation;
}
.ar-record-dot { width: 10px; height: 10px; border-radius: 50%; background: #ff6b78; box-shadow: 0 0 0 3px rgba(255,107,120,.18); }
.ar-record.is-recording { background: #b21f35; border-color: rgba(255,190,200,.7); }
.ar-record.is-recording .ar-record-dot { background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.22); }
.ar-record-state { min-width: 64px; color: rgba(255,255,255,.78); font-size: 10px; font-variant-numeric: tabular-nums; text-align: center; }
.ar-action-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; align-items: center; }
.ar-move-pad { flex: 0 0 64px; height: 46px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 2px; }
.ar-move-pad button { border: 1px solid rgba(255,255,255,.38); border-radius: 6px; background: rgba(0,0,0,.22); color: #fff; font-size: 12px; font-weight: 900; touch-action: manipulation; }
.ar-move-pad button:first-child { grid-column: 2; }
.ar-move-pad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.ar-move-pad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.ar-move-pad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.ar-pill {
  flex: 1 1 56px; height: 30px; padding: 0 8px; border: 1px solid rgba(255,255,255,.32); border-radius: 10px;
  background: rgba(0,0,0,.25); color: #fff; font-size: 12px; font-weight: 800; white-space: nowrap; touch-action: manipulation;
}
.ar-shutter {
  width: 52px; height: 52px; border-radius: 50%; border: 4px solid rgba(255,255,255,.85);
  background: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.4);
  pointer-events: auto; touch-action: manipulation;
}
.ar-shutter:active { transform: scale(.94); }

.ar-preview {
  position: fixed; inset: 0; z-index: 9200; background: rgba(8,6,18,.92); overscroll-behavior: contain;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.ar-preview img { display: block; width: auto; height: auto; max-width: 92vw; max-height: 62dvh; border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.ar-preview video { display: block; width: auto; height: auto; max-width: 92vw; max-height: 62dvh; border-radius: 14px; background: #000; box-shadow: 0 16px 40px rgba(0,0,0,.5); }
.ar-preview-actions { display: flex; gap: 14px; }
.ar-preview-actions > * {
  padding: 12px 22px; border: 0; border-radius: 12px; font-size: 15px; font-weight: 800;
  background: rgba(255,255,255,.16); color: #fff; text-decoration: none; cursor: pointer;
}
.ar-preview-actions .primary { background: linear-gradient(135deg, #8b7fd4, #d696b2); }
.ar-preview-tip { color: #cfc8e8; font-size: 12px; text-align: center; max-width: 560px; }

.app-logo {
  width: 26px; height: 26px; border-radius: 7px; vertical-align: -5px; margin-right: 8px;
  object-fit: cover; box-shadow: 0 2px 6px rgba(120, 90, 200, .35);
}

.toast {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 9500; max-width: min(86vw, 360px); padding: 10px 16px; border-radius: 12px;
  background: rgba(24, 16, 40, .92); color: #fff; font-size: 13px; font-weight: 700; line-height: 1.45;
  text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.35); pointer-events: none;
}

/* 防误触缩放：按钮/滑杆/输入框禁用双击缩放；舞台只允许平移滚动 */
button, input, select, textarea { touch-action: manipulation; }
.pet-stage, #petStage, #petFrame { touch-action: pan-x pan-y; }

/* 舞台不再允许自由拖动（隐藏拖动层，保留自动等距队形） */
.stage-grab-layer { display: none !important; }

.ar-dance-picker {
  position: fixed; left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  pointer-events: auto;
  max-width: 400px; margin: 0 auto; padding: 6px; display: grid; gap: 5px;
  border: 1px solid rgba(255,255,255,.3); border-radius: 14px;
  background: rgba(10,10,16,.34); backdrop-filter: blur(6px);
  z-index: 1;
}
.ar-dance-stop {
  height: 30px; border: 1px solid rgba(255,140,150,.55); border-radius: 9px;
  background: rgba(178,31,53,.66); color: #fff; font-size: 12px; font-weight: 800; touch-action: manipulation;
}
.ar-dance-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 4px; }
.ar-dance-item {
  height: 30px; border: 1px solid rgba(255,255,255,.26); border-radius: 8px;
  background: rgba(0,0,0,.3); color: #fff; font-size: 12px; font-weight: 700; touch-action: manipulation;
}

@media (max-width: 700px) {
  .ar-topbar .ar-hint { display: none; }
  .ar-control-dock { max-width: calc(100vw - 18px); }
  .ar-pill { flex-basis: 54px; font-size: 11px; }
  .ar-record { min-width: 88px; font-size: 11px; }
  .ar-shutter { width: 50px; height: 50px; }
  .ar-action-row { display: grid; grid-template-columns: 64px repeat(3, minmax(0, 1fr)); gap: 4px; }
  .ar-move-pad { grid-column: auto; }
}

