*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #06142e 0%, #01010a 55%, #000 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: #f8f8ff;
}

.wrapper {
  width: 100%;
  max-width: 620px;
  padding: 16px;
  position: relative;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: #7ee8ff;
  text-decoration: none;
  font-size: 0.85rem;
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.back-link:hover {
  opacity: 1;
  text-decoration: underline;
}

canvas:focus {
  outline: 2px solid rgba(0, 255, 255, 0.45);
  outline-offset: 2px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.title {
  font-size: 1.8rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: center;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: center;
  font-size: 0.9rem;
}

.score-label,
.level-label,
.highscore-label,
.lives-label {
  background: rgba(0, 0, 0, 0.4);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.level-label {
  border-color: rgba(0, 255, 255, 0.3);
}

.highscore-label {
  border-color: rgba(245, 195, 59, 0.4);
  color: #ffd966;
}

.restart-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  background: #f5c33b;
  color: #1b1b1b;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease,
    background 0.15s ease;
}

.restart-btn:hover {
  background: #ffd54a;
}

.restart-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  width: 100%;
}

.power-bar-track {
  width: 100%;
  max-width: 560px;
  height: 6px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(33, 33, 222, 0.4);
}

.power-bar-track.hidden {
  visibility: hidden;
  opacity: 0;
}

.power-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #2121de, #4bc6ff);
  border-radius: 999px;
  transition: width 0.08s linear;
}

.power-bar-fill.warning {
  background: linear-gradient(90deg, #ff4b4b, #ffd966);
  animation: power-flash 0.4s ease infinite alternate;
}

@keyframes power-flash {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

canvas {
  border-radius: 8px;
  border: 2px solid #0ff;
  background: #000016;
  box-shadow: 0 0 18px rgba(0, 255, 255, 0.3);
  max-width: 100%;
}

canvas.touch-play-active,
.dpad.touch-play-active {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.hint {
  font-size: 0.8rem;
  opacity: 0.75;
  text-align: center;
}

.dpad {
  display: none;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
  user-select: none;
}

.dpad-btn {
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 12px;
  background: rgba(0, 255, 255, 0.12);
  color: #7ee8ff;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 255, 255, 0.25),
    0 4px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.1s ease, transform 0.08s ease;
}

.dpad-btn:active {
  background: rgba(0, 255, 255, 0.28);
  transform: scale(0.94);
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 2; }

@media (pointer: coarse), (max-width: 720px) {
  .dpad {
    display: grid;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.timer-label {
  background: rgba(255, 75, 75, 0.15);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 75, 75, 0.35);
  color: #ff8a8a;
}

.rating-label {
  background: rgba(245, 195, 59, 0.12);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(245, 195, 59, 0.35);
  color: #ffd966;
}

.hidden {
  display: none !important;
}

.overlay-panel {
  width: 100%;
  max-width: 560px;
  background: rgba(0, 8, 30, 0.92);
  border: 1px solid rgba(0, 255, 255, 0.25);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.mode-menu {
  margin-bottom: 4px;
}

.panel-title {
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 6px;
  color: #7ee8ff;
}

.panel-sub {
  font-size: 0.8rem;
  text-align: center;
  opacity: 0.75;
  margin-bottom: 12px;
}

.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-card {
  text-align: left;
  border: 1px solid rgba(0, 255, 255, 0.2);
  background: rgba(0, 255, 255, 0.06);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
  touch-action: manipulation;
}

.mode-card:hover {
  background: rgba(0, 255, 255, 0.14);
  border-color: rgba(0, 255, 255, 0.45);
}

.mode-name {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  color: #ffd966;
}

.mode-desc {
  display: block;
  font-size: 0.78rem;
  opacity: 0.8;
  margin-top: 4px;
}

.mode-best {
  display: block;
  font-size: 0.75rem;
  color: #7ee8ff;
  margin-top: 4px;
}

.streak-label,
.friend-score {
  text-align: center;
  font-size: 0.8rem;
  color: #7ee8ff;
  margin-top: 8px;
}

.pact-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pact-card {
  border: 1px solid rgba(255, 214, 102, 0.3);
  background: rgba(255, 214, 102, 0.08);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  color: inherit;
  text-align: left;
  touch-action: manipulation;
}

.pact-name {
  display: block;
  font-weight: 700;
  color: #ffd966;
}

.pact-desc {
  display: block;
  font-size: 0.78rem;
  opacity: 0.85;
  margin-top: 4px;
}

.run-summary .summary-rating {
  text-align: center;
  font-size: 2.4rem;
  font-weight: 800;
  color: #ffd966;
  margin: 8px 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-item {
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.bar-chart {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.75rem;
}

.bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #2121de, #4bc6ff);
  border-radius: 999px;
}

.summary-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.restart-btn.secondary {
  background: transparent;
  color: #7ee8ff;
  border: 1px solid rgba(0, 255, 255, 0.35);
  box-shadow: none;
}

.share-hint {
  text-align: center;
  font-size: 0.8rem;
  color: #7ee8ff;
  margin-top: 8px;
}

@media (max-width: 520px) {
  .title {
    font-size: 1.4rem;
  }

  .scoreboard {
    font-size: 0.82rem;
    gap: 6px;
  }

  canvas {
    width: 100%;
    height: auto;
  }
}
