:root {
  --bg: #2e3e58;
  --bg2: #3a4d6b;
  --cream: #f4f7fb;
  --cream-dim: #d3dbe4;
  --red: #6e87aa;
  --red-dark: #2a3a57;
  --gold: #8db8da;
  --gold-dark: #5f8fb5;
  --green: #5aa0d0;
  --green-dark: #3b77a3;
  --ink: #22304a;
  --card: #f9fbfd;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, #4a6286 0%, var(--bg) 55%, #1c2738 100%) fixed var(--bg);
  color: var(--cream);
  font-family: var(--round);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
input { -webkit-user-select: text; user-select: text; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#snow, #fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#snow { z-index: 0; opacity: .7; }
#fx { z-index: 50; }
#glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 40; opacity: 0;
  box-shadow: inset 0 0 80px 20px var(--gold);
}
#glow.flash { animation: glow .7s ease-out; }
#glow.bad { box-shadow: inset 0 0 70px 14px var(--red); }
@keyframes glow { 0% { opacity: .9 } 100% { opacity: 0 } }

#app {
  position: relative; z-index: 1;
  height: 100dvh; height: 100svh;
  max-width: 480px; margin: 0 auto;
}
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding: calc(var(--safe-t) + 14px) var(--pad) calc(var(--safe-b) + 16px);
}
.screen.active { display: flex; animation: screenIn .45s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes screenIn { from { opacity: 0; transform: translateY(24px) scale(.97); } to { opacity: 1; transform: none; } }

.shake { animation: shake .4s cubic-bezier(.36,.07,.19,.97) both; }
.bump { animation: bump .35s ease-out both; }
@keyframes shake {
  10%, 90% { transform: translate3d(-2px,0,0) } 20%, 80% { transform: translate3d(4px,0,0) }
  30%, 50%, 70% { transform: translate3d(-7px,0,0) } 40%, 60% { transform: translate3d(7px,0,0) }
}
@keyframes bump { 0% { transform: scale(1) } 40% { transform: scale(1.015) translateY(-3px) } 100% { transform: none } }

/* ---------- buttons ---------- */
.btn {
  font: 800 18px/1.1 var(--round);
  border: 0; border-radius: 18px;
  padding: 16px 20px; min-height: 56px; width: 100%;
  color: #fff; cursor: pointer;
  box-shadow: 0 6px 0 var(--shadow, rgba(0,0,0,.35)), 0 10px 24px rgba(0,0,0,.3);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  position: relative;
}
.btn:active, .btn.pressed { transform: translateY(5px) scale(.97); box-shadow: 0 1px 0 var(--shadow, rgba(0,0,0,.35)), 0 4px 10px rgba(0,0,0,.3); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn-big { font-size: 21px; min-height: 64px; }
.btn-red { background: linear-gradient(180deg, #6e87aa, #4b6185); --shadow: var(--red-dark); }
.btn-gold { background: linear-gradient(180deg, #a9cde9, var(--gold)); color: #1f2c42; --shadow: var(--gold-dark); }
.icon-btn {
  position: fixed; z-index: 60;
  top: calc(var(--safe-t) + 10px); right: max(10px, calc(50vw - 230px));
  width: 42px; height: 42px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.12); color: #fff; font-size: 20px;
  cursor: pointer; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform .1s;
}
.icon-btn:active { transform: scale(.85); }

/* ---------- title ---------- */
#screen-title { justify-content: space-between; text-align: center; }
.title-top { margin-top: 4vh; }
.ornaments { font-size: 30px; display: flex; justify-content: center; gap: 18px; margin-bottom: 8px; }
.ornaments span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.ornaments span:nth-child(2) { animation-delay: .3s; }
.ornaments span:nth-child(3) { animation-delay: .6s; }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-6deg) } 50% { transform: translateY(-8px) rotate(6deg) } }
.kicker { margin: 0; font: italic 500 17px var(--serif); color: var(--cream-dim); letter-spacing: .02em; }
.title {
  margin: 2px 0 0; font: 900 clamp(52px, 17vw, 78px)/.95 var(--round);
  letter-spacing: -.02em;
  background: linear-gradient(180deg, #fff 30%, #cfe3f3 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 var(--red-dark)) drop-shadow(0 10px 18px rgba(0,0,0,.4));
}
.title span { display: block; font-size: .42em; letter-spacing: .3em; margin-bottom: 2px; }
.year {
  display: inline-block; margin: 14px 0 0; padding: 6px 14px; border-radius: 999px;
  background: var(--gold); color: #1f2c42; font-weight: 900; font-size: 15px; letter-spacing: .08em; text-transform: uppercase;
  transform: rotate(-3deg);
}
.lede { font-size: 18px; line-height: 1.4; margin: 18px 0 0; color: var(--cream); }
.howto { list-style: none; padding: 0; margin: 18px auto 0; display: inline-grid; gap: 6px; text-align: left; font-size: 15px; color: var(--cream-dim); }
.howto b { display: inline-block; width: 26px; }
.title-bottom { display: grid; gap: 12px; }
#name {
  font: 700 18px var(--round); color: var(--ink);
  padding: 15px 18px; border-radius: 16px; border: 3px solid transparent;
  background: var(--cream); text-align: center; width: 100%;
  box-shadow: inset 0 2px 6px rgba(0,0,0,.15);
}
#name:focus { outline: none; border-color: var(--gold); }
#start { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.03) } }
#start:active { animation: none; }

/* ---------- HUD ---------- */
.hud { padding-right: 50px; }
.progress { display: flex; gap: 5px; margin-top: 6px; }
.progress i {
  flex: 1; height: 8px; border-radius: 4px; background: rgba(255,255,255,.15);
  transition: background .3s, transform .3s;
}
.progress i.now { background: var(--cream); transform: scaleY(1.4); }
.progress i.ok { background: var(--green); }
.progress i.no { background: var(--red); }
.hud-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.score-box { display: flex; align-items: baseline; gap: 8px; }
.score-box .lbl { font-size: 13px; color: var(--cream-dim); text-transform: uppercase; letter-spacing: .1em; font-weight: 800; }
.num { font: 900 30px var(--round); font-variant-numeric: tabular-nums; color: var(--gold); display: inline-block; }
.num.pop { animation: numPop .4s cubic-bezier(.2,1.6,.4,1); }
@keyframes numPop { 0% { transform: scale(1.5) } 100% { transform: scale(1) } }
.streak {
  font-weight: 900; font-size: 18px; padding: 5px 12px; border-radius: 999px;
  background: rgba(255,255,255,.1); opacity: .45; transition: opacity .3s, background .3s;
}
.streak.hot { opacity: 1; background: linear-gradient(90deg, #a9cde9, var(--red)); animation: flame 1s ease-in-out infinite; }
.streak.up { animation: streakUp .6s cubic-bezier(.2,1.8,.4,1); }
@keyframes flame { 0%,100% { box-shadow: 0 0 8px #a9cde9 } 50% { box-shadow: 0 0 22px #a9cde9 } }
@keyframes streakUp { 0% { transform: scale(1.8) rotate(-10deg) } 100% { transform: none } }
.timer { margin-top: 12px; height: 10px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
#timer-fill {
  height: 100%; width: 100%; border-radius: 6px; transform-origin: left center;
  background: linear-gradient(90deg, var(--green), var(--gold));
}
#timer-fill.low { background: linear-gradient(90deg, var(--red), #a9cde9); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55 } }

/* ---------- question ---------- */
.q-body { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 10px 2px; min-height: 0; }
.who {
  align-self: flex-start; font-weight: 900; font-size: 14px; letter-spacing: .08em; text-transform: uppercase;
  padding: 5px 12px; border-radius: 999px; background: var(--gold); color: #1f2c42; transform: rotate(-2deg);
}
.q-text { font: 800 clamp(23px, 6.6vw, 30px)/1.22 var(--round); margin: 14px 0 0; text-wrap: balance; }
.enter > * { animation: rise .5s cubic-bezier(.2,.9,.3,1.3) both; }
.enter > *:nth-child(2) { animation-delay: .07s; }
@keyframes rise { from { opacity: 0; transform: translateY(22px) } to { opacity: 1; transform: none } }

.answers { display: grid; gap: 11px; }
.ans {
  font: 800 18px/1.2 var(--round); text-align: left; color: var(--ink);
  background: var(--card); border: 0; border-radius: 18px;
  min-height: 60px; padding: 12px 16px 12px 56px; width: 100%;
  box-shadow: 0 5px 0 #b8c4d3, 0 8px 18px rgba(0,0,0,.28);
  position: relative; cursor: pointer;
  transition: transform .09s ease, box-shadow .09s ease, background .2s, color .2s, opacity .3s;
  animation: ansIn .45s cubic-bezier(.2,.9,.3,1.35) both;
}
.ans::before {
  content: attr(data-letter);
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center;
  font-size: 16px; background: #dfe7f0; color: #4b6185;
}
.ans:active:not(:disabled), .ans.pressed { transform: translateY(4px) scale(.96, .93); box-shadow: 0 1px 0 #b8c4d3, 0 3px 8px rgba(0,0,0,.25); }
@keyframes ansIn { from { opacity: 0; transform: translateX(40px) scale(.9) } to { opacity: 1; transform: none } }
.ans:disabled { cursor: default; }
.ans.dim { opacity: .38; transform: scale(.97); }
.ans.right {
  background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-dark), 0 0 0 4px rgba(255,255,255,.6), 0 8px 24px rgba(141,184,218,.7);
  animation: rightPop .5s cubic-bezier(.2,1.8,.4,1) both;
}
.ans.right::before { content: "✓"; background: rgba(255,255,255,.25); color: #fff; }
.ans.wrong { background: var(--red); color: #fff; box-shadow: 0 5px 0 var(--red-dark); animation: wobble .5s ease both; }
.ans.wrong::before { content: "✗"; background: rgba(255,255,255,.25); color: #fff; }
.ans.reveal-right { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-dark); animation: glowPulse .8s ease-in-out 2; }
.ans.reveal-right::before { content: "✓"; background: rgba(255,255,255,.25); color: #fff; }
@keyframes rightPop { 0% { transform: scale(.9) } 60% { transform: scale(1.06) } 100% { transform: scale(1) } }
@keyframes wobble {
  0%,100% { transform: none } 15% { transform: translateX(-10px) rotate(-2deg) } 30% { transform: translateX(8px) rotate(1.5deg) }
  45% { transform: translateX(-6px) rotate(-1deg) } 60% { transform: translateX(4px) } 75% { transform: translateX(-2px) }
}
@keyframes glowPulse { 50% { transform: scale(1.03); filter: brightness(1.15) } }

/* floating "+1,200" */
.floater {
  position: fixed; z-index: 55; pointer-events: none; font: 900 30px var(--round); color: var(--gold);
  text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 0 16px rgba(242,193,78,.7);
  animation: floatUp 1.1s cubic-bezier(.2,.8,.3,1) forwards; white-space: nowrap; transform: translate(-50%, -50%);
}
.floater small { display: block; font-size: 15px; color: #fff; text-align: center; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(.5) }
  20% { opacity: 1; transform: translate(-50%, -70%) scale(1.2) }
  100% { opacity: 0; transform: translate(-50%, -220%) scale(1) }
}

/* ---------- reveal ---------- */
.reveal {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(20,29,44,.72); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; justify-content: center;
  animation: fadeIn .25s ease both;
}
.reveal[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0 } }
.reveal-inner {
  width: 100%; max-width: 480px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) var(--pad) calc(var(--safe-b) + 16px); perspective: 1200px;
}
.verdict { font: 900 34px var(--round); text-shadow: 0 4px 0 rgba(0,0,0,.35); animation: stamp .5s cubic-bezier(.2,1.8,.4,1) both; }
.verdict.good { color: #bfe0f7; }
.verdict.bad { color: #d3dbe4; }
@keyframes stamp { 0% { opacity: 0; transform: scale(2.2) rotate(-8deg) } 100% { opacity: 1; transform: rotate(-2deg) } }
.polaroid {
  margin: 10px 0; background: var(--card); color: var(--ink);
  padding: 10px 10px 14px; border-radius: 6px; max-width: 100%;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  transform-origin: 50% 60%;
  animation: flipIn .75s cubic-bezier(.2,.9,.25,1.15) .12s both;
  display: flex; flex-direction: column; min-height: 0; flex-shrink: 1;
}
@keyframes flipIn {
  0% { opacity: 0; transform: rotateY(-95deg) rotateZ(-8deg) scale(.6) }
  60% { opacity: 1 }
  100% { opacity: 1; transform: rotateY(0) rotateZ(var(--tilt, -2deg)) scale(1) }
}
.photo-wrap { overflow: hidden; border-radius: 3px; background: #e3e9f0; min-height: 0; display: flex; justify-content: center; }
.photo-wrap img {
  display: block; max-width: 100%; max-height: 52svh; width: auto; height: auto;
  animation: kenBurns 4s ease-out .2s both;
}
@keyframes kenBurns { from { transform: scale(1.25) } to { transform: scale(1) } }
.placeholder {
  width: min(78vw, 360px); aspect-ratio: 4 / 5; max-height: 52svh;
  display: grid; place-content: center; text-align: center; gap: 8px;
  background: repeating-linear-gradient(45deg, #6e87aa 0 22px, #7f98bb 22px 44px);
  color: #fff;
}
.placeholder .big { font-size: 96px; line-height: 1; animation: bob 2s ease-in-out infinite; }
.placeholder .soon { font: 800 15px var(--round); letter-spacing: .12em; text-transform: uppercase; background: rgba(0,0,0,.25); padding: 6px 12px; border-radius: 999px; }
figcaption { padding: 12px 4px 0; text-align: center; max-width: 360px; align-self: center; }
figcaption b { display: block; font: 900 20px var(--round); color: var(--red); }
figcaption span { display: block; margin-top: 4px; font: italic 500 16px/1.35 var(--serif); color: #4b5a72; }
figcaption span::before { content: "Fun fact: "; font-style: normal; font-weight: 700; font-family: var(--round); color: var(--gold-dark); }
#next { animation: rise .4s ease .7s both; }

/* ---------- results ---------- */
#screen-results { overflow-y: auto; -webkit-overflow-scrolling: touch; gap: 14px; }
.res-top { text-align: center; padding-top: 18px; }
.final-score {
  font: 900 clamp(64px, 20vw, 92px)/1 var(--round); font-variant-numeric: tabular-nums;
  color: var(--gold); text-shadow: 0 5px 0 var(--gold-dark), 0 14px 30px rgba(0,0,0,.4);
}
.rank {
  display: inline-block; margin-top: 12px; padding: 8px 18px; border-radius: 12px;
  background: var(--red); font: 900 22px var(--round); transform: rotate(-2deg);
  box-shadow: 0 5px 0 var(--red-dark);
}
.rank.stamp { animation: stamp .6s cubic-bezier(.2,1.8,.4,1) both; }
.res-line { color: var(--cream-dim); margin: 12px 0 0; font-size: 16px; }
.board { background: rgba(255,255,255,.07); border-radius: 18px; padding: 12px 14px; }
.board h3 { margin: 0 0 8px; font-size: 17px; }
.board ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.board li {
  display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center;
  padding: 7px 10px; border-radius: 10px; font-weight: 700; font-size: 16px;
  animation: rise .4s ease both;
}
.board li .r { color: var(--cream-dim); font-variant-numeric: tabular-nums; }
.board li .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .s { font-variant-numeric: tabular-nums; color: var(--gold); }
.board li.me { background: var(--gold); color: #1f2c42; box-shadow: 0 0 0 3px rgba(255,255,255,.5); }
.board li.me .r, .board li.me .s { color: #1f2c42; }
.board li.gap { display: block; text-align: center; padding: 0; color: var(--cream-dim); }
.board .loading { color: var(--cream-dim); font-weight: 500; }
.res-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; padding-top: 6px; }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 120px); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--cream); color: var(--ink); font-weight: 800; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 8px 20px rgba(0,0,0,.3); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  .howto { display: none; }
  .title-top { margin-top: 1vh; }
  .ans { min-height: 52px; font-size: 17px; }
  .photo-wrap img, .placeholder { max-height: 44svh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .01ms !important; }
  #snow { display: none; }
}

/* ---------- Gallery + viewer ---------- */
.res-actions #see-photos { grid-column: 1 / -1; }
.btn-ghost { background: rgba(255,255,255,.12); --shadow: rgba(0,0,0,.25); }
.gallery { padding: 8px 0 24px; }
.gallery h3 { margin: 6px 0 10px; font-size: 19px; }

.g-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.g-item { padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: rgba(255,255,255,.08); cursor: zoom-in; }
.g-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.g-item:active img { transform: scale(.94); }
.lb { position: fixed; inset: 0; z-index: 200; background: rgba(14,20,32,calc(.96 * var(--fade, 1))); opacity: 0; transition: opacity .2s; touch-action: none; }
.lb.on { opacity: 1; }
.lb-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; cursor: grab; }
.lb-track { position: absolute; inset: 0; will-change: transform; }
.lb-slide { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.lb-slide:nth-child(1) { transform: translateX(calc(-100% - 16px)); }
.lb-slide:nth-child(3) { transform: translateX(calc(100% + 16px)); }
.lb-slide img { max-width: 100%; max-height: 100%; object-fit: contain; transform-origin: center; will-change: transform; -webkit-user-drag: none; user-select: none; pointer-events: none; }
.lb-btn { position: absolute; z-index: 2; border: 0; color: #fff; background: rgba(0,0,0,.35); width: 44px; height: 44px; border-radius: 50%; font-size: 22px; cursor: pointer; }
.lb-close { top: calc(var(--safe-t) + 12px); right: 12px; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); font-size: 30px; }
.lb-prev { left: 10px; } .lb-next { right: 10px; }
@media (hover: none) { .lb-prev, .lb-next { display: none; } }
.lb-foot { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; padding: 14px 18px calc(var(--safe-b) + 16px); background: linear-gradient(transparent, rgba(0,0,0,.65)); pointer-events: none; }
.lb-count { font-size: 13px; color: var(--cream-dim); }
.lb-cap { margin: 4px 0 0; font-size: 15px; line-height: 1.35; }
.lb-cap strong { display: block; font-size: 17px; }
.lb-cap span { color: var(--cream-dim); }
