* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #0b1030;
  font-family: 'Pixelify Sans', ui-monospace, monospace;
  color: #3a2418;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }

#game {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  touch-action: none;
  image-rendering: pixelated;
  cursor: grab;
}

/* ---------- Pixel-Panels ---------- */
.panel {
  background: #fdf6e3;
  border: 3px solid #3a2418;
  box-shadow: inset -3px -3px 0 #e6d6b0, 3px 3px 0 rgba(0, 0, 0, .35);
  border-radius: 0;
}
.btn {
  font: inherit; font-size: 18px; color: #3a2418;
  padding: 8px 12px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.btn:active { transform: translate(2px, 2px); box-shadow: inset -3px -3px 0 #e6d6b0; }
.small { font-size: 13px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none;
}
#banner {
  padding: 8px 14px; font-size: 18px; text-align: center; max-width: 92vw;
}
#banner b { color: #b3262b; }
#banner small { display: block; font-size: 13px; opacity: .8; margin-top: 2px; }
#status { padding: 3px 10px; opacity: .92; }

#controls {
  position: fixed; right: 12px; bottom: max(12px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
#controls .row { display: flex; gap: 6px; }
#controls .btn { min-width: 44px; min-height: 44px; }
#btn-hint { background: #fff3c4; animation: wiggle 2.4s infinite; }
@keyframes wiggle {
  0%, 80%, 100% { transform: rotate(0); }
  85% { transform: rotate(-6deg); } 90% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); }
}

/* ---------- Sprechblase ---------- */
#bubble {
  position: fixed; left: 0; top: 0;
  background: #fff; border: 3px solid #3a2418;
  padding: 6px 10px; font-size: 15px; max-width: 240px; text-align: center;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .3);
  pointer-events: none; margin-top: -8px;
}
#bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -9px; margin-left: -6px;
  border: 6px solid transparent; border-top-color: #3a2418; border-bottom: 0;
}
#bubble button {
  pointer-events: auto; display: block; margin: 6px auto 0;
  font: inherit; font-size: 13px; background: #fdf6e3; border: 2px solid #3a2418; padding: 4px 8px; cursor: pointer;
}
#bubble.pop { animation: pop .25s ease-out; }
@keyframes pop { from { opacity: 0; scale: .6; } to { opacity: 1; scale: 1; } }

#hint-arrow {
  position: fixed; left: 0; top: 0; width: 56px; height: 56px; pointer-events: none;
  display: grid; place-items: center;
}
#hint-arrow .arrow { position: absolute; font-size: 34px; color: #ffd740; text-shadow: 0 0 6px #000; }
#hint-arrow .bell { font-size: 20px; animation: wiggle 1s infinite; }

/* ---------- Dialoge ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 10, 30, .6);
  display: grid; place-items: center; padding: 16px;
  animation: fade .2s;
}
@keyframes fade { from { opacity: 0; } }
.box {
  position: relative; width: min(420px, 100%); max-height: 90vh; overflow: auto;
  padding: 18px; text-align: center; font-size: 17px; line-height: 1.4;
}
.box.wide { width: min(560px, 100%); }
.box h2 { margin: 6px 0 12px; font-size: 24px; color: #b3262b; }
.box p { margin: 8px 0; }
#modal-from { font-size: 15px; opacity: .85; }

#present-stage { cursor: pointer; padding: 10px 0; }
.present { position: relative; width: 160px; height: 160px; margin: 0 auto; animation: shake 1.6s infinite; }
.present canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
#present-lid { transition: transform .6s cubic-bezier(.3, 1.6, .5, 1), opacity .6s; }
#present-stage.open .present { animation: none; }
#present-stage.open #present-lid { transform: translate(40px, -120px) rotate(35deg); opacity: 0; }
.tap-hint { font-size: 14px; opacity: .7; }
@keyframes shake {
  0%, 70%, 100% { transform: rotate(0); }
  75% { transform: rotate(-5deg); } 80% { transform: rotate(5deg); } 85% { transform: rotate(-4deg); } 90% { transform: rotate(3deg); }
}
#gift-content { animation: fade .4s; }
#gift-text { white-space: pre-line; }
#gift-image { max-width: 100%; border: 3px solid #3a2418; margin: 6px 0; }
#gift-link { margin: 8px 0; background: #fff3c4; }
#modal-close, #book-close, #welcome-go { margin-top: 12px; }

#confetti, #confetti-2 { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#confetti i, #confetti-2 i {
  position: absolute; top: 30%; width: 6px; height: 6px;
  animation: confetti 1.6s ease-out forwards;
}
@keyframes confetti {
  0% { transform: translate(0, 0); opacity: 1; }
  30% { transform: translate(calc(var(--dx) * .5), -90px); }
  100% { transform: translate(var(--dx), 260px); opacity: 0; }
}

/* ---------- Rätselschloss ---------- */
.lock-icon { font-size: 54px; line-height: 1; margin: 6px 0; }
.lock-title { font-size: 15px; opacity: .8; }
#lock-question { font-size: 20px; font-weight: 600; margin: 12px 0; }
#lock-image { display: block; max-width: 100%; max-height: 45vh; margin: 0 auto 12px; border: 3px solid #3a2418; cursor: zoom-in; }
#lock-image[hidden] { display: none; }
#lock-form { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
#lock-input {
  font: inherit; font-size: 18px; padding: 8px 10px; width: min(240px, 100%);
  -webkit-user-select: text; user-select: text;
}
#lock-feedback { min-height: 1.4em; font-weight: 600; color: #b3262b; }
#lock-stage.solved #lock-feedback { color: #1e7a45; }
#lock-stage.solved .lock-icon { animation: pop .4s; }
#lock-stage.wrong { animation: shake-x .4s; }
@keyframes shake-x { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
#lock-hint { background: #fff3c4; border: 2px dashed #e8b923; padding: 6px 10px; }
#gift-audio { width: 100%; margin: 8px 0; }

/* ---------- Zugangscode ---------- */
#gate { background: rgba(8, 10, 30, .82); backdrop-filter: blur(3px); z-index: 50; }
#gate-form { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
#gate-input { font: inherit; font-size: 18px; padding: 8px 10px; width: min(220px, 100%); -webkit-user-select: text; user-select: text; }
#gate-error { color: #b3262b; min-height: 1.3em; font-weight: 600; }
#gate .box.wrong { animation: shake-x .4s; }

/* ---------- Live-Überraschungen ---------- */
#live-msg { z-index: 40; }
#live-msg .box { animation: pop .35s ease-out; }
#live-text { white-space: pre-line; font-size: 19px; }
#live-audio { width: 100%; margin: 8px 0; }
#live-banner {
  position: fixed; left: 0; top: 0; pointer-events: none;
  background: #fff3c4; border: 3px solid #3a2418; padding: 4px 10px; font-size: 15px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .3); white-space: nowrap; max-width: 80vw; overflow: hidden; text-overflow: ellipsis;
}
#book-push { margin-top: 8px; background: #e3f4ff; }

/* ---------- Installieren ---------- */
#btn-install { background: #e3f4ff; font-size: 15px; }
.steps { text-align: left; margin: 10px auto; padding-left: 24px; max-width: 300px; }
.steps li { margin: 6px 0; }
.ios-share { display: inline-block; border: 2px solid #2e86c1; color: #2e86c1; padding: 0 4px; font-size: 13px; }
#status { pointer-events: auto; cursor: default; }

/* ---------- Brief & Toast ---------- */
.letter { background: #fffaf0; }
#note-text { white-space: pre-line; font-size: 18px; }
#finale-text { white-space: pre-line; }
#toast {
  position: fixed; left: 50%; top: 120px; transform: translateX(-50%);
  padding: 8px 14px; font-size: 15px; max-width: 88vw; text-align: center;
  pointer-events: none; background: #fff3c4;
}
#toast.pop { animation: fade .3s; }

/* ---------- Stallbuch ---------- */
#book-finale { margin-top: 12px; background: #fff3c4; }
#book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.cell {
  font: inherit; font-size: 12px; color: #3a2418;
  background: #fff; border: 2px solid #3a2418; padding: 6px 2px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 84px; justify-content: center;
}
.cell canvas { width: 52px; height: 56px; image-rendering: pixelated; }
.cell .q { font-size: 26px; height: 48px; display: grid; place-items: center; }
.cell.locked { opacity: .5; cursor: default; background: #eee; }
.cell.hidden-deer { background: #fff3c4; cursor: default; }

/* ---------- Testmodus ---------- */
#debug {
  position: fixed; left: 10px; bottom: 10px; padding: 8px 10px; font-size: 13px;
  display: flex; flex-direction: column; gap: 4px; max-width: 220px;
}
#debug input, #debug select, #debug button { font: inherit; font-size: 13px; }
