:root {
  --page-bg: #ffffff;
  --chat-bg: #ffffff;
  --topbar-bg: #ffffff;
  --topbar-text: #262626;
  --border: #dfe3e6;
  --bubble-bg: #f3f3f5;
  --text-main: #202020;
  --text-sub: #4a5560;
  --text-sub-soft: #5c6b77;
  --name-color: #46525c;
  --accent: #fee500;
  --accent-text: #3c1e1e;
  --input-bg: #f3f3f5;
  --input-text: #9aa2a8;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* Twemoji: 폰트 대신 이미지로 렌더링되는 이모지 - 텍스트와 자연스럽게 어울리도록 크기/정렬 보정 */
img.emoji {
  height: 1.2em;
  width: 1.2em;
  margin: 0 .04em 0 .08em;
  vertical-align: -0.2em;
  display: inline-block;
}

html, body {
  margin: 0;
  padding: 0;
  background: #ffffff;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  color: var(--text-main);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06), 0 0 18px rgba(0,0,0,0.18);
  position: relative;
  overflow: hidden;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar-bg);
}
.topbar-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 12px;
}
.back {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--topbar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.back svg { width: 23px; height: 23px; }
.peer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.peer h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--topbar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icons {
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--topbar-text);
  flex-shrink: 0;
  justify-self: end;
}
.icons svg { width: 21px; height: 21px; }
.icons button {
  border: none;
  background: none;
  padding: 0;
  display: flex;
  cursor: pointer;
  color: inherit;
}

.nav-strip {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
}

.years {
  display: flex;
  gap: 20px;
  padding: 0 16px;
}
.year-pill {
  flex: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: #a3a8ad;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 3px 1px 6px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.year-pill:hover { color: #4a4a4a; }
.year-pill.active {
  color: #1c1c1e;
  font-weight: 800;
  border-bottom-color: var(--accent);
}

.months {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 4px 12px 8px;
  scrollbar-width: none;
}
/* 기본: 연도만 보이고, 연도를 누르면(.open) 월/날짜 칸이 펼쳐짐 */
.nav-strip:not(.open) .months,
.nav-strip:not(.open) .days { display: none; }
.nav-strip.open .years { padding-bottom: 0; }
.months::-webkit-scrollbar { display: none; }
.month-pill {
  flex: 1 1 0;
  min-width: 30px;
  max-width: 54px;
  text-align: center;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #6b7075;
  background: #f1f2f3;
  border: none;
  padding: 5px 0;
  white-space: nowrap;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.month-pill:hover { background: #e7e8e9; }
.month-pill.active {
  color: var(--accent-text);
  background: var(--accent);
  font-weight: 700;
}

.days {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding: 0 12px 10px;
  scrollbar-width: none;
}
.days::-webkit-scrollbar { display: none; }
.days:empty { display: none; padding: 0; }
.day-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  font-size: 10px;
  font-weight: 500;
  color: #9aa1a6;
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-variant-numeric: tabular-nums;
}
.day-pill .day-num {
  font-size: 12.5px;
  font-weight: 700;
  color: #4a4a4a;
}
.day-pill:hover { background: #f5f5f5; }
.day-pill.active {
  color: rgba(60,30,30,0.55);
  background: var(--accent);
  border-color: var(--accent);
}
.day-pill.active .day-num { color: var(--accent-text); }

/* ---------- chat area ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 40px;
  scroll-behavior: smooth;
  background: var(--chat-bg);
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.18) transparent;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background:#fff; border:1px solid rgba(0,0,0,.15); background-clip:padding-box; border-radius:999px; }
.chat::-webkit-scrollbar-thumb:hover { background:#fff; border-color:rgba(0,0,0,.28); }
.chat-inner {
  display: flex;
  flex-direction: column;
}

.day-divider {
  text-align: center;
  margin: 16px 0 14px;
  font-size: 11.5px;
  font-weight: 600;
  color: #8f959a;
}
.day-divider:first-child { margin-top: 4px; }
.day-divider span {
  background: #f1f2f3;
  padding: 4px 12px;
  border-radius: 999px;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #e2e8ec, #a9b7c1);
  margin-top: 2px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .fallback {
  display: none;
  width: 100%; height: 100%;
  align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 13px;
}

.msg-body { min-width: 0; }

.sender-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--name-color);
  margin: 0 0 4px;
}

.bubble-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.bubble {
  background: var(--bubble-bg);
  color: var(--text-main);
  padding: 9px 12px;
  border-radius: 15px;
  border-top-left-radius: 3px;
  font-size: 14.5px;
  line-height: 1.46;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 240px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}

.time {
  font-size: 10.5px;
  color: var(--text-sub);
  flex-shrink: 0;
  padding-bottom: 2px;
  white-space: nowrap;
}

/* ---------- link wrapper ---------- */
.src-link-wrap {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

/* ---------- attachment cards ---------- */
.attach-card {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bubble-bg);
  border-radius: 15px;
  border-top-left-radius: 3px;
  padding: 11px 14px;
  max-width: 220px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.attach-media {
  display: block;
  border-radius: 15px;
  border-top-left-radius: 3px;
  max-width: 230px;
  max-height: 300px;
}
.photo-media { object-fit: cover; background: #e8e8e8; }
.video-media { max-width: 230px; background: #000; }
.voice-card audio { display: block; width: 210px; height: 36px; }
.attach-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f1f1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}
.attach-icon.photo { background: #eef4ff; }
.attach-icon.video { background: #fff0f0; }
.attach-icon.voice { background: #f0f4ff; }
.attach-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.attach-label {
  font-size: 13.5px;
  font-weight: 600;
  color: #333;
}
.attach-sub {
  font-size: 11.5px;
  color: var(--text-sub-soft);
}
.voice-card {
  background: var(--bubble-bg);
  border-radius: 15px;
  border-top-left-radius: 3px;
  padding: 10px 12px;
  max-width: 240px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.06);
}
.voice-card .attach-label { margin-bottom: 6px; }

/* ---------- jump to latest button ---------- */
.jump {
  position: absolute;
  right: 18px;
  bottom: 22px;
  z-index: 20;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  color: #4a4a4a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.jump svg { width: 18px; height: 18px; }
.jump.show { opacity: 1; pointer-events: auto; }

.empty-state {
  text-align: center;
  color: #9aa1a6;
  font-size: 13px;
  padding: 60px 20px;
  opacity: 0.85;
}

/* ---------- password gate ---------- */
.pw-gate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}
.pw-gate.unlocked { display: none; }
.pw-lock { font-size: 30px; }
.pw-title { font-size: 14.5px; font-weight: 700; color: #221F1C; }
.pw-input {
  padding: 10px 14px;
  border: 1px solid #DEDAD2;
  border-radius: 10px;
  font-size: 14px;
  width: 200px;
  text-align: center;
  outline: none;
}
.pw-input:focus { border-color: #b7afa1; }
.pw-submit {
  padding: 9px 26px;
  border: none;
  border-radius: 999px;
  background: #221F1C;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.pw-error { color: #E8556B; font-size: 12px; visibility: hidden; }
.pw-error.show { visibility: visible; }

/* ---------- search overlay ---------- */
.search-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
}
.search-overlay[hidden] { display: none; }
.search-bar {
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px;
  flex-shrink: 0;
}
.search-back {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--topbar-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.search-back svg { width: 21px; height: 21px; }
.search-input {
  flex: 1;
  border: none;
  outline: none;
  background: #f1f2f3;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-main);
  min-width: 0;
}
.search-input::placeholder { color: #a0a6ab; }
.search-clear {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  color: #9aa1a6;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
.search-clear svg { width: 20px; height: 20px; }
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 30px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.18) transparent;
}
.search-results::-webkit-scrollbar { width: 6px; }
.search-results::-webkit-scrollbar-track { background: transparent; }
.search-results::-webkit-scrollbar-thumb { background:#fff; border:1px solid rgba(0,0,0,.15); background-clip:padding-box; border-radius:999px; }
.search-results::-webkit-scrollbar-thumb:hover { background:#fff; border-color:rgba(0,0,0,.28); }
.search-meta {
  padding: 10px 16px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-sub);
}
.search-empty {
  text-align: center;
  color: var(--text-sub);
  font-size: 13px;
  padding: 60px 20px;
}
.search-result-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  cursor: pointer;
  padding: 10px 16px;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.search-result-item:hover,
.search-result-item:active { background: rgba(255,255,255,0.35); }
.search-result-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 3px;
}
.search-result-snippet {
  font-size: 13.5px;
  color: var(--text-main);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-snippet mark {
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 3px;
  padding: 0 1px;
}

/* ---------- profile / media / voice overlay ---------- */
.profile-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: var(--chat-bg);
  display: flex;
  flex-direction: column;
}
.profile-overlay[hidden] { display: none; }

.profile-header {
  display: flex;
  align-items: center;
  padding: 14px 12px 4px;
  flex-shrink: 0;
}

.profile-tabs {
  display: flex;
  gap: 22px;
  padding: 14px 18px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.profile-tab {
  border: none;
  background: none;
  padding: 0 2px 12px;
  font-size: 15.5px;
  font-weight: 700;
  color: #b0b5ba;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.profile-tab.active {
  color: #222426;
  border-bottom-color: #222426;
}

.profile-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.18) transparent;
}
.profile-body::-webkit-scrollbar { width: 6px; }
.profile-body::-webkit-scrollbar-track { background: transparent; }
.profile-body::-webkit-scrollbar-thumb { background:#fff; border:1px solid rgba(0,0,0,.15); background-clip:padding-box; border-radius:999px; }
.profile-body::-webkit-scrollbar-thumb:hover { background:#fff; border-color:rgba(0,0,0,.28); }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-content: start;
}
.profile-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: #eceff1;
}
.profile-item img,
.profile-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.profile-item.is-video::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at center, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.15) 100%);
  pointer-events: none;
}
.profile-item.is-video::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 8px 0 8px 13px;
  border-color: transparent transparent transparent #ffffff;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
  z-index: 1;
}
.profile-download {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  z-index: 2;
}
.profile-download svg { width: 14px; height: 14px; }

/* voice message list */
.voice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bubble-bg);
  border-radius: 13px;
  padding: 10px 12px;
}
.voice-row-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f0f4ff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
}
.voice-row-main {
  flex: 1;
  min-width: 0;
}
.voice-row-date {
  font-size: 11px;
  color: var(--text-sub);
  margin-bottom: 4px;
}
.voice-row-main audio {
  display: block;
  width: 100%;
  height: 34px;
}
.voice-row-download {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #f1f2f3;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}
.voice-row-download svg { width: 14px; height: 14px; }

/* shared empty state (matches KakaoTalk-style empty screen) */
.profile-empty {
  text-align: center;
  padding: 130px 30px 0;
}
.profile-empty-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 20px;
  border-radius: 16px;
  border: 2px solid #d8dbde;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.profile-empty-icon svg { width: 100%; height: 100%; }
.profile-empty-title {
  font-size: 17px;
  font-weight: 700;
  color: #3d4148;
  margin-bottom: 10px;
}
.profile-empty-sub {
  font-size: 13px;
  color: #b0b5ba;
  line-height: 1.55;
  white-space: pre-line;
}

/* ---------- jump-to-message highlight ---------- */
@keyframes bubbleFlash {
  0% { box-shadow: 0 0 0 3px rgba(254,229,0,0.9), 0 1px 1px rgba(0,0,0,0.06); }
  100% { box-shadow: 0 1px 1px rgba(0,0,0,0.06); }
}
.msg-row.flash .bubble,
.msg-row.flash .attach-card,
.msg-row.flash .voice-card {
  animation: bubbleFlash 1.6s ease-out;
}

/* ---------- landing (intro) screen ---------- */
.landing {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  color: #ffffff;
  overflow: hidden;
}
.landing.hidden { display: none; }

.landing-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #2b2b2b;
}
.landing-bg-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 1;
}
.landing-bg-img.load-error { display: none; }
.landing-bg-fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: linear-gradient(160deg, #4f5f52 0%, #2f3a32 55%, #23291f 100%);
}
.landing-bg-shade {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(
    to bottom,
    rgba(0,0,0,0.35) 0%,
    rgba(0,0,0,0.05) 22%,
    rgba(0,0,0,0.05) 55%,
    rgba(0,0,0,0.55) 78%,
    rgba(0,0,0,0.8) 100%
  );
}

.landing-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 0;
}
.landing-top-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.landing-icon-btn {
  width: 30px;
  height: 30px;
  border: none;
  outline: none;
  background: none;
  background-color: transparent;
  box-shadow: none;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
  text-decoration: none;
}
.landing-icon-btn:focus,
.landing-icon-btn:active {
  background: none;
  background-color: transparent;
  box-shadow: none;
  outline: none;
}
.landing-icon-btn svg { width: 22px; height: 22px; }

.landing-dday {
  position: relative;
  z-index: 2;
  margin-top: 16%;
  text-align: center;
}
.landing-dday-label {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
.landing-dday-count {
  margin-top: 10px;
  font-size: 26px;
  font-weight: 800;
}
.landing-dday-count span {
  text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

.landing-bottom {
  position: relative;
  z-index: 2;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px 26px;
  text-align: center;
}
.landing-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  border: 3px solid rgba(255,255,255,0.85);
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
  background: linear-gradient(135deg, #e2e8ec, #a9b7c1);
  margin-bottom: 12px;
}
.landing-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.landing-avatar img.load-error { display: none; }
.landing-avatar-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 26px;
}
.landing-name {
  font-size: 19px;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.landing-sub {
  margin-top: 4px;
  font-size: 13.5px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.landing-cta {
  margin-top: 18px;
  width: 100%;
  max-width: 400px;
  border: none;
  border-radius: 999px;
  padding: 15px 0;
  background: #ff4f6d;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255,79,109,0.4);
}
.landing-cta:active { background: #ea3f5c; }
