:root {
  /* Paleta extraída del personaje de 4Dry (sprite) */
  --brand-blue-light: #7caedb;
  --brand-blue: #538db7;
  --brand-blue-dark: #1a2e41;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  /* 100vh en móvil no coincide con el alto real visible cuando la barra de
     direcciones se muestra/oculta -eso empuja los botones fuera de pantalla-.
     100dvh sí se ajusta; se declara después como mejora progresiva. */
  height: 100vh;
  height: 100dvh;
  background: #12122a;
  overflow: hidden;
  font-family: "Nunito", "Trebuchet MS", Verdana, Arial, sans-serif;
  color: #f2f2ff;
  user-select: none;
  touch-action: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  background: #2b2f6b;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
  border-radius: 6px;
}

#hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

#scoreBox {
  background: rgba(10, 10, 30, 0.55);
  border: 2px solid var(--brand-blue);
  border-radius: 10px;
  padding: 6px 16px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: nowrap;
  pointer-events: none;
}

.iconBtn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(10, 10, 30, 0.55);
  border: 2px solid var(--brand-blue);
  color: #f2f2ff;
  cursor: pointer;
  padding: 0;
}

.iconBtn:active {
  background: rgba(255, 255, 255, 0.15);
}

.iconBtn.hidden {
  display: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 26, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  z-index: 10;
}

.hidden {
  display: none !important;
}

.title {
  font-size: 34px;
  font-weight: 900;
  margin: 0 0 4px 0;
  text-shadow: 0 3px 0 var(--brand-blue);
}

.title.small {
  font-size: 26px;
}

.accent {
  color: var(--brand-blue-light);
}

.subtitle {
  margin: 0 0 10px 0;
  opacity: 0.85;
}

.instructions {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px 16px;
  margin-bottom: 6px;
  width: 100%;
  max-width: 320px;
}

.instructionsTitle {
  margin: 0 0 10px 0;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  color: var(--brand-blue-light);
  letter-spacing: 0.2px;
}

.instructionsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.instructionsList li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  line-height: 1.35;
  text-align: left;
}

.instrIcon {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
}

.instrIcon.move {
  background: var(--brand-blue);
}

.instrIcon.jump {
  background: var(--brand-blue-dark);
}

.instrIcon.platform {
  background: #b29c61;
  color: #241d10;
}

.instrIcon.blood {
  background: #9e2a2a;
}

.instrIcon.speed {
  background: rgba(255, 255, 255, 0.14);
  font-size: 11px;
}

/* En dispositivos táctiles el movimiento es sólo por inclinación; en desktop,
   sólo por teclado. Mismo criterio que el resto de los controles (pointer).
   Especificidad ".instructionsList .mobileOnly" a propósito: debe ganarle a
   ".instructionsList li" (que fija display:flex para todas las filas). */
.instructionsList .mobileOnly {
  display: none;
}

@media (pointer: coarse) {
  .instructionsList .desktopOnly {
    display: none;
  }
  .instructionsList .mobileOnly {
    display: flex;
  }
}

.instructionsList .mobileOnly.hidden {
  display: none;
}

/* Selector "Botones" / "Inclinación": sólo tiene sentido en táctil. */
#controlModeToggle {
  display: none;
}

@media (pointer: coarse) {
  #controlModeToggle {
    display: flex;
  }
}

.segmented {
  gap: 4px;
  padding: 4px;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  width: 100%;
  max-width: 320px;
}

.segmentBtn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  border-radius: 999px;
  padding: 9px 4px;
  background: transparent;
  color: rgba(242, 242, 255, 0.65);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.segmentBtn svg {
  flex: 0 0 auto;
}

.segmentBtn[aria-selected='true'] {
  background: var(--brand-blue);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* En pantallas angostas, con 4 opciones el texto no entra cómodo: se deja
   sólo el ícono (con el label como aria-label / tooltip nativo del button). */
@media (max-width: 380px) {
  .segmentBtn .label {
    display: none;
  }
  .segmentBtn {
    padding: 10px 6px;
  }
}

/* Joystick virtual: se posiciona por JS pegado al recuadro real del canvas
   (ver resizeCanvas en game.js), igual que los demás controles táctiles. */
#joystickControl {
  display: none;
}

@media (pointer: coarse) {
  #joystickControl {
    display: block;
    position: absolute;
    bottom: 38px;
    z-index: 4;
  }
  #joystickControl.hidden {
    display: none;
  }
}

#joystickBase {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(20, 20, 45, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

#joystickKnob {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(83, 141, 183, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  /* Sin transition por defecto: durante el arrastre debe seguir al dedo 1:1,
     sin ningún retraso (si no, la perilla puede verse "yendo" hacia un lado
     mientras el personaje ya responde a la nueva posición real del dedo).
     La animación de vuelta al centro se agrega sólo al soltar, con .snapBack. */
}

#joystickKnob.snapBack {
  transition: transform 0.12s ease-out;
}

.brandFooter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  opacity: 0.85;
}

.brandFooter span {
  font-size: 11px;
  letter-spacing: 0.4px;
  color: rgba(242, 242, 255, 0.6);
  text-transform: uppercase;
}

/* medix-logo.png es un cuadrado de 1080x1080 con mucho margen transparente
   arriba/abajo; el logo real ocupa sólo una franja angosta al centro. Se
   recorta con background-size/position en vez de mostrar todo el cuadrado
   (si no, quedaría un espacio vacío enorme alrededor del texto). */
.brandLogo {
  width: 180px;
  height: 52px;
  background-image: url('images/ui/medix-logo.png');
  background-repeat: no-repeat;
  background-size: 194.4px 194.4px;
  background-position: -7.2px -71.3px;
}

/* Enlace sutil a los créditos: discreto, no debe competir con "Jugar". */
.creditsLink {
  margin-top: 10px;
  background: none;
  border: none;
  padding: 4px 8px;
  color: rgba(242, 242, 255, 0.4);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.creditsLink:hover,
.creditsLink:active {
  color: rgba(242, 242, 255, 0.7);
}

.creditsList {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 14px 16px;
  max-height: 44vh;
  overflow-y: auto;
}

.creditsList li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  font-size: 13px;
  text-align: left;
}

.creditsSoundName {
  font-weight: 800;
  flex-basis: 100%;
  color: var(--brand-blue-light);
}

.creditsList a {
  color: #f2f2ff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.creditsAuthor {
  opacity: 0.7;
}

.btn {
  background: var(--brand-blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 28px;
  font-size: 18px;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--brand-blue-dark);
  transition: transform 0.08s ease;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--brand-blue-dark);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.btn.secondary {
  background: #3d4a9c;
  box-shadow: 0 4px 0 #232c62;
}

.btn.secondary:active {
  box-shadow: 0 1px 0 #232c62;
}

.finalScore {
  font-size: 22px;
  margin: 0 0 8px 0;
}

#scoreForm {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

#playerNameInput {
  border-radius: 8px;
  border: none;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  width: 160px;
  text-align: center;
}

.leaderboard {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 10px 18px;
  min-width: 220px;
  max-height: 34vh;
  overflow-y: auto;
  font-size: 14px;
}

.leaderboard h3 {
  margin: 0 0 6px 0;
  font-size: 15px;
  color: var(--brand-blue-light);
}

.leaderboard ol {
  margin: 0;
  padding-left: 20px;
  text-align: left;
}

.leaderboard li {
  padding: 2px 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.leaderboard li span.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

