:root {
  /* Font mặc định của macOS, có dự phòng cho hệ điều hành khác. */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica,
    "Segoe UI", Roboto, Arial, sans-serif;

  --bg: #fdf6f4;
  --card: #ffffff;
  --border: #f0dcde;
  --border-strong: #e6c6ca;
  --ink: #2c2827;
  --muted: #9a8f8d;
  --accent: #d4788f;
  --accent-soft: #fbeef0;
  --ok: #4f8a5f;
  --err: #c0564e;
}

* {
  box-sizing: border-box;
}

/* Thuộc tính hidden phải thắng display của .composer và .gate. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 12% 8%, #fce9ec 0%, transparent 42%),
    radial-gradient(circle at 88% 92%, #fbe8e2 0%, transparent 45%);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* --- Trái tim bay nhè nhẹ ở nền --- */

.hearts {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.hearts span {
  position: absolute;
  bottom: -40px;
  color: var(--accent);
  opacity: 0;
  font-size: 18px;
  animation: float-up 17s linear infinite;
}

.hearts span:nth-child(1) { left: 8%;  animation-delay: 0s;   font-size: 14px; }
.hearts span:nth-child(2) { left: 24%; animation-delay: 3.5s; font-size: 20px; }
.hearts span:nth-child(3) { left: 45%; animation-delay: 7s;   font-size: 12px; }
.hearts span:nth-child(4) { left: 63%; animation-delay: 10s;  font-size: 17px; }
.hearts span:nth-child(5) { left: 79%; animation-delay: 5s;   font-size: 13px; }
.hearts span:nth-child(6) { left: 92%; animation-delay: 13s;  font-size: 19px; }

@keyframes float-up {
  0%   { transform: translateY(0) rotate(0deg);        opacity: 0; }
  12%  { opacity: 0.35; }
  85%  { opacity: 0.2; }
  100% { transform: translateY(-110vh) rotate(24deg);  opacity: 0; }
}

/* --- Khung trang --- */

.page {
  position: relative;
  z-index: 1;
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px 64px;
}

.brand {
  text-align: center;
  margin-bottom: 26px;
}

.brand h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.4px;
}

.brand-mark {
  display: inline-block;
  animation: beat 2.4s ease-in-out infinite;
}

@keyframes beat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.16); }
  28%      { transform: scale(1); }
}

.tagline {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px;
  box-shadow: 0 12px 34px -22px rgba(140, 90, 96, 0.5);
}

/* --- Màn hình đăng nhập --- */

.gate {
  text-align: center;
  padding: 44px 26px;
}

.gate-line {
  margin: 0 0 22px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
}

.gate .field {
  margin-bottom: 12px;
  padding: 0 16px;
}

.gate .field input {
  width: 100%;
  border: 0;
  outline: 0;
  background: none;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  padding: 13px 0;
  text-align: left;
}

.gate-submit {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

.gate-note {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* --- Ô soạn thư --- */

.composer {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.route {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.route-people {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.route-people strong {
  font-weight: 600;
}

.route-arrow {
  color: var(--accent);
  font-size: 15px;
}

.link-button {
  border: 0;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.link-button:hover {
  color: var(--accent);
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  background: #fffdfd;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field:focus-within {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.subject-prefix {
  flex: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--accent);
  user-select: none;
}

#subject {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 13px 0;
}

#subject::placeholder,
#body::placeholder {
  color: #c3b8b6;
}

#body {
  width: 100%;
  min-height: 52vh;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fffdfd;
  padding: 20px 18px;
  font-family: inherit;
  font-size: 17px;
  line-height: 1.75;
  color: var(--ink);
  outline: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#body:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.counter {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.send-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.send-button:hover:not(:disabled) {
  background: #c46781;
  transform: translateY(-1px);
}

.send-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-button.confirming {
  background: #b8546f;
}

.send-heart {
  font-size: 15px;
}

/* --- Dòng trạng thái --- */

.status {
  margin: 18px 2px 0;
  min-height: 20px;
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  color: var(--muted);
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--err);
}

/* --- Dòng thư --- */

.feed {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 20px 0 20px;
}

.feed-empty {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  padding: 30px 0;
}

.letter {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  border-radius: 14px;
  padding: 20px 22px;
}

.letter.from-partner {
  border-left-color: var(--accent);
}

.letter.unread {
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.letter.unread:hover {
  background: var(--accent-soft);
}

.letter-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.letter-from {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
}

.letter-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.letter-time {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.letter-subject {
  margin: 8px 0 12px;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.4;
}

.letter-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
}

.letter-receipt {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}

/* --- Màn hình nhỏ --- */

@media (max-width: 560px) {
  .page { padding: 30px 14px 44px; }
  .card { padding: 20px; border-radius: 16px; }
  #body { min-height: 46vh; font-size: 16px; }
  .route { flex-wrap: wrap; }
  .letter { padding: 16px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .hearts span,
  .brand-mark {
    animation: none;
  }
  .hearts { display: none; }
  * { transition: none !important; }
}
