@property --top { syntax: "<color>"; inherits: true; initial-value: #f7d9d4; }
@property --bot { syntax: "<color>"; inherits: true; initial-value: #fbeee3; }
@property --ink { syntax: "<color>"; inherits: true; initial-value: #3a2a3f; }
@property --orb { syntax: "<color>"; inherits: true; initial-value: #ffd9b8; }
@property --orb-y { syntax: "<number>"; inherits: true; initial-value: 0.62; }
@property --night { syntax: "<number>"; inherits: true; initial-value: 0; }

:root {
  --serif: "Fraunces", "Times New Roman", serif;
  --sans: "Be Vietnam Pro", -apple-system, system-ui, sans-serif;
  --g: max(22px, env(safe-area-inset-left), env(safe-area-inset-right));
  --paper: #fffaf2;
  --ease: cubic-bezier(.2, .8, .2, 1);
  transition: --top 1.8s ease, --bot 1.8s ease, --ink 1.2s ease, --orb 1.8s ease,
    --orb-y 2.6s cubic-bezier(.45, 0, .2, 1), --night 2.2s ease;
}

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; background: var(--bot); scroll-behavior: smooth; }
html:has(.lb[open]) { overflow: hidden; }
body {
  font: 300 16px/1.7 var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
img { display: block; width: 100%; height: 100%; object-fit: cover; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

/* ---------- bầu trời ---------- */
.sky, .stars { position: fixed; inset: -10lvh 0; pointer-events: none; }
.sky { z-index: -3; background: linear-gradient(180deg, var(--top) 10%, var(--bot) 90%); }
.stars { z-index: -1; opacity: var(--night); }
.stars i { position: absolute; border-radius: 50%; background: #fff8ec; animation: tw 3s ease-in-out infinite alternate; }
@keyframes tw { from { opacity: .15; } to { opacity: 1; } }
.orb {
  position: fixed; z-index: -2; left: 70%; top: 0;
  width: 130vmax; aspect-ratio: 1;
  translate: -50% -50%;
  transform: translateY(calc(var(--orb-y) * 100lvh));
  background: radial-gradient(circle, var(--orb) 0 3.2%, color-mix(in srgb, var(--orb) 55%, transparent) 4.5%, color-mix(in srgb, var(--orb) 18%, transparent) 16%, transparent 45%);
  pointer-events: none;
}
/* hạt phim */
body::after {
  content: ""; position: fixed; inset: 0; z-index: 50; pointer-events: none; opacity: .09;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- mật khẩu ---------- */
.gate { min-height: 100svh; display: grid; place-content: center; justify-items: center; gap: 14px; padding: var(--g); text-align: center; }
.gate[hidden] { display: none; }
.gate-title { font: italic 200 clamp(64px, 20vw, 140px)/1 var(--serif); font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1; margin-bottom: 18px; }
.gate label { font-size: 14px; opacity: .75; }
.gate-row { display: flex; gap: 8px; width: min(320px, 100%); }
.gate input {
  flex: 1; min-width: 0; font: 400 16px var(--sans); color: var(--ink);
  padding: 12px 16px; border-radius: 99px; border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  background: color-mix(in srgb, #fff 55%, transparent);
}
.gate button { padding: 12px 22px; border-radius: 99px; background: var(--ink); color: var(--bot); font-weight: 500; }
.gate button:disabled { opacity: .6; }
.gate-err { min-height: 1.4em; font-size: 14px; color: #a3263a; }

/* ---------- mở đầu ---------- */
.hero {
  min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: calc(env(safe-area-inset-top) + 24px) var(--g) calc(env(safe-area-inset-bottom) + 16px);
}
.hero-dates { margin-top: auto; font-size: 13px; letter-spacing: .08em; opacity: .7; }
.hero h1 { display: grid; justify-items: center; font-weight: normal; margin-top: 4px; }
.six {
  font: 900 min(150vw, 62svh, 860px)/.78 var(--serif);
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 0;
  letter-spacing: -.04em;
  color: transparent;
  background: var(--img) var(--crop) no-repeat;
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 24px 40px rgba(90, 40, 60, .22));
  padding: .04em .04em 0;
}
.nam {
  font: italic 300 min(17vw, 9svh, 110px)/1 var(--serif);
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  margin-top: -.42em; margin-left: 1.6em;
}
.names {
  font: 400 clamp(26px, 7.5vw, 44px)/1.15 var(--serif);
  font-variation-settings: "opsz" 72, "SOFT" 50;
  margin-top: 18px;
}
.names span { font-style: italic; font-weight: 200; padding: 0 .1em; }
.days { margin-top: 6px; font-size: 15px; opacity: .8; }
.days b { font-weight: 500; }
.cue {
  margin-top: auto; padding-top: 28px;
  color: inherit; text-decoration: none; font-size: 12px; letter-spacing: .1em; opacity: .65;
  display: grid; justify-items: center; gap: 10px;
}
.cue::after { content: ""; width: 1px; height: 44px; background: currentColor; transform-origin: top; animation: drip 2.4s var(--ease) infinite; }
@keyframes drip { 0% { transform: scaleY(0); } 50% { transform: scaleY(1); transform-origin: top; } 51% { transform-origin: bottom; } 100% { transform: scaleY(0); transform-origin: bottom; } }

/* ---------- cột mốc ---------- */
.chapter {
  min-height: 100svh;
  padding: 18svh var(--g) 14svh;
  display: grid; align-content: center; gap: 36px;
}
.ch-text { position: relative; max-width: 34rem; }
.ch-year {
  position: absolute; z-index: -1; left: -.06em; top: -.85em;
  font: 100 min(42vw, 260px)/1 var(--serif);
  font-variation-settings: "opsz" 144, "SOFT" 0;
  letter-spacing: -.05em;
  opacity: .13;
  white-space: nowrap;
}
.ch-date { font-size: 13px; letter-spacing: .08em; opacity: .75; }
h2 {
  font: 400 clamp(38px, 11vw, 68px)/1.02 var(--serif);
  font-variation-settings: "opsz" 144, "SOFT" 30, "WONK" 1;
  letter-spacing: -.02em;
  margin: 6px 0 16px;
  text-wrap: balance;
}
.ch-body { white-space: pre-line; max-width: 30em; font-size: 16.5px; opacity: .88; text-wrap: pretty; }
.hint { margin-top: 14px; position: relative; font-size: 12.5px; opacity: .6; text-align: center; }

.ph { display: block; overflow: hidden; background: color-mix(in srgb, var(--ink) 12%, transparent); }

/* xoè như bộ bài */
.fan {
  margin-bottom: 44px;
  --w: min(54vw, 300px);
  position: relative; height: calc(var(--w) * 1.62);
}
.fan .ph {
  --mid: calc((var(--n) - 1) / 2);
  position: absolute; left: 50%; bottom: 0;
  width: var(--w); aspect-ratio: var(--ratio, 3 / 4);
  margin-left: calc(var(--w) / -2);
  padding: 7px 7px 26px; background: var(--paper);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(40, 20, 30, .18), 0 18px 34px -10px rgba(40, 20, 30, .35);
  transform-origin: 50% 150%;
  transform: rotate(calc((var(--i) - var(--mid)) * 1.5deg)) translateY(30px);
  opacity: 0;
  transition: transform 1.3s var(--ease) calc(var(--i) * 70ms), opacity .6s ease calc(var(--i) * 70ms);
}
.fan .ph img { border-radius: 1px; }
.in .fan .ph { opacity: 1; transform: rotate(calc((var(--i) - var(--mid)) * 9deg)); }
.fan:has(.ph:only-child) { --w: min(72vw, 380px); height: calc(var(--w) * 1.42); }
.fan.wide { --w: min(80vw, 520px); height: calc(var(--w) * 1.08); }
.in .fan .ph:only-child { transform: rotate(-3deg); }
.chapter:nth-of-type(odd).in .fan .ph:only-child { transform: rotate(3deg); }

/* vuốt ngang */
.strip {
  display: flex; gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  margin-inline: calc(var(--g) * -1);
  padding-inline: var(--g);
  scroll-padding-inline: var(--g);
}
.strip::-webkit-scrollbar { display: none; }
.strip .ph { flex: 0 0 80%; aspect-ratio: var(--ratio, 4 / 5); scroll-snap-align: start; border-radius: 4px; }
.strip.wide .ph { flex-basis: 88%; }
.strip .ph:nth-child(even) { margin-top: 28px; }

/* ghép ảnh */
.ch-album { container-type: inline-size; }
.collage { display: grid; grid-template-columns: repeat(6, 1fr); grid-auto-rows: calc((100cqi - 40px) / 6); grid-auto-flow: dense; gap: 8px; }
.collage .ph { border-radius: 3px; clip-path: inset(100% 0 0 0); transition: clip-path 1.2s var(--ease) calc(var(--i) * 110ms); }
.in .collage .ph { clip-path: inset(0); }
.collage .ph:nth-child(5n + 1) { grid-column: span 4; grid-row: span 5; }
.collage .ph:nth-child(5n + 2) { grid-column: span 2; grid-row: span 3; }
.collage .ph:nth-child(5n + 3) { grid-column: span 2; grid-row: span 2; }
.collage .ph:nth-child(5n + 4),
.collage .ph:nth-child(5n + 5) { grid-column: span 3; grid-row: span 4; }
/* ảnh lẻ cuối hàng thì trải hết chiều ngang, khỏi để trống */
.collage .ph:nth-child(5n + 4):last-child { grid-column: span 6; }
.collage .ph:nth-child(5n + 6):last-child { grid-column: span 6; grid-row: span 4; }
/* đúng 2 ảnh: xếp thành cặp so le */
.collage:has(> .ph:nth-child(2):last-child) .ph { grid-column: span 3; grid-row: span 5; }
.collage:has(> .ph:nth-child(2):last-child) .ph:last-child { translate: 0 12%; }

/* ---------- 6 năm: ảnh "hiện hình" như polaroid ---------- */
.finale { padding: 22svh var(--g) 10svh; }
.fin-head { text-align: center; margin-bottom: 56px; }
.fin-head .ch-body { margin-inline: auto; }
.finale h2 { font-size: clamp(64px, 22vw, 150px); font-style: italic; font-weight: 200; }
.prints { display: grid; grid-template-columns: repeat(2, 1fr); gap: 34px 16px; max-width: 1100px; margin: auto; }
.print {
  background: var(--paper); color: #3a2a3f;
  padding: 8px 8px 0; border-radius: 2px;
  rotate: var(--r);
  box-shadow: 0 0 60px -10px color-mix(in srgb, var(--orb) 35%, transparent), 0 20px 30px -12px rgba(0, 0, 0, .6);
}
.print:nth-child(odd) { translate: 0 22px; }
@media (max-width: 759px) { .print:last-child:nth-child(odd) { grid-column: 1 / -1; justify-self: center; width: calc(50% - 8px); translate: none; } }
.print .ph { aspect-ratio: 4 / 5; }
.print img { filter: brightness(2) contrast(.45) sepia(.7) blur(6px); transition: filter 3.2s ease .2s; }
.print.in img { filter: none; }
.print figcaption { min-height: 38px; padding: 6px 2px 8px; font: italic 300 16px/1.3 var(--serif); font-variation-settings: "WONK" 1; text-align: center; }

/* ---------- thư ---------- */
.letter {
  max-width: 34rem; margin: auto;
  padding: 18svh var(--g);
  font: 300 clamp(21px, 5.6vw, 28px)/1.6 var(--serif);
  font-variation-settings: "opsz" 36, "SOFT" 100;
}
.letter p + p { margin-top: 1.1em; }
.letter p:first-child { font-style: italic; }
.letter .sign { text-align: right; font-style: italic; font-size: 1.5em; margin-top: 1.4em; }
.letter [data-reveal] { opacity: 0; filter: blur(4px); transition: opacity 1.6s ease, filter 1.6s ease; }
.letter .in { opacity: 1; filter: none; }

/* ---------- cuối ---------- */
.end {
  min-height: 100svh; text-align: center;
  display: grid; place-content: center; gap: 28px;
  padding: 10svh var(--g) calc(env(safe-area-inset-bottom) + 10svh);
}
.clock { display: grid; grid-template-columns: repeat(4, auto); justify-content: center; gap: 4px 18px; }
.clock b { display: block; font: 300 clamp(34px, 10vw, 72px)/1 var(--serif); font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 144; }
.clock span { font-size: 12px; opacity: .65; }
.ending { font: italic 300 clamp(26px, 7.5vw, 44px)/1.2 var(--serif); font-variation-settings: "SOFT" 100, "WONK" 1; }
.end [data-reveal] { opacity: 0; transition: opacity 2s ease; }
.end .in { opacity: 1; }
.replay { justify-self: center; margin-top: 24px; font-size: 14px; padding: 12px 22px; border: 1px solid color-mix(in srgb, var(--ink) 40%, transparent); border-radius: 99px; }

/* ---------- thanh mốc bên phải ---------- */
.rail {
  position: fixed; z-index: 10; top: 50%; translate: 0 -50%;
  right: max(8px, env(safe-area-inset-right));
  display: grid; gap: 10px; padding: 8px 4px;
  opacity: 0; pointer-events: none; transition: opacity .6s;
}
.past-hero .rail { opacity: 1; pointer-events: auto; }
.rail { gap: 0; }
.rail a { display: grid; place-items: center; width: 28px; min-height: 16px; }
.rail a::before { content: ""; width: 4px; height: 4px; border-radius: 4px; background: var(--ink); opacity: .35; transition: height .5s var(--ease), opacity .5s; }
.rail a.on::before { height: 22px; opacity: .9; }

/* ---------- xem ảnh ---------- */
.lb {
  width: 100vw; height: 100dvh; max-width: none; max-height: none;
  padding: 0; border: 0; background: rgba(8, 8, 14, .96); color: #f3ece4;
}
.lb[open] { animation: lbIn .35s ease; }
@keyframes lbIn { from { opacity: 0; } }
.lb::backdrop { background: transparent; }
.lb-track { display: flex; height: 100%; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior: contain; }
.lb-track::-webkit-scrollbar { display: none; }
.lb-track figure {
  flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always;
  display: grid; place-items: center; align-content: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 56px) 12px calc(env(safe-area-inset-bottom) + 56px);
}
.lb-track img { width: auto; height: auto; max-width: 100%; max-height: calc(100dvh - 160px); object-fit: contain; border-radius: 3px; }
.lb-track figcaption { font: italic 300 18px var(--serif); }
.lb-count { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 18px); text-align: center; font-size: 13px; opacity: .7; font-variant-numeric: tabular-nums; }
.lb-close { position: absolute; top: calc(env(safe-area-inset-top) + 10px); right: max(10px, env(safe-area-inset-right)); width: 44px; height: 44px; font-size: 18px; border-radius: 50%; background: rgba(255, 255, 255, .1); }

/* ---------- iPad / màn rộng ---------- */
@media (min-width: 760px) {
  :root { --g: max(56px, env(safe-area-inset-left)); }
  .chapter { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: center; gap: 56px; padding-block: 14svh; }
  .chapter:nth-of-type(odd) .ch-text { order: 2; }
  .ch-text { position: sticky; top: 22svh; align-self: start; }
  .ch-year { top: -.95em; }
  .fan { --w: min(26vw, 320px); }
  .strip { margin-inline: 0 calc(var(--g) * -1); padding-inline: 0 var(--g); scroll-padding-inline: 0; }
  .strip .ph { flex-basis: 62%; }
  .strip.wide .ph { flex-basis: 78%; }
  .prints { grid-template-columns: repeat(3, 1fr); gap: 56px 36px; }
  .print:nth-child(odd) { translate: none; }
  .print:nth-child(3n + 2) { translate: 0 40px; }
}

/* ---------- hiệu ứng theo cuộn (Safari 26+, máy cũ tự bỏ qua) ---------- */
@supports (animation-timeline: view()) {
  .hero h1 { animation: heroOut linear both; animation-timeline: view(); animation-range: exit 0% exit 100%; }
  @keyframes heroOut { to { transform: scale(1.18); opacity: 0; } }
  .ch-year { animation: drift linear both; animation-timeline: view(); }
  @keyframes drift { from { translate: 0 30%; } to { translate: 0 -60%; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01s !important; transition-delay: 0s !important; }
  :root { transition: none; }
}
