:root {
  --bg: #000;
  --glow-r: 255;
  --glow-g: 200;
  --glow-b: 40;
  /* Width of the playable stage: full width in portrait, centered 9:16
     stage in landscape. Used for UI that must scale with the game. */
  --stage-width: 100vw;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100dvh;
  height: 100svh;
  padding: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden;
}

#screensaverOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#screensaverOverlay[hidden] {
  display: none;
}

#screensaverVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

#screensaverOverlay:hover .close-button {
  opacity: 1;
}

#screensaverOverlay .close-button {
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.close-button {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 30px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1001;
  border: 2px solid white;
}

.close-button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.preview-container {
  position: fixed;
  width: 160px;
  height: 90px;
  border-radius: 8px;
  overflow: hidden;
  z-index: 1001;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(5px);
  background: rgba(0, 0, 0, 0.3);
}

#fullscreenPreview {
  top: 20px;
  right: 20px;
  animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#previewVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@font-face {
  font-family: 'Enfanutra';
  src: url('../assets/fonts/Enfanutra-Black.otf') format('opentype');
  /* font-weight: 900; */
  font-style: normal;
}

@font-face {
  font-family: 'EnfanutraBold';
  src: url('../assets/fonts/Enfanutra-Bold.otf') format('opentype');
  /* font-weight: 900; */
  font-style: normal;
}

#backgroundVideo {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  height: 100svh;
  object-fit: cover;
  z-index: 0;
  display: none;
}

.welcome-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}

.welcome-screen[hidden] {
  display: none;
}

.mechanics-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12vh;
  z-index: 24;
}

.mechanics-screen[hidden] {
  display: none;
}

.timeup-screen {
  position: fixed;
  inset: 0;
  z-index: 23;
}

.timeup-screen[hidden] {
  display: none;
}

.play-again {
    position: absolute;
    width: 24%;
    height: 5.3%;
    left: 38%;
    bottom: 34.6%;
}

.restart-play {
    position: absolute;
    width: 10%;
    height: 5%;
    right: 2%;
    bottom: 0.6%;
    background-image: url(../assets/images/home-button.webp);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.restart-play.visible {
    opacity: 1;
    pointer-events: auto;
}

#startGameButton {
    position: absolute;
    width: 32%;
    height: 8.3%;
    left: 34%;
    bottom: 19.6%;
}

#playGameButton {
    position: absolute;
    width: 24%;
    height: 5.3%;
    left: 38%;
    bottom: 34.6%;
}

.action-button {
  cursor: pointer;
}

.screensaver-button {
  position: absolute;
  top: 0;
  left: 0;
  width: 10%;
  height: 5%;
  z-index: 60;
}

.fullscreen-button {
    position: absolute;
    top: 0;
    right: 0;
    width: 10%;
    height: 5%;
    z-index: 60;
}

#gameContainer {
  position: relative;
  width: 100vw;
  height: 100dvh;
  height: 100svh;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: hidden;
  border-radius: 0;
  user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  z-index: 1;
  display: none;
}

#gameContainer.active {
  display: block;
}

#gameBackgroundVideo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

#gameScene {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#sceneSky {
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(10, 42, 168, 0.4) 0%, rgba(11, 58, 214, 0.4) 60%, rgba(6, 26, 120, 0.4) 100%);
}

#sceneGrid {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(140, 190, 255, 0.08) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(140, 190, 255, 0.08) 1px, transparent 1px);
  background-size: clamp(18px, 1.5vmin, 30px) clamp(18px, 1.5vmin, 30px);
}

#sceneFloor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 18%;
  background: linear-gradient(rgba(10, 59, 208, 0.5), rgba(4, 26, 112, 0.5));
}

#towerStack {
  position: absolute;
  left: 50%;
  bottom: 10%;
  transform: translateX(-50%);
}

.tower-block {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.block {
  position: absolute;
  width: 56%;
  height: 19%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  isolation: isolate;
}

#pendulumContainer {
  position: absolute;
  left: 50%;
  top: 0;
  transform-origin: top center;
  z-index: 4;
}

#pendulumString {
  position: absolute;
  left: 50%;
  top: 0;
  width: clamp(4px, 0.8vmin, 16px);
  margin-left: -1px;
  background: rgba(255, 255, 255, 0.85);
  transform-origin: top center;
}

#swingBlock {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -50%);
}

#fallingBlock {
  position: absolute;
  width: 56%;
  height: 19%;
  transform: translate(-50%, -50%);
  background-size: 100% 100%;
  background-repeat: no-repeat;
  isolation: isolate;
}

#fallingBlock[hidden] {
  display: none;
}

#dropButton {
    position: absolute;
    right: 6.5%;
    bottom: 9%;
    width: 18%;
    aspect-ratio: 1;
    border-radius: 50%;
    border: clamp(2px, 1vmin, 58px) solid #e0bf64;
    background: radial-gradient(circle at 50% 30%, #6fa4ff, #1c46d8 70%);
    color: #fff;
    font: 800 clamp(10px, 4.4vmin, 94px) "EnfanutraBold";
    cursor: pointer;
    box-shadow: 0 0 0 clamp(1px, 0.8vmin, 6px) #0c2a8a, 0 clamp(4px, 2vmin, 12px) clamp(10px, 4vmin, 28px) rgba(0, 0, 0, 0.4);
    z-index: 10;
    pointer-events: auto;
}

#dropButton:disabled {
  filter: grayscale(0.5) brightness(0.8);
  cursor: default;
}

#dropButton:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.brand-logo {
  position: absolute;
  left: 4%;
  top: 3.5%;
  padding: clamp(3px, 1vw, 10px) clamp(8px, 2.4vw, 24px) clamp(2px, 0.8vw, 8px);
  border: clamp(1px, 0.6vw, 4px) solid #d8b85a;
  border-radius: 999px;
  background: #0f2a6b;
  color: #fff;
  text-align: center;
  line-height: 1.05;
  z-index: 5;
}

.brand-logo b {
  display: block;
  font-style: italic;
  font-size: clamp(10px, 3.2vw, 34px);
}

.brand-logo i {
  display: block;
  font-size: clamp(6px, 1.8vw, 18px);
  color: #e8cf86;
  font-style: normal;
  letter-spacing: 0.08em;
}

.game-timer {
    position: absolute;
    top: 6% !important;
    font-size: clamp(1.25rem, calc(var(--stage-width) * 0.065), 8rem);
    /* font-weight: 800; */
    font-family: 'EnfanutraBold';
    right: 4.5% !important;
    color: #ffffff;
    white-space: nowrap;
    -webkit-text-stroke: clamp(2px, calc(var(--stage-width) * 0.0061), 12px) #2A3B7E;
    /* text-shadow: -2.5px -2.5px 0 #2A3B7E, 2.5px -2.5px 0 #2A3B7E, -2.5px 2.5px 0 #2A3B7E, 2.5px 2.5px 0 #2A3B7E; */
    animation: timerFadeIn 1s ease-in;
    
  /* position: absolute;
  right: 0;
  top: 3.5%;
  display: flex;
  align-items: center;
  gap: clamp(4px, 1.6vw, 16px);
  padding: clamp(4px, 1.2vw, 12px) clamp(10px, 2.8vw, 28px) clamp(4px, 1.2vw, 12px) clamp(6px, 2vw, 20px);
  background: #fff;
  border: clamp(1px, 0.6vw, 4px) solid #d8b85a;
  border-right: 0;
  border-radius: 999px 0 0 999px;
  color: #14297c;
  font-family: 'Enfanutra', serif;
  font-weight: 900;
  font-size: clamp(14px, 5.4vw, 56px);
  font-variant-numeric: tabular-nums;
  z-index: 5; */
}

.game-timer svg {
  width: 1.2em;
  height: 1.2em;
}

.game-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7.5%;
  padding: 0 5%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(#e6cd86, #b8923c);
  color: #6b4d14;
  font-size: clamp(6px, 1.7vw, 8px);
  line-height: 1.35;
  z-index: 5;
}

#gameView {
  opacity: 1;
  transition: opacity 0.35s ease;
}

#gameView.fade-out {
  opacity: 0;
}

#gameOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  background: rgba(5, 15, 70, 0.78);
  color: #fff;
  font-size: clamp(24px, 8vw, 36px);
  font-weight: 800;
  z-index: 10;
}

#gameOverlay[hidden] {
  display: none;
}

#timeupOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  background: rgba(5, 15, 70, 0.78);
  color: #fff;
  font-size: clamp(24px, 8vw, 36px);
  font-weight: 800;
  z-index: 10;
}

#timeupOverlay[hidden] {
  display: none;
}

@media (orientation: landscape) and (min-width: 480px) {
  :root {
    --stage-width: calc(100dvh * 9 / 16);
  }

  body {
    padding: 0;
  }
  #gameContainer {
    aspect-ratio: 9/16;
    width: auto;
    height: 100dvh;
    height: 100svh;
    max-width: calc(100dvh * 9 / 16);
    border-radius: 0;
    box-shadow: none;
  }

  /* Keep the background art and UI overlays inside the same centered
     9:16 stage as the game, so landscape/desktop screens see the full
     composition instead of a cropped or misaligned one. */
  #backgroundVideo {
    left: 50%;
    right: auto;
    width: calc(100dvh * 9 / 16);
    max-width: 100vw;
    transform: translateX(-50%);
  }

  .welcome-screen,
  .mechanics-screen,
  .timeup-screen {
    left: 50%;
    right: auto;
    width: calc(100dvh * 9 / 16);
    max-width: 100vw;
    transform: translateX(-50%);
  }

  /* Keep the screensaver video in the same centered 9:16 stage as the
     rest of the experience. The overlay itself stays full-screen so a
     click anywhere still dismisses it. */
  #screensaverVideo {
    left: 50%;
    right: auto;
    width: calc(100dvh * 9 / 16);
    max-width: 100vw;
    transform: translateX(-50%);
  }

  /* Size the DROP label against the 9:16 stage instead of the full
     viewport, so it fits the pillarboxed button on wide screens. */
  #dropButton {
    font-size: clamp(10px, calc(100dvh * 9 / 16 * 0.044), 94px);
  }
}

@media (orientation: portrait) and (min-width: 1000px) {
  #gameContainer {
    width: 100vw;
    height: 100dvh;
    height: 100svh;
    max-width: 100vw;
    max-height: 100dvh;
  }
}

@media (min-width: 2000px) and (min-height: 3500px) {
  body {
    padding: 0;
  }
  #gameContainer {
    aspect-ratio: 9/16;
    width: auto;
    height: 100dvh;
    height: 100svh;
    max-width: calc(100dvh * 9 / 16);
  }
  #towerStack {
    bottom: 15%;
  }
  #sceneFloor {
    height: 20%;
  }
}
