@import url("https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap");

:root {
  --bg: #09090c;
  --bg-2: #111218;
  --panel: #151623;
  --maze: #0b0b10;
  --wall: #2e4bff;
  --wall-glow: rgba(46, 75, 255, 0.35);
  --text: #e8e7f0;
  --muted: #a5a4b0;
  --yellow: #f6d54c;
  --blue: #5ecbff;
  --green: #34d399;
  --cyanide: #ff3b3b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1a1b28 0%, #0b0b12 40%, #050507 100%);
  color: var(--text);
  font-family: "Press Start 2P", "Trebuchet MS", Verdana, sans-serif;
}

.wrap {
  width: min(920px, 95vw);
  padding: 28px 24px 32px;
  background: linear-gradient(135deg, rgba(21, 22, 35, 0.95), rgba(9, 10, 18, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.45);
}

.title {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.title h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 28px);
  letter-spacing: 1px;
}

.title p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(10px, 1.6vw, 12px);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  background: var(--maze);
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 30px var(--wall-glow);
  image-rendering: pixelated;
  touch-action: none;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font-size: 14px;
}

.dot.pellet {
  background: var(--yellow);
  box-shadow: 0 0 10px rgba(246, 213, 76, 0.5);
}

.dot.diamond {
  width: 16px;
  height: 16px;
  background: var(--blue);
  transform: rotate(45deg);
  border-radius: 3px;
  box-shadow: 0 0 12px rgba(94, 203, 255, 0.6);
}

.dot.rapa {
  background: var(--green);
  box-shadow: 0 0 12px rgba(52, 211, 153, 0.6);
}

.dot.cyanide {
  background: var(--cyanide);
  box-shadow: 0 0 12px rgba(255, 59, 59, 0.7);
}

.dot.scientist {
  background: #1b1b22;
}

.controls {
  margin-top: 18px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.touch-controls {
  margin-top: 16px;
  display: none;
  grid-template-columns: repeat(3, 78px);
  grid-template-rows: repeat(2, 78px);
  gap: 12px;
  justify-content: center;
  align-items: center;
}

.touch-btn {
  width: 78px;
  height: 78px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(21, 22, 35, 0.9);
  color: var(--text);
  font-family: "Press Start 2P", sans-serif;
  font-size: 20px;
  cursor: pointer;
  touch-action: none;
}

.touch-btn:active {
  background: rgba(94, 203, 255, 0.35);
  border-color: rgba(94, 203, 255, 0.6);
}

.touch-btn:focus-visible {
  outline: 2px solid rgba(94, 203, 255, 0.8);
  outline-offset: 2px;
}

.touch-btn.up {
  grid-column: 2;
  grid-row: 1;
}

.touch-btn.left {
  grid-column: 1;
  grid-row: 2;
  transform: rotate(-90deg);
}

.touch-btn.down {
  grid-column: 2;
  grid-row: 2;
  transform: rotate(180deg);
}

.touch-btn.right {
  grid-column: 3;
  grid-row: 2;
  transform: rotate(90deg);
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }
}

.leaderboard {
  margin-top: 20px;
  padding: 16px;
  background: rgba(10, 11, 18, 0.7);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard h2 {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text);
}

.leaderboard ol {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 10px;
  display: grid;
  gap: 6px;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.leaderboard .score {
  color: var(--text);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 10, 0.75);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: min(360px, 90vw);
  background: #121421;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 14px;
}

.modal-text {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.modal-score {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 10px;
}

.modal-card label {
  font-size: 10px;
  color: var(--muted);
}

.modal-card input {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #0b0c15;
  color: var(--text);
  font-family: inherit;
  font-size: 10px;
}

.modal-card button {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #5ecbff, #3a79ff);
  color: #08101a;
  font-family: inherit;
  font-size: 10px;
  cursor: pointer;
}

.modal-card button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.modal-card ol {
  margin: 0 0 16px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 10px;
  display: grid;
  gap: 6px;
}

.modal-card ol li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal-card ol .score {
  color: var(--text);
}

.modal-error {
  margin: 10px 0 0;
  font-size: 9px;
  color: #ff8a8a;
  min-height: 12px;
}

@media (max-width: 640px) {
  .wrap {
    padding: 20px 16px 24px;
  }

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