:root {
  --primary: #7c9cff;
  --primary-dark: #5b7cfa;
  --text: #1e1b4b;
  --muted: #64748b;
  --bubble: #fff8e7;
  --shadow: 0 10px 40px rgba(91, 124, 250, 0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  user-select: none;
  transition: background 0.5s ease;
}

/* 背景 */
body.bg-default {
  background: linear-gradient(160deg, #e0e7ff 0%, #fce7f3 50%, #fef3c7 100%);
}
body.bg-sunset {
  background: linear-gradient(160deg, #ff9a9e 0%, #fad0c4 50%, #fbc2eb 100%);
}
body.bg-night {
  background: linear-gradient(160deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
}
body.bg-sakura {
  background: linear-gradient(160deg, #fff1f2 0%, #fce7f3 40%, #fbcfe8 100%);
}
body.bg-room {
  background: linear-gradient(180deg, #f5f0e8 0%, #e8d5c4 100%);
}
body.bg-pure {
  background: #f8fafc;
}

/* 桌宠 */
.pet {
  position: fixed;
  width: 180px;
  z-index: 100;
  cursor: grab;
  touch-action: none;
}
.pet:active { cursor: grabbing; }
.pet img {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.15));
  pointer-events: none;
  user-select: none;
}
.pet.happy img {
  animation: bounce 0.5s ease;
}
.pet.thinking img {
  animation: sway 1.2s ease-in-out infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  30% { transform: translateY(-14px); }
  60% { transform: translateY(-5px); }
}
@keyframes sway {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

/* 气泡 */
.bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bubble);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  max-width: 200px;
  text-align: center;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
  z-index: 20;
  margin-bottom: 8px;
  line-height: 1.45;
}
.bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--bubble);
}
.bubble.hidden { display: none; }

/* 面板 */
.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, 92vw);
  max-height: 78vh;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(124, 156, 255, 0.3);
}
.panel.hidden { display: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: linear-gradient(90deg, #7c9cff, #a78bfa);
  color: white;
  font-weight: 600;
}
.btn-icon {
  background: transparent;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
}
.tab {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.tab.active {
  color: var(--primary-dark);
  border-bottom: 2px solid var(--primary-dark);
  font-weight: 600;
}

.tab-content {
  padding: 14px;
  overflow-y: auto;
  flex: 1;
  max-height: 48vh;
}
.tab-content.hidden { display: none; }

/* 换装 */
.outfit-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.outfit-btn {
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  background: white;
  padding: 8px 4px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.outfit-btn img {
  width: 100%;
  height: 90px;
  object-fit: contain;
  display: block;
  margin-bottom: 4px;
}
.outfit-btn span { font-size: 12px; }
.outfit-btn.active {
  border-color: var(--primary-dark);
  background: #eef2ff;
}

/* 背景选择 */
.bg-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.bg-btn {
  padding: 12px 8px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  font-size: 13px;
}
.bg-btn.active {
  border-color: var(--primary-dark);
  background: #eef2ff;
  color: var(--primary-dark);
  font-weight: 600;
}

/* 聊天 */
.chat-log {
  height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
}
.msg.ai {
  align-self: flex-start;
  background: #f1f5f9;
}
.msg.system {
  align-self: center;
  color: var(--muted);
  font-size: 11px;
  background: transparent;
}

.chat-input-row {
  display: flex;
  gap: 8px;
}
.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 14px;
  outline: none;
}
.btn-primary {
  padding: 10px 14px;
  background: var(--primary-dark);
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary {
  margin-top: 12px;
  width: 100%;
  padding: 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
}

.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 14px;
  border-bottom: 1px solid #f1f5f9;
}
.switch-row input { width: 18px; height: 18px; accent-color: var(--primary-dark); }
.hint {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

/* 快速输入 */
.quick-chat {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, 90vw);
  z-index: 50;
}
.quick-chat.hidden { display: none; }
.quick-chat input {
  width: 100%;
  padding: 12px 18px;
  border: none;
  border-radius: 24px;
  background: white;
  box-shadow: var(--shadow);
  font-size: 14px;
  outline: none;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e1b4b;
  color: white;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 13px;
  z-index: 300;
}
.toast.hidden { display: none; }

@media (max-width: 480px) {
  .pet { width: 140px; }
  .outfit-btn img { height: 70px; }
}