/* ============ Màu sắc ============
   --accent và --accent-strong đổi theo ngày (đặt bằng JS).
   Các màu nhạt được pha từ --accent để luôn hài hòa với nền. */
:root {
  --accent: #f6b93b;
  --accent-strong: #9a6400;

  --bg: #faf6f1;
  --surface: #ffffff;
  --ink: #2e2828;
  --muted: #8a7f7c;
  --line: rgba(46, 40, 40, 0.09);
  --accent-soft: color-mix(in srgb, var(--accent) 20%, #ffffff);
  --accent-text: var(--accent-strong);
  --glow: color-mix(in srgb, var(--accent) 22%, transparent);
  --shadow: 0 1px 2px rgba(60, 40, 20, 0.04), 0 18px 48px -18px rgba(90, 60, 30, 0.22);
  --face-ink: #3b2f2f;
}

:root[data-theme="dark"] {
  --bg: #16131b;
  --surface: #211d27;
  --ink: #f2ebe5;
  --muted: #a39aa8;
  --line: rgba(255, 255, 255, 0.08);
  --accent-soft: color-mix(in srgb, var(--accent) 16%, #211d27);
  --accent-text: color-mix(in srgb, var(--accent) 72%, #ffffff);
  --glow: color-mix(in srgb, var(--accent) 14%, transparent);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 48px -18px rgba(0, 0, 0, 0.7);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16131b;
    --surface: #211d27;
    --ink: #f2ebe5;
    --muted: #a39aa8;
    --line: rgba(255, 255, 255, 0.08);
    --accent-soft: color-mix(in srgb, var(--accent) 16%, #211d27);
    --accent-text: color-mix(in srgb, var(--accent) 72%, #ffffff);
    --glow: color-mix(in srgb, var(--accent) 14%, transparent);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 18px 48px -18px rgba(0, 0, 0, 0.7);
    color-scheme: dark;
  }
}

/* ============ Nền & bố cục ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at 50% -120px, var(--glow), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background-color 0.3s, color 0.3s;
}

.wrap {
  max-width: 600px; margin: 0 auto;
  padding: 28px 20px 40px;
  min-height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
}

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.greet { margin: 0; font-weight: 800; font-size: 1.3rem; }
.date { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.date::first-letter { text-transform: uppercase; }

/* ============ Nút tròn dùng chung ============ */
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer; padding: 0;
  transition: transform 0.15s, background 0.2s, color 0.2s, border-color 0.2s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover:not(:disabled) { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; transform: translateY(-1px); }
.icon-btn:active:not(:disabled) { transform: scale(0.94); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:focus-visible, .chip:focus-visible, .favs-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.theme-toggle { width: 40px; height: 40px; color: var(--ink); }
.theme-toggle svg { width: 18px; height: 18px; }

/* ============ Thẻ câu nói ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 30px 30px 22px;
  box-shadow: var(--shadow);
  text-align: center;
  margin-top: 56px;
  animation: pop 0.5s cubic-bezier(.2, 1.2, .4, 1) both;
}
.card.swap { animation: swap 0.4s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(16px); } }
@keyframes swap { from { opacity: 0.2; transform: translateY(6px); } }

.mascot { margin: -78px auto 4px; width: 88px; height: 88px; animation: bob 3.4s ease-in-out infinite; }
.mascot svg { width: 100%; height: 100%; display: block; }
.mascot .halo { fill: var(--surface); stroke: var(--line); stroke-width: 1; }
.mascot .face { fill: var(--accent); }
.mascot .ink { fill: var(--face-ink); }
.mascot .mouth { stroke: var(--face-ink); }
.mascot .eyes { transform-origin: 60px 58px; animation: blink 4.5s infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }

.day { margin: 0 0 8px; font-size: 0.88rem; font-weight: 700; color: var(--muted); letter-spacing: 0.03em; }
.day b { color: var(--ink); font-size: 1.1rem; font-weight: 800; }

.label {
  display: inline-block; margin: 0 0 16px;
  font-size: 0.74rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent-text); background: var(--accent-soft);
  padding: 5px 12px; border-radius: 999px;
}

.quote {
  margin: 0 auto; max-width: 30ch;
  font-family: "Lora", Georgia, serif; font-style: italic; font-weight: 500;
  font-size: clamp(1.25rem, 3.6vw, 1.55rem);
  line-height: 1.55;
  text-wrap: balance;
}
.quote::before, .quote::after { color: var(--accent); font-size: 1.15em; }
.quote::before { content: "“"; }
.quote::after  { content: "”"; }

.author { margin: 14px 0 0; color: var(--muted); font-weight: 700; font-size: 0.95rem; }
.author::before { content: "— "; }
.author:empty { display: none; }

.reflect {
  margin-top: 26px; padding-top: 22px;
  border-top: 1px solid var(--line);
  text-align: left;
}
.reflect-title {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 10px; font-size: 1rem; font-weight: 800; color: var(--ink);
}
.reflect-body {
  margin: 0; line-height: 1.8; font-size: 1rem;
  color: color-mix(in srgb, var(--ink) 85%, var(--muted));
  text-align: justify; /* canh đều hai bên */
  text-wrap: pretty;
}

.note {
  display: block;
  margin: 20px 0 0; padding: 18px 22px;
  background: var(--accent-soft); color: var(--ink);
  border-radius: 18px;
  text-align: center; /* câu kết canh giữa, các dòng dài gần bằng nhau */
  text-wrap: balance;
  font-weight: 700; line-height: 1.6;
}
.note-icon { margin-right: 6px; }

/* ============ Thanh công cụ dưới thẻ ============ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-top: 22px; padding-top: 18px;
  border-top: 1px solid var(--line);
}
.toolbar .middle { display: flex; gap: 10px; }
#likeBtn.on { color: #e5486f; background: color-mix(in srgb, #e5486f 12%, var(--surface)); border-color: transparent; }
#likeBtn.on svg { fill: currentColor; animation: beat 0.35s ease; }
@keyframes beat { 50% { transform: scale(1.25); } }

.chip {
  margin-top: 14px;
  border: 0; cursor: pointer;
  background: var(--accent-soft); color: var(--accent-text);
  font: inherit; font-weight: 800; font-size: 0.85rem;
  padding: 7px 14px; border-radius: 999px;
}

/* ============ Yêu thích ============ */
.favs-toggle {
  width: 100%; text-align: left;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 14px 18px; color: var(--ink);
  font: inherit; font-weight: 700; cursor: pointer;
}
.favs-toggle .chev { color: var(--muted); transition: transform 0.2s; }
.favs-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.fav-list { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.fav-list li {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 44px 14px 18px; position: relative; line-height: 1.55;
}
.fav-list small { display: block; color: var(--muted); margin-top: 4px; }
.fav-list .rm {
  position: absolute; top: 10px; right: 10px; border: 0; background: none;
  color: var(--muted); cursor: pointer; font-size: 1rem;
}
.fav-list .empty { color: var(--muted); text-align: center; padding-right: 18px; }

.foot { margin-top: auto; text-align: center; color: var(--muted); font-size: 0.88rem; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 700; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: 0.3s; z-index: 10; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ Lịch tháng (cửa sổ nổi) ============ */
.top-actions { display: flex; gap: 8px; }

.cal {
  width: min(420px, calc(100vw - 24px));
  padding: 18px 18px 14px;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45);
}
.cal[open] { animation: calIn 0.25s cubic-bezier(.2, 1.1, .4, 1); }
.cal::backdrop { background: rgba(20, 16, 24, 0.45); backdrop-filter: blur(3px); }
@keyframes calIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

.cal-head { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; }
.cal-head .icon-btn { width: 36px; height: 36px; }
.cal-head .icon-btn svg { width: 18px; height: 18px; }
.cal-title { flex: 1; margin: 0; text-align: center; font-size: 1.05rem; font-weight: 800; }
.cal-close { margin-left: 4px; }

.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-week span { text-align: center; font-size: 0.72rem; font-weight: 800; color: var(--muted); padding: 4px 0; }
.cal-week span:last-child { color: #e5486f; }

.cal-day {
  position: relative; aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid transparent; border-radius: 12px;
  background: transparent; color: var(--ink);
  font: inherit; font-weight: 700; font-size: 0.92rem;
  cursor: pointer; padding: 0;
  transition: background 0.15s, transform 0.15s;
}
.cal-day.empty { visibility: hidden; }
.cal-day:not(:disabled):hover { background: var(--accent-soft); transform: translateY(-1px); }
.cal-day:disabled { cursor: default; color: var(--muted); opacity: 0.4; }
.cal-day .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-day.today { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.cal-day.viewing { background: var(--accent); color: #2b2320; }
.cal-day.viewing .dot { background: #2b2320; }
.cal-day .fav { position: absolute; top: 3px; right: 5px; font-size: 0.6rem; color: #e5486f; line-height: 1; }
.cal-day .ev { position: absolute; top: 2px; left: 4px; font-size: 0.65rem; line-height: 1; }
.cal-day:disabled .ev { opacity: 1; }

.cal-events { list-style: none; margin: 12px 0 0; padding: 10px 0 0; border-top: 1px solid var(--line); display: grid; gap: 4px; font-size: 0.84rem; color: var(--muted); }
.cal-events:empty { display: none; }
.cal-events b { color: var(--ink); font-weight: 800; margin-right: 4px; }

.cal-legend { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin: 10px 0 0; font-size: 0.76rem; color: var(--muted); }
.cal-legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); display: inline-block; }
.lg-today { width: 12px; height: 12px; border-radius: 4px; border: 1.5px solid var(--accent); display: inline-block; }
.lg-heart { color: #e5486f; font-style: normal; font-size: 0.8rem; }

@media (max-width: 480px) {
  .wrap { padding: 22px 14px 32px; }
  .card { padding: 26px 18px 18px; border-radius: 24px; }
  .note { padding: 14px 16px; }
  .toolbar .middle { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
