/* ═══════════════════════════════════════════════════════════
   Et hemmelig brev — 60-årsoverraskelse
   ═══════════════════════════════════════════════════════════ */

:root {
  --ink:     #f4efe6;
  --ink-dim: #a9a4b8;
  --gold:    #f0c987;
  --gold-deep: #b98a45;
  --bad:     #ff7f8f;
  --good:    #86e8ae;

  --r-card: 26px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #05060d;
  color: var(--ink);
  font-family: Outfit, system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
body { overscroll-behavior: none; }

#gl {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  touch-action: manipulation;   /* no double-tap zoom on the envelope */
}

/* faint film grain so the gradients never look plasticky */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

/* ── layers ───────────────────────────────────────────────── */
/* Only visibility is toggled here. Cross-fading this full-viewport layer over
   the WebGL canvas makes the compositor re-blend the whole frame for the
   length of the transition, which shows up as a long frame. The card fades
   itself (.card.in / .card.out), so the effect is the same at a fraction of
   the composited area. */
.layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 40px);
  visibility: hidden;
  pointer-events: none;
}
.layer.on {
  visibility: visible;
  pointer-events: auto;
}

/* ── quiz card ────────────────────────────────────────────── */
#quiz { perspective: 1500px; }

.card {
  width: min(660px, 100%);
  padding: clamp(26px, 4.2vw, 42px);
  border-radius: var(--r-card);
  border: 1px solid rgba(255, 255, 255, .11);
  /* No backdrop-filter: over a WebGL canvas it makes the compositor re-read
     the canvas as the layer appears and disappears, which flashes black. The
     scene behind is smooth enough that a translucent gradient reads the same. */
  background: linear-gradient(155deg, rgba(32, 31, 54, .95), rgba(11, 11, 22, .97));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, .12) inset,
    0 34px 80px -34px rgba(0, 0, 0, .95);
  /* pointer tilt, driven from JS through --rx / --ry */
  transform: rotateY(var(--ry, 0deg)) rotateX(var(--rx, 0deg));
  transition: transform .6s var(--ease), opacity .45s var(--ease);
  will-change: transform;
}
.card.out { opacity: 0; }
.card.in  { animation: cardIn .5s var(--ease); }
@keyframes cardIn { from { opacity: 0; } to { opacity: 1; } }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: clamp(20px, 3vw, 28px);
}

.pips { display: flex; gap: 9px; }
.pip {
  width: 30px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, .13);
  position: relative;
  overflow: hidden;
}
.pip::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left;
  background: var(--gold);
  transition: transform .55s var(--ease);
}
.pip.done::after { transform: scaleX(1); }
.pip.now { background: rgba(255, 255, 255, .26); }

.qcount {
  font-size: 12px;
  font-weight: 300;
  letter-spacing: .12em;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.qcount b { color: var(--gold); font-weight: 500; }
.qcount i { opacity: .4; margin: 0 5px; font-style: normal; }

.qlabel {
  font-size: 10px;
  letter-spacing: .4em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin-bottom: 12px;
}

.qtext {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  font-size: clamp(26px, 4.1vw, 38px);
  line-height: 1.18;
  margin-bottom: clamp(22px, 3.4vw, 30px);
  text-wrap: balance;
}

/* ── answers ──────────────────────────────────────────────────
   Nothing here changes an answer's geometry on hover, press or
   feedback. Moving a button under the pointer makes the hover
   state flicker and can swallow the click. ─────────────────── */
.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (max-width: 640px) {
  .answers { grid-template-columns: 1fr; }
}

.ans {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, .11);
  background: rgba(255, 255, 255, .045);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 300;
  text-align: left;
  cursor: pointer;
  transition: background .28s ease, border-color .28s ease, box-shadow .28s ease;
  animation: ansIn .5s var(--ease) var(--d, 0s) backwards;
}
@keyframes ansIn { from { opacity: 0; } }

/* Gated on (hover: hover): a touch device applies :hover on tap and leaves it
   stuck there, so the last answer tapped would keep the gold highlight. */
.ans:focus-visible,
.ans.hoverable:hover {
  background: rgba(255, 255, 255, .095);
  border-color: rgba(240, 201, 135, .55);
  box-shadow: 0 0 0 1px rgba(240, 201, 135, .18);
  outline: none;
}
.ans:active { background: rgba(255, 255, 255, .13); }

.ans .key {
  flex: 0 0 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .10);
  font-size: 12px;
  font-weight: 500;
  color: var(--gold);
  transition: background .28s ease, border-color .28s ease, color .28s ease;
}
.ans.hoverable:hover .key {
  background: rgba(240, 201, 135, .16);
  border-color: rgba(240, 201, 135, .4);
}

.ans.wrong {
  background: rgba(255, 127, 143, .14);
  border-color: rgba(255, 127, 143, .55);
  box-shadow: none;
}
.ans.wrong .key {
  color: var(--bad);
  background: rgba(255, 127, 143, .16);
  border-color: rgba(255, 127, 143, .4);
}

.ans.right {
  background: rgba(134, 232, 174, .16);
  border-color: rgba(134, 232, 174, .6);
  box-shadow: 0 0 0 1px rgba(134, 232, 174, .25);
}
.ans.right .key { color: #0d2b1a; background: var(--good); border-color: var(--good); }

.ans.dim { opacity: .35; }
.answers.locked .ans { pointer-events: none; }

.feedback {
  min-height: 22px;
  margin-top: 18px;
  font-size: 13px;
  font-weight: 300;
  color: var(--ink-dim);
  opacity: 0;
  transition: opacity .3s ease;
}
.feedback.show { opacity: 1; }
.feedback.bad  { color: var(--bad); }
.feedback.good { color: var(--good); }

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