:root {
  color-scheme: light;
  --bg-top: #170b2e;
  --bg-mid: #2a1450;
  --bg-bottom: #421d72;
  --text: #f5f0ff;
  --frame: #b584ff;
  --panel: rgba(34, 14, 62, 0.75);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 15% 8%, #7e43df 0%, transparent 35%),
    radial-gradient(circle at 85% 95%, #4c1d95 0%, transparent 38%),
    linear-gradient(165deg, var(--bg-top), var(--bg-mid), var(--bg-bottom));
  color: var(--text);
}

.app {
  width: min(96vw, 860px);
  padding: 10px 0 16px;
}

h1 {
  margin: 0 0 10px;
  text-align: center;
  letter-spacing: 0.05em;
  text-shadow: 0 0 16px rgba(181, 132, 255, 0.45);
}

.exit-row {
  margin: 0 0 10px;
  text-align: center;
}

.exit-game {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(211, 171, 255, 0.62);
  background: rgba(39, 14, 67, 0.75);
  color: #f8e8ff;
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.exit-game:hover {
  background: rgba(62, 24, 102, 0.88);
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(0, 1fr);
  align-items: start;
  gap: 14px;
}

.player-panel {
  margin: 0 auto 12px;
  max-width: 760px;
  border: 1px solid rgba(211, 171, 255, 0.45);
  border-radius: 14px;
  padding: 10px;
  background: rgba(35, 13, 63, 0.7);
}

.player-top {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 78px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.player-label {
  font-size: 0.8rem;
  opacity: 0.9;
}

.player-input,
.player-select {
  width: 100%;
  border: 1px solid rgba(211, 171, 255, 0.55);
  border-radius: 8px;
  background: rgba(17, 7, 31, 0.9);
  color: #f5f0ff;
  padding: 8px;
  font-size: 0.84rem;
}

.player-btn {
  border: 0;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #2f0d4f;
  background: #d5a0ff;
}

.player-status {
  margin: 4px 0 8px;
  font-size: 0.8rem;
  color: #edd6ff;
}

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

.board-box {
  border: 1px solid rgba(211, 171, 255, 0.35);
  border-radius: 10px;
  padding: 8px;
  background: rgba(20, 7, 36, 0.65);
}

.board-box h3 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.board-box ol {
  margin: 0;
  padding-left: 18px;
  font-size: 0.8rem;
  line-height: 1.35;
  min-height: 40px;
}

.quick-guide {
  text-align: left;
  border: 1px solid rgba(211, 171, 255, 0.45);
  border-radius: 16px;
  padding: 14px 14px 12px;
  background:
    radial-gradient(circle at 75% 12%, rgba(255, 182, 244, 0.22), transparent 50%),
    linear-gradient(180deg, rgba(55, 22, 92, 0.94), rgba(26, 11, 47, 0.9));
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.quick-guide h2 {
  margin: 0 0 7px;
  font-family: "Copperplate", "Avenir Next", "Trebuchet MS", sans-serif;
  letter-spacing: 0.06em;
  font-size: 1rem;
}

.guide-main {
  margin: 0 0 8px;
  font-size: 0.93rem;
  line-height: 1.35;
  color: #ffe9ff;
}

.guide-device {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.34;
  opacity: 0.92;
}

.game-column {
  text-align: center;
}

canvas {
  width: 100%;
  max-width: 480px;
  border: 2px solid var(--frame);
  border-radius: 14px;
  background: #080412;
  box-shadow:
    0 18px 42px rgba(0, 0, 0, 0.5),
    0 0 28px rgba(181, 132, 255, 0.28);
  touch-action: none;
}

.controls {
  margin: 10px 0 0;
  font-size: 0.89rem;
  line-height: 1.35;
  opacity: 0.92;
}

.controls-mobile,
.guide-mobile {
  display: none;
}

body.touch-device .controls-desktop,
body.touch-device .guide-desktop {
  display: none;
}

body.touch-device .controls-mobile,
body.touch-device .guide-mobile {
  display: block;
}

.mobile-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.mobile-actions {
  display: grid;
  gap: 10px;
}

.control-btn {
  border: 0;
  border-radius: 999px;
  width: 110px;
  height: 84px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #f4f6fb;
  background: rgba(181, 132, 255, 0.18);
  box-shadow: inset 0 0 0 2px rgba(181, 132, 255, 0.42);
  touch-action: manipulation;
}

.control-btn.action {
  background: rgba(255, 132, 226, 0.2);
  box-shadow: inset 0 0 0 2px rgba(255, 132, 226, 0.55);
}

.control-btn.restart {
  background: rgba(110, 204, 255, 0.18);
  box-shadow: inset 0 0 0 2px rgba(110, 204, 255, 0.55);
  height: 56px;
  font-size: 0.9rem;
}

.control-btn.pause {
  background: rgba(255, 194, 121, 0.2);
  box-shadow: inset 0 0 0 2px rgba(255, 194, 121, 0.6);
  height: 56px;
  font-size: 0.9rem;
}

.control-btn:active {
  transform: translateY(1px) scale(0.99);
}

.joystick {
  position: relative;
  width: 130px;
  height: 130px;
  border-radius: 999px;
  background: rgba(181, 132, 255, 0.16);
  box-shadow: inset 0 0 0 2px rgba(181, 132, 255, 0.35);
  touch-action: none;
}

.joystick::after {
  content: "";
  position: absolute;
  inset: 24px;
  border-radius: 999px;
  border: 1px solid rgba(181, 132, 255, 0.48);
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 30%, #f8e7ff 0%, #c999ff 65%, #9d60f7 100%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: transform 0.06s linear;
}

@media (min-width: 901px) {
  .mobile-controls {
    display: none;
  }
}

@media (max-width: 900px) {
  .app {
    width: min(92vw, 540px);
  }

  .play-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .quick-guide {
    text-align: center;
    padding: 12px;
  }

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

@media (max-width: 420px) {
  .player-top {
    grid-template-columns: 1fr;
  }

  .joystick {
    width: 108px;
    height: 108px;
  }

  .control-btn {
    width: 92px;
    height: 72px;
    font-size: 0.92rem;
  }

  .control-btn.restart {
    height: 48px;
    font-size: 0.82rem;
  }

  .control-btn.pause {
    height: 48px;
    font-size: 0.82rem;
  }
}
