@font-face { font-family: 'Poppins'; src: url('assets/fonts/poppins-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('assets/fonts/poppins-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('assets/fonts/poppins-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('assets/fonts/poppins-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('assets/fonts/playfair-display-latin-700-italic.woff2') format('woff2'); font-style: italic; font-weight: 700; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('assets/fonts/playfair-display-latin-400-italic.woff2') format('woff2'); font-style: italic; font-weight: 400; font-display: swap; }

:root {
  /* St. Joseph School: SJS Navy, Spirit Blue, Golden Light, Sky Mist, Steel Gray. */
  --navy: #002855;
  --blue: #0076c0;
  --blue-dark: #005f9c;
  --gold: #f4b400;
  --mist: #d9eaf7;
  --tint: #eef5fc;
  --ink: #2f3a45;
  --ink-2: #4a4a4a;
  --sky: #ffffff; /* the child's sky colour after a scan, as a soft tint */
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: #fff;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- page backdrop: white with a soft sky, and a few golden twinkles ---------- */
.sky { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(90% 55% at 50% 0%, var(--tint), #fff 70%); }
body[data-screen='result'] .sky {
  background: radial-gradient(75% 50% at 50% 50%, color-mix(in srgb, var(--sky) 22%, #fff), #fff 75%);
}
.twinkle { position: absolute; width: 22px; fill: var(--gold); opacity: 0.55; animation: twinkle 3.6s ease-in-out infinite; }
.t-1 { top: 9%; left: 10%; }
.t-2 { top: 22%; right: 9%; width: 16px; animation-delay: 1.2s; }
.t-3 { top: 52%; left: 6%; width: 13px; animation-delay: 2.3s; }

/* ---------- 3D stage ---------- */
#stage {
  position: fixed; inset: 0; z-index: 1;
  width: 100%; height: 100%;
  touch-action: none; display: block;
}
body:not([data-screen='result']) #stage { visibility: hidden; }

/* ---------- layout ---------- */
main { position: relative; z-index: 2; min-height: 100dvh; display: flex; }
.screen {
  width: min(100%, 480px); margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center;
}

/* The school's crest, always exactly as supplied. */
.crest { display: block; width: min(30vw, 116px); height: auto; filter: drop-shadow(0 6px 12px rgba(0, 40, 85, 0.18)); }
.crest.small { width: 54px; filter: none; }

.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.eyebrow { margin: 0; font-weight: 600; font-size: 1rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--blue); }
h1, h2 {
  font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-weight: 700; margin: 0; line-height: 1.08;
  color: var(--navy);
}
h1 { font-size: clamp(2.1rem, 9.5vw, 3rem); }
h2 { font-size: clamp(1.7rem, 7.5vw, 2.3rem); }
h1:focus, h2:focus, .status:focus, .hint:focus { outline: none; }
.lead { margin: 0; font-size: 1.08rem; line-height: 1.45; color: var(--ink); }
.lead em { font-style: normal; color: var(--blue); font-weight: 700; }
.allsaints { margin: 2px 0 0; padding: 4px 14px; border-radius: 99px; background: #fff8e0; color: #7a5a00; font-size: 0.9rem; font-weight: 500; }

/* ---------- buttons ---------- */
/* Button text is 19px+ bold: white on Spirit Blue meets the large-text contrast bar. */
.actions { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; }
.row .btn { flex: 1 1 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 54px; padding: 0 22px; border-radius: 999px;
  font: 600 1.15rem/1.1 'Poppins', system-ui, sans-serif; color: var(--navy);
  background: #fff; border: 2px solid var(--navy);
  cursor: pointer; text-decoration: none; user-select: none; -webkit-user-select: none;
  transition: transform 0.12s, background 0.2s, box-shadow 0.2s;
}
.btn:hover { background: var(--tint); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, input:focus-visible + .btn { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn.primary {
  background: var(--blue); color: #fff; border-color: var(--blue);
  box-shadow: 0 6px 18px rgba(0, 118, 192, 0.32), inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}
.btn.primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn.big { min-height: 64px; font-size: 1.2rem; width: 100%; }
.btn.small { min-height: 42px; padding: 0 16px; font-size: 0.98rem; }
.btn.link { border-color: transparent; background: rgba(255, 255, 255, 0.85); text-decoration: underline; text-underline-offset: 4px; }
.btn svg { width: 26px; height: 26px; flex: none; }
.btn[aria-busy='true'] { opacity: 0.7; pointer-events: none; }

/* ---------- loader + tips ---------- */
.loader { width: 100%; }
.bar { height: 8px; background: var(--tint); border-radius: 99px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--gold)); transition: width 0.25s; }
.loader[data-state='ready'] .bar { visibility: hidden; }
.loader[data-state='error'] #loader-text { color: #b3261e; }
#loader-text { margin: 8px 0 0; font-size: 0.95rem; color: var(--ink-2); }

.tips { list-style: none; margin: 0; padding: 0; width: 100%; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.tips li { position: relative; padding: 12px 14px 12px 44px; background: var(--tint); border-radius: 16px; font-size: 1.02rem; line-height: 1.35; color: var(--ink); }
.tips li::before { content: ''; position: absolute; left: 14px; top: 14px; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #ffd96a, var(--gold)); }
.tips.mini { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px; }
.tips.mini li { padding: 6px 12px; font-size: 0.86rem; font-weight: 500; color: var(--navy); border-radius: 99px; }
.tips.mini li::before { display: none; }

.fine { margin: 0; font-size: 0.9rem; color: var(--ink-2); }
.fine a { color: var(--blue); font-weight: 600; }
/* The printer's credit: small, at the bottom. */
.credit { margin: 4px 0 0; max-width: 36em; font-size: 0.72rem; line-height: 1.5; color: #6b6b6b; }
.credit a { color: inherit; font-weight: 600; }

.banner { width: 100%; background: #fff8e0; color: var(--ink); border: 2px solid var(--gold); border-radius: 18px; padding: 14px 16px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.banner p { margin: 0; }

/* ---------- working ---------- */
.scanframe { position: relative; width: min(74vw, 330px); aspect-ratio: 3 / 4; border-radius: 22px; overflow: hidden; background: #f4f4f4; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18), 0 0 0 3px var(--navy); }
.scanframe img { width: 100%; height: 100%; object-fit: cover; }
.sweep { position: absolute; left: 0; right: 0; top: 0; height: 30%; background: linear-gradient(180deg, transparent, rgba(244, 180, 0, 0.45), transparent); animation: sweep 1.5s ease-in-out infinite alternate; }
.status { margin: 0; font-size: 1.25rem; font-weight: 700; min-height: 1.6em; color: var(--navy); }

/* ---------- result ---------- */
#result { position: fixed; inset: 0; width: 100%; max-width: none; justify-content: flex-start; gap: 12px; pointer-events: none; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
body[data-screen='result'] main { pointer-events: none; } /* touches reach the 3D canvas */
#result .btn { pointer-events: auto; }
.result-top { width: min(100%, 480px); display: flex; justify-content: space-between; }
.result-actions { margin-top: auto; width: min(100%, 480px); display: flex; flex-direction: column; gap: 10px; align-items: center; }
.result-actions > .btn { width: 100%; }
.hint { margin: 0; padding: 8px 18px; border-radius: 99px; background: var(--navy); color: #fff; font-weight: 600; animation: pulse 1.8s ease-in-out infinite; }
/* A short line pops up over the saint. */
.say {
  position: fixed; top: 19%; left: 50%; z-index: 3; pointer-events: none;
  max-width: min(90vw, 440px); padding: 10px 20px; border-radius: 26px;
  background: #fff; border: 3px solid var(--gold); color: var(--navy);
  font: 700 clamp(1.25rem, 5.6vw, 1.6rem)/1.2 'Poppins', sans-serif; text-align: center;
  box-shadow: 0 10px 26px rgba(0, 40, 85, 0.18);
  opacity: 0; transform: translate(-50%, 0) scale(0.4);
}
.say.pop { animation: say 2.2s ease-out; }
/* The introduction and the facts: a caption near the top, with the saint's name. */
.caption {
  position: fixed; top: calc(max(20px, env(safe-area-inset-top)) + 58px); left: 50%; z-index: 3; pointer-events: none;
  width: min(92vw, 440px); margin: 0; padding: 12px 18px; transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.96); border: 3px solid var(--blue); border-radius: 22px;
  font-size: 1.02rem; line-height: 1.42; text-align: center; color: var(--ink);
  box-shadow: 0 10px 28px rgba(0, 40, 85, 0.15); animation: caption-in 0.35s ease-out;
}
.caption strong { font-family: 'Playfair Display', Georgia, serif; font-style: italic; font-size: 1.2rem; color: var(--navy); }
.caption::after { content: ''; position: absolute; left: 50%; bottom: -14px; width: 24px; height: 24px; background: #fff; border: 3px solid var(--blue); border-top: 0; border-left: 0; transform: translateX(-50%) rotate(45deg); }
@keyframes caption-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- oops ---------- */
.oops-photo { max-width: 100%; max-height: 34vh; border-radius: 14px; border: 3px solid var(--tint); }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 10;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); transition: opacity 0.25s, transform 0.25s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.nojs { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px; text-align: center; background: #fff; color: var(--ink); font-size: 1.2rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@keyframes twinkle { 50% { transform: scale(0.6) rotate(20deg); opacity: 0.25; } }
@keyframes sweep { to { top: 70%; } }
@keyframes pulse { 50% { transform: scale(1.05); } }
@keyframes say {
  0% { opacity: 0; transform: translate(-50%, 16px) scale(0.5); }
  12% { opacity: 1; transform: translate(-50%, 0) scale(1.08); }
  20% { transform: translate(-50%, 0) scale(1); }
  82% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -20px) scale(0.96); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .say.pop { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
