/* ══════════════════════════════════════
   일기장 스타일 — 라이트/다크 모드 지원
   ══════════════════════════════════════ */

/* 라이트 테마 (기본) */
:root {
  --bg: #faf7f2;
  --bg-alt: #f3ede0;
  --surface: #ffffff;
  --primary: #d4a574;
  --primary-dark: #b8895a;
  --primary-light: #f5e6d0;
  --text: #2d2418;
  --text-dim: #8a7f73;
  --border: #e8e0d4;
  --danger: #c74646;
  --danger-bg: #fbeded;
  --shadow: 0 2px 8px rgba(90, 70, 40, 0.08);
  --shadow-hover: 0 4px 16px rgba(90, 70, 40, 0.15);
  --radius: 14px;
}

/* 다크 테마 */
body.dark {
  --bg: #1a1714;
  --bg-alt: #252119;
  --surface: #2a251d;
  --primary: #d4a574;
  --primary-dark: #e8b98a;
  --primary-light: #3a2f20;
  --text: #f0e8db;
  --text-dim: #9a8f81;
  --border: #3a342a;
  --danger: #e57b7b;
  --danger-bg: #3a1f1f;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

/* ── 앱 컨테이너 (최대 폭 제한 + 중앙 정렬) ── */
.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
  transition: background 0.2s;
}

/* ── 화면 전환 ── */
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.28s ease, background 0.2s;
  will-change: transform;
}
.view.active { transform: translateX(0); }

/* ══ 헤더 ══ */
.app-header {
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 0;
  box-shadow: var(--shadow);
  z-index: 10;
  transition: background 0.2s, border-color 0.2s;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.header-top h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.edit-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 10px;
}
.edit-center {
  flex: 1;
  text-align: center;
  min-width: 0;
}
.edit-date {
  font-size: 0.88rem;
  color: var(--text-dim);
  font-weight: 500;
}
.auto-save-indicator {
  font-size: 0.72rem;
  color: var(--primary-dark);
  margin-top: 2px;
  opacity: 0;
  transition: opacity 0.3s;
}
.auto-save-indicator.show { opacity: 1; }

.icon-btn {
  width: 38px; height: 38px;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background 0.15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-alt); }
.favorite-btn { color: var(--primary); }
.favorite-btn.active { color: #f0c040; }

.save-btn {
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.save-btn:hover, .save-btn:active { background: var(--primary-dark); }

/* ══ 탭 ══ */
.tabs {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
  margin-bottom: 10px;
}
.tab-btn {
  flex: 1;
  padding: 9px 4px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 90px;
  -webkit-overflow-scrolling: touch;
}
.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ══ 필터 바 ══ */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filter-bar input[type=search] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s, background 0.2s;
}
.filter-bar input[type=search]:focus { border-color: var(--primary); }
.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.filter-row::-webkit-scrollbar { display: none; }
.mood-filter {
  display: flex;
  gap: 4px;
}
.chip {
  flex: none;
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 16px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip:hover { background: var(--bg-alt); }
.chip.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.mood-chip { font-size: 1rem; padding: 4px 10px; }

/* ══ 연속 작성 / 이 날 이전 섹션 ══ */
.streak-display {
  background: linear-gradient(135deg, var(--primary-light), var(--bg-alt));
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}
.streak-icon { font-size: 1.6rem; }
.streak-text strong { color: var(--primary-dark); font-size: 1.15rem; }
.streak-sub { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }

.memories-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  border: 1px dashed var(--primary);
}
.memories-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--primary-dark);
  font-weight: 600;
  margin-bottom: 8px;
}
.memory-item {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.memory-item:first-of-type { border-top: none; padding-top: 0; }
.memory-year { font-size: 0.75rem; color: var(--text-dim); margin-bottom: 2px; }
.memory-title { font-size: 0.95rem; font-weight: 500; }

/* ══ 일기 카드 ══ */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.entry-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, background 0.2s;
  border: 1px solid transparent;
  position: relative;
}
.entry-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.entry-card:active { transform: scale(0.98); }
.entry-card.favorite { border-color: #f0c040; }
.entry-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.entry-mood {
  flex: none;
  font-size: 1.05rem;
  line-height: 1;
}
.entry-title {
  font-size: 1.05rem;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-weather {
  flex: none;
  font-size: 1rem;
  line-height: 1;
}
.entry-star {
  flex: none;
  color: #f0c040;
  font-size: 1rem;
}
.entry-date {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.entry-preview {
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.entry-tag {
  background: var(--bg);
  color: var(--primary-dark);
  font-size: 0.72rem;
  padding: 3px 9px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.entry-tag:hover {
  background: var(--primary);
  color: white;
}

/* ══ 빈 상태 ══ */
.empty-state {
  display: none;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state.show { display: block; }
.empty-icon { font-size: 3.5rem; margin-bottom: 14px; }
.empty-title { font-size: 1.05rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-hint { font-size: 0.85rem; }

/* ══ FAB (+ 버튼) ══ */
.fab {
  position: absolute;
  bottom: 22px;
  right: 22px;
  width: 60px; height: 60px;
  padding: 0;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(212, 165, 116, 0.5);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 20px rgba(212, 165, 116, 0.7);
  transform: scale(1.05);
}
.fab:active { transform: scale(0.95); }

/* ══ 달력 ══ */
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}
.calendar-header h2 { font-size: 1.1rem; font-weight: 600; }
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  padding: 6px 0;
}
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  font-size: 0.85rem;
  padding: 2px;
  transition: background 0.12s, color 0.12s;
  overflow: hidden;
}
.calendar-day:hover { background: var(--primary-light); }
.calendar-day.outside { opacity: 0.3; cursor: default; }
.calendar-day.outside:hover { background: var(--bg-alt); }
.calendar-day.today {
  border: 2px solid var(--primary);
  font-weight: 700;
}
.calendar-day.has-entry {
  background: var(--primary-light);
}
.calendar-day.selected {
  background: var(--primary);
  color: white;
}
.calendar-day .cal-mood {
  font-size: 0.9rem;
  line-height: 1;
  margin-top: 1px;
}
.calendar-day-entries {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.calendar-day-entries:empty { display: none; }
.calendar-selected-title {
  font-size: 0.88rem;
  color: var(--text-dim);
  padding: 0 2px;
  margin-top: 8px;
}

/* ══ 통계 ══ */
#statsContent {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card-title {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 10px;
  font-weight: 500;
}
.stat-big-row {
  display: flex;
  gap: 10px;
}
.stat-big {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-big-num {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--primary-dark);
}
.stat-big-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 2px;
}
.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 0.88rem;
}
.stat-bar-label { flex: none; min-width: 60px; }
.stat-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.4s;
}
.stat-bar-count {
  flex: none;
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 30px;
  text-align: right;
}
.stat-tags-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.stat-tag {
  background: var(--bg);
  color: var(--primary-dark);
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.stat-tag .count {
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-left: 4px;
}
.stat-empty {
  color: var(--text-dim);
  font-size: 0.88rem;
  text-align: center;
  padding: 20px 0;
}

/* ══ 편집 화면 ══ */
.edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}
.title-input {
  width: 100%;
  padding: 12px 0;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  font-size: 1.3rem;
  font-weight: 600;
  outline: none;
  transition: border-color 0.15s;
}
.title-input:focus { border-bottom-color: var(--primary); }
.meta-row {
  display: flex;
  gap: 12px;
}
.meta-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.meta-item label {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-left: 2px;
}
.meta-item select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  outline: none;
  cursor: pointer;
  transition: background 0.2s, border-color 0.15s;
}
.meta-item select:focus { border-color: var(--primary); }
.tags-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tags-row label {
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-left: 2px;
}
.tags-row input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s, background 0.2s;
}
.tags-row input:focus { border-color: var(--primary); }
.content-input {
  flex: 1;
  min-height: 280px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.98rem;
  line-height: 1.7;
  outline: none;
  resize: none;
  transition: border-color 0.15s, background 0.2s;
}
.content-input:focus { border-color: var(--primary); }
.edit-footer { padding-top: 10px; }
.delete-btn {
  width: 100%;
  padding: 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.delete-btn:hover { background: var(--danger-bg); }

/* ══ 설정 모달 ══ */
.modal {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.2s;
}
.modal-content {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 92%;
  width: 400px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  animation: slideUp 0.25s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.05rem; font-weight: 600; }
.modal-body { padding: 16px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px;
  font-size: 0.95rem;
}
.setting-section { margin-top: 16px; }
.setting-section-title {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding-left: 2px;
}
.setting-btn {
  display: block;
  width: 100%;
  padding: 11px 14px;
  margin-bottom: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s;
}
.setting-btn:hover { background: var(--primary-light); }
.setting-btn.danger { color: var(--danger); }
.setting-btn.danger:hover { background: var(--danger-bg); }
.setting-info {
  margin-top: 18px;
  padding: 12px;
  background: var(--bg-alt);
  border-radius: 10px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.6;
}
.setting-info strong { color: var(--text); }

/* ── 토글 스위치 ── */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex: none;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 26px;
  transition: background 0.2s;
}
.switch-slider::before {
  content: '';
  position: absolute;
  width: 20px; height: 20px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(22px); }

/* ══ 토스트 ══ */
.toast {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: rgba(45, 36, 24, 0.92);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
}
body.dark .toast { background: rgba(240, 232, 219, 0.95); color: #2d2418; }
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ══ 데스크톱 ══ */
@media (min-width: 720px) {
  body { background: #ece6dc; }
  body.dark { background: #0f0c09; }
  .app-container {
    box-shadow: 0 0 40px rgba(90, 70, 40, 0.12);
  }
}
