@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: #086375;
  --gold-hi: #0a7d92;
  --gold-shadow: #05414c;
  --door-w: clamp(280px, min(88vw, 62vh), 640px);
  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: var(--door-w);
  min-height: 2.7em;
  margin: 0 0 clamp(8px, 1.7vh, 20px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  text-align: right;
  font-size: clamp(.8rem, 1.7vw, 1.3rem);
  font-weight: 900;
  line-height: 1.22;
  letter-spacing: -.015em;
  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; position: relative; top: -.5em; }

.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; }
/* The text block shrinks to its content and is centered by the flex parent; lines right-align inside. */
.msg-text { max-width: 100%; }

.stage {
  position: relative;
  width: var(--door-w);
  aspect-ratio: 1992 / 1507;
  margin-top: clamp(14px, 3.5vh, 34px);
}

/* One image fills the stage: the still tv.png, swapped for a clip on press, then back. */
.tv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.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(#0a7d92 0 8%, var(--gold) 9% 100%);
  color: #fff;
  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;
}

.credit-bar {
  position: fixed;
  z-index: 20;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  text-align: right;
}

.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;
}

.slide-counter {
  position: fixed;
  z-index: 30;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  padding: 4.8px 11.2px;
  border-radius: 999px;
  background: var(--gold);
  color: #fff;
  font: 800 .8rem/1 "Bitter", Georgia, serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: .06em;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .28);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 220ms ease, transform 220ms ease;
  pointer-events: none;
}

html[lang="he"] .slide-counter { font-family: "Heebo", Arial, sans-serif; }

.slide-counter.show { opacity: 1; transform: translateY(0); }

/* Finale: a soft glow blooms behind the show as fin.gif plays, then lingers on the end card. */
.game.finishing::before,
.game.ended::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(circle at 50% 42%, rgba(10, 125, 146, .20), rgba(255, 255, 255, 0) 62%);
  opacity: 0;
  animation: finale-glow 1400ms ease forwards;
}
@keyframes finale-glow { to { opacity: 1; } }

.game.finishing .stage { filter: brightness(1.06); transition: filter 1.2s ease; }

/* The restart button gently breathes so "להתחלה" reads as an invitation. */
.game.ended .door-button { animation: restart-pulse 2.4s ease-in-out infinite; }
@keyframes restart-pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.13); } }

@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: -.8em; }
}

@media (max-width: 600px) {
  /* TV fills 88vw, leaving ~6% margin on each side; the font scales up to match. */
  :root { --door-w: 88vw; }

  .game {
    position: static;
    justify-content: flex-end;
    padding-bottom: calc(12dvh + 9px - 2rem);   /* button sits ~1.5 lines higher than before */
  }

  /* arch.png 10% smaller (visual scale keeps the layout/overlap math unchanged). */
  .game-title-image { transform: scale(.9); }

  .message {
    width: var(--door-w);
    min-height: 4.4em;
    font-size: clamp(1.15rem, 5.5vw, 2.1rem);
    line-height: 1.24;
  }

  /* Button 12% smaller than the enlarged size, lifted ~1.5 lines (top gap keeps the TV in place). */
  .door-button {
    margin-top: calc(clamp(18px, 3vh, 30px) + 2rem);
    padding: 20px 2.3ch 18px;
    border-radius: 23px;
    box-shadow: 0 11px 0 var(--gold-shadow), 0 16px 28px rgba(0,0,0,.65);
  }

  html[lang="he"] .door-button {
    font-size: clamp(1.14rem, 4.2vw, 1.67rem);
  }

  .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; }
}
