/* ============================================================
   Sentimind — Shared Components
   다크모드 변수, 스켈레톤, 분석 로딩, 토스트, 접근성,
   애니메이션/이펙트, 푸터, 그림일기, Entry Edit
   ============================================================ */

/* --- Dark mode variables (must load first) --- */
/* Dark mode — Stone warm dark */
[data-theme="dark"] {
  --color-bg: #141211;
  --color-surface: #1C1917;
  --color-surface-warm: #292524;
  --color-surface-hover: #211F1E;
  --color-primary: #FB923C;
  --color-primary-hover: #F97316;
  --color-secondary: #FDBA74;
  --color-text: #FAFAF9;
  --color-text-light: #A8A29E;
  --color-text-muted: #57534E;
  --color-border: #292524;
  --color-divider: #1C1917;
  --color-error: #EF4444;
  --color-error-bg: #2E1A1A;
  --color-success: #22C55E;
  --color-success-bg: #1A2E1E;
  --gradient-response: linear-gradient(160deg, #1C1917 0%, #292524 100%);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 20px rgba(251,146,60,0.12);
}
[data-theme="dark"] .history-item { background: var(--color-surface); border-color: var(--color-border); }
[data-theme="dark"] .history-item:hover { border-color: var(--color-divider); }
[data-theme="dark"] .history-emotion { background: rgba(251, 146, 60, 0.12); color: var(--color-primary); }
[data-theme="dark"] .btn-detail-delete:hover { background: var(--color-error-bg); }
[data-theme="dark"] .summary-card { border-color: var(--color-border); }
[data-theme="dark"] .summary-card:hover { border-color: rgba(251, 146, 60, 0.3); }
[data-theme="dark"] .dashboard-section { border-color: var(--color-border); }
[data-theme="dark"] .trend-chart { border-color: var(--color-border); }
[data-theme="dark"] .search-input:focus { box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.1); }
[data-theme="dark"] .diary-input:focus-within { box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.1); }
[data-theme="dark"] .followup-start-btn { background: var(--color-primary); opacity: 0.95; }
[data-theme="dark"] .followup-start-btn:hover { opacity: 0.85; }
[data-theme="dark"] .empty-state { background: var(--color-surface); border-color: var(--color-border); }
[data-theme="dark"] .btn-load-more { background: var(--color-surface); border-color: var(--color-border); }
[data-theme="dark"] .btn-load-more:hover { border-color: var(--color-primary); background: var(--color-surface-warm); }


/* --- Skeleton loading --- */
/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, #e0d5c8 25%, #ebe3d9 37%, #e0d5c8 63%);
  background-size: 400% 100%;
  animation: skeletonPulse 1.6s ease infinite;
  border-radius: var(--radius-sm);
}
[data-theme="dark"] .situation-tag {
  color: #6ec0d8;
}
[data-theme="dark"] .skeleton {
  background: linear-gradient(90deg, #292524 25%, #3a3533 37%, #292524 63%);
  background-size: 400% 100%;
}
@keyframes skeletonPulse {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
.skeleton-line { height: 1em; margin-bottom: 0.5rem; }
.skeleton-line:last-child { width: 60%; }
.skeleton-card { height: 60px; margin-bottom: 0.5rem; border-radius: var(--radius-md); }
.skeleton-summary { height: 70px; border-radius: var(--radius-md); }

/* ===== Analyze Loading (마음이 reading state) ===== */
.analyze-loading {
  background: var(--gradient-response);
  border-radius: var(--radius-xl);
  padding: 2.5rem 1.5rem;
  box-shadow: var(--shadow-md);
  text-align: center;
  overflow-anchor: none;
  animation: fadeInUp 400ms ease both;
}
.analyze-loading[hidden] { display: none; }
.analyze-loading-glow {
  width: 48px;
  height: 48px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(194,113,79,0.3) 0%,
    rgba(194,113,79,0.08) 50%,
    transparent 70%
  );
  animation: warmGlow 3s ease-in-out infinite;
}
@keyframes warmGlow {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 20px rgba(194,113,79,0.15);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.15);
    box-shadow: 0 0 40px rgba(194,113,79,0.25);
    opacity: 1;
  }
}
.analyze-loading-primary {
  font-family: var(--font-diary);
  font-size: var(--text-base);
  color: var(--color-text);
  margin-bottom: 0.35rem;
  transition: opacity 400ms ease, transform 400ms ease;
  min-height: 1.6em;
}
.analyze-loading-primary.fade-out {
  opacity: 0;
  transform: translateY(-4px);
}
.analyze-loading-secondary {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.analyze-loading.exit {
  animation: loadingExit 300ms ease-in forwards;
}
@keyframes loadingExit {
  to { opacity: 0; transform: scale(0.96) translateY(-8px); }
}
[data-theme="dark"] .analyze-loading {
  background: linear-gradient(160deg, #1c1917 0%, #292524 100%);
}
[data-theme="dark"] .analyze-loading-glow {
  background: radial-gradient(circle,
    rgba(194,113,79,0.25) 0%,
    rgba(194,113,79,0.06) 50%,
    transparent 70%
  );
}
@media (prefers-reduced-motion: reduce) {
  .analyze-loading-glow { animation: none; opacity: 0.9; }
  .analyze-loading-primary { transition: none; }
  .analyze-loading.exit { animation: none; }
}

/* Entry skeleton: mimics history-item layout */
.skeleton-entry {
  background: var(--color-surface-warm);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.skeleton-entry .skeleton-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}
.skeleton-entry .skeleton-body {
  flex: 1; min-width: 0;
}
.skeleton-entry .skeleton-body-line {
  height: 0.85em;
  margin-bottom: 0.4rem;
}
.skeleton-entry .skeleton-body-line:first-child { width: 80%; }
.skeleton-entry .skeleton-body-line:last-child { width: 45%; margin-bottom: 0; }

/* Stats skeleton: mimics summary cards + bar chart */
.skeleton-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.skeleton-stats-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column;
  align-items: center; gap: 0.5rem;
}
.skeleton-stats-card .skeleton-value {
  width: 50px; height: 1.5em;
  border-radius: var(--radius-sm);
}
.skeleton-stats-card .skeleton-label {
  width: 70px; height: 0.8em;
  border-radius: var(--radius-sm);
}
.skeleton-bar-group {
  display: flex; flex-direction: column; gap: 0.5rem;
}
.skeleton-bar-row {
  display: flex; align-items: center; gap: 0.5rem;
}
.skeleton-bar-label {
  width: 50px; height: 0.85em;
  flex-shrink: 0;
}
.skeleton-bar-track {
  flex: 1; height: 20px;
  border-radius: var(--radius-sm);
}
.skeleton-bar-row:nth-child(2) .skeleton-bar-track { width: 75%; }
.skeleton-bar-row:nth-child(3) .skeleton-bar-track { width: 55%; }
.skeleton-bar-row:nth-child(4) .skeleton-bar-track { width: 35%; }

/* --- Footer --- */
/* Footer */
.app-footer {
  text-align: center;
  margin-top: 3rem;
  padding-bottom: 2rem;
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.8rem);
  color: var(--color-text-muted);
}

/* --- Toast notification system --- */
/* Toast notification system */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  align-items: center;
  pointer-events: none;
  max-width: calc(100% - 32px);
  width: 400px;
}
.toast {
  pointer-events: auto;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-family: var(--font-body);
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: toastSlideUp 300ms cubic-bezier(0.25,0.46,0.45,0.94) both;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: center;
}
.toast-action-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: inherit;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: bold;
  white-space: nowrap;
  transition: background 0.2s;
}
.toast-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}
.toast.toast-info .toast-action-btn {
  background: var(--color-surface-hover);
  border-color: var(--color-border);
}
.toast.toast-error {
  background: #c62828;
  color: #fff;
}
.toast.toast-success {
  background: #2e7d32;
  color: #fff;
}
.toast.toast-info {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
[data-theme="dark"] .toast.toast-info {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.toast.toast-dismissing {
  animation: toastSlideDown 300ms cubic-bezier(0.55,0.06,0.68,0.19) forwards;
}
@keyframes toastSlideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastSlideDown {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(16px); }
}

/* Legacy error-toast (kept for backward compat) */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #c62828;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: transform 300ms ease;
  max-width: calc(100% - 32px);
  text-align: center;
}
.error-toast.show { transform: translateX(-50%) translateY(0); }

/* Focus trap overlay for modals */
.focus-trap-active { overflow: hidden; }

/* Improved focus indicators */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* aria-busy loading state */
[aria-busy="true"] {
  cursor: wait;
}

/* --- Streak sparkle/badges, confetti, particles --- */
/* === Feature 2: Streak sparkle & badges === */
@keyframes sparkle {
  0%, 100% { box-shadow: var(--shadow-sm); }
  50% { box-shadow: 0 0 15px rgba(232,168,124,0.5), 0 0 30px rgba(232,168,124,0.3); }
}
.sparkle { animation: sparkle 0.75s ease 2; }
.profile-badges { margin-top: 1rem; }
.profile-badges-title {
  font-family: var(--font-diary); font-size: 0.9rem; font-weight: 600;
  color: var(--color-text); margin-bottom: 0.75rem;
}
.badges-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
}
.badge-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 0.75rem 0.5rem; border-radius: var(--radius-md);
  background: var(--color-surface); border: 1px solid var(--color-border);
  opacity: 0.4; filter: grayscale(1); transition: all 300ms ease;
}
.badge-item.achieved { opacity: 1; filter: none; border-color: var(--color-primary); }
.badge-emoji { font-size: 1.5rem; }
.badge-name { font-size: 0.7rem; color: var(--color-text); font-weight: 500; text-align: center; }
.badge-days { font-size: 0.65rem; color: var(--color-text-muted); }

/* === Feature 3: Confetti animation === */
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(120vh) rotate(720deg); opacity: 0; }
}
@keyframes gradientPulse {
  0% { background-size: 100% 100%; }
  50% { background-size: 150% 150%; }
  100% { background-size: 100% 100%; }
}
.confetti-container {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 9999; overflow: hidden;
}
.confetti-piece {
  position: absolute; top: -10px;
  width: 10px; height: 10px; border-radius: 2px;
  animation: confettiFall 2s ease-out forwards;
}
/* Gentle floating particles for negative emotions */
@keyframes gentleFloat {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 0;
  }
  20% {
    opacity: 0.6;
    transform: translateY(-15vh) scale(1);
  }
  100% {
    transform: translateY(-60vh) scale(0.3);
    opacity: 0;
  }
}
.gentle-particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0;
  animation: gentleFloat 3s ease-out forwards;
}
@media (prefers-reduced-motion: reduce) {
  .gentle-particle { animation: none; display: none; }
}

.response-card.pulse-bg {
  animation: gradientPulse 1s ease-in-out 1;
}

/* --- Card press feedback, load more btn --- */
/* Card active/press feedback */
.history-item:active {
  transform: translateY(0) scale(0.99);
  transition-duration: 50ms;
}

/* Load more button */
.btn-load-more {
  display: block;
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.75rem;
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
  color: var(--color-text-light);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 200ms, color 200ms, background 200ms;
}
.btn-load-more:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-surface-warm);
}


/* --- Footer legal links --- */
/* Footer legal links */
.footer-legal {
  font-size: 0.7rem;
  margin-top: 0.3rem;
  opacity: 0.6;
}
.footer-legal a { color: inherit; }


/* --- Illustrated Diary Card --- */
/* ======================================================
   Illustrated Diary Card (그림일기 3컷 카드)
   ====================================================== */
.illustrated-diary-btn {
  display: block;
  margin: 1.2rem auto 0;
  padding: 0.7rem 1.6rem;
  border: 2px dashed var(--accent, #8b7ec8);
  border-radius: 12px;
  background: transparent;
  color: var(--accent, #8b7ec8);
  font-family: 'Gowun Dodum', sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s ease;
}
.illustrated-diary-btn:hover:not(:disabled) {
  background: var(--accent, #8b7ec8);
  color: #fff;
  border-style: solid;
}
.illustrated-diary-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.illustrated-diary-card {
  margin-top: 1rem;
  padding: 1.5rem;
  border-radius: 16px;
  background: var(--color-surface);
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  animation: fadeInUp 0.5s ease-out;
  overflow: hidden;
}

.illust-title {
  text-align: center;
  font-family: 'Gowun Batang', serif;
  font-size: 1.2rem;
  color: var(--text-primary, #2c2c2c);
  margin: 0 0 1.2rem;
  letter-spacing: 0.02em;
}

.illust-panels {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.illust-panel {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 1rem 1.2rem;
  border-radius: 12px;
  animation: fadeInUp 0.4s ease-out both;
  position: relative;
  overflow: hidden;
}

.illust-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.3);
  pointer-events: none;
}

.illust-panel-emoji {
  font-size: 1.8rem;
  flex-shrink: 0;
  z-index: 1;
}

.illust-panel-num {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(0,0,0,0.15);
  font-family: 'Gowun Dodum', sans-serif;
  z-index: 1;
}

.illust-panel-caption {
  font-family: 'Gowun Batang', serif;
  font-size: 0.95rem;
  line-height: 1.5;
  color: rgba(0,0,0,0.75);
  margin: 0;
  z-index: 1;
}

.illust-closing {
  text-align: center;
  font-family: 'Gowun Batang', serif;
  font-size: 0.9rem;
  color: var(--text-secondary, #666);
  margin: 1.2rem 0 0.5rem;
  font-style: italic;
}

.illust-brand {
  text-align: right;
  font-size: 0.7rem;
  color: var(--text-muted, #aaa);
  margin: 0.3rem 0 0;
  letter-spacing: 0.05em;
}

/* 다크모드 */
[data-theme="dark"] .illustrated-diary-card {
  background: var(--color-surface);
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}
[data-theme="dark"] .illust-title {
  color: var(--color-text);
}
[data-theme="dark"] .illust-panel::before {
  background: rgba(0,0,0,0.15);
}
[data-theme="dark"] .illust-panel-caption {
  color: rgba(255,255,255,0.85);
}
[data-theme="dark"] .illust-panel-num {
  color: rgba(255,255,255,0.2);
}
[data-theme="dark"] .illust-closing {
  color: var(--color-text-light);
}
[data-theme="dark"] .illustrated-diary-btn {
  color: var(--color-text-light);
  border-color: var(--color-border);
}

/* 모바일 반응형 */
@media (max-width: 480px) {
  .illustrated-diary-card {
    padding: 1rem;
  }
  .illust-panel {
    padding: 0.8rem 1rem;
  }
  .illust-panel-emoji {
    font-size: 1.5rem;
  }
  .illust-panel-caption {
    font-size: 0.88rem;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .illust-panel {
    animation: none;
  }
  .illustrated-diary-card {
    animation: none;
  }
}

/* --- Entry Edit (legacy) --- */
/* Entry Edit */
.entry-edit-btn {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #666);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}
.entry-edit-btn:hover {
  background: var(--accent, #8b7ec8);
  color: #fff;
  border-color: var(--accent, #8b7ec8);
}
.entry-edit-textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.8rem;
  border: 2px solid var(--accent, #8b7ec8);
  border-radius: 8px;
  font-family: 'Gowun Batang', serif;
  font-size: 0.95rem;
  line-height: 1.6;
  resize: vertical;
  background: var(--color-surface);
  color: var(--color-text);
}
.entry-edit-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.entry-edit-save {
  padding: 0.4rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent, #8b7ec8);
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}
.entry-edit-save:disabled {
  opacity: 0.6;
  cursor: wait;
}
.entry-edit-cancel {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary, #666);
  font-size: 0.85rem;
  cursor: pointer;
}
