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

:root {
  --bg: #faf5f0;
  --bg-top: #f7ede2;
  --bubble-me: #fcd5ce;
  --bubble-wife: #fff;
  --text: #3d2c2c;
  --text-secondary: #a89080;
  --border: #e8ddd0;
  --me-color: #e8967a;
  --wife-color: #c77d9e;
  --heart: #e8967a;
  --shadow: 0 1px 3px rgba(139, 109, 91, 0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin: 0 auto;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  background: var(--bg-top);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.heart-icon {
  color: var(--heart);
  display: flex;
  align-items: center;
  animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.15); }
  30% { transform: scale(1); }
  45% { transform: scale(1.1); }
  60% { transform: scale(1); }
}

.topbar-left h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.msg-count {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(139, 109, 91, 0.08);
}

.search-bar {
  padding: 8px 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-bar.hidden {
  display: none;
}

.search-bar input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  background: #fff;
  font-family: inherit;
}

.search-bar input:focus {
  border-color: var(--me-color);
}

.search-clear {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(139, 109, 91, 0.1);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Sync Bar */
.sync-bar {
  text-align: center;
  padding: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(232, 150, 122, 0.1);
  flex-shrink: 0;
}

.sync-bar.hidden {
  display: none;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--me-color);
  animation: pulse 0.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Chat Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.messages-container {
  padding: 0 12px;
}

/* Welcome / Empty */
.welcome-hint {
  text-align: center;
  padding: 80px 20px 0;
  color: var(--text-secondary);
}

.welcome-icon {
  color: #e0cfc0;
  margin-bottom: 16px;
  opacity: 0.8;
}

.welcome-hint p {
  font-size: 15px;
  line-height: 1.6;
}

.welcome-sub {
  font-size: 13px !important;
  color: #c5b0a0 !important;
  margin-top: 4px;
}

.empty-hint {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Date Divider */
.date-divider {
  text-align: center;
  padding: 20px 0 10px;
}

.date-divider span {
  font-size: 12px;
  color: #c5b0a0;
  background: var(--bg);
  padding: 4px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Message Row */
.msg-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 14px;
  gap: 8px;
}

.msg-me {
  flex-direction: row-reverse;
}

/* Avatar */
.avatar-bubble {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  margin-top: 2px;
}

.me-avatar {
  background: linear-gradient(135deg, #f0a58a, #e8967a);
  box-shadow: 0 2px 6px rgba(232, 150, 122, 0.3);
}

.wife-avatar {
  background: linear-gradient(135deg, #d49bb3, #c77d9e);
  box-shadow: 0 2px 6px rgba(199, 125, 158, 0.3);
}

/* Message Bubble Wrapper */
.msg-bubble-wrapper {
  max-width: 70%;
  min-width: 40px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.bubble-me {
  background: var(--bubble-me);
  border-top-right-radius: 6px;
}

.bubble-wife {
  background: var(--bubble-wife);
  border-top-left-radius: 6px;
  box-shadow: var(--shadow);
}

.msg-text {
  white-space: pre-wrap;
  color: var(--text);
}

/* Message Meta */
.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.msg-row:hover .msg-meta,
.msg-row:active .msg-meta {
  opacity: 1;
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
}

.msg-actions {
  display: flex;
  gap: 2px;
}

.msg-action-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.msg-action-btn:hover {
  background: rgba(139, 109, 91, 0.08);
}

.msg-action-btn.starred {
  color: #e8967a;
}

.msg-me .msg-meta {
  justify-content: flex-end;
}

/* Input Area */
.input-area {
  flex-shrink: 0;
  background: var(--bg-top);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.sender-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sender-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px 6px 8px;
  border: 1.5px solid transparent;
  border-radius: 20px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.25s;
  font-family: inherit;
}

.sender-btn.active {
  color: var(--text);
  font-weight: 500;
}

.sender-btn#sender-me.active {
  border-color: var(--me-color);
  background: rgba(232, 150, 122, 0.08);
}

.sender-btn#sender-wife.active {
  border-color: var(--wife-color);
  background: rgba(199, 125, 158, 0.08);
}

.sender-btn .sender-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.sender-btn#sender-me .sender-avatar {
  background: var(--me-color);
}

.sender-btn#sender-wife .sender-avatar {
  background: var(--wife-color);
}

.sender-btn:not(.active) .sender-avatar {
  opacity: 0.4;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.memo-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 15px;
  outline: none;
  resize: none;
  font-family: inherit;
  line-height: 1.45;
  background: #fff;
  max-height: 120px;
  transition: border-color 0.2s;
}

.memo-input:focus {
  border-color: var(--me-color);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #f0a58a, #e8967a);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(232, 150, 122, 0.3);
}

.send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(232, 150, 122, 0.4);
}

.send-btn:active {
  transform: scale(0.95);
}

/* Scroll customization */
.chat-area::-webkit-scrollbar {
  width: 4px;
}

.chat-area::-webkit-scrollbar-thumb {
  background: rgba(139, 109, 91, 0.15);
  border-radius: 2px;
}

/* Mobile tweaks */
@media (max-width: 480px) {
  .msg-bubble-wrapper {
    max-width: 78%;
  }
  .topbar-inner {
    padding: 10px 12px;
  }
  .messages-container {
    padding: 0 8px;
  }
}
