/* Red, white & blue — Old Glory Red (#B31942) and Old Glory Blue (#0A3161) on white paper.
   Tuned mobile-first for a Pixel 10a (~412×915 CSS px). */
:root {
  --paper: #f3f5fa;
  --paper-dark: #d9e0ec;
  --card: #ffffff;
  --ink: #0a1f3d;
  --ink-soft: #5a6b85;
  --red: #b31942;
  --red-dark: #8e1234;
  --blue: #0a3161;
  --blue-soft: #e4ebf6;
  --note: #e4ebf6;
  --tape: rgba(179, 25, 66, 0.22);
  --shadow: 0 2px 4px rgba(10, 49, 97, 0.10), 0 10px 24px rgba(10, 49, 97, 0.14);
  --hand: "Caveat", cursive;
  --serif: "Lora", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }
body {
  background-color: var(--paper);
  background-image:
    radial-gradient(rgba(10, 49, 97, 0.07) 1px, transparent 1px),
    radial-gradient(rgba(179, 25, 66, 0.05) 1px, transparent 1px);
  background-size: 22px 22px, 13px 13px;
  background-position: 0 0, 7px 11px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button { touch-action: manipulation; }

.screen {
  min-height: 100vh; min-height: 100dvh;
  padding: calc(20px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

/* ---------- Login ---------- */
#login { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 36px; }

.envelope {
  position: relative;
  width: min(340px, 100%);
  aspect-ratio: 3 / 2;
  background: var(--card);
  border-radius: 6px;
  box-shadow: var(--shadow);
  perspective: 800px;
}
.envelope-flap {
  position: absolute; inset: 0 0 auto 0; height: 46%;
  background: var(--paper-dark);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform 0.8s ease;
  z-index: 2;
}
.envelope.open .envelope-flap { transform: rotateX(180deg); z-index: 0; }
.envelope-body { position: absolute; inset: auto 0 0 0; padding: 0 22px 16px; text-align: center; }
.envelope-to { font-family: var(--hand); font-size: 2rem; margin: 0; }
.envelope-from { margin: 0; color: var(--ink-soft); font-style: italic; font-size: 0.9rem; }
.seal {
  position: absolute; left: 50%; top: 46%; z-index: 3;
  width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border: none; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d23a5f, var(--red-dark));
  color: #fff; font-size: 1.5rem; cursor: pointer;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.5s ease, opacity 0.5s ease;
}
.envelope.open .seal { transform: scale(1.4) rotate(25deg); opacity: 0; }
.envelope.shake { animation: shake 0.4s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

.login-form { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(340px, 100%); }
.login-form label { font-family: var(--hand); font-size: 1.9rem; line-height: 1.2; text-align: center; }
.login-kicker { margin: 0; font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); }
.answer-form { margin: 8px auto 0; }
.login-form input {
  width: 100%; padding: 14px; font-size: 16px; /* 16px stops mobile browsers zooming on focus */
  border: 1px solid var(--paper-dark); border-radius: 8px;
  background: var(--card); color: var(--ink);
  font: inherit; text-align: center;
}
.login-form input:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.login-form button, .btn {
  min-height: 48px; padding: 10px 32px; border: none; border-radius: 999px;
  background: var(--red); color: #fff; font: 600 1rem var(--serif);
  cursor: pointer; box-shadow: 0 2px 6px rgba(142, 18, 52, 0.3);
}
.login-form button:hover, .btn:hover { background: var(--red-dark); }
.login-error { min-height: 1.6em; margin: 0; color: var(--red); font-family: var(--hand); font-size: 1.3rem; }

/* ---------- Book ---------- */
.book-header { text-align: center; max-width: 760px; margin: 0 auto; }
.book-header h1::before, .book-header h1::after { content: "★"; font-size: 0.55em; vertical-align: middle; margin: 0 0.35em; color: var(--red); }
.book-header h1 { font-family: var(--hand); font-weight: 700; font-size: clamp(2.2rem, 7vw, 3.2rem); margin: 0 0 10px; color: var(--blue); }

.tabs { display: flex; justify-content: center; flex-wrap: nowrap; gap: 6px; margin-bottom: 22px; }
.tab {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px dashed var(--ink-soft); background: transparent;
  color: var(--ink-soft); font: 700 1.3rem var(--hand); cursor: pointer;
}
.tab.unlocked { border-style: solid; border-color: var(--blue); color: var(--blue); background: var(--card); }
.tab.active { background: var(--red); color: #fff; }
.tab.locked { opacity: 0.55; }
.tab.ask { border-style: dashed; border-color: var(--red); color: var(--red); background: var(--card); }

.page-wrap { position: relative; max-width: 760px; margin: 0 auto; display: flex; align-items: flex-start; }
.nav-arrow {
  position: sticky; top: 45vh; flex: none;
  width: 36px; height: 36px; border: none; border-radius: 50%;
  background: var(--card); color: var(--red); font-size: 1.6rem; line-height: 1;
  cursor: pointer; box-shadow: var(--shadow);
}
.nav-arrow:disabled { visibility: hidden; }
.nav-arrow.prev { margin-right: -18px; z-index: 2; }
.nav-arrow.next { margin-left: -18px; z-index: 2; }

.page {
  flex: 1; min-width: 0;
  background: var(--card);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 32px 28px 40px;
  position: relative;
  animation: turn 0.6s ease;
}
.page::after { /* flag stripes along the top edge */
  content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; border-radius: 4px 4px 0 0;
  background: repeating-linear-gradient(90deg, var(--red) 0 24px, #fff 24px 36px, var(--blue) 36px 60px, #fff 60px 72px);
}
.page::before { /* a strip of tape at the top */
  content: ""; position: absolute; top: -12px; left: 50%;
  width: 110px; height: 26px; margin-left: -55px;
  background: var(--tape); transform: rotate(-3deg);
}
@keyframes turn { from { opacity: 0; transform: rotateY(-12deg) translateX(20px); } to { opacity: 1; transform: none; } }

@media (max-width: 560px) {
  .page { padding: 30px 18px 32px; }
  .nav-arrow { display: none; }
  .coupons { grid-template-columns: 1fr; }
  .player { height: 352px; }
}

.day-label { font-family: var(--hand); color: var(--ink-soft); font-size: 1.3rem; margin: 0; text-align: center; }
.page h2 { font-family: var(--hand); font-size: clamp(2.2rem, 9vw, 2.9rem); line-height: 1.1; margin: 4px 0 4px; text-align: center; color: var(--red); }
.subtitle { text-align: center; font-style: italic; color: var(--ink-soft); margin: 0 0 24px; }

.letter p { margin: 0 0 1em; }
.letter .signature { font-family: var(--hand); font-size: 2rem; text-align: right; margin-top: -0.4em; }

.reason {
  margin: 32px auto 0; max-width: 340px; padding: 16px 18px;
  background: var(--note); border-top: 4px solid var(--blue); transform: rotate(-1.5deg);
  box-shadow: 2px 4px 10px rgba(0, 0, 0, 0.12);
  font-family: var(--hand); font-size: 1.45rem; line-height: 1.25; text-align: center;
}
.reason small { display: block; font-size: 1rem; color: var(--ink-soft); }

/* Polaroids */
.timeline { display: grid; gap: 28px; }
.polaroid {
  background: #fff; padding: 12px 12px 14px; box-shadow: var(--shadow);
  max-width: 340px; margin: 0 auto; width: 100%;
}
.timeline .polaroid:nth-child(odd) { transform: rotate(-2deg); }
.timeline .polaroid:nth-child(even) { transform: rotate(2deg); }
.polaroid img, .polaroid .photo-placeholder { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.photo-placeholder { background: repeating-linear-gradient(180deg, #f6dde4, #f6dde4 14px, #fff 14px, #fff 28px); display: grid; place-items: center; color: var(--ink-soft); font-family: var(--hand); font-size: 1.4rem; }
.polaroid figcaption { font-family: var(--hand); font-size: 1.4rem; text-align: center; margin-top: 8px; line-height: 1.2; }
.polaroid figcaption span { display: block; font-size: 1.05rem; color: var(--ink-soft); }

/* Coupons */
.coupons { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.coupon {
  border: 2px dashed var(--red); border-radius: 10px; padding: 18px 16px;
  text-align: center; background: #fff; position: relative;
}
.coupon h3 { font-family: var(--hand); font-size: 1.8rem; margin: 0; color: var(--red-dark); line-height: 1.1; }
.coupon p { margin: 4px 0 12px; color: var(--ink-soft); font-size: 0.95rem; }
.coupon.redeemed { opacity: 0.6; }
.coupon.redeemed::after {
  content: "REDEEMED"; position: absolute; inset: 0; display: grid; place-items: center;
  font: 700 1.6rem var(--serif); color: var(--red); letter-spacing: 0.1em; transform: rotate(-14deg);
}

/* Playlist */
.player { width: 100%; height: 380px; border: 0; border-radius: 12px; margin-bottom: 20px; }
.tracks { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.tracks li { border-left: 3px solid var(--red); padding-left: 12px; }
.tracks strong { display: block; }
.tracks span { font-family: var(--hand); font-size: 1.3rem; color: var(--ink-soft); }

/* Quiz */
.quiz-q { margin-bottom: 22px; }
.quiz-q p { font-weight: 600; margin: 0 0 8px; }
.quiz-options { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-options button {
  min-height: 44px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--ink-soft);
  background: #fff; color: var(--ink); font: inherit; font-size: 0.95rem; cursor: pointer;
}
.quiz-options button.right { background: var(--blue); border-color: var(--blue); color: #fff; }
.quiz-options button.wrong { background: var(--red); border-color: var(--red); color: #fff; animation: shake 0.4s; }
.prize { text-align: center; font-family: var(--hand); font-size: 1.7rem; color: var(--red-dark); padding: 16px; border: 2px solid var(--red); border-radius: 10px; }

/* Hunt + reveal */
.riddle { font-family: var(--hand); font-size: 1.7rem; line-height: 1.35; text-align: center; margin: 0 0 20px; }
.hint-wrap { text-align: center; }
.hint { margin-top: 12px; font-style: italic; color: var(--ink-soft); }
.countdown { display: flex; justify-content: center; gap: 10px; margin: 20px 0; flex-wrap: wrap; }
.countdown div { background: var(--blue); color: #fff; border-radius: 8px; padding: 8px 12px; min-width: 64px; text-align: center; }
.countdown b { display: block; font-size: 1.6rem; line-height: 1.1; }
.countdown small { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
.media { width: 100%; border-radius: 8px; margin: 8px 0 16px; }

/* Locked page */
.locked-page { text-align: center; padding: 30px 0; }
.locked-page .blur { filter: blur(6px); user-select: none; opacity: 0.5; font-family: var(--hand); font-size: 1.5rem; line-height: 1.4; }
.stamp {
  display: inline-block; margin: 24px 0 10px; padding: 10px 20px;
  border: 3px double var(--blue); color: var(--blue); border-radius: 6px;
  font: 700 1.1rem var(--serif); letter-spacing: 0.1em; text-transform: uppercase;
  transform: rotate(-6deg);
}
.locked-page .when { font-family: var(--hand); font-size: 1.6rem; }

/* Floating hearts */
#hearts { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.heart { position: absolute; bottom: -40px; animation: float linear forwards; }
@keyframes float { to { transform: translateY(-115vh) rotate(var(--spin)); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
