:root {
  --ink: #2b2d4a;
  --ink-soft: #6b6d8c;
  --night-1: #0d1030;
  --night-2: #1b1f4b;
  --night-3: #3a2f6b;

  --tham-bg-1: #fff0f4;
  --tham-bg-2: #fbd9e5;
  --tham-accent: #e0507a;
  --tham-accent-soft: #f7c3d4;

  --phuc-bg-1: #eef5ff;
  --phuc-bg-2: #d3e4fb;
  --phuc-accent: #3f74d1;
  --phuc-accent-soft: #bcd3f6;

  --card: rgba(255, 255, 255, 0.78);
  --radius: 22px;
  --shadow: 0 10px 30px rgba(43, 45, 74, 0.12);
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-hand: 'Dancing Script', 'Nunito', cursive;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--night-1);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ───────────── Đăng nhập ───────────── */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: radial-gradient(120% 90% at 50% 110%, #f6a6b8 0%, #7d5fb3 38%, var(--night-2) 70%, var(--night-1) 100%);
  overflow: hidden;
}
.login-sky {
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 42%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 70% 12%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 84% 36%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 46% 8%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 64%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 6% 70%, #fff 50%, transparent 51%);
  animation: twinkle 4s ease-in-out infinite alternate;
}
.login-card {
  position: relative;
  width: min(360px, 100%);
  padding: 72px 28px 28px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  color: #fff;
  text-align: center;
}
.login-moon {
  position: absolute; top: -42px; left: 50%;
  width: 84px; height: 84px; margin-left: -42px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffbe8, #ffe9a8 60%, #f5d27a);
  box-shadow: 0 0 40px rgba(255, 233, 168, 0.75), 0 0 90px rgba(255, 233, 168, 0.35);
  animation: float 5s ease-in-out infinite;
}
.login-card h1 { margin: 0 0 4px; font-size: 30px; font-weight: 900; letter-spacing: 0.2px; }
.login-sub { margin: 0 0 22px; opacity: 0.85; }
.login-card input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font: inherit; font-size: 17px; text-align: center; letter-spacing: 2px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.login-card input:focus { border-color: #ffe9a8; box-shadow: 0 0 0 4px rgba(255, 233, 168, 0.35); }
.login-btn {
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  border: 0; border-radius: 16px;
  background: linear-gradient(135deg, #ffd27a, #f59ab5);
  color: #3a2140;
  font-weight: 800; font-size: 17px;
  box-shadow: 0 8px 20px rgba(245, 154, 181, 0.45);
  transition: transform .15s, filter .2s;
}
.login-btn:hover { filter: brightness(1.05); }
.login-btn:active { transform: scale(0.97); }
.login-btn:disabled { opacity: .7; cursor: wait; }
.login-error { min-height: 1.4em; margin: 12px 0 0; color: #ffd1dc; font-weight: 700; }
.login-card.shake { animation: shake .45s; }

/* ───────────── Bố cục chính ───────────── */
.app {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}
.panel {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px;
  padding: 40px clamp(16px, 4vw, 56px);
  overflow: hidden;
  --accent: var(--tham-accent);
  --accent-soft: var(--tham-accent-soft);
}
.panel::before {
  /* hoạ tiết sao mờ trang trí */
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image:
    radial-gradient(3px 3px at 15% 20%, var(--accent-soft) 50%, transparent 51%),
    radial-gradient(2px 2px at 80% 12%, var(--accent-soft) 50%, transparent 51%),
    radial-gradient(4px 4px at 88% 78%, var(--accent-soft) 50%, transparent 51%),
    radial-gradient(2px 2px at 10% 88%, var(--accent-soft) 50%, transparent 51%);
}
.panel--tham { background: linear-gradient(160deg, var(--tham-bg-1), var(--tham-bg-2)); }
.panel--phuc {
  background: linear-gradient(200deg, var(--phuc-bg-1), var(--phuc-bg-2));
  --accent: var(--phuc-accent);
  --accent-soft: var(--phuc-accent-soft);
}
.panel > * { position: relative; width: min(440px, 100%); }

.seam {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; margin-left: -1px;
  background: linear-gradient(to bottom, transparent, rgba(43, 45, 74, .12) 20%, rgba(43, 45, 74, .12) 80%, transparent);
  pointer-events: none;
}
.seam span {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow);
}

.logout {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, .85); box-shadow: var(--shadow);
  font-size: 16px; z-index: 5;
  transition: transform .15s;
}
.logout:hover { transform: translateX(-50%) scale(1.08); }

/* ───────────── Header từng bên ───────────── */
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 88px;
}
.panel-name {
  margin: 0;
  font-size: clamp(34px, 4.4vw, 46px);
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -0.5px;
  line-height: 1.05;
}
.me-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 13px; font-weight: 800; letter-spacing: .3px;
  transform: translateY(-4px);
}
.panel.is-readonly .calendar { box-shadow: 0 6px 18px rgba(43, 45, 74, .07); }
.panel-stats { margin: 6px 0 0; color: var(--ink-soft); font-weight: 700; font-size: 14.5px; }
.panel-stats b { color: var(--ink); }
.panel-stats span { white-space: nowrap; }

.letter-spot {
  position: relative;
  width: 96px; height: 88px;
  flex: none;
  display: grid; place-items: center;
}

/* ───────────── Calendar ───────────── */
.calendar {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 16px 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.cal-title { font-weight: 800; font-size: 17px; text-transform: capitalize; }
.cal-nav {
  width: 36px; height: 36px; border-radius: 12px;
  border: 0; background: transparent;
  font-size: 20px; font-weight: 800; color: var(--accent);
  transition: background .15s;
}
.cal-nav:hover:not(:disabled) { background: var(--accent-soft); }
.cal-nav:disabled { opacity: .25; cursor: default; }
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  text-align: center; font-size: 12px; font-weight: 800;
  color: var(--ink-soft); padding: 4px 0 6px;
  text-transform: uppercase;
}
.cal-dow:last-child { color: var(--accent); }
.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent;
  font-weight: 700; font-size: 15px;
  transition: background .15s, transform .12s;
}
button.cal-day:hover:not(:disabled) { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
button.cal-day:active:not(:disabled) { transform: scale(.9); }
.cal-day.is-future { color: #b8b9cc; cursor: default; }
div.cal-day { cursor: default; }
.cal-day.is-today { color: var(--accent); font-weight: 900; }
.cal-day.is-today::after {
  content: ''; position: absolute; bottom: 12%; left: 50%;
  width: 4px; height: 4px; margin-left: -2px; border-radius: 50%;
  background: var(--accent);
}
.cal-day.is-done { color: var(--accent); font-weight: 900; }
.cal-day .ring {
  position: absolute; inset: -2px;
  width: calc(100% + 4px); height: calc(100% + 4px);
  pointer-events: none;
  overflow: visible;
}
.cal-day .ring path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.cal-day .ring.draw path { animation: draw-ring .55s ease-out both; }
.cal-legend {
  margin: 10px 4px 0; font-size: 12.5px; color: var(--ink-soft); text-align: center;
}

/* ───────────── Nút nhắc ───────────── */
.remind-btn {
  padding: 16px 22px;
  border: 0; border-radius: 18px;
  background: var(--accent);
  color: #fff;
  font-weight: 800; font-size: 17px;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform .15s, filter .2s, opacity .2s;
}
.remind-btn:hover { filter: brightness(1.07); }
.remind-btn:active { transform: scale(.97); }
.remind-btn:disabled { opacity: .6; cursor: wait; }
.remind-btn span { display: inline-block; margin-right: 4px; }
.remind-btn.sent span { animation: pop .5s; }

/* ───────────── Lá thư ───────────── */
.letter {
  position: relative;
  width: 78px; height: 58px;
  padding: 0; border: 0; background: none;
  filter: drop-shadow(0 8px 12px rgba(43, 45, 74, .22));
  animation: bob 3.2s ease-in-out infinite;
}
.letter.arrive { animation: arrive .6s cubic-bezier(.2, 1.6, .4, 1) both, bob 3.2s ease-in-out .6s infinite; }
.letter.wiggle { animation: wiggle .6s; }
.letter.leaving { animation: leave .4s ease-in both; }
.letter svg { width: 100%; height: 100%; overflow: visible; display: block; }
.letter .flap { transform-origin: 50% 0; transition: transform .45s ease; transform-box: fill-box; }
.letter.opening .flap { transform: scaleY(-1); }
.letter.opening { animation: none; transform: scale(1.25); transition: transform .4s; }
.letter::after {
  /* chấm thông báo */
  content: ''; position: absolute; top: -4px; right: -4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #ffb547; border: 2px solid #fff;
  animation: pulse 1.6s infinite;
}
.letter.is-sent { cursor: default; }
.letter.is-sent::after { display: none; }
.letter.is-sent::before {
  content: 'chờ mở…';
  position: absolute; left: 50%; bottom: -20px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 12px; font-weight: 800;
  color: var(--ink-soft);
}
.letter:focus-visible { outline: 3px solid var(--accent); outline-offset: 6px; border-radius: 8px; }

.flyer {
  position: absolute; top: 0; left: 0;
  width: 78px; height: 58px;
  z-index: 50; pointer-events: none;
  filter: drop-shadow(0 10px 16px rgba(43, 45, 74, .3));
}
.flyer svg { width: 100%; height: 100%; display: block; }
.trail {
  position: absolute; z-index: 49; pointer-events: none;
  font-size: 14px;
  animation: trail 1s ease-out forwards;
}

/* ───────────── Màn đêm ───────────── */
.night {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 16px;
  overflow: hidden;
  color: #fff;
}
.night-sky {
  position: absolute; inset: -2px;
  background:
    radial-gradient(80% 60% at 50% 100%, rgba(122, 92, 180, .55), transparent 70%),
    linear-gradient(to bottom, var(--night-1) 0%, var(--night-2) 55%, var(--night-3) 100%);
  transform: translateY(-100%);
}
.night.show .night-sky { animation: night-fall 1.4s cubic-bezier(.6, .05, .25, 1) forwards; }
.night.hide { animation: fade-out .6s ease forwards; }

.night-stars { position: absolute; inset: 0; pointer-events: none; }
.star {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  opacity: 0;
  box-shadow: 0 0 6px rgba(255, 255, 255, .8);
}
.night.show .star { animation: star-in .8s ease forwards, twinkle 2.4s ease-in-out infinite alternate; }

.night-moon {
  position: absolute; top: 12%; right: 14%;
  width: clamp(80px, 14vw, 140px); aspect-ratio: 1;
  border-radius: 50%;
  box-shadow: inset clamp(-26px, -4vw, -16px) clamp(-12px, -2vw, -8px) 0 0 #ffe9a8;
  filter: drop-shadow(0 0 30px rgba(255, 233, 168, .6));
  opacity: 0; transform: translateY(40px) rotate(-20deg);
}
.night.show .night-moon { animation: moon-rise 1.6s ease-out .9s forwards; }

.shooting-star {
  position: absolute; top: 18%; left: -10%;
  width: 140px; height: 2px;
  background: linear-gradient(to right, transparent, #fff);
  border-radius: 2px;
  opacity: 0;
  transform: rotate(18deg);
}
.night.show .shooting-star { animation: shoot 1.4s ease-in 2.4s forwards; }

.night-card {
  position: relative;
  width: min(760px, 100%);
  padding: 34px 16px 28px;
  text-align: center;
  opacity: 0; transform: translateY(24px) scale(.96);
}
.night.show .night-card { animation: card-in .9s ease-out 1.3s forwards; }
.night-title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 700;
  font-size: clamp(40px, 8vw, 68px);
  line-height: 1.15;
  text-shadow: 0 0 24px rgba(255, 233, 168, .45);
}
.night-from { margin: 14px 0 28px; font-size: 17px; opacity: .85; }
.night-zzz { margin: 0 0 8px; font-weight: 900; font-size: 22px; color: #cdd3ff; letter-spacing: 4px; }
.night-zzz span { display: inline-block; animation: zzz 2.4s ease-in-out infinite; }
.night-zzz span:nth-child(2) { animation-delay: .3s; font-size: 1.2em; }
.night-zzz span:nth-child(3) { animation-delay: .6s; font-size: 1.5em; }
.night-close {
  padding: 14px 26px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(255, 255, 255, .12);
  color: #fff; font-weight: 800; font-size: 16px;
  backdrop-filter: blur(6px);
  transition: background .2s, transform .15s;
}
.night-close:hover { background: rgba(255, 255, 255, .22); }
.night-close:active { transform: scale(.97); }

/* ───────────── Toast ───────────── */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 200;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(27, 31, 59, .92);
  color: #fff; font-weight: 700; font-size: 15px; text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  opacity: 0; transform: translate(-50%, 16px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ───────────── Mobile: Thắm trên, Phúc dưới ───────────── */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto; }
  .panel { min-height: auto; padding: 64px 16px 32px; justify-content: flex-start; }
  .panel--phuc { padding-top: 40px; }
  .seam { display: none; }
  .panel-head { min-height: 76px; }
  .letter-spot { width: 86px; height: 76px; }
  .remind-btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ───────────── Keyframes ───────────── */
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes twinkle { from { opacity: .35; } to { opacity: 1; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
@keyframes draw-ring { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.5) rotate(-12deg); } 100% { transform: scale(1); } }
@keyframes bob {
  0%, 100% { transform: translate(0, 0) rotate(-5deg); }
  25% { transform: translate(3px, -8px) rotate(2deg); }
  50% { transform: translate(0, -12px) rotate(6deg); }
  75% { transform: translate(-3px, -6px) rotate(-1deg); }
}
@keyframes arrive { from { transform: scale(.4) rotate(-20deg); opacity: 0; } to { transform: scale(1) rotate(-5deg); opacity: 1; } }
@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-14deg) scale(1.1); }
  40% { transform: rotate(12deg) scale(1.1); }
  60% { transform: rotate(-8deg); }
  80% { transform: rotate(5deg); }
}
@keyframes leave { to { transform: scale(.3) translateY(-20px); opacity: 0; } }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 181, 71, .6); }
  100% { box-shadow: 0 0 0 10px rgba(255, 181, 71, 0); }
}
@keyframes trail {
  from { opacity: 1; transform: translate(0, 0) scale(1); }
  to { opacity: 0; transform: translate(0, 18px) scale(.4); }
}
@keyframes night-fall { to { transform: translateY(0); } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes star-in { to { opacity: 1; } }
@keyframes moon-rise { to { opacity: 1; transform: translateY(0) rotate(-20deg); } }
@keyframes shoot {
  0% { opacity: 0; transform: translate(0, 0) rotate(18deg); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(120vw, 38vw) rotate(18deg); }
}
@keyframes card-in { to { opacity: 1; transform: none; } }
@keyframes zzz { 0%, 100% { transform: translateY(0); opacity: .5; } 50% { transform: translateY(-8px); opacity: 1; } }
