:root {
  --bg: #1b1713;
  --ink: #f3e9d8;
  --accent: #d9a441;
  --card: rgba(24, 19, 14, 0.82);
  --photo-filter: none;
  --font-head: Georgia, "Times New Roman", serif;
  --font-body: "Helvetica Neue", Arial, sans-serif;
}

/* ===== Era looks ===== */
body[data-era="1940s"], body[data-era="1950s"] {
  --bg: #2a2118; --ink: #efe2c6; --accent: #c9a36a; --card: rgba(36, 27, 18, 0.86);
  --photo-filter: sepia(0.85) contrast(1.05) brightness(0.95);
}
body[data-era="1960s"], body[data-era="1970s"] {
  --bg: #2b1d12; --ink: #f5e3c3; --accent: #e08a3c; --card: rgba(43, 26, 14, 0.84);
  --photo-filter: sepia(0.35) saturate(1.25) contrast(1.05);
}
body[data-era="1980s"] {
  --bg: #14202b; --ink: #eef3f7; --accent: #f06a5a; --card: rgba(15, 26, 36, 0.84);
  --photo-filter: saturate(1.35) contrast(1.1) brightness(1.03);
}
body[data-era="today"] {
  --bg: #12231c; --ink: #f7f5ef; --accent: #8fd18a; --card: rgba(14, 30, 24, 0.84);
  --photo-filter: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-body); line-height: 1.55;
  transition: background 1.2s ease, color 1.2s ease;
}
#map { position: fixed; inset: 0; z-index: 0; filter: saturate(0.7) brightness(0.7); transition: filter 1.2s; }
body[data-era="1940s"] #map, body[data-era="1950s"] #map { filter: sepia(0.9) brightness(0.65); }
body[data-era="1960s"] #map, body[data-era="1970s"] #map { filter: sepia(0.35) saturate(1.1) brightness(0.7); }

/* ===== Opening ===== */
#begin {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  background: radial-gradient(circle at 50% 40%, #3a2b1a, #120e09);
  transition: opacity 1.2s ease;
}
#begin.gone { opacity: 0; pointer-events: none; }
#begin h1 { font-family: var(--font-head); font-size: clamp(2rem, 7vw, 4.2rem); margin: 0 0 8px; color: #f3e3c3; }
#begin .sub { font-family: var(--font-head); font-style: italic; color: #cdb88f; margin-bottom: 36px; font-size: clamp(1rem, 3vw, 1.4rem); }
#begin button {
  font: 600 1.1rem var(--font-body); color: #1b1208; background: #d9a441; border: 0;
  padding: 16px 34px; border-radius: 999px; cursor: pointer; box-shadow: 0 6px 30px rgba(217,164,65,0.35);
}
#begin button:hover { background: #e8b657; }
#begin .hint { margin-top: 18px; color: #9a8866; font-size: 0.85rem; }

/* ===== HUD ===== */
#hud {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 50; display: flex;
  justify-content: space-between; gap: 8px; pointer-events: none; font-size: 0.85rem;
}
#hud .pill { background: var(--card); padding: 6px 12px; border-radius: 999px; backdrop-filter: blur(6px); }
#mute { pointer-events: auto; cursor: pointer; border: 0; color: var(--ink); font: inherit; }

/* ===== Scroll chapters ===== */
#story { position: relative; z-index: 10; }
.chapter { min-height: 100vh; display: flex; align-items: center; padding: 14vh 16px; }
.chapter:nth-child(odd) { justify-content: flex-start; }
.chapter:nth-child(even) { justify-content: flex-end; }
.card {
  width: min(560px, 100%); background: var(--card); backdrop-filter: blur(8px);
  border-radius: 14px; padding: 26px 24px; box-shadow: 0 12px 50px rgba(0,0,0,0.5);
  opacity: 0; transform: translateY(40px); transition: opacity 0.9s ease, transform 0.9s ease;
}
.chapter.active .card { opacity: 1; transform: none; }
.meta { color: var(--accent); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.78rem; margin-bottom: 6px; }
.card h2 { font-family: var(--font-head); font-size: clamp(1.5rem, 4.5vw, 2.1rem); margin: 0 0 12px; line-height: 1.2; }
.card p { margin: 0 0 10px; font-size: 1.02rem; }
.quote { border-left: 3px solid var(--accent); margin: 14px 0; padding: 4px 0 4px 14px; font-family: var(--font-head); font-size: 1.25rem; font-style: italic; }
.quote cite { display: block; font-size: 0.85rem; font-style: normal; color: var(--accent); margin-top: 4px; }
.draft-note { margin-top: 10px; padding: 8px 10px; background: rgba(255,200,0,0.13); border: 1px dashed #c9a100; font-size: 0.8rem; color: #ffe08a; border-radius: 6px; display: none; }
body.draft .draft-note { display: block; }

/* ===== Photos ===== */
.photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 14px; }
.photos figure { margin: 0; opacity: 0; transform: translateY(14px) scale(0.98); transition: opacity 0.8s ease, transform 0.8s ease; }
.chapter.active .photos figure { opacity: 1; transform: none; }
.chapter.active .photos figure:nth-child(2) { transition-delay: 0.25s; }
.chapter.active .photos figure:nth-child(3) { transition-delay: 0.5s; }
.chapter.active .photos figure:nth-child(4) { transition-delay: 0.75s; }
.photos img { width: 100%; display: block; filter: var(--photo-filter); border: 8px solid #f4ecdc; border-bottom-width: 22px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); background: #ddd; }
body[data-era="1940s"] .photos img, body[data-era="1950s"] .photos img { border-radius: 2px; }
body[data-era="1980s"] .photos img { border-width: 4px; border-bottom-width: 4px; border-radius: 3px; }
body[data-era="today"] .photos img { border-width: 0; border-radius: 10px; }
.ph-missing { aspect-ratio: 4/3; display: none; align-items: center; justify-content: center; text-align: center; font-size: 0.75rem; color: #8a7a55; border: 2px dashed #8a7a55; border-radius: 6px; padding: 6px; word-break: break-all; }
body.draft .ph-missing { display: flex; }

/* ===== Special visuals ===== */
.caliper { display: none; margin-top: 12px; font-family: "Courier New", monospace; font-size: 1.4rem; color: var(--accent); }
.chapter.active .caliper { display: block; }
.floss-wrap { margin-top: 16px; }
.floss-stage { position: relative; height: 70px; border-radius: 8px; background: #2c2218; overflow: hidden; }
.floss-stage .stock { position: absolute; left: 0; right: 0; top: 0; height: 28px; background: #4a3a28; }
.floss-stage .barrel { position: absolute; left: 0; right: 0; bottom: 0; height: 28px; background: #8a8f95; }
.floss-stage .thread { position: absolute; top: 33px; left: -100%; width: 100%; height: 3px; background: #f4f4ee; transition: left 2.2s ease; }
.chapter.active .floss-stage .thread { left: 0; }
.target { position: relative; width: 150px; height: 150px; margin: 14px auto 0; border-radius: 50%; border: 2px solid #ccc; background: radial-gradient(#fff 0 12%, #222 13% 30%, #fff 31% 48%, #222 49% 66%, #fff 67% 100%); }
.target .hole { position: absolute; width: 9px; height: 9px; border-radius: 50%; background: #111; opacity: 0; box-shadow: 0 0 0 1px #fff; }
.chapter.active .target .hole { animation: pop 0.2s ease forwards; }
.dime { position: absolute; left: 50%; top: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fafafa, #b9bec3); border: 2px solid #8d9297; opacity: 0; transform: translateY(-80px); }
.chapter.active .dime { animation: drop 0.7s ease 3s forwards; }
.dime-line { text-align: center; margin-top: 8px; font-family: var(--font-head); font-style: italic; opacity: 0; transition: opacity 1s ease 3.8s; }
.chapter.active .dime-line { opacity: 1; }
@keyframes pop { from { opacity: 0; transform: scale(2); } to { opacity: 1; transform: scale(1); } }
@keyframes drop { from { opacity: 0; transform: translateY(-80px); } to { opacity: 0.92; transform: none; } }

.blueprint svg { width: 100%; height: auto; margin-top: 14px; }
.blueprint path { stroke: var(--accent); fill: none; stroke-width: 2; stroke-dasharray: 600; stroke-dashoffset: 600; }
.chapter.active .blueprint path { animation: draw 4s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* ===== Footprints on the map ===== */
.step { font-size: 18px; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.8)); animation: fade 6s ease forwards; }
@keyframes fade { 0% { opacity: 0; } 8% { opacity: 1; } 75% { opacity: 0.9; } 100% { opacity: 0.25; } }
.pin { background: var(--accent); width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 12px var(--accent); }

/* ===== Videos ===== */
#wishes { position: relative; z-index: 10; padding: 16vh 16px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
#wishes h2, #end h2 { font-family: var(--font-head); font-size: clamp(1.6rem, 5vw, 2.4rem); text-align: center; }
.vids { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; }
.vid { width: min(320px, 90vw); background: var(--card); padding: 12px; border-radius: 12px; }
.vid video { width: 100%; border-radius: 8px; background: #000; }
.vid div { text-align: center; margin-top: 6px; color: var(--accent); }

/* ===== Ending ===== */
#end { position: relative; z-index: 10; min-height: 100vh; padding: 14vh 16px 20vh; background: linear-gradient(transparent, rgba(0,0,0,0.75) 25%); text-align: center; }
#candles { display: grid; grid-template-columns: repeat(17, 1fr); gap: 6px; max-width: 520px; margin: 24px auto; }
.candle { height: 26px; position: relative; opacity: 0.35; }
.candle::before { content: ""; position: absolute; left: 50%; bottom: 0; width: 5px; height: 15px; margin-left: -2.5px; background: #f1e6c8; border-radius: 1px; }
.candle.lit { opacity: 1; }
.candle.lit::after { content: ""; position: absolute; left: 50%; top: 0; width: 8px; height: 12px; margin-left: -4px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: radial-gradient(#fff6c0, #ff9f1a); box-shadow: 0 0 10px #ffb02e; animation: flick 0.4s infinite alternate; }
@keyframes flick { from { transform: scale(1) rotate(-3deg); } to { transform: scale(1.12) rotate(3deg); } }
#letter { max-width: 560px; margin: 36px auto 0; text-align: left; font-family: "Courier New", monospace; font-size: 1.05rem; white-space: pre-wrap; min-height: 14em; background: var(--card); padding: 24px; border-radius: 10px; }
#candle-count { font-family: var(--font-head); font-size: 1.4rem; }

@media (max-width: 640px) {
  .chapter, .chapter:nth-child(even), .chapter:nth-child(odd) { justify-content: center; align-items: flex-end; padding: 10vh 10px 6vh; }
  #candles { grid-template-columns: repeat(12, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
}

/* ===== Grandkids' reasons ===== */
#reasons { position: relative; z-index: 10; padding: 16vh 16px; text-align: center; }
#reasons h2 { font-family: var(--font-head); font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 0 0 28px; }
#reasons-grid { display: flex; flex-wrap: wrap; gap: 22px; justify-content: center; max-width: 980px; margin: 0 auto; }
.reason-card { flex: 1 1 320px; max-width: 460px; background: var(--card); backdrop-filter: blur(8px); border-radius: 14px; padding: 22px 22px 14px; text-align: left; box-shadow: 0 12px 50px rgba(0,0,0,0.5); }
.reason-card h3 { font-family: var(--font-head); color: var(--accent); margin: 0 0 12px; font-size: 1.3rem; }
.reason-card ol { margin: 0; padding-left: 1.4em; }
.reason-card li { margin: 0 0 10px; opacity: 0; transform: translateX(-12px); transition: opacity 0.8s ease, transform 0.8s ease; }
.reason-card li::marker { color: var(--accent); font-weight: 700; }
.reason-card li.on { opacity: 1; transform: none; }

#reasons h2, #wishes h2, #end h2 { text-shadow: 0 2px 14px rgba(0,0,0,0.85), 0 0 3px rgba(0,0,0,0.9); }

/* Phone: two photos per row so tall chapters leave the map visible */
@media (max-width: 640px) { .photos { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); } }
