* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  height: calc(var(--app-vh, 1vh) * 100); /* real visible height on mobile Safari, see index.html */
  background: #000;
  overflow: hidden;
  font-family: 'Georgia', serif;
}
.hidden { display: none !important; }

/* ============================================================
   LEVEL SELECT SCREEN
   ============================================================ */
#level-select-screen {
  position: relative;
  width: 100vw; height: 100vh; height: calc(var(--app-vh, 1vh) * 100);
  overflow-y: auto;
  background: #0a0805;
}
#level-select-bg {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, #1a1410 0%, #050403 100%);
  z-index: 0;
  /* Swap in a real background image later:
     background-image: url('assets/icons/level-select-bg.jpg');
     background-size: cover; background-position: center; */
}
#level-list {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 22px;
  padding: 60px 20px 80px;
}

.level-item {
  position: relative;
  width: 260px;
  max-width: 80vw;
  padding: 14px 20px;
  font-family: 'Georgia', serif;
  font-size: 22px;
  font-weight: bold;
  letter-spacing: 1px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
}

.level-item-thumb {
  width: 52px; height: 52px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.level-item-thumb-empty {
  background: rgba(255,255,255,0.06);
}

.level-item.unlocked {
  background: linear-gradient(180deg, #1f4a52, #122e33);
  border: 3px solid #4a91a4;
  color: #eaf7f9;
  box-shadow: 0 0 20px rgba(74,145,164,0.4), 0 6px 14px rgba(0,0,0,0.5);
}
.level-item.unlocked:active { transform: scale(0.97); }
.level-item.unlocked .level-item-thumb { filter: none; }

.level-item.locked {
  background: #201d1a;
  border: 3px solid #4a453e;
  color: #6b665e;
  cursor: default;
}
.level-item.locked .level-item-thumb { filter: grayscale(1) brightness(0.6); }

.level-item.completed.unlocked {
  border-color: #7CFFB2;
  box-shadow: 0 0 20px rgba(124,255,178,0.4), 0 6px 14px rgba(0,0,0,0.5);
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
#game-screen { width: 100vw; height: 100vh; height: calc(var(--app-vh, 1vh) * 100); }

#game-container {
  position: relative;
  width: 100vw; height: 100vh; height: calc(var(--app-vh, 1vh) * 100);
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden; /* keeps the oversized, blurred backdrop from spilling out */
}

/* Sits behind #scene-img/#scene-video (z-index 1/2). Now that the
   foreground scene itself is edge-to-edge cover-fit (see #scene-img
   below), this backdrop is normally fully covered and invisible — it's
   kept only as a safety net for the brief instant before an image's
   natural size is known (see updateHotspotLayerBounds in engine.js).
   Never receives clicks. */
.scene-backdrop {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  filter: blur(35px) brightness(0.55) saturate(1.1);
  transform: scale(1.15); /* hides the softened edge from the blur radius */
  z-index: 0;
  pointer-events: none;
}

#scene-img {
  /* width/height/object-fit here are just the fallback for the instant
     before the image's natural size is known — Engine.updateHotspotLayerBounds()
     (engine.js) then takes over, setting explicit left/top/width/height
     in JS at a capped cover-fit scale, so the fill can never crop a
     hotspot out of reach. */
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.55s ease;
  /* Stacked directly on top of #scene-video (same box, via inset:0) and
     always above it in z-index. This is what actually stops the
     video-hub flash: some browsers keep a playing <video>'s last frame
     composited for a beat after it's hidden (display:none doesn't tear
     down its layer instantly), so rather than race that timing, the
     image simply always covers it. */
  position: absolute; inset: 0; z-index: 2;
}
#scene-img.zoom-out { transform: scale(2.2); opacity: 0; }
#scene-img.zoom-in-start { transition: none !important; transform: scale(2.2); opacity: 0; }
#scene-img.zoom-return-out { transform: scale(1.35); opacity: 0; transition: transform 0.45s ease, opacity 0.45s ease; }
#scene-img.zoom-return-in-start { transition: none !important; transform: scale(1.35); opacity: 0; }

#hotspot-layer { position: absolute; z-index: 10; }
.hotspot { position: absolute; cursor: pointer; border-radius: 8px; }

/* Caption text under a playing video (e.g. Level 7's tv_boy clip) */
#video-subtitle {
  position: absolute;
  left: 50%; bottom: 6%;
  transform: translateX(-50%);
  z-index: 12;
  max-width: 86%;
  margin: 0;
  padding: 8px 16px;
  background: rgba(0,0,0,0.6);
  border-radius: 6px;
  color: #fff;
  font-size: 1rem;
  text-align: center;
  pointer-events: none;
}

/* Character overlays */
.char-overlay {
  position: absolute; z-index: 25; pointer-events: none;
  transition: transform 0.7s cubic-bezier(0.22,1,0.36,1), opacity 0.7s ease;
}
.char-overlay.danny {
  left: 2%; bottom: 2%; top: auto; width: 26%;
  transform: translateY(-260%); opacity: 0;
}
.char-overlay.danny.show { transform: translateY(0); opacity: 1; }
.char-overlay.parcel {
  right: 3%; top: 4%; width: 16%;
  transform: translateY(220%); opacity: 0;
}
.char-overlay.parcel.show { transform: translateY(0); opacity: 1; }

/* ============================================================
   HUD (hint / notebook / timer) — top-right
   ============================================================ */
#hud {
  position: absolute;
  top: 3%; right: 3%;
  z-index: 35;
  display: flex;
  gap: 10px;
}
.hud-icon-btn {
  position: relative;
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 2px solid #4a91a4;
  background: rgba(10,15,20,0.85);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.4s ease;
}
.hud-icon-btn img { width: 60%; height: 60%; object-fit: contain; }
.hud-icon-btn svg { width: 60%; height: 60%; color: #eaf7f9; }
.hud-icon-btn:active { transform: scale(0.94); }

/* Sound/mute toggle: the strike-through line overlays the sound icon
   (a single static image, not separate wave/no-wave art) only when muted. */
.hud-icon-btn .sound-mute-line {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
}
.hud-icon-btn.muted .sound-mute-line { display: block; }
.hud-icon-btn.disabled {
  cursor: default;
  opacity: 0.4;
  filter: grayscale(1);
}
.hud-icon-btn.disabled:active { transform: none; }

.hud-icon-btn.emphasis {
  transform: scale(1.35);
  box-shadow: 0 0 22px rgba(74,145,164,0.8), 0 4px 12px rgba(0,0,0,0.5);
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.4s ease;
}


/* Back to map button */
.back-btn {
  position: absolute;
  top: 3%; left: 3%;
  z-index: 35;
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid #4a91a4;
  background: rgba(10,15,20,0.85);
  color: #f2e9ff;
  font-family: 'Georgia', serif;
  font-size: 14px;
  cursor: pointer;
}
.back-btn:active { transform: scale(0.96); }

/* ============================================================
   UNIFIED GAME BOX — used for EVERY popup in the game
   ============================================================ */
.game-box {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}
.game-box.hidden { display: none; }

.game-box.box-position-bottom { align-items: flex-end; padding-bottom: 6%; }
.game-box.box-position-left { justify-content: flex-start; padding-left: 4%; }

.game-box-inner {
  pointer-events: auto;
  background: rgba(10, 15, 20, 0.94);
  border: 3px solid #4a91a4;
  border-radius: 14px;
  padding: 22px 26px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  max-width: 340px;
  width: 86vw;
  max-height: 88vh; /* rotated / short viewports: scroll instead of overflowing */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: gameBoxIn 0.5s cubic-bezier(0.22,1,0.36,1);
}
.box-position-left .game-box-inner { animation: gameBoxInLeft 0.5s cubic-bezier(0.22,1,0.36,1); }

@keyframes gameBoxIn { 0% { transform: translateY(24px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } }
@keyframes gameBoxInLeft { 0% { transform: translateX(-40px); opacity: 0; } 100% { transform: translateX(0); opacity: 1; } }

.game-box-subtitle {
  font-size: 13px;
  color: #bfe4ea;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.game-box-text {
  font-size: 16px;
  color: #eaf7f9;
  line-height: 1.5;
  margin-bottom: 16px;
}
#game-box-body { margin-bottom: 4px; }

.game-text-input {
  font-size: 18px;
  text-align: center;
  width: 100%;
  max-width: 200px;
  padding: 8px;
  border: 2px solid #4a91a4;
  border-radius: 6px;
  background: #fff;
  margin-bottom: 12px;
}

.letters-inputs {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}
.letters-inputs input {
  width: 42px; height: 50px;
  font-size: 24px;
  text-align: center;
  text-transform: uppercase;
  border: 2px solid #4a91a4;
  border-radius: 6px;
  background: #fff;
}

.game-box-feedback {
  font-size: 14px;
  min-height: 20px;
  font-weight: bold;
  color: #ffffff;
  margin-bottom: 8px;
}
.game-box-feedback.correct { color: #7CFFB2; }
.game-box-feedback.wrong { color: #FF8A8A; }

#game-box-actions, .game-box-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.game-btn {
  font-size: 15px;
  padding: 9px 20px;
  border: 2px solid #4a91a4;
  border-radius: 20px;
  background: #4a91a4;
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
}
.game-btn:active { transform: scale(0.96); }
.game-btn-secondary {
  background: transparent;
  color: #bfe4ea;
}

/* Notebook */
.notebook-inner { max-width: 300px; text-align: left; }
.notebook-line {
  display: block;
  color: #eaf7f9;
  font-size: 14px;
  margin-bottom: 10px;
}
.notebook-line input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  border: 2px solid #4a91a4;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
}

/* Auto-dismissing tutorial callout: smooth fade-out (entrance already
   uses the normal gameBoxIn animation) */
.game-box.fade-mode .game-box-inner {
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.game-box.fade-mode.fade-out .game-box-inner {
  opacity: 0;
  transform: translateY(-10px);
}

/* Video playback (level 2/3 movie hotspot, and the video hub scenes) */
#scene-video {
  /* Same fallback-then-JS-takes-over pattern as #scene-img — see its
     comment. */
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  /* Same box as #scene-img, stacked underneath it — see the comment on
     #scene-img for why. */
  position: absolute; inset: 0; z-index: 1;
}

/* Info form (level 2+) */
.notebook-inner { max-width: 380px; width: 90vw; text-align: left; }
.info-row {
  margin-bottom: 14px;
}
.info-row label {
  display: block;
  color: #bfe4ea;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.info-row .letters-inputs {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.info-row .letters-inputs input {
  width: 30px; height: 38px;
  font-size: 18px;
}

/* Locked (already-correct) Info form inputs */
.info-row .letters-inputs input.locked {
  background: #d9f7e4;
  border-color: #2fae6a;
  color: #14532d;
  font-weight: bold;
}

/* Just-submitted-and-wrong Info form inputs — cleared as soon as the
   player edits that group again (see the input listener in buildInfoForm). */
.info-row .letters-inputs input.wrong {
  background: #fddede;
  border-color: #e04b4b;
  color: #7a1a1a;
  font-weight: bold;
}

/* ============================================================
   COVER SCREEN
   ============================================================ */
#cover-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#cover-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
}
#cover-progress-track {
  position: absolute;
  bottom: 8%;
  left: 15%;
  right: 15%;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.15);
  overflow: hidden;
}
#cover-progress-bar {
  height: 100%;
  width: 0%;
  background: #4a91a4;
  border-radius: 3px;
  transition: width 3s linear;
}

/* Idle-hint particle drift */
.idle-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(circle, #dff4ff 0%, #7fd6ff 60%, transparent 100%);
  box-shadow: 0 0 8px 3px rgba(127,214,255,0.7);
  pointer-events: none;
  z-index: 32;
  opacity: 0.9;
  transition: transform 1.6s ease-out, opacity 1.6s ease-out;
}

/* ============================================================
   ROTATE DEVICE OVERLAY — shown only in portrait mode
   ============================================================ */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #0a0a0a;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #eaf7f9;
  padding: 20px;
}
#rotate-icon {
  font-size: 60px;
  margin-bottom: 18px;
  animation: rotateHint 1.8s ease-in-out infinite;
  color: #4a91a4;
}
#rotate-overlay p {
  font-family: 'Georgia', serif;
  font-size: 16px;
  line-height: 1.5;
}
@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
@media (orientation: portrait) and (max-width: 900px) {
  #rotate-overlay { display: flex; }
}
