:root {
  --bg-a: #05060A;
  --bg-b: #0B0F1A;
  --bg-c: #13091E;
  --text: rgba(255, 255, 255, 0.92);
  --text-dim: rgba(255, 255, 255, 0.60);
  --text-faint: rgba(255, 255, 255, 0.32);
  --accent: #F4EEDD;
  --glass: rgba(255, 255, 255, 0.10);
  --glass-strong: rgba(255, 255, 255, 0.18);
  --card-bg: rgba(255, 255, 255, 0.35);
  --card-border: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: "PingFang SC", "Noto Sans SC", "Inter", -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 30% 20%, #160f2a 0%, transparent 55%),
    radial-gradient(circle at 70% 80%, #0a1530 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-a) 0%, var(--bg-b) 60%, var(--bg-c) 100%);
  background-color: var(--bg-a);
  position: relative;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.6;
  transition: filter 600ms ease;
}
body.mood-dim { filter: brightness(0.7) saturate(0.85); }

#particles {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  pointer-events: none;
}

/* 通用屏幕容器 */
.screen {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  pointer-events: none;
}
.screen.entering { animation: screenIn 400ms ease-out both; }
.screen.exiting { animation: screenOut 300ms ease-in both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes screenOut { from { opacity: 1; } to { opacity: 0; } }

/* === 状态 1: 首次问候 === */
.greeting-line {
  font-size: 22px;
  color: var(--text);
  text-align: center;
  letter-spacing: 0.05em;
  white-space: pre-wrap;
  margin: 0;
  pointer-events: auto;
}

/* === 状态 2: 心情选择 === */
#screen-mood { gap: 60px; pointer-events: auto; }
.prompt {
  font-size: 22px;
  color: var(--text);
  text-align: center;
  margin: 0;
  letter-spacing: 0.04em;
}
.mood-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 380px;
}
.mood-chip {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(145deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 22px 16px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 300ms ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  animation: chipIn 360ms ease-out both;
}
.mood-chip:hover {
  background: linear-gradient(145deg, rgba(255,255,255,0.1), rgba(255,255,255,0.04));
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border-color: rgba(255,255,255,0.2);
}
.mood-chip:nth-child(1) { animation-delay: 60ms; }
.mood-chip:nth-child(2) { animation-delay: 120ms; }
.mood-chip:nth-child(3) { animation-delay: 180ms; }
.mood-chip:nth-child(4) { animation-delay: 240ms; }
@keyframes chipIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.mood-chip:active { transform: scale(0.96); background: var(--glass-strong); }
.mood-chip.selected { border-color: rgba(244, 238, 221, 0.5); background: var(--glass-strong); transform: scale(1.04); }
.mood-emoji { font-size: 36px; line-height: 1; }
.mood-label { font-size: 14px; color: var(--text-dim); letter-spacing: 0.05em; }

/* === 状态 3: 卡片层 === */
#screen-cards { pointer-events: auto; gap: 32px; }
.last-mood-hint {
  font-size: 13px;
  color: var(--text-faint);
  margin: 0;
  letter-spacing: 0.05em;
  min-height: 1em;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 380px;
}
.card {
  appearance: none;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text);
  font: inherit;
  padding: 24px 18px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  transition: transform 200ms ease, background 200ms ease, border-color 200ms ease, box-shadow 300ms ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  text-align: left;
  min-height: 120px;
}
.card:active { transform: scale(0.97); }
.card.highlighted {
  border-color: rgba(244, 238, 221, 0.4);
  background: rgba(244, 238, 221, 0.08);
  box-shadow: 0 0 24px rgba(244, 238, 221, 0.08);
}
.card-icon { font-size: 28px; line-height: 1; }
.card-label { font-size: 17px; color: var(--text); letter-spacing: 0.03em; font-weight: 500; }
.card-sub { font-size: 12px; color: var(--text-faint); letter-spacing: 0.05em; }
.quiet-link {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 13px;
  letter-spacing: 0.06em;
  padding: 14px 24px;
  cursor: pointer;
  transition: color 200ms ease;
}
.quiet-link:active { color: var(--text-dim); }

/* === 状态 4: Idle 兜底 === */
#screen-idle {
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  z-index: 2;
}

/* === 状态 5: 子应用容器 === */
#screen-subapp { padding: 0; pointer-events: auto; z-index: 5; background: rgba(5, 7, 12, 0.85); backdrop-filter: blur(10px); }
/* 返回按钮：靠左上角，明确"返回"文案，避免与右上角设置按钮重叠 */
.subapp-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 14px 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  letter-spacing: 0.06em;
  cursor: pointer;
  z-index: 20;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: background 150ms ease, transform 120ms ease;
}
.subapp-close:active { background: rgba(255, 255, 255, 0.22); transform: scale(0.96); }
.subapp-close-arrow { font-size: 20px; line-height: 1; margin-top: -1px; }
.subapp-close-label { font-size: 13px; }
.subapp-host {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}
.subapp-host > iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

/* === 设置按钮 === */
.settings-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--glass);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 400ms ease;
  z-index: 4;
}
.settings-btn.enter { opacity: 0.7; }

/* === Sheet（设置）=== */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  animation: fadein 200ms ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.sheet-inner {
  width: 100%;
  max-width: 560px;
  background: rgba(18, 22, 30, 0.95);
  border-radius: 24px 24px 0 0;
  padding: 28px 24px calc(env(safe-area-inset-bottom, 0px) + 28px);
  color: var(--text);
  animation: slideup 260ms ease-out;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-title { margin: 0 0 18px; font-size: 18px; font-weight: 500; color: var(--text-dim); }
.sheet-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 15px;
}
.sheet-row:last-of-type { border-bottom: none; }
.sheet-row select {
  background: var(--glass);
  color: #fff;
  border: none;
  padding: 6px 10px;
  border-radius: 10px;
  font: inherit;
}
.ghost, .danger-link {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 14px 0;
  width: 100%;
  text-align: center;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  margin-top: 6px;
}
.ghost:active { color: var(--text); }
.danger-link { color: rgba(240, 170, 170, 0.8); }
/* iOS 风开关 */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: rgba(255,255,255,0.18);
  border-radius: 24px;
  transition: background 200ms ease;
}
.switch .track::before {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 200ms ease;
}
.switch input:checked + .track { background: rgba(255,255,255,0.45); }
.switch input:checked + .track::before { transform: translateX(18px); }

/* === Chat 子应用：复用旧聊天 UI 的容器（在 chat 卡片内激活）=== */
.chat-stage {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 120px;
  text-align: center;
  pointer-events: auto;
}
.chat-message {
  max-width: min(80%, 560px);
  font-size: 20px;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  transition: opacity 600ms ease;
}
.chat-echo {
  font-size: 14px;
  color: var(--text-faint);
  margin-bottom: 18px;
  min-height: 1em;
}
.chat-input-bar {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  pointer-events: auto;
}
.mic {
  appearance: none;
  border: none;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--glass);
  cursor: pointer;
  position: relative;
  transition: transform 150ms ease, background 150ms ease;
}
.mic::before {
  content: '';
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.8);
}
.mic.active { transform: scale(1.08); background: var(--glass-strong); }
.mic[disabled] { opacity: 0.4; cursor: not-allowed; }
.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  opacity: 0.75;
  cursor: pointer;
  width: 36px; height: 36px;
  border-radius: 50%;
}
.text-form { flex: 1; max-width: min(500px, 80%); margin: 0 16px; }
.text-form[hidden] { display: none; }
.chat-input {
  width: 100%;
  appearance: none;
  background: var(--glass);
  border: none;
  color: #fff;
  font: inherit;
  padding: 12px 18px;
  border-radius: 20px;
  outline: none;
}
.chat-input::placeholder { color: rgba(255,255,255,0.4); }

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  .screen.entering, .screen.exiting, .mood-chip { animation: none; }
}
