/* ============================================
   茶海心遇 - TeaHaiXin PWA Styles
   ============================================ */

/* --- Reset & Variables --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a14;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --bg-input: #12122a;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --text: #e0d6ff;
  --text-dim: #8a82b0;
  --text-muted: #5a5480;
  --border: rgba(108, 92, 231, 0.15);
  --border-active: rgba(108, 92, 231, 0.4);
  --happy: #FFD700;
  --sad: #4A90E2;
  --angry: #E74C3C;
  --peaceful: #2ECC71;
  --anxious: #95A5A6;
  --romantic: #FF69B4;
  --radius: 16px;
  --radius-sm: 10px;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { position: relative; min-height: 100vh; min-height: 100dvh; }

/* --- Screen System --- */
.screen {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s 0.4s;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.4s ease, transform 0.4s ease, visibility 0s 0s;
  position: relative;
}

.screen-content {
  padding: 20px 16px 24px;
  max-width: 600px;
  margin: 0 auto;
}

.screen-content.with-nav {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #8b7cf7);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:hover { box-shadow: 0 6px 28px rgba(108, 92, 231, 0.5); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-outline {
  background: transparent;
  color: var(--accent-light);
  border: 1.5px solid var(--border-active);
}
.btn-outline:hover { background: rgba(108, 92, 231, 0.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.btn-danger { color: var(--angry); }

.btn-lg { padding: 14px 32px; font-size: 1.05rem; border-radius: var(--radius); }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }

.btn-icon {
  background: transparent; border: none; color: var(--text-dim);
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; transition: all var(--transition);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--text); }

/* --- Welcome Screen --- */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 40px 24px;
  text-align: center;
}

.welcome-logo {
  position: relative;
  margin-bottom: 24px;
}

.logo-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--bg-card), #2a2a4e);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border-active);
  position: relative;
  z-index: 1;
  animation: float 4s ease-in-out infinite;
}

.logo-emoji { font-size: 52px; }

.logo-ripple {
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0;
  animation: ripple 3s ease-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes ripple {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

.welcome-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 2.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.welcome-slogan {
  font-size: 1rem;
  color: var(--text-dim);
  letter-spacing: 4px;
}

.welcome-divider {
  margin: 32px 0;
  width: 200px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-active), transparent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.divider-leaf {
  background: var(--bg);
  padding: 0 12px;
  font-size: 1.2rem;
}

.welcome-form {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-group { position: relative; }

.input-group input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: all var(--transition);
}

.input-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input-group input::placeholder { color: var(--text-muted); }

.input-hint {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.guest-hint { font-size: 0.8rem; opacity: 0.7; }

.welcome-footer {
  margin-top: 40px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Home Screen --- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 24px;
}

.greeting { display: flex; flex-direction: column; gap: 2px; }
.greeting-time { font-size: 0.85rem; color: var(--text-dim); }
.greeting-name { font-family: 'Noto Serif SC', serif; font-size: 1.4rem; font-weight: 600; }
.header-tea { font-size: 2rem; animation: float 4s ease-in-out infinite; }

.home-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px 20px;
  border: 1px solid var(--border);
}

.card-title {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.2rem;
  margin-bottom: 6px;
}

.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.textarea-wrapper { position: relative; margin-bottom: 16px; }

.textarea-wrapper textarea {
  width: 100%;
  padding: 14px 16px;
  padding-bottom: 30px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  min-height: 120px;
  outline: none;
  transition: all var(--transition);
}

.textarea-wrapper textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.textarea-wrapper textarea::placeholder { color: var(--text-muted); }

.char-counter {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.mood-chips { margin-bottom: 20px; }
.chips-label { font-size: 0.8rem; color: var(--text-dim); display: block; margin-bottom: 10px; }
.chips-container { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.chip:hover, .chip.active { border-color: var(--accent); color: var(--accent-light); background: rgba(108, 92, 231, 0.1); }

.btn-submit {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
  border-radius: var(--radius-sm);
}

.btn-submit .btn-loader { display: none; align-items: center; gap: 10px; }
.btn-submit.loading .btn-text { display: none; }
.btn-submit.loading .btn-loader { display: flex; }

.tea-loader span {
  display: inline-block;
  animation: teaSpin 1.2s ease-in-out infinite;
  font-size: 1.3rem;
}

@keyframes teaSpin {
  0%, 100% { transform: rotate(0) scale(1); }
  50% { transform: rotate(20deg) scale(1.15); }
}

/* Recent section */
.section-title {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  padding-top: 24px;
}

.home-recent .recent-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
}
.home-recent .recent-card:hover { border-color: var(--border-active); }

.recent-emoji { font-size: 1.6rem; }
.recent-info { flex: 1; min-width: 0; }
.recent-text { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-date { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* --- Result Screen --- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 12px 0;
  transition: color var(--transition);
}
.back-btn:hover { color: var(--text); }

.result-container {
  max-width: 600px;
  margin: 0 auto;
  animation: resultFadeIn 0.6s ease-out;
}

@keyframes resultFadeIn {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.result-image-wrapper {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  aspect-ratio: 1;
  background: var(--bg-card);
}

.result-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  display: flex;
  justify-content: flex-start;
}

.emotion-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.15);
}

.result-poem-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 16px;
  text-align: center;
  border: 1px solid var(--border);
}

.poem-decoration {
  color: var(--accent);
  font-size: 0.9rem;
  opacity: 0.5;
  margin: 8px 0;
}

.result-poem {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.15rem;
  line-height: 2;
  color: var(--text);
  white-space: pre-line;
}

.result-input-echo {
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

.echo-label { color: var(--text-muted); }
.echo-text { color: var(--text-dim); }

.result-audio-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.audio-info { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.audio-label { font-size: 0.85rem; color: var(--text-dim); }

.result-audio-card audio {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  filter: invert(1) hue-rotate(180deg) brightness(0.8);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 40px;
}

.result-actions .btn { flex: 1; min-width: 120px; }
.result-actions .btn-ghost { flex-basis: 100%; }

/* --- History Screen --- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 20px;
}

.page-header h2 {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.4rem;
}

.history-list { display: flex; flex-direction: column; gap: 12px; }

.history-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
  animation: cardIn 0.3s ease-out both;
}

.history-card:hover { border-color: var(--border-active); transform: translateY(-2px); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.history-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}

.history-body { flex: 1; min-width: 0; }

.history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.history-date { font-size: 0.75rem; color: var(--text-muted); }

.history-emotion-tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(108,92,231,0.15);
  color: var(--accent-light);
}

.history-excerpt {
  font-size: 0.85rem;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-title { font-size: 1.1rem; margin-bottom: 6px; }
.empty-desc { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 20px; }

/* --- Profile Screen --- */
.profile-card {
  text-align: center;
  padding: 32px 20px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b7cf7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  margin: 0 auto 12px;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.profile-name {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.profile-joined { font-size: 0.8rem; color: var(--text-muted); }

.stats-card, .about-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-light);
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.emotion-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.chart-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.chart-label {
  width: 70px;
  text-align: right;
  color: var(--text-dim);
  flex-shrink: 0;
}

.chart-bar-bg {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

.chart-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.chart-count {
  width: 24px;
  text-align: left;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.about-content { margin: 12px 0; }
.about-content p { font-size: 0.88rem; color: var(--text-dim); line-height: 1.7; margin-bottom: 8px; }

.about-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}

.feature-item {
  font-size: 0.82rem;
  color: var(--text-dim);
  padding: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.about-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 10, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.68rem;
  cursor: pointer;
  padding: 8px 20px;
  transition: color var(--transition);
  position: relative;
}

.nav-item.active { color: var(--accent-light); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 2px;
  background: var(--accent);
  border-radius: 0 0 2px 2px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text);
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 0.85rem;
  border: 1px solid var(--border-active);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 200;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Loading placeholder for image --- */
.result-image-wrapper.loading {
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-image-wrapper.loading::after {
  content: '🍵 画作生成中...';
  position: absolute;
  font-size: 0.9rem;
  color: var(--text-dim);
  animation: teaSpin 1.2s ease-in-out infinite;
}

.result-image-wrapper.loading .result-image { opacity: 0; }
.result-image-wrapper .result-image { transition: opacity 0.5s ease; }

/* --- Confirm dialog --- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.confirm-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  animation: scaleIn 0.25s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.confirm-dialog p { margin-bottom: 20px; font-size: 0.95rem; line-height: 1.5; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .btn { min-width: 80px; }

/* --- Responsive --- */
@media (min-width: 768px) {
  .screen-content { padding: 32px 24px; }
  .welcome-title { font-size: 3rem; }
  .home-card { padding: 32px; }
  .result-image-wrapper { max-height: 500px; aspect-ratio: auto; }
  .result-image { max-height: 500px; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* --- Selection --- */
::selection { background: var(--accent); color: #fff; }
