/* ===== 기본 변수 (다크모드) ===== */
:root {
  --bg: #0f0f17;
  --bg-elev: #1a1a26;
  --bg-card: #20202e;
  --border: #2c2c3d;
  --text: #ececf1;
  --text-dim: #9a9aae;
  --muted: #6b6b80;
  --accent: #ff6b8a;
  --accent-2: #b76bff;
  --accent-soft: rgba(255, 107, 138, 0.15);
  --danger: #ff5e5e;
  --success: #5eda9b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(72px + var(--safe-bottom));
}

h1, h2, h3 { margin: 0; font-weight: 700; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }

/* ===== 헤더 ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 18px 12px;
  background: rgba(15, 15, 23, 0.85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.app-header h1 { font-size: 18px; letter-spacing: 0.5px; }
.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 12px var(--accent);
}
.icon-btn {
  background: transparent;
  color: var(--text);
  border: none;
  font-size: 20px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-elev); }

/* ===== 메인 ===== */
main {
  flex: 1;
  padding: 18px 18px 28px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel { display: none; animation: fadeIn .25s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== D-day 영역 ===== */
.dday-hero {
  margin: 8px 0 28px;
  padding: 32px 20px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255,107,138,0.18), rgba(183,107,255,0.18));
  border: 1px solid var(--border);
  border-radius: 24px;
  position: relative;
  overflow: hidden;
}
.dday-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(255,107,138,0.25), transparent 50%),
              radial-gradient(circle at 80% 80%, rgba(183,107,255,0.25), transparent 50%);
  pointer-events: none;
}
.dday-label { margin: 0; color: var(--text-dim); font-size: 13px; letter-spacing: 1px; }
.dday-hero h2 {
  font-size: 48px;
  margin: 10px 0 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
  letter-spacing: -1px;
}
.dday-sub { margin: 0; color: var(--text-dim); font-size: 13px; }

/* 섹션 헤더 */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 4px 12px;
}
.section-head h3 { font-size: 15px; color: var(--text-dim); font-weight: 600; }
.btn-add {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(255,107,138,0.3);
  width: 32px; height: 32px;
  border-radius: 10px;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.btn-add:hover { background: rgba(255,107,138,0.25); }

/* 카드 리스트 */
.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.card-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; margin: 0 0 2px; font-size: 15px; }
.card-sub { margin: 0; font-size: 12px; color: var(--text-dim); }
.card-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.card-delete {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 4px 6px;
  font-size: 16px;
}
.card-delete:hover { color: var(--danger); }

/* ===== 캘린더 ===== */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.cal-header h3 { font-size: 17px; }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  padding: 6px 0;
}
.cal-weekdays span:first-child { color: #ff8a8a; }
.cal-weekdays span:last-child { color: #8aaaff; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.cal-cell {
  aspect-ratio: 1 / 1.05;
  background: var(--bg-card);
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 6px;
  position: relative;
  transition: background .15s, border-color .15s;
}
.cal-cell.muted { color: var(--muted); background: transparent; }
.cal-cell.today { border-color: var(--accent); }
.cal-cell.selected { background: var(--accent-soft); border-color: var(--accent); }
.cal-cell.has-event::after {
  content: "";
  position: absolute;
  bottom: 6px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.cal-cell.sunday { color: #ff8a8a; }
.cal-cell.saturday { color: #8aaaff; }

/* ===== 앨범 ===== */
.album-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.album-grid img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .15s;
}
.album-grid img:active { transform: scale(0.96); }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .muted { font-size: 13px; }

/* ===== 교환일기 ===== */
.diary-compose {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.diary-compose textarea,
.diary-compose select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  resize: vertical;
  width: 100%;
}
.diary-compose textarea:focus,
.diary-compose select:focus { outline: none; border-color: var(--accent); }

.diary-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.diary-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
}
.diary-item.me { border-left: 3px solid var(--accent); }
.diary-item.partner { border-left: 3px solid var(--accent-2); }
.diary-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.diary-author { font-weight: 700; color: var(--text); }
.diary-content { font-size: 14px; white-space: pre-wrap; word-break: break-word; }

/* ===== 하단 탭 ===== */
.bottom-tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: space-around;
  background: rgba(20, 20, 30, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 40;
}
.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  transition: color .15s;
}
.tab-icon { font-size: 20px; }
.tab-label { font-size: 11px; letter-spacing: 0.5px; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active .tab-icon { transform: scale(1.05); }

/* ===== 모달 ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card h2, .modal-card h3 { margin-bottom: 12px; }
.modal-card label {
  display: block;
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}
.modal-card input,
.modal-card textarea {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
}
.modal-card input:focus,
.modal-card textarea:focus { outline: none; border-color: var(--accent); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }

/* 버튼 */
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  width: 100%;
  transition: transform .1s, opacity .15s;
}
.btn-primary:active { transform: scale(0.98); opacity: 0.92; }
.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
}
.btn-ghost:hover { background: var(--border); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
}
.btn-danger:hover { background: rgba(255, 94, 94, 0.12); }

/* 사진 뷰어 */
#photo-viewer {
  background: rgba(0,0,0,0.95);
  padding: 0;
}
#photo-viewer img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
}
.photo-close {
  position: absolute;
  top: calc(20px + var(--safe-top));
  right: 20px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
}
.photo-delete {
  position: absolute;
  bottom: calc(30px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  min-width: 140px;
}

/* 반응형: 데스크탑 */
@media (min-width: 768px) {
  body { font-size: 16px; }
  main { padding: 30px 30px 60px; }
  .dday-hero h2 { font-size: 64px; }
  .album-grid { grid-template-columns: repeat(4, 1fr); }
}
