/* ---------- Page layout ----------
   The page is a column: the game (sized by game.js to fit, without stretching),
   then the touch controls on phones and tablets. */
html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #111;
  font-family: Arial, sans-serif;
  touch-action: none;   /* stops pinch-zoom and scrolling while playing */
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* game.js sets the width and height of this box to match the game picture */
#game-container {
  position: relative;
  flex: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

/* Red border around the whole browser window, shown briefly when KorbyKid is hurt */
#damage-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 0 30px rgba(255, 0, 0, 0.85);
  transition: opacity 0.15s;
}

#damage-flash.show {
  opacity: 1;
}

/* ---------- Title screen ---------- */
/* The title + Play button sit on top of the game picture */
#menu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 1s;
}

#menu.hidden {
  opacity: 0;
  pointer-events: none;
}

#menu.visible {
  opacity: 1;
  pointer-events: auto;
}

/* The title words are hidden on the title screen; only the Play button shows */
#menu h1 {
  display: none;
  margin: 0;
  color: #fff;
  font-size: clamp(32px, 6vw, 64px);
  text-shadow: 3px 3px 0 #000;
}

/* ---------- Buttons ---------- */
#play-button,
#continue-button,
#title-button {
  font-size: 28px;
  font-weight: bold;
  padding: 12px 48px;
  border: none;
  border-radius: 10px;
  background: #ffcc00;
  box-shadow: 0 6px 0 #b38f00;
  cursor: pointer;
}

#play-button:active {
  transform: translateY(4px);
  box-shadow: none;
}

/* The Continue and Return to Title buttons stack in the center of the death screen */
#continue-button,
#title-button {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
}

#continue-button {
  top: calc(50% - 40px);
}

#title-button {
  top: calc(50% + 50px);
  font-size: 22px;
  padding: 10px 36px;
  background: #cfd8dc;
  box-shadow: 0 6px 0 #78909c;
}

#continue-button[hidden],
#title-button[hidden] {
  display: none;
}

#continue-button:active {
  transform: translate(-50%, calc(-50% + 4px));
  box-shadow: none;
}

#title-button:active {
  transform: translate(-50%, calc(-50% + 4px));
  box-shadow: none;
}

/* ---------- Background darkness setting (on the title screen) ---------- */
#darkness-setting,
.volume-setting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #fff;
  font-size: 18px;
  text-shadow: 2px 2px 0 #000;
}

#darkness-slider,
#music-slider,
#sound-slider {
  width: 220px;
  cursor: pointer;
}

/* The Return to Title button on the win screen, below the message */
#win-title-button {
  position: absolute;
  left: 62%;
  top: 62%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  font-weight: bold;
  padding: 12px 48px;
  border: none;
  border-radius: 10px;
  background: #ffcc00;
  box-shadow: 0 6px 0 #b38f00;
  cursor: pointer;
}

#win-title-button[hidden] {
  display: none;
}

#win-title-button:active {
  transform: translate(-50%, calc(-50% + 4px));
  box-shadow: none;
}

/* ---------- Characters screen ---------- */
#characters-button,
#characters-back-button {
  font-weight: bold;
  border: none;
  border-radius: 10px;
  background: #cfd8dc;
  box-shadow: 0 6px 0 #78909c;
  cursor: pointer;
}

#characters-button {
  font-size: 22px;
  padding: 10px 36px;
}

#characters-button:active,
#characters-back-button:active {
  transform: translateY(4px);
  box-shadow: none;
}

/* Covers the game picture; the grid of characters scrolls if it is too tall */
#characters-screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  box-sizing: border-box;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
}

#characters-screen[hidden] {
  display: none;
}

.characters-title {
  margin: 4px 0;
  font-size: clamp(24px, 4vw, 40px);
}

#characters-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 860px;
}

.character-card {
  padding: 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
}

.character-card img {
  width: 90px;
  height: 90px;
  object-fit: contain;
}

.character-card h3 {
  margin: 6px 0 4px;
  font-size: 18px;
}

.character-card p {
  margin: 0;
  font-size: 14px;
  line-height: 1.35;
}

#characters-back-button {
  font-size: 20px;
  padding: 8px 32px;
}

/* ---------- Polish: hover, pop-in and gentle motion ----------
   The motion is skipped for people who have asked their computer to reduce motion. */
#play-button,
#continue-button,
#title-button,
#characters-button,
#characters-back-button,
.touch-button {
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

#play-button:hover,
#continue-button:hover,
#title-button:hover,
#characters-button:hover,
#characters-back-button:hover {
  filter: brightness(1.08);
}


.character-card {
  transition: transform 0.2s ease, background 0.2s ease;
}

.character-card:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.14);
}

@media (prefers-reduced-motion: no-preference) {
  /* The Play button gently breathes, to invite a press */
  @keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
  }

  #play-button {
    animation: breathe 2.4s ease-in-out infinite;
  }

  #play-button:active {
    animation: none;
  }

  /* Continue and Return to Title pop in when the death screen appears */
  @keyframes pop-in {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    70% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
    100% { transform: translate(-50%, -50%) scale(1); }
  }

  #continue-button:not([hidden]),
  #title-button:not([hidden]) {
    animation: pop-in 0.35s ease-out both;
  }

  #title-button:not([hidden]) {
    animation-delay: 0.1s;
  }

  /* The characters screen fades and slides up */
  @keyframes slide-up {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
  }

  #characters-screen:not([hidden]) {
    animation: slide-up 0.3s ease-out both;
  }

  .character-card {
    animation: slide-up 0.4s ease-out both;
  }

  .character-card:nth-child(2) { animation-delay: 0.05s; }
  .character-card:nth-child(3) { animation-delay: 0.10s; }
  .character-card:nth-child(4) { animation-delay: 0.15s; }
  .character-card:nth-child(5) { animation-delay: 0.20s; }
  .character-card:nth-child(6) { animation-delay: 0.25s; }
  .character-card:nth-child(7) { animation-delay: 0.30s; }
}

/* ---------- Touch controls (shown only on touch screens) ---------- */
#touch-controls {
  display: none;
  box-sizing: border-box;
  width: 100%;
  padding: 10px 14px 14px;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body.touch-device #touch-controls {
  display: flex;
}

.touch-group {
  display: flex;
  gap: 14px;
}

.touch-button {
  width: 76px;
  height: 76px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  touch-action: none;
  -webkit-touch-callout: none;
}

.touch-button.pressed {
  background: rgba(255, 255, 255, 0.45);
}

/* On a phone held sideways, the buttons are smaller so they don't crowd the game */
@media (max-height: 500px) {
  .touch-button {
    width: 60px;
    height: 60px;
    font-size: 18px;
  }
}
