/*
 * Styles for the Idle RPG Clicker game.
 *
 * This stylesheet defines a portrait-oriented layout tailored to 9:16
 * displays.  It contains all of the rules necessary to create a simple
 * clicker game: a dark theme, a status HUD at the top, a central monster
 * area with animated features, upgrade/reset controls at the bottom and an
 * overlay prompting players to rotate their device when in landscape.  By
 * bundling these rules directly with the plugin you avoid external
 * dependencies and ensure the game always looks correct when the plugin
 * loads.
 */

/* CSS custom properties for easy theming */
:root {
  --background: #0a192f; /* Dark backdrop */
  --panel: #14213d;     /* Panels and HUD backgrounds */
  --accent: #e5e5e5;    /* Light text */
  --gold: #f4c542;      /* Gold colour used for currency */
  --hp-full: #3fb950;   /* Colour of full health bar */
  --hp-empty: #8644a0;  /* Colour of empty health bar */
  --button-primary: #0066cc; /* Upgrade button background */
  --button-secondary: #444;
  --button-text: #ffffff;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--background);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--accent);
  /* ✅ Prevent desktop scrollbars due to 100vh/ratio math */
  overflow: hidden;
}

/* Outer wrapper centres the game vertically and horizontally */
.app-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fill the entire viewport so the game can break out of parent container
     restrictions imposed by themes like Hello Elementor. */
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
  /* Allow JS to mirror level background here if desired */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Game container is constrained in size for mobile aspect ratios */
.game {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* Heads-up display (HUD) showing stats */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.4);
  font-size: 12px;
  /* ✅ Ensure reset button doesn’t cover gold: leave space on the right */
  padding-right: 52px;
  position: relative;
  z-index: 10;
}

.badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  background: var(--panel);
  border-radius: 6px;
}

.badge .label {
  font-size: 9px;
  text-transform: uppercase;
  color: #888;
  letter-spacing: 0.5px;
}

.badge span:not(.label) {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.grow {
  flex-grow: 1;
}

/* Arena holds the monster and bottom controls */
.arena {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 0;
  position: relative;
}

.monster-zone {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  /* ✅ Ensure the background fully covers the playable canvas */
  width: 100%;
  height: 100%;
  /* Enable custom backgrounds for each level. Set in JS. */
  background-size: cover !important;
  background-position: center !important;
  background-repeat: no-repeat !important;
}

/* Monster container defines clickable area */
.monster {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  user-select: none;
  /* Establish a positioning context so floating texts can be positioned
     absolutely relative to the monster when damage/gold effects appear. */
  position: relative;

  /* --- ADDED: For fast multi-tap --- */
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
  touch-action: manipulation; /* Disable double-tap zoom, reduce tap delay */
}

/* Monster face uses simple shapes (eyes and mouth) to evoke a creature */
.face {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #79c24a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.monster.hit .face {
  transform: scale(0.95);
}

.eyes {
  display: flex;
  gap: 18px;
  margin-bottom: 8px;
}

.eye {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  overflow: hidden;
  position: relative;
}

.pupil {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #000;
  position: absolute;
  top: 7px;
  left: 7px;
  transition: transform 0.1s;
}

/* Simple mouth drawn as a line; can be animated if desired */
.mouth {
  width: 50px;
  height: 0;
  border-bottom: 5px solid #d72638;
  border-radius: 0 0 25px 25px;
}

/* Health bar below the monster */
.hpbar {
  width: 180px;
  height: 12px;
  background: var(--hp-empty);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 12px;
}

.hpbar .fill {
  height: 100%;
  background: var(--hp-full);
  width: 100%;
  transition: width 0.2s ease;
}

.monster-name {
  margin-top: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* Monster image placeholder.  When a custom image is provided for a level,
   this image is shown instead of the default face. */
.monster-img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  display: none; /* hidden by default; shown via JS when image is loaded */
}

/* Top-right reset button.  Visible only to administrators when output by PHP.
   This is positioned absolutely inside the game container. */
.reset-top {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 4px;
  width: 32px;
  height: 32px;
  font-size: 14px;
  font-weight: 600;
  color: var(--button-text);
  background: var(--button-secondary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  z-index: 50; /* ✅ above HUD but content leaves space for it */
  opacity: 0.8;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reset-top:hover {
  opacity: 1;
}

/* Enlarged DMG display inside the stats tooltip */
.stat-dmg {
  font-size: 32px;
  font-weight: 700;
  color: var(--gold);
  margin-right: 4px;
}

/* Stats modal overlay */
.stats-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.upgrade-modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}

.upgrade-content {
  background: var(--panel);
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 360px;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

.upgrade-content h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 20px;
  color: var(--gold);
}

.upgrade-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  justify-content: flex-end;
}

.dps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.dps-item {
  background: var(--panel);
  border: 1px solid #1f2a44;
  border-radius: 6px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: background 0.2s ease;
}
.dps-item:hover {
  filter: brightness(90%);
}
.dps-item.purchased {
  opacity: 0.5;
  cursor: default;
}
.dps-item img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

/* Intro video overlay */
.intro-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.intro-video {
  width: 90%;
  max-width: 480px;
  border-radius: 8px;
  outline: none;
}
.stats-content {
  background: var(--panel);
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 320px;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.stats-content h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 20px;
  color: var(--gold);
}

.stats-content ul {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
}

.stats-content ul li {
  margin-bottom: 6px;
  font-size: 14px;
}

/* Bottom panel for buttons and stats */
.bottom {
  width: 100%;
  padding: 12px 10px;
  background: rgba(0, 0, 0, 0.45);
  box-sizing: border-box;
}

.row {
  display: flex;
  margin-bottom: 8px;
}

button {
  flex-grow: 1;
  padding: 8px 10px;
  margin: 0 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--button-text);
  background: var(--button-primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  /* Use flex layout inside buttons to align icons and text nicely */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button.secondary {
  background: var(--button-secondary);
}

button.primary {
  background: var(--button-primary);
}

/* Style icons inside buttons */
button i {
  font-size: 16px;
  line-height: 1;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button:not(:disabled):hover {
  /* Slightly darken the button on hover using filter for broad browser support */
  filter: brightness(90%);
}

button:not(:disabled):active {
  transform: scale(0.97);
}

/* Tooltip used for stats display */
.tooltip {
  font-size: 12px;
  color: #ccc;
  background: rgba(0, 0, 0, 0.75);
  padding: 6px;
  border-radius: 4px;
  min-height: 20px;
  text-align: center;
}

/* Overlay prompting users to rotate to portrait */
.rotate {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  color: var(--accent);
  padding: 20px;
  z-index: 100;
}

.rotate .card {
  background: var(--panel);
  padding: 20px;
  border-radius: 8px;
  max-width: 280px;
}

.rotate h2 {
  margin: 0 0 10px;
  font-size: 20px;
  color: var(--gold);
}

.rotate p {
  margin: 0;
  font-size: 14px;
  line-height: 1.4;
}

/* Show rotate overlay and hide the game when in landscape */
@media screen and (orientation: landscape) and (max-width: 600px) {
  .rotate {
    display: flex;
  }
  .game {
    display: none;
  }
}

/*
 * Responsive sizing rules.  These use viewport units and the
 * orientation media feature to size the game container.  In portrait
 * orientation the game fills the entire viewport (both width and height),
 * while in landscape orientation the height fills the viewport and the
 * width is computed from a 9:16 aspect ratio.  This ensures the game is
 * maximised on phones and larger screens alike without distortion.
 */
@media screen and (orientation: portrait) {
  .game {
    width: 100vw;
    height: 100vh;
  }
}

@media screen and (orientation: landscape) {
  .game {
    height: 100vh;
    width: calc(100vh * 9 / 16);
  }
}

/* Floating damage/gold effects */
.floating-text {
  position: absolute;
  font-weight: 600;
  pointer-events: none;
  z-index: 100;
  animation: float-up 1s ease-out forwards;
  white-space: nowrap;
  font-size: 18px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  /* Reset any default transform; the JS will position this and the
     keyframe animation will handle upward movement. */
  transform: translateY(0);
}

.floating-text.damage {
  color: #e74c3c; /* red */
  /* Increase the floating damage text size for greater visibility */
  font-size: 36px;
}

.floating-text.gold {
  color: var(--gold);
  /* Slightly enlarge gold text compared to the default */
  font-size: 26px;
}

@keyframes float-up {
  0% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px);
  }
}

/* Bounce animation for monster when taking damage.  The monster
   bounces up slightly and scales before returning to its original
   position, giving a sense of impact. */
@keyframes bounce {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  30% {
    transform: translateY(-15px) scale(1.05);
  }
  60% {
    transform: translateY(0) scale(0.98);
  }
}

/* Apply the bounce animation to the entire monster container (face or
   image).  Combined with .hit this produces a satisfying hit effect. */
.monster.bounce {
  animation: bounce 0.3s ease-out;
}