@import url('https://fonts.googleapis.com/css2?family=Bitter:ital,wght@0,700;0,800;0,900;1,800&family=Heebo:wght@700;800;900&display=swap');

:root {
  --gold: #e2ac3b;
  --gold-hi: #f1c75b;
  --gold-shadow: #98651e;
  --door-w: clamp(230px, min(41vw, 35vh), 390px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  margin: 0;
  background: #fff;
  color: #17140f;
  font-family: "Bitter", Georgia, serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html[lang="he"] body,
html[lang="he"] .game-title text,
html[lang="he"] .door-button {
  font-family: "Heebo", Arial, sans-serif;
}

.game {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  isolation: isolate;
}

.message {
  width: min(92vw, calc(var(--door-w) * 2));
  min-height: 2.7em;
  margin: 0 0 clamp(8px, 1.7vh, 20px);
  display: grid;
  place-items: end center;
  text-align: center;
  font-size: clamp(1.05rem, 2.6vw, 2rem);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -.025em;
  text-wrap: balance;
  text-shadow: 0 2px 0 rgba(226, 172, 59, .55);
  opacity: 0;
  transform: scale(.72) translateY(10px);
  pointer-events: none;
}

.game-title {
  width: min(92vw, calc(var(--door-w) * 2));
  height: clamp(64px, 10vw, 95px);
  flex: 0 0 auto;
  margin: 0 0 clamp(8px, 1.7vh, 20px);
  opacity: 1;
  overflow: visible;
  transition: opacity 260ms ease, transform 260ms ease;
}

.game-title text {
  fill: #17140f;
  font-family: "Bitter", Georgia, serif;
  font-size: 42px;
  font-weight: 900;
  letter-spacing: -1px;
}

.game-title-image { object-fit: contain; }

.game-title.hidden {
  opacity: 0;
  transform: translateY(-6px);
}

.game-title + .message { margin-top: calc(clamp(64px, 10vw, 95px) * -1 - clamp(8px, 1.7vh, 20px)); }

.message.show { animation: message-pop 320ms cubic-bezier(.2, 1.6, .45, 1) forwards; }
.message.angry { animation: angry-pop 390ms cubic-bezier(.2, 1.7, .3, 1) forwards; }
.message.hide { animation: message-out 130ms ease-in forwards; }
.message.giant { font-size: clamp(2.8rem, 7vw, 5rem); line-height: .95; }

.stage {
  position: relative;
  width: var(--door-w);
  aspect-ratio: 626 / 788;
  filter: drop-shadow(0 16px 14px rgba(0,0,0,.2));
}

.doorway {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 22px rgba(0,0,0,.18);
}

.glow {
  position: absolute;
  inset: -20%;
  background: #fefdff;
  opacity: 0;
  transition: opacity 400ms ease;
}

.monster {
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 100%;
  left: 0;
  bottom: 0;
  object-fit: contain;
  opacity: 0;
  transform: scale(.92) translateY(4%);
  transition: opacity 130ms ease, transform 260ms cubic-bezier(.2, 1.35, .4, 1);
  pointer-events: none;
}

.stage.revealed .monster { opacity: 1; transform: scale(1) translateY(0); }
.stage.empty .monster { opacity: 0; transform: translateX(72%) scale(.94); transition: none; }
.stage.late-entry .monster { animation: monster-slide-in 430ms cubic-bezier(.18, 1.25, .35, 1) both; }
.stage.tiny .monster {
  width: 22%;
  height: 22%;
  left: 39%;
  bottom: 18%;
}
.stage.roaming .monster {
  width: var(--monster-size, 65%);
  height: var(--monster-size, 65%);
  left: var(--monster-x, 18%);
  bottom: var(--monster-y, 8%);
}
.stage.revealed .glow { opacity: 1; }
.stage.retreat .monster { opacity: 0; transform: scale(.88) translateY(9%); transition-duration: 120ms; }

.door {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.door-panel {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  object-fit: fill;
  filter: drop-shadow(0 12px 10px rgba(35, 25, 10, .28));
  pointer-events: none;
  will-change: transform;
  transition: transform 700ms cubic-bezier(.65, 0, .2, 1);
}

.door-panel-left { left: 0; object-position: left center; }
.door-panel-right { right: 0; object-position: right center; }
.stage.opening .door-panel-left,
.stage.open .door-panel-left { transform: translateX(-102%); }
.stage.opening .door-panel-right,
.stage.open .door-panel-right { transform: translateX(102%); }
.stage.peek .door-panel-left { transform: translateX(-34%); }
.stage.peek .door-panel-right { transform: translateX(34%); }
.stage.closing .door-panel { transition-duration: 420ms; transition-timing-function: cubic-bezier(.7, 0, .9, .5); }

.stage.nudge .door { animation: nudge 240ms ease-in-out; }
.game.shake { animation: screen-shake 190ms linear; }

.dust { position: absolute; z-index: 5; inset: auto 0 0; height: 20%; pointer-events: none; }
.dust.burst::before, .dust.burst::after {
  content: ""; position: absolute; left: 50%; bottom: 2%; width: 7px; height: 7px; border-radius: 50%;
  background: #a78961; box-shadow: -38px -5px 0 #715c42, 33px -9px 0 #8e7350, 18px -20px 0 #5f503d;
  animation: dust 420ms ease-out forwards;
}
.dust.burst::after { transform: scale(.65); animation-delay: 35ms; }

.impact {
  position: absolute;
  z-index: 8;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  pointer-events: none;
}

.impact.burst::before {
  content: "";
  position: absolute;
  inset: -40px;
  background: #ffd45a;
  clip-path: polygon(50% 0, 59% 34%, 83% 12%, 70% 40%, 100% 50%, 68% 59%, 88% 85%, 59% 70%, 50% 100%, 41% 69%, 14% 87%, 31% 59%, 0 50%, 32% 41%, 13% 14%, 41% 32%);
  filter: drop-shadow(0 0 7px #ff7a00);
  animation: impact-pop 360ms cubic-bezier(.2, 1.4, .3, 1) forwards;
}

.impact.burst::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  background: #fff6b0;
  box-shadow: -42px -20px 0 -1px #e96b21, 38px -27px 0 -2px #ffd45a, -35px 31px 0 -2px #ffd45a, 45px 24px 0 -1px #e96b21;
  animation: impact-particles 430ms ease-out forwards;
}

.door-button {
  position: relative;
  min-width: 0;
  margin-top: clamp(18px, 3vh, 30px);
  padding: 18px 2ch 16px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(#f0c451 0 8%, var(--gold) 9% 100%);
  color: #211808;
  box-shadow: 0 9px 0 var(--gold-shadow), 0 14px 25px rgba(0,0,0,.65);
  font: 900 clamp(1rem, 3.7vw, 1.45rem)/1 "Bitter", Georgia, serif;
  letter-spacing: .035em;
  cursor: pointer;
  transform: translateY(0);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
  touch-action: manipulation;
}
.door-button:hover { transform: translateY(-3px); filter: brightness(1.06); box-shadow: 0 12px 0 var(--gold-shadow), 0 18px 30px rgba(0,0,0,.75); }
.door-button:active, .door-button.pressed { transform: translateY(7px) scale(.985, .96); box-shadow: 0 2px 0 var(--gold-shadow), 0 5px 10px rgba(0,0,0,.65); }
.door-button:focus-visible { outline: 3px solid #fff; outline-offset: 7px; }

html[lang="he"] .door-button {
  font-family: "Heebo", Arial, sans-serif;
  font-size: clamp(calc(1rem - 4px), calc(3.7vw - 4px), calc(1.45rem - 4px));
  font-weight: 800;
}

.language-panel {
  position: fixed;
  z-index: 20;
  top: 22px;
  left: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}

.language-toggle {
  width: 84px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid #211f1c;
  border-radius: 6px;
  color: #211f1c;
  background: #fff;
  font: 800 1rem/1 "Heebo", Arial, sans-serif;
  letter-spacing: .12em;
  text-decoration: none;
}

.language-toggle:hover,
.language-toggle:focus-visible {
  background: #211f1c;
  color: #fff;
}

.credit {
  color: #000;
  background: none;
  font-size: .72rem;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  opacity: .7;
}

.credit a {
  color: inherit;
  text-decoration: none;
}

.credit a:hover,
.credit a:focus-visible {
  text-decoration: underline;
}

@keyframes nudge { 20% { transform: rotateZ(-.6deg) translateX(-2px); } 45% { transform: rotateZ(.7deg) translateX(2px); } 70% { transform: rotateZ(-.35deg); } }
@keyframes message-pop { to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes angry-pop { 0% { opacity: 0; transform: scale(.65) rotate(-2deg); } 55% { opacity: 1; transform: scale(1.09) rotate(1deg); } 72% { transform: translateX(-4px) rotate(-.5deg); } 85% { transform: translateX(4px); } 100% { opacity: 1; transform: scale(1); } }
@keyframes message-out { to { opacity: 0; transform: scale(.9) translateY(-7px); } }
@keyframes monster-slide-in {
  from { opacity: 0; transform: translateX(72%) scale(.94); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes screen-shake { 20% { transform: translate(4px, 1px); } 40% { transform: translate(-5px, -2px); } 60% { transform: translate(3px, 2px); } 80% { transform: translate(-2px, 0); } }
@keyframes dust { to { opacity: 0; transform: translateY(-30px) scale(2.1); } }
@keyframes impact-pop { 0% { opacity: 0; transform: scale(.15) rotate(0); } 45% { opacity: 1; transform: scale(1.15) rotate(8deg); } 100% { opacity: 0; transform: scale(1.65) rotate(-5deg); } }
@keyframes impact-particles { to { opacity: 0; transform: scale(1.75) rotate(18deg); } }

@media (max-height: 650px) {
  :root { --door-w: clamp(175px, 31vh, 250px); }
  .door-button { margin-top: 13px; padding-block: 14px 12px; }
  .message { min-height: 2.2em; margin-bottom: 6px; }
}

@media (min-width: 601px) {
  .game-title-image { position: relative; top: -.5em; }
}

@media (max-width: 600px) {
  .game {
    position: static;
    justify-content: flex-end;
    padding-bottom: calc(12dvh + 9px);
  }

  .message {
    width: min(94vw, calc(var(--door-w) * 2));
    min-height: 4.4em;
    font-size: clamp(2rem, 8.5vw, 2.5rem);
    line-height: 1.04;
    overflow-wrap: anywhere;
  }

  .message.giant {
    font-size: clamp(3rem, 14vw, 4.3rem);
  }

  .game-title {
    width: min(96vw, calc(var(--door-w) * 2));
    height: clamp(76px, 20vw, 104px);
  }

  .game-title text {
    font-size: 52px;
    letter-spacing: -1.5px;
  }

  .game-title + .message {
    margin-top: calc(clamp(76px, 20vw, 104px) * -1 - clamp(8px, 1.7vh, 20px));
  }

  .game-title + .message:empty {
    min-height: 0;
    margin-top: 0;
    margin-bottom: 0;
  }

}

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