@font-face {
  font-family: "Pixelify Sans";
  src: url("fonts/PixelifySans.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --u: 2px; /* ein Logikpixel des Canvas in CSS-Pixeln, wird per JS gesetzt */
  --b: calc(var(--u) * 1);
  --ink: #5a3b62;
  --ink-soft: #7d5f8b;
  --cream: #fff8ef;
  --pink: #ffbcd4;
  --pink-l: #ffdbe8;
  --pink-d: #f598b9;
  --rose: #ff86ab;
  --butter: #ffe7a0;
  --butter-l: #fff6d3;
  --butter-d: #f4c665;
  --mint: #b7f0d5;
  --mint-d: #84d8b4;
  --sky: #b9e0ff;
  --lav: #cfc0ff;
  --lav-l: #e6ddff;
  --lav-d: #a994ee;
  --night: #3a2957;
  --fs: calc(var(--u) * 11);
  --lh: calc(var(--u) * 14);
  --font: "Pixelify Sans", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  color: var(--ink);
  font: 400 var(--fs)/var(--lh) var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

body { position: fixed; inset: 0; }

#safe-probe {
  position: fixed; top: 0; left: 0; width: 0;
  height: env(safe-area-inset-top, 0px);
  pointer-events: none; visibility: hidden;
}

/* Auf dem iPhone füllt die Bühne den Bildschirm; am Desktop bleibt sie hochkant */
#stage {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 100%;
  max-width: 62vh;
  transform: translateX(-50%);
  overflow: hidden;
  background: #cbbdff;
}

#game {
  position: absolute; top: 0; left: 0;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  touch-action: none;
}

/* ------------------------------------------------ Pixel-Rahmen als Baustein */
.px-box {
  background: var(--cream);
  box-shadow:
    0 calc(-1 * var(--b)) 0 0 var(--ink),
    0 var(--b) 0 0 var(--ink),
    calc(-1 * var(--b)) 0 0 0 var(--ink),
    var(--b) 0 0 0 var(--ink),
    0 calc(var(--b) * 3) 0 0 rgba(58, 41, 87, .35);
}

button {
  font: inherit; color: inherit;
  border: 0; margin: 0; padding: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

#sound {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + var(--u) * 4);
  right: calc(var(--u) * 4);
  width: calc(var(--u) * 22); height: calc(var(--u) * 22);
  font-size: var(--fs); line-height: 1;
  background: var(--cream);
  box-shadow:
    0 calc(-1 * var(--b)) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
    calc(-1 * var(--b)) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink);
  opacity: .9;
}
#menu {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + var(--u) * 4);
  left: calc(var(--u) * 4);
  width: calc(var(--u) * 22); height: calc(var(--u) * 22);
  font-size: var(--fs); line-height: 1;
  background: var(--cream);
  box-shadow:
    0 calc(-1 * var(--b)) 0 0 var(--ink), 0 var(--b) 0 0 var(--ink),
    calc(-1 * var(--b)) 0 0 0 var(--ink), var(--b) 0 0 0 var(--ink);
  opacity: .9;
}
#menu[hidden] { display: none; }
#sound.off { color: var(--ink-soft); text-decoration: line-through; background: var(--lav-l); }

/* ------------------------------------------------------------- Inhalt */
#reveal, .overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 18px calc(env(safe-area-inset-bottom, 0px) + 24px);
  background: rgba(58, 41, 87, .45);
  animation: fade .25s ease-out both;
  touch-action: manipulation;
}
#reveal[hidden], .overlay[hidden] { display: none; }
/* Hinter der Karte läuft die Party weiter, deshalb nur ein Hauch Abdunklung */
#reveal { background: rgba(58, 41, 87, .16); }
/* Feuerwerk vom Antippen liegt über der Karte und fängt selbst keine Berührungen ab */
#fx {
  position: absolute; top: 0; left: 0; z-index: 4;
  pointer-events: none;
  image-rendering: pixelated;
}
.overlay { -webkit-user-select: text; user-select: text; }

.card {
  --b: calc(var(--u) * 1.5);
  position: relative;
  width: 100%;
  max-height: 100%;
  display: flex; flex-direction: column;
  animation: pop .5s cubic-bezier(.2, 1.5, .4, 1) both;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 10px 16px;
  background: var(--pink);
  border-bottom: var(--b) solid var(--ink);

}
/* Der Titel darf schrumpfen, damit auch „24. DEZEMBER" auf schmalen iPhones nicht an das X stößt */
.px-title { image-rendering: pixelated; height: auto; flex: 0 1 auto; min-width: 0; }
.card-head { gap: calc(var(--u) * 3); }
.card-close { flex: none; }
.card.voice .card-head { background: var(--lav); }
.card.meme .card-head { background: var(--butter); }
.card.quiz .card-head { background: var(--mint); }
.card.quote .card-head { background: var(--sky); }
.card-close {
  width: calc(var(--u) * 22); height: calc(var(--u) * 22);
  line-height: 1;
  background: var(--cream);
  box-shadow: 0 0 0 var(--b) var(--ink);
}
.card-close:active, .opt:not(.locked):active, .play:active { transform: translateY(calc(var(--u) * 1)); }
.card-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex; flex-direction: column; gap: 14px;
}
.caption { margin: 0; text-align: center; text-wrap: balance; }
.note { margin: 0; color: var(--ink-soft); text-align: center; }

.polaroid {
  align-self: center;
  padding: 10px 10px 14px;
  background: #fff;
  box-shadow: 0 0 0 var(--b) var(--ink), calc(var(--u) * 2) calc(var(--u) * 3) 0 0 rgba(58, 41, 87, .25);
  transform: rotate(-2deg);
  max-width: 100%;
}
.polaroid img { display: block; max-width: 100%; max-height: 52vh; }
.polaroid:has(img.px) { width: 78%; }
img.px { image-rendering: pixelated; width: 100%; }

/* Zitat (Memes: siehe meme.js) */
.quote-text { margin: 0; padding: calc(var(--u) * 6); text-align: center; text-wrap: balance; background: #fff; box-shadow: 0 0 0 var(--b) var(--ink); }
.quote-by { margin: 0; text-align: right; color: var(--ink-soft); }
.verdict { margin: 0; text-align: center; color: var(--ink-soft); }
.verdict.right { color: var(--ink); }

/* Sprachnachricht */
.player { display: flex; align-items: center; gap: 14px; }
.play {
  flex: none;
  width: 64px; height: 64px;
  line-height: 1;
  background: var(--lav);
  box-shadow: 0 0 0 var(--b) var(--ink), 0 calc(var(--u) * 2.5) 0 0 var(--ink);
}
.bars { flex: 1; display: flex; align-items: center; gap: 2px; height: 64px; min-width: 0; }
.bars i { flex: 1; background: var(--lav-l); min-width: 2px; }
.bars i.done { background: var(--lav-d); }
.time { text-align: right; font-variant-numeric: tabular-nums; }

/* Quiz */
.question { margin: 0; text-align: center; text-wrap: balance; }
.opts { display: flex; flex-direction: column; gap: 14px; padding: 0 2px 4px; }
.opt {
  padding: calc(var(--u) * 5) calc(var(--u) * 6);
  text-align: center;
  background: #fff;
  box-shadow: 0 0 0 var(--b) var(--ink), 0 calc(var(--u) * 2.5) 0 0 var(--ink);
}
.opt.wrong { background: var(--pink-l); color: var(--ink-soft); animation: shake .35s; }
.opt.right { background: var(--mint); animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
.opt.locked { cursor: default; }
.explain { margin: 0; padding: calc(var(--u) * 6); text-align: center; background: var(--butter-l); box-shadow: 0 0 0 var(--b) var(--ink); }

/* Menü für frühere Türchen */
#past-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: calc(var(--u) * 6); padding: calc(var(--u) * 2) calc(var(--u) * 2) calc(var(--u) * 4); }
.day-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: calc(var(--u) * 2);
  aspect-ratio: 1; min-width: 0; width: 100%; padding: calc(var(--u) * 2);
  background: var(--pink-l);
  box-shadow: 0 0 0 var(--b) var(--ink), 0 calc(var(--u) * 2.5) 0 0 var(--ink);
}
.day-tile.open { background: #fff; }
.day-tile.mega { background: var(--lav-l); }
.day-tile.today { box-shadow: 0 0 0 var(--b) var(--ink), 0 0 0 calc(var(--b) * 2.5) var(--butter-d), 0 calc(var(--u) * 3.5) 0 0 var(--ink); }
.day-tile:active { transform: translateY(calc(var(--u) * 1)); }
.day-tile img { image-rendering: pixelated; max-width: 100%; }
.day-tile .px-title { height: auto; }

/* Passwort */
#login { background: #cbbdff; }
#pw {
  width: 100%; padding: calc(var(--u) * 5);
  font: inherit; color: var(--ink); text-align: center;
  background: #fff; border: 0; border-radius: 0;
  box-shadow: 0 0 0 var(--b) var(--ink);
  -webkit-appearance: none; appearance: none;
  -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
#pw:focus { outline: calc(var(--u) * 1.5) solid var(--butter-d); outline-offset: var(--b); }
#login.wrong .card { animation: shake .35s; }
button.opt { width: 100%; }

/* Testleiste, nur mit ?dev */
#dev {
  position: absolute; left: 8px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 8px);
  display: flex; gap: 8px;
  font-size: 15px; line-height: 1.2;
  z-index: 5;
}
#dev[hidden] { display: none; }
#dev select, #dev button {
  font: inherit; color: var(--ink);
  padding: 6px 10px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 0;
}

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.6) translateY(40px); opacity: 0; } }
@keyframes shake {
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  #reveal, .card, .opt.right, .opt.wrong { animation: none; }
}
