/* ===========================================================
   Sinh nhật Ken — hero điện ảnh: ảnh nền Ken Burns + thẻ kính mờ
   Tất cả gói gọn trong 1 màn hình, tối ưu mobile.
   =========================================================== */

:root {
  --fg: #ffffff;
  --muted: rgba(255, 255, 255, 0.72);
  --accent: #ff7a66;
  --glass: rgba(255, 255, 255, 0.10);
  --glass-bd: rgba(255, 255, 255, 0.22);
  --kb: 9s;        /* thời lượng Ken Burns */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #0e0d12;
  color: var(--fg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;                 /* không cuộn — tất cả trong 1 màn */
  position: fixed;
  inset: 0;
}

/* ---------- ẢNH NỀN (2 lớp crossfade + Ken Burns) ---------- */
.bg { position: fixed; inset: 0; z-index: 0; background: #0e0d12; }

.bg .layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.2s ease;
  overflow: hidden;
}
.bg .layer.active { opacity: 1; }

.bg .layer img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  will-change: transform;
}
/* Nền mờ lấp đầy khoảng trống (cùng tấm ảnh, phủ kín + làm mờ) */
.bg .layer img.fill {
  object-fit: cover;
  transform: scale(1.12);
  filter: blur(30px) brightness(0.7) saturate(1.1);
}
/* Ảnh chính: hiển thị TRỌN VẸN, không cắt (ngang/dọc đều thấy đủ) */
.bg .layer img.main {
  object-fit: contain;
}
/* Ken Burns chỉ chạy trên NỀN MỜ của lớp đang hiện (ảnh chính giữ nguyên để thấy đủ) */
.bg .layer.active img.fill { animation: kenburns var(--kb) ease-out forwards; }
.bg .layer.kb1.active img.fill { animation-name: kb1; }
.bg .layer.kb2.active img.fill { animation-name: kb2; }
.bg .layer.kb3.active img.fill { animation-name: kb3; }

@keyframes kenburns { from { transform: scale(1.12); } to { transform: scale(1.24); } }
@keyframes kb1 { from { transform: scale(1.12) translate(0,0); }      to { transform: scale(1.26) translate(-2%, -2%); } }
@keyframes kb2 { from { transform: scale(1.26) translate(2%, 1%); }   to { transform: scale(1.12) translate(0, 0); } }
@keyframes kb3 { from { transform: scale(1.13) translate(2%, -1%); }  to { transform: scale(1.24) translate(-2%, 2%); } }

/* Lớp tối + vignette cho chữ luôn đọc rõ */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(120% 90% at 50% 45%, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.55) 100%),
    linear-gradient(to bottom, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.15) 35%, rgba(0,0,0,0.55) 100%);
  pointer-events: none;
  transition: opacity 0.9s ease;
}
/* Khi panel đã thu thành dock: giảm tối để ảnh hiện rực rỡ */
body.docked .scrim { opacity: 0.4; }

/* ---------- SÂN KHẤU + THẺ KÍNH ---------- */
.stage {
  position: relative;
  z-index: 2;
  height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 18px max(64px, env(safe-area-inset-bottom));
}

.card {
  position: fixed;
  left: 50%;
  bottom: 50%;
  transform: translate(-50%, 50%);   /* căn giữa màn hình */
  width: min(540px, calc(100% - 32px));
  z-index: 3;
  text-align: center;
  padding: clamp(26px, 5vw, 44px) clamp(20px, 5vw, 46px);
  border-radius: 28px;
  background: var(--glass);
  border: 1px solid var(--glass-bd);
  backdrop-filter: blur(22px) saturate(135%);
  -webkit-backdrop-filter: blur(22px) saturate(135%);
  box-shadow: 0 24px 70px rgba(0,0,0,0.45);
  animation: fadeIn 0.9s ease both;
  transition:
    bottom 0.85s cubic-bezier(.22,.61,.21,1),
    transform 0.85s cubic-bezier(.22,.61,.21,1),
    width 0.85s cubic-bezier(.22,.61,.21,1),
    padding 0.7s ease,
    border-radius 0.7s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Phần co lại (ẩn mượt khi thành dock) — kỹ thuật grid 1fr -> 0fr */
.extras { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .55s ease, opacity .4s ease; }
.extras-inner { overflow: hidden; min-height: 0; }

/* Trong lúc intro: panel nằm sẵn ở ĐÁY (full nội dung), chừa cả vùng trên cho số lớn.
   Tới 0 chỉ việc co gọn tại chỗ thành dock -> chuyển cảnh mượt, không nhảy vị trí. */
body.intro-active .card {
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translate(-50%, 0);
}

/* ====== Trạng thái DOCK (sau ~5s): trượt xuống đáy, chỉ còn countdown (kiểu dock macOS) ====== */
body.docked .card {
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translate(-50%, 0);
  width: min(330px, calc(100% - 24px));
  padding: 12px 18px;
  border-radius: 26px;
}
body.docked .extras { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
body.docked .countdown { margin-top: 0; gap: clamp(4px, 1.4vw, 10px); }
body.docked .unit { min-width: 0; gap: 3px; }
body.docked .unit .value { font-size: clamp(1.5rem, 6vw, 2.2rem); }
body.docked .unit .label { font-size: clamp(0.5rem, 2vw, 0.6rem); }
body.docked .sep { font-size: clamp(1.1rem, 4vw, 1.7rem); padding-top: 2px; }

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.26em;
  font-size: clamp(0.6rem, 2.6vw, 0.74rem);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 12px;
}

.name {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: clamp(2.8rem, 13vw, 5.2rem);
  line-height: 1;
  letter-spacing: -0.01em;
  text-shadow: 0 2px 24px rgba(0,0,0,0.35);
}

.date-line {
  margin-top: 10px;
  font-size: clamp(0.9rem, 3.4vw, 1.1rem);
  color: var(--muted);
}

/* Đồng hồ */
.countdown {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(6px, 2.5vw, 14px);
  margin-top: clamp(22px, 5vw, 32px);
  transition: margin-top .6s ease, gap .6s ease;
}
.unit { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: clamp(48px, 16vw, 74px); }
.unit .value {
  font-size: clamp(2.1rem, 11vw, 3.7rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 2px 18px rgba(0,0,0,0.3);
  transition: font-size .6s ease;
}
.unit .label {
  font-size: clamp(0.56rem, 2.4vw, 0.7rem);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.sep {
  font-size: clamp(1.6rem, 8vw, 2.6rem);
  font-weight: 300;
  line-height: 1;
  color: rgba(255,255,255,0.4);
  padding-top: clamp(2px, 1vw, 6px);
  transition: font-size .6s ease;
}

.wish {
  margin-top: clamp(20px, 4vw, 28px);
  font-size: clamp(0.92rem, 3.6vw, 1.08rem);
  color: rgba(255,255,255,0.92);
  white-space: pre-line;
}

/* Trạng thái khi tới ngày */
body.is-birthday .name { color: var(--accent); }
body.is-birthday .eyebrow { color: var(--accent); }

/* ---------- ĐIỀU KHIỂN GALLERY ---------- */
.nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--glass-bd);
  background: rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.nav:hover { background: rgba(0,0,0,0.5); }
.nav:active { transform: translateY(-50%) scale(0.92); }
.nav.prev { left: 14px; }
.nav.next { right: 14px; }

/* Thanh tiến trình mảnh ở đỉnh — KHÔNG hiển thị số thứ tự / tổng số ảnh */
.progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 5;
  height: 3px;
  background: rgba(255,255,255,0.18);
  overflow: hidden;
  pointer-events: none;
}
.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: #fff;
}

/* ---------- NÚT NHẠC ---------- */
.music-btn {
  position: fixed;
  right: 16px;
  top: max(16px, env(safe-area-inset-top));
  z-index: 6;
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 1px solid var(--glass-bd);
  background: rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s;
}
.music-btn:hover { background: rgba(0,0,0,0.5); }
.music-btn:active { transform: scale(0.92); }
.music-btn .icon-off { display: none; }
.music-btn.muted .icon-on { display: none; }
.music-btn.muted .icon-off { display: block; }

/* ---------- CONFETTI ---------- */
#confetti { position: fixed; inset: 0; z-index: 7; pointer-events: none; }

/* ---------- INTRO ĐẾM NGƯỢC (5→0) ---------- */
/* Cụm intro nằm ở VÙNG TRÊN, panel ở giữa vẫn hiển thị rõ song song */
#intro {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(6px, 1.6vw, 14px);
  text-align: center;
  padding: clamp(28px, 7vh, 64px) 24px 0;
  /* Chỉ làm tối phần trên cho số dễ đọc; vùng giữa (panel) để trong */
  background: linear-gradient(to bottom,
      rgba(0,0,0,0.62) 0%, rgba(0,0,0,0.34) 18%, rgba(0,0,0,0.06) 36%, rgba(0,0,0,0) 50%);
  cursor: pointer;
  transition: opacity 0.7s ease, visibility 0.7s ease;
}
#intro.hide { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-caption {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: clamp(0.64rem, 2.8vw, 0.84rem);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.7);
  padding-left: 0.3em; /* bù letter-spacing */
}
.intro-num {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  /* To gấp ~3 lần, nhưng giới hạn theo chiều cao màn để không đè panel */
  font-size: max(7rem, min(56vw, 24vh));
  line-height: 0.95;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 6px 44px rgba(0, 0, 0, 0.7);
}
@keyframes numpop {
  0% { transform: scale(1.45); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- MOBILE ---------- */
@media (max-width: 540px) {
  /* Panel (lúc còn to) gọn hơn để đỡ che ảnh trong 5s đầu */
  .card {
    border-radius: 24px;
    background: rgba(255,255,255,0.13);
    backdrop-filter: blur(18px) saturate(130%);
    -webkit-backdrop-filter: blur(18px) saturate(130%);
    padding: 22px 16px 24px;
  }
  .eyebrow { margin-bottom: 8px; }
  .name { font-size: clamp(2.3rem, 12vw, 3.3rem); }
  .date-line { margin-top: 5px; }
  /* Countdown gọn, không tràn ô Giây */
  .countdown { gap: 5px; margin-top: 16px; }
  .unit { min-width: 0; }
  .unit .value { font-size: clamp(1.7rem, 9.5vw, 2.7rem); }
  .unit .label { font-size: 0.55rem; letter-spacing: 0.1em; }
  .sep { font-size: clamp(1.3rem, 5.5vw, 1.9rem); padding-top: 3px; }
  .wish { margin-top: 13px; font-size: 0.83rem; line-height: 1.4; }

  .nav { width: 38px; height: 38px; background: rgba(0,0,0,0.22); }
  .nav.prev { left: 8px; }
  .nav.next { right: 8px; }
}

/* Màn rất hẹp: thu gọn thêm */
@media (max-width: 360px) {
  .countdown { gap: 3px; }
  .unit .value { font-size: 8.5vw; }
  .sep { font-size: 5.5vw; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .layer.active img { animation: none; }
  .card { animation: none; }
}
