:root {
  --bg: #050b15;
  --panel: rgba(5, 17, 31, .94);
  --panel2: rgba(8, 30, 46, .88);
  --green: #4dffbd;
  --blue: #55baff;
  --yellow: #ffe66d;
  --red: #ff5f7a;
  --purple: #b982ff;
  --white: #edf8ff;
  --muted: #9fb8c7;
  --line: rgba(77,255,189,.42);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--white);
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top left, rgba(85,186,255,.16), transparent 30%),
              radial-gradient(circle at top right, rgba(77,255,189,.14), transparent 28%),
              linear-gradient(135deg, #020610, #061321, #021b22);
  overflow-x: hidden;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .28;
  background-image:
    radial-gradient(#ffffff55 1px, transparent 1px),
    linear-gradient(rgba(85,186,255,.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77,255,189,.09) 1px, transparent 1px);
  background-size: 90px 90px, 42px 42px, 42px 42px;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 24px;
  align-items: center;
  justify-content: center;
}

.screen.active { display: flex; }

.card, .modal-card, .side {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0 38px rgba(77,255,189,.13), inset 0 0 24px rgba(85,186,255,.06);
  border-radius: 24px;
  backdrop-filter: blur(10px);
}

.card {
  width: min(850px, 96vw);
  padding: 32px;
  text-align: center;
}

.menu-card { padding: 40px; }

.badge {
  width: 88px;
  height: 88px;
  margin: 0 auto 18px;
  border-radius: 25px;
  display: grid;
  place-items: center;
  color: #011820;
  font-size: 46px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--green), var(--blue));
  box-shadow: 0 0 34px rgba(77,255,189,.45);
}

h1 {
  margin: 0;
  font-size: clamp(38px, 7vw, 76px);
  letter-spacing: 1px;
}

h2 { color: var(--green); margin-top: 8px; }

p { color: var(--muted); line-height: 1.55; }

label {
  display: block;
  margin: 22px 0 8px;
  color: var(--green);
  font-weight: 800;
}

input {
  width: min(420px, 92%);
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.32);
  color: var(--white);
  font-size: 18px;
  outline: none;
}

button {
  border: 0;
  cursor: pointer;
  border-radius: 14px;
  padding: 13px 20px;
  font-weight: 900;
  color: #011820;
  background: linear-gradient(135deg, var(--green), var(--blue));
  transition: transform .12s ease, filter .12s ease;
}

button:hover { transform: translateY(-2px); filter: brightness(1.08); }

button.secondary {
  color: var(--white);
  border: 1px solid rgba(85,186,255,.45);
  background: rgba(85,186,255,.12);
}

button.danger {
  color: var(--white);
  border: 1px solid rgba(255,95,122,.55);
  background: rgba(255,95,122,.14);
}

.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 22px;
}

.hud {
  position: fixed;
  z-index: 30;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(1280px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.hud div {
  border: 1px solid rgba(77,255,189,.26);
  background: rgba(3, 12, 22, .86);
  border-radius: 14px;
  padding: 9px 10px;
}

.hud span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.hud b {
  color: var(--green);
  font-size: 17px;
}

#game {
  padding-top: 78px;
}

.game-layout {
  width: min(1380px, 100%);
  display: grid;
  grid-template-columns: 1fr 285px;
  gap: 16px;
  align-items: start;
}

.canvas-wrap { width: 100%; }

canvas {
  width: 100%;
  max-width: 1024px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: #061120;
  box-shadow: 0 0 35px rgba(85,186,255,.12);
}

.side {
  padding: 20px;
  min-height: 520px;
}

.ability-list {
  display: grid;
  gap: 9px;
  margin: 15px 0;
}

.ability {
  padding: 10px;
  border-radius: 14px;
  border: 1px solid rgba(85,186,255,.34);
  background: rgba(85,186,255,.08);
}

.ability.unlocked {
  border-color: rgba(77,255,189,.65);
  background: rgba(77,255,189,.13);
  color: var(--green);
}

.ability.locked { color: var(--muted); }

.legend p {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.dot {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  display: inline-block;
}

.dot.mission { background: var(--yellow); box-shadow: 0 0 15px var(--yellow); }
.dot.chest { background: var(--purple); box-shadow: 0 0 15px var(--purple); }
.dot.crystal { background: var(--green); box-shadow: 0 0 15px var(--green); }
.dot.door { background: var(--red); box-shadow: 0 0 15px var(--red); }
.dot.portal { background: var(--blue); box-shadow: 0 0 15px var(--blue); }

.toast {
  position: fixed;
  z-index: 70;
  top: 88px;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, calc(100vw - 24px));
  padding: 14px 18px;
  border-radius: 16px;
  border: 1px solid rgba(77,255,189,.5);
  background: rgba(3, 14, 24, .94);
  color: var(--white);
  text-align: center;
  box-shadow: 0 0 24px rgba(77,255,189,.2);
}

.toast.hidden { display: none; }

.mobile-controls {
  display: none;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  padding: 0 15px;
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.dpad-row-up {
  display: flex;
  justify-content: center;
}

.dpad-row-mid {
  display: flex;
  gap: 5px;
}

.action-buttons {
  position: relative;
  width: 130px;
  height: 130px;
}

.mobile-controls button {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  background: rgba(3, 14, 24, 0.85);
  border: 1px solid rgba(85,186,255,0.5);
  color: var(--blue);
  box-shadow: inset 0 0 8px rgba(85,186,255,0.2), 0 0 12px rgba(85,186,255,0.1);
  transition: all 0.1s;
}

.mobile-controls button:active {
  background: rgba(85,186,255,0.3);
  box-shadow: inset 0 0 15px rgba(85,186,255,0.5);
}

.action-buttons button {
  position: absolute;
  width: 48px;
  height: 48px;
  font-size: 16px;
  border-color: rgba(77,255,189,.5);
  color: var(--green);
  box-shadow: inset 0 0 8px rgba(77,255,189,.2), 0 0 12px rgba(77,255,189,.1);
}

.action-buttons button:active {
  background: rgba(77,255,189,.3);
  box-shadow: inset 0 0 15px rgba(77,255,189,.5);
}

#mobileDash { bottom: 0; left: 41px; }
#mobileShield { top: 41px; left: 0; }
#mobileHint { top: 0; left: 41px; }

.modal {
  position: fixed;
  z-index: 90;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 5, 12, .75);
  padding: 18px;
}

.modal.hidden { display: none; }

.modal-card {
  width: min(820px, 96vw);
  padding: 24px;
}

.mission-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}

.mini {
  margin: 0;
  color: var(--blue);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 1px;
}

.method-tag {
  color: var(--green);
  border: 1px solid rgba(77,255,189,.48);
  background: rgba(77,255,189,.09);
  padding: 10px 14px;
  border-radius: 999px;
  white-space: nowrap;
}

.equations {
  margin: 16px 0;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(85,186,255,.35);
  background: rgba(0,0,0,.28);
  font-family: "Courier New", monospace;
  font-size: 21px;
  white-space: pre-line;
}

.question { color: var(--white); }

.answer-box {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.answer-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.answer-row input { width: 150px; }

.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.option {
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(85,186,255,.45);
  background: rgba(85,186,255,.09);
  cursor: pointer;
}

.option.selected {
  border-color: var(--green);
  background: rgba(77,255,189,.18);
  box-shadow: 0 0 18px rgba(77,255,189,.25);
}

.hint-box {
  margin: 12px 0;
  padding: 12px;
  border-radius: 15px;
  border: 1px solid rgba(255,230,109,.55);
  background: rgba(255,230,109,.10);
  color: var(--yellow);
}

.hint-box.hidden { display: none; }

.feedback {
  margin-top: 16px;
  padding: 15px;
  border-radius: 16px;
  white-space: pre-line;
}

.feedback.ok {
  border: 1px solid rgba(77,255,189,.6);
  background: rgba(77,255,189,.12);
}

.feedback.bad {
  border: 1px solid rgba(255,95,122,.58);
  background: rgba(255,95,122,.12);
}

.hidden { display: none; }

.score-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  margin: 10px 0;
  border-radius: 14px;
  border: 1px solid rgba(85,186,255,.35);
  background: rgba(85,186,255,.09);
  text-align: left;
}

.end-icon { font-size: 70px; }

@media (max-width: 980px) {
  .game-layout { grid-template-columns: 1fr; }
  .side { min-height: auto; }
  .mobile-controls { display: block; }
  .hud { grid-template-columns: repeat(3, 1fr); }
  #game { padding-top: 125px; }
}

@media (max-width: 620px) {
  .hud { grid-template-columns: repeat(2, 1fr); }
  #game { padding-top: 185px; }
  .mission-head { flex-direction: column; }
}


/* Ajustes extra para jugar desde celular */
html, body {
  touch-action: none;
  overscroll-behavior: none;
}

.canvas-wrap {
  position: relative;
}

.mobile-controls {
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.mobile-controls button {
  font-size: 13px;
  border-radius: 14px;
}

@media (max-width: 980px) {
  .screen {
    padding: 10px;
  }

  #game {
    padding-top: 138px;
    align-items: flex-start;
  }

  .game-layout {
    gap: 10px;
  }

  canvas {
    width: 100%;
    height: auto;
    max-height: 56vh;
    object-fit: contain;
    display: block;
  }

  .side {
    padding: 14px;
    font-size: 14px;
  }

  .side h2 {
    margin: 4px 0 8px;
  }

  .side p {
    margin: 6px 0;
  }

  .ability-list {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .ability {
    padding: 8px;
  }

  .legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 8px;
  }

  .legend p {
    margin: 5px 0;
    font-size: 12px;
  }

  .mobile-controls {
    display: flex;
  }

  .modal-card {
    max-height: 92vh;
    overflow-y: auto;
    padding: 18px;
  }

  .equations {
    font-size: 18px;
  }
}

@media (max-width: 620px) {
  .hud {
    top: 6px;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .hud div {
    padding: 6px 8px;
  }

  .hud span {
    font-size: 10px;
  }

  .hud b {
    font-size: 14px;
  }

  #game {
    padding-top: 170px;
  }

  .card, .modal-card, .side {
    border-radius: 18px;
  }

  .menu-card {
    padding: 24px;
  }

  h1 {
    font-size: 38px;
  }

  input {
    width: 100%;
  }

  .answer-row input {
    width: 120px;
  }

  .options {
    grid-template-columns: 1fr;
  }
}
