:root {
  --bg: #fff4e0;
  --paper: #ffffff;
  --paper-2: #fff9ef;
  --ink: #1b1b1b;
  --muted: #5c5245;
  --accent: #ff5a36;
  --yellow: #ffd23f;
  --teal: #3bceac;
  --blue: #5b8cff;
  --env: #f4d58d;
  --env-dark: #e3b448;
  --radius: 18px;
  --shadow: 6px 6px 0 var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom while mashing buttons */
}

button { -webkit-user-select: none; user-select: none; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(27, 27, 27, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(27, 27, 27, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    calc(48px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

/* ---------- card ---------- */

.card {
  position: relative;
  width: 100%;
  max-width: 520px;
  padding: 40px 26px 32px;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 8px 8px 0 var(--ink);
}

.card::before {
  content: "🦆";
  position: absolute;
  top: -30px;
  right: 18px;
  font-size: 46px;
  transform: scaleX(-1) rotate(-8deg);
}

.card.wide { max-width: 640px; }

.pop-in { animation: pop-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.9) rotate(-1.5deg); }
  to { opacity: 1; transform: none; }
}

.mascot {
  font-size: 60px;
  line-height: 1;
  margin-bottom: 12px;
  display: inline-block;
  animation: waddle 1.2s ease-in-out infinite;
}

@keyframes waddle {
  0%, 100% { transform: rotate(-6deg); }
  50% { transform: rotate(6deg) translateY(-3px); }
}

.title {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: clamp(2.2rem, 8vw, 3rem);
  letter-spacing: -0.02em;
  margin: 4px 0 10px;
  line-height: 1.1;
}

.q {
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: clamp(1.4rem, 5.2vw, 1.8rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 24px;
  line-height: 1.2;
}

.sub, .lead {
  font-size: 1.1rem;
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 24px;
}

.lead b {
  color: var(--ink);
  background: var(--yellow);
  padding: 0 4px;
}

.handwritten {
  font-family: "Permanent Marker", cursive;
  font-size: 1.2rem;
  line-height: 1.55;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 13px 24px;
  cursor: pointer;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform 0.1s, box-shadow 0.1s, font-size 0.3s, padding 0.3s;
  touch-action: manipulation;
  text-decoration: none;
  display: inline-block;
}

.btn:hover { transform: translate(-1px, -1px) rotate(-1deg); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 4px; }
.btn:disabled { opacity: 0.6; cursor: default; }

.btn.yes { background: var(--accent); color: var(--paper); }
.btn.ghost { background: var(--paper); }
.btn.big { font-size: 1.25rem; padding: 15px 30px; }

.options.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  min-height: 70px;
}

.reply {
  min-height: 1.6em;
  margin: 22px 0 0;
  font-size: 1.12rem;
  font-weight: 700;
}

.reply.show { animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }
.reply.bad { color: var(--accent); }

.next { margin-top: 18px; }
.hidden { display: none !important; }

.shake { animation: shake 0.45s; }

@keyframes shake {
  20%, 60% { transform: translateX(-8px) rotate(-2deg); }
  40%, 80% { transform: translateX(8px) rotate(2deg); }
}

.escapee {
  position: fixed;
  z-index: 50;
  margin: 0;
  transition: left 0.25s ease, top 0.25s ease;
}

/* ---------- progress ---------- */

.progress {
  width: 100%;
  max-width: 520px;
  margin-bottom: 38px;
}

.progress-label {
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.bar {
  height: 18px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
}

.fill {
  height: 100%;
  width: 0;
  background: repeating-linear-gradient(45deg, var(--yellow) 0 10px, var(--accent) 10px 20px);
  border-right: 3px solid var(--ink);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ---------- envelope ---------- */

.envelope {
  position: relative;
  width: 240px;
  height: 160px;
  margin: 70px auto 18px;
  cursor: pointer;
  perspective: 600px;
  filter: drop-shadow(5px 5px 0 var(--ink));
  animation: wiggle 2.2s ease-in-out infinite;
}

.envelope:focus-visible { outline: 3px solid var(--blue); outline-offset: 10px; border-radius: 12px; }

@keyframes wiggle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg); }
}

.env-back, .env-front, .flap, .letter { position: absolute; }

.env-back { inset: 0; background: var(--env-dark); border-radius: 10px; }

.letter {
  left: 14px; right: 14px; top: 10px; height: 130px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border-radius: 6px;
  font-family: "Permanent Marker", cursive;
  font-size: 1.6rem;
  z-index: 1;
  transition: transform 0.6s 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.env-front {
  inset: 0;
  background: var(--env);
  clip-path: polygon(0 0, 50% 56%, 100% 0, 100% 100%, 0 100%);
  border-radius: 10px;
  z-index: 2;
}

.flap {
  left: 0; right: 0; top: 0; height: 100px;
  background: #ecc35f;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top;
  transition: transform 0.5s;
  z-index: 3;
}

.seal {
  position: absolute;
  left: 50%; top: 92px;
  transform: translate(-50%, -50%);
  font-size: 2.2rem;
  z-index: 4;
  transition: opacity 0.2s;
}

.envelope.open { animation: none; }
.envelope.open .flap { transform: rotateX(180deg); z-index: 0; }
.envelope.open .seal { opacity: 0; }
.envelope.open .letter { transform: translateY(-80px); }

.hint { color: var(--muted); font-weight: 600; margin: 8px 0 0; }

/* ---------- slider ---------- */

.slider-val {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: 3.2rem;
  margin-bottom: 6px;
}

/* chunky slider with a big thumb that's easy to drag with a thumb */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  margin: 14px 0 28px;
  background: var(--paper-2);
  border: 3px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  touch-action: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

input[type="range"]::-moz-range-thumb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

/* ---------- minigames ---------- */

.hud {
  display: flex;
  justify-content: space-between;
  max-width: 440px;
  margin: 0 auto 14px;
  padding: 8px 16px;
  font-weight: 700;
  font-size: 1.15rem;
  background: var(--paper-2);
  border: 3px solid var(--ink);
  border-radius: 12px;
}

.game-msg {
  min-height: 1.5em;
  margin: 4px 0 14px;
  font-weight: 600;
}

.game-msg.flash { animation: pop-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }

.whack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.5vw, 16px);
  max-width: 440px;
  margin: 0 auto 12px;
}

.hole {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 62%, #3b2a17 0 40%, #6cc070 41%);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.15);
  touch-action: manipulation;
}

.critter {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4%;
  font-size: clamp(2.2rem, 12vw, 3.6rem);
  line-height: 1;
  transform: translateY(120%);
  transition: transform 0.12s ease-out;
  pointer-events: none;
}

.hole.up .critter { transform: translateY(-8%); }

.memory {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2.5vw, 14px);
  max-width: 400px;
  margin: 0 auto 12px;
  perspective: 900px;
}

.mcard {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.35s;
  touch-action: manipulation;
}

.mcard.flip { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: clamp(2rem, 10vw, 3rem);
}

.face.back {
  background: repeating-linear-gradient(45deg, var(--yellow) 0 8px, #ffe37a 8px 16px);
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  color: var(--ink);
}

.face.front { background: var(--paper); transform: rotateY(180deg); }
.mcard.matched .front { background: var(--teal); }

.skip {
  display: block;
  margin: 14px auto 0;
  padding: 10px;
  font: inherit;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

#arcade { max-width: 560px; max-height: 92dvh; overflow-y: auto; }
#arcade .game-host { margin-bottom: 8px; }

/* ---------- celebration ---------- */

.block {
  margin-top: 28px;
  padding: 22px 18px;
  background: var(--paper-2);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 5px 5px 0 var(--ink);
}

.block h3 {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  margin: 0 0 14px;
  font-size: 1.3rem;
}

.together {
  display: inline-block;
  margin: 0 0 4px;
  padding: 8px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--teal);
  font-weight: 700;
}

.cert {
  margin-top: 26px;
  padding: 24px 20px;
  background: var(--paper-2);
  border: 3px dashed var(--ink);
  border-radius: 12px;
  transform: rotate(-1deg);
}

.cert h2 {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: 1.45rem;
  margin: 0 0 10px;
  text-decoration: underline wavy var(--accent);
  text-underline-offset: 6px;
}

.cert .handwritten { margin: 0; }
.cert .stamp { font-size: 2rem; margin-top: 10px; letter-spacing: 4px; }
.cert small { color: var(--muted); }

.answers {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  text-align: left;
  display: grid;
  gap: 8px;
}

.answers li {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  line-height: 1.4;
}

.answers b { font-weight: 700; }

.btn-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

.jar {
  font-size: 76px;
  line-height: 1;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 4px;
}

.jar.jiggle { animation: shake 0.45s; }

.reason { min-height: 3em; margin: 10px 0 0; }

.letters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.letter-btn {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 14px 10px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
}

.letter-btn span { display: block; font-size: 2rem; margin-bottom: 4px; }
.letter-btn:hover { transform: translate(-1px, -2px) rotate(-1.5deg); }
.letter-btn:active { transform: translate(3px, 3px); box-shadow: none; }

.final-letter { text-align: left; }
.final-letter .handwritten, #modal-body { white-space: pre-line; }
.final-letter .sign { text-align: right; margin: 10px 0 0; }

.replay { margin-top: 28px; }

.foot {
  margin-top: 26px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

/* ---------- modal ---------- */

dialog {
  width: calc(100% - 32px);
  max-width: 440px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 28px 24px;
  background: var(--bg);
  color: var(--ink);
  text-align: center;
  box-shadow: 8px 8px 0 var(--ink);
}

dialog[open] { animation: pop-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
dialog::backdrop { background: rgba(27, 27, 27, 0.45); }
dialog h3 { font-family: "Bricolage Grotesque", sans-serif; font-weight: 800; font-size: 1.35rem; margin: 6px 0 8px; }
.modal-emoji { font-size: 3rem; }

/* ---------- effects ---------- */

#sky, #fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
#sky { z-index: 0; }
#fx { z-index: 60; }

.walker {
  position: absolute;
  left: 100%;
  opacity: 0.85;
  animation: walk var(--d, 14s) linear forwards;
}

.waddle { display: inline-block; animation: waddle 0.5s ease-in-out infinite; }

@keyframes walk {
  to { transform: translateX(calc(-100vw - 120px)); }
}

.spark {
  position: absolute;
  font-size: 18px;
  animation: spark 0.8s ease-out forwards;
}

@keyframes spark {
  from { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.4); opacity: 0; }
}

.confetti {
  position: absolute;
  top: -30px;
  animation: fall var(--d, 3s) cubic-bezier(0.25, 0.6, 0.5, 1) forwards;
}

.confetti.paper { width: 10px; height: 14px; border-radius: 2px; border: 1.5px solid var(--ink); }

@keyframes fall {
  to { transform: translate(var(--x, 0), 110vh) rotate(var(--r, 360deg)); }
}

@media (max-width: 480px) {
  .card { padding: 36px 16px 26px; }
  .card::before { font-size: 38px; top: -24px; }
  dialog { padding: 22px 16px; }
}

/* tablets: more room, bigger everything */
@media (min-width: 768px) {
  .card, .progress { max-width: 640px; }
  .card { padding: 52px 44px 40px; }
  .card.wide { max-width: 760px; }
  .mascot { font-size: 76px; }
  .q { font-size: 2.1rem; }
  .lead, .sub { font-size: 1.25rem; }
  .btn { font-size: 1.2rem; padding: 15px 28px; }
  .btn.big { font-size: 1.4rem; }
  .memory { grid-template-columns: repeat(4, 1fr); max-width: 520px; }
  .whack, .hud { max-width: 500px; }
  .handwritten { font-size: 1.35rem; }
}

/* short landscape phones: don't waste vertical space */
@media (max-height: 520px) and (orientation: landscape) {
  #app { justify-content: flex-start; padding-top: 40px; }
  .mascot { font-size: 44px; margin-bottom: 4px; }
  .whack, .memory { max-width: 300px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
