:root {
  --bg: #fffaf5;
  --card: #ffffff;
  --peach: #ffd9c2;
  --peach-deep: #ffb999;
  --rose: #ffc2d1;
  --rose-deep: #ff7a9c;
  --rose-dark: #e8567c;
  --ink: #5a3b3b;
  --muted: #9a7b7b;
  --line: #ffe6d8;
  --shadow: 0 14px 34px -10px rgba(255, 140, 120, .32), 0 2px 8px rgba(255, 140, 120, .12);
  --shadow-sm: 0 4px 12px -2px rgba(255, 140, 120, .3);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --pop: cubic-bezier(.34, 1.56, .64, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
button, a, .env-head { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 12% 8%, #ffe8de 0, transparent 42%),
    radial-gradient(circle at 90% 92%, #ffe3ec 0, transparent 46%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Fredoka", ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- háttér: lebegő emojik ---------- */
.floaties {
  position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0;
}
.floaties span {
  position: absolute; bottom: -60px; opacity: 0;
  animation: drift var(--dur, 14s) linear var(--delay, 0s) infinite;
  will-change: transform;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: .55; }
  50%  { transform: translate3d(var(--sway, 24px), -55vh, 0) rotate(12deg); }
  90%  { opacity: .55; }
  100% { transform: translate3d(calc(var(--sway, 24px) * -1), -112vh, 0) rotate(-10deg); opacity: 0; }
}

.confetti-canvas {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 60;
  view-transition-name: confetti;
}

/* ---------- betöltés ---------- */
.boot {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center; z-index: 5; transition: opacity .4s;
}
.boot-heart { font-size: 3rem; animation: heartbeat 1s ease-in-out infinite; }
.boot-msg { margin: 0; color: var(--muted); font-size: 1.05rem; }
body:not(.booting) .boot { opacity: 0; pointer-events: none; visibility: hidden; }
.stage { opacity: 0; transition: opacity .5s var(--ease); }
body:not(.booting) .stage { opacity: 1; }
@keyframes heartbeat { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.18); } 60% { transform: scale(1.05); } }

/* ---------- elrendezés ---------- */
.stage {
  position: relative; z-index: 1;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.phase { width: 100%; max-width: 540px; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 32px;
  box-shadow: var(--shadow);
  padding: 30px 22px 28px;
  text-align: center;
}
.hero { view-transition-name: hero; }
.hero-emoji {
  font-size: 3.4rem; line-height: 1; margin-bottom: 8px; display: inline-block;
  view-transition-name: hero-emoji;
  animation: bob 3.2s ease-in-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }

h1 {
  margin: 0 0 6px; font-weight: 600; letter-spacing: .1px;
  font-size: clamp(1.55rem, 6.4vw, 2.1rem); line-height: 1.22;
}
.ask-title { margin-bottom: 26px; }
.sub { margin: 0 0 14px; color: var(--muted); font-size: 1.05rem; }

/* ---------- gombok ---------- */
.buttons { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px; }
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  font-size: 1.12rem; padding: 14px 28px; border-radius: 999px;
  text-decoration: none; display: inline-block; line-height: 1.2;
  transition: transform .25s var(--pop), box-shadow .25s, background-color .25s;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 3px solid var(--rose-deep); outline-offset: 3px; }
.btn-yes {
  color: #fff; background: linear-gradient(135deg, #ff9ab0, var(--rose-deep));
  box-shadow: 0 8px 20px -6px rgba(255, 90, 130, .6);
  --yes-scale: 1;
  font-size: calc(1.25rem * var(--yes-scale));
  padding: calc(16px * var(--yes-scale)) calc(34px * var(--yes-scale));
  white-space: nowrap; max-width: 100%;
  transition: transform .25s var(--pop), box-shadow .25s, font-size .5s var(--pop), padding .5s var(--pop);
  animation: glow 2.2s ease-in-out infinite;
}
.btn-yes:hover { transform: scale(1.07); }
.btn-yes:active { transform: scale(.97); }
@keyframes glow {
  0%, 100% { box-shadow: 0 8px 20px -6px rgba(255, 90, 130, .6), 0 0 0 0 rgba(255, 122, 156, .35); }
  50%      { box-shadow: 0 8px 20px -6px rgba(255, 90, 130, .6), 0 0 0 12px rgba(255, 122, 156, 0); }
}

.no-slot { display: inline-block; transition: width .45s var(--ease), height .45s var(--ease), margin .45s var(--ease); }
.no-slot.gone { width: 0 !important; height: 0 !important; margin-left: -14px; }
.btn-no {
  color: #9a6b6b; background: #fff; box-shadow: var(--shadow-sm); border: 2px solid var(--peach);
  white-space: nowrap;
}
.btn-no.dodging {
  position: fixed; z-index: 40; margin: 0;
  transition: left .28s var(--pop), top .28s var(--pop), transform .2s;
}

.btn-map {
  color: #fff; background: linear-gradient(135deg, #ffb48a, #ff8f6b);
  box-shadow: 0 8px 18px -6px rgba(255, 130, 90, .55);
  font-size: 1rem; padding: 12px 22px;
}
.btn-map:hover { transform: translateY(-2px) scale(1.03); }

/* ---------- visszaszámláló ---------- */
.countdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 420px; margin: 0 auto; }
.tile {
  background: linear-gradient(180deg, #fff6f0, #ffeee4);
  border: 2px solid var(--line); border-radius: 20px; padding: 12px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.num { font-size: clamp(1.7rem, 8vw, 2.5rem); font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--rose-dark); }
.unit { font-size: .85rem; color: var(--muted); }
.go { margin: 6px 0 0; font-size: 1.6rem; font-weight: 600; color: var(--rose-dark); animation: heartbeat 1.6s ease-in-out infinite; }
.go small { font-size: 1rem; font-weight: 400; color: var(--muted); }
.clock-status { margin: 12px 0 0; font-size: .9rem; color: var(--muted); }
.clock-status:empty { display: none; }

/* ---------- borítékok ---------- */
.env-heading { margin: 30px 4px 14px; text-align: center; font-weight: 600; font-size: 1.35rem; }
.envelopes { display: flex; flex-direction: column; gap: 14px; }
.foot { text-align: center; color: var(--muted); margin: 28px 0 0; }

.envelope {
  background: var(--card); border: 2px solid var(--line); border-radius: 26px;
  box-shadow: var(--shadow); transition: border-color .3s, box-shadow .3s;
  animation: rise .8s var(--ease) both;
  animation-delay: calc(.5s + var(--i, 0) * .14s);
}
.envelope[data-state="ready"] { border-color: var(--rose); }
.envelope[data-state="open"], .envelope[data-state="opening"] { border-color: var(--peach-deep); }
@keyframes rise { from { opacity: 0; transform: translateY(28px) scale(.96); } to { opacity: 1; transform: none; } }

.env-head {
  appearance: none; width: 100%; border: 0; background: none; font: inherit; color: inherit; text-align: left;
  display: flex; align-items: center; gap: 16px; padding: 28px 18px 18px; cursor: pointer; border-radius: 24px;
  -webkit-tap-highlight-color: transparent;
}
.env-head:focus-visible { outline: 3px solid var(--rose-deep); outline-offset: -3px; }
.env-head.shake { animation: shake .55s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); } 15% { transform: translateX(-9px) rotate(-1deg); }
  30% { transform: translateX(8px) rotate(1deg); } 45% { transform: translateX(-6px); }
  60% { transform: translateX(5px); } 75% { transform: translateX(-3px); }
}

.env-label { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.env-time {
  background: var(--peach); color: #a4572f; font-weight: 600; font-size: .9rem;
  padding: 2px 11px; border-radius: 999px;
}
.env-name { font-size: 1.12rem; font-weight: 500; line-height: 1.3; }
.env-chip { font-size: .86rem; color: var(--muted); }
.envelope[data-state="ready"] .env-chip { color: var(--rose-dark); font-weight: 600; }

/* a boríték ikon: tisztán CSS-ből */
.env-icon {
  position: relative; flex: none; width: 70px; height: 50px; border-radius: 10px;
  background: linear-gradient(#ffd3b8, #ffbc9d); box-shadow: var(--shadow-sm);
  transition: filter .4s;
}
.env-icon .paper {
  position: absolute; left: 9px; right: 9px; top: 7px; bottom: 7px; border-radius: 5px;
  background: #fff repeating-linear-gradient(transparent 0 5px, #ffe3d6 5px 6px);
  transition: transform .7s var(--pop) .15s;
}
.env-icon .front {
  position: absolute; inset: 0; border-radius: 10px; z-index: 2;
  background: linear-gradient(#ffc9ab, #ffb190);
  clip-path: polygon(0 0, 50% 58%, 100% 0, 100% 100%, 0 100%);
}
.env-icon .flap {
  position: absolute; left: 0; right: 0; top: 0; height: 58%; z-index: 3;
  background: linear-gradient(#ffc4a3, #ffa985);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: 50% 0; transform: perspective(240px) rotateX(0deg);
  transition: transform .65s var(--ease), z-index 0s .3s;
}
.env-icon::after { /* a pecsét */
  content: "💗"; position: absolute; left: 50%; top: 40%; z-index: 4; font-size: 15px; line-height: 1;
  transform: translate(-50%, -50%); transition: opacity .25s, transform .25s;
}
.envelope[data-state="open"] .flap, .envelope[data-state="opening"] .flap {
  transform: perspective(240px) rotateX(180deg); z-index: 0;
}
.envelope[data-state="open"] .paper, .envelope[data-state="opening"] .paper { transform: translateY(-17px); }
.envelope[data-state="open"] .env-icon::after, .envelope[data-state="opening"] .env-icon::after {
  opacity: 0; transform: translate(-50%, -50%) scale(.4);
}
.envelope[data-state="locked"] .env-icon { filter: grayscale(.45) brightness(1.04); opacity: .9; }
.envelope[data-state="locked"] .env-icon::after { content: "🔒"; font-size: 14px; }
.envelope[data-state="ready"] .env-icon { animation: wiggle 1.8s ease-in-out infinite; }
@keyframes wiggle {
  0%, 60%, 100% { transform: rotate(0) scale(1); } 68% { transform: rotate(-7deg) scale(1.08); }
  76% { transform: rotate(6deg) scale(1.08); } 84% { transform: rotate(-4deg); } 92% { transform: rotate(2deg); }
}

.env-hint {
  margin: -6px 18px 0; padding: 0 14px; border-radius: 16px; background: #fff1f4; color: var(--rose-dark);
  font-size: .95rem; text-align: center;
  max-height: 0; opacity: 0; overflow: hidden;
  transition: max-height .4s var(--ease), opacity .3s, padding .4s var(--ease), margin .4s var(--ease);
}
.env-hint.show { max-height: 120px; opacity: 1; padding: 10px 14px; margin: -2px 18px 16px; }

.env-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .7s var(--ease); }
.envelope[data-state="opening"] .env-body { grid-template-rows: 1fr; transition-delay: .35s; }
.envelope[data-state="open"] .env-body { grid-template-rows: 1fr; }
.env-inner { overflow: hidden; min-height: 0; visibility: hidden; }
.envelope[data-state="open"] .env-inner, .envelope[data-state="opening"] .env-inner { visibility: visible; }

/* találós kérdés → megfejtés után a tényleges tartalom */
.riddle-wrap, .reveal-wrap { display: grid; transition: grid-template-rows .65s var(--ease); }
.riddle-wrap { grid-template-rows: 1fr; }
.reveal-wrap { grid-template-rows: 0fr; }
.envelope[data-solved="true"] .riddle-wrap { grid-template-rows: 0fr; }
.envelope[data-solved="true"] .reveal-wrap { grid-template-rows: 1fr; }
.riddle-inner, .reveal-inner { overflow: hidden; min-height: 0; }
.envelope[data-solved="true"] .riddle-inner { visibility: hidden; transition: visibility 0s .65s; }
.envelope[data-solved="false"] .reveal-inner { visibility: hidden; }
.reveal-pad { padding-bottom: 18px; } /* hogy a gomb árnyékát ne vágja le az overflow */
.envelope[data-solved="true"] .reveal-pad { animation: rise .6s var(--ease) .2s both; }
.riddle-pad { padding-bottom: 6px; }

.riddle {
  margin: 0; padding: 16px 16px 8px; text-align: left; border-radius: 22px;
  background: linear-gradient(180deg, #fff2f6, #fff8f3); border: 2px solid var(--rose);
}
.riddle-title { margin: 0 0 6px; font-weight: 600; color: var(--rose-dark); }
.riddle-q { margin: 0 0 14px; font-size: 1.06rem; }
.riddle-row { display: flex; flex-wrap: wrap; gap: 8px; }
.riddle-input {
  flex: 1 1 150px; min-width: 0; font: inherit; font-size: 1.1rem; /* >=16px, hogy iOS ne nagyítson rá */
  padding: 12px 18px; color: var(--ink); background: #fff; border: 2px solid var(--peach); border-radius: 999px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.riddle-input::placeholder { color: #c9aaa0; }
.riddle-input:focus { border-color: var(--rose-deep); box-shadow: 0 0 0 4px rgba(255, 122, 156, .18); }
.riddle-input.wrong { border-color: var(--rose-dark); animation: shake .5s ease; }
.btn-answer {
  flex: none; font-size: 1rem; padding: 12px 22px; color: #fff;
  background: linear-gradient(135deg, #ff9ab0, var(--rose-deep)); box-shadow: 0 6px 16px -6px rgba(255, 90, 130, .6);
}
.btn-answer:active { transform: scale(.96); }
.riddle-msg { min-height: 1.5em; margin: 8px 4px 0; font-size: .95rem; color: var(--rose-dark); }
.riddle-tip {
  appearance: none; background: none; border: 0; font: inherit; font-size: .95rem; color: var(--muted);
  text-decoration: underline; text-underline-offset: 3px; padding: 10px 4px; cursor: pointer;
}
.riddle-tip:focus-visible { outline: 3px solid var(--rose-deep); outline-offset: 2px; border-radius: 8px; }
.riddle-tip.nudge { color: var(--rose-dark); font-weight: 600; animation: wiggle 1.8s ease-in-out infinite; }
.riddle-tips p { margin: 0 4px 8px; font-size: .95rem; color: var(--muted); }
.solved-badge { margin: 0 0 10px; font-weight: 600; color: var(--rose-dark); }
.env-content { padding: 4px 22px 8px; opacity: 0; transform: translateY(10px); transition: opacity .5s .5s, transform .6s var(--ease) .5s; }
.envelope[data-state="open"] .env-content, .envelope[data-state="opening"] .env-content { opacity: 1; transform: none; }
.env-text { margin: 0 0 16px; font-size: 1.08rem; padding: 16px 18px; background: #fff8f3; border-radius: 18px; border: 2px dashed var(--peach); }
.env-content .btn-map { margin-top: 2px; }

.noscript { text-align: center; padding: 24px; }

/* ---------- morph átmenet (View Transitions) ---------- */
::view-transition-group(root) { animation-duration: .55s; }
::view-transition-group(hero),
::view-transition-group(hero-emoji) {
  animation-duration: .95s;
  animation-timing-function: cubic-bezier(.22, 1, .36, 1);
}
::view-transition-old(confetti) { display: none; }
::view-transition-new(confetti) { animation: none; opacity: 1; }
::view-transition-group(confetti) { animation: none; }

/* View Transitions nélküli böngészőkben ez a belépő animáció adja az átmenetet */
.phase.enter .hero { animation: rise .8s var(--ease) both; }

@media (max-width: 380px) {
  .card { padding: 26px 16px 24px; border-radius: 28px; }
  .env-icon { width: 60px; height: 44px; }
  .env-head { gap: 12px; padding: 26px 14px 16px; }
  .btn-yes { padding: 14px 26px; }
}

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