*{box-sizing:border-box;margin:0;padding:0}

body{
  background:radial-gradient(circle at top,#2b2106,#050505 55%);
  color:#f7d774;
  font-family:Arial,Helvetica,sans-serif;
  overflow:hidden;
  touch-action:none;
}

#gameWrap{
  width:100vw;
  height:100vh;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:flex-start;
  padding:12px;
}

.header{
  width:100%;
  max-width:520px;
  text-align:center;
  padding:8px 0 10px;
}

h1{
  font-size:22px;
  letter-spacing:.5px;
  text-shadow:0 0 12px #d6a800;
}

.tagline{
  font-size:13px;
  color:#fff2b2;
  margin-top:3px;
}

.stats{
  margin:10px auto;
  display:flex;
  justify-content:space-between;
  gap:8px;
  max-width:520px;
}

.statBox{
  flex:1;
  background:rgba(0,0,0,.55);
  border:1px solid #d6a800;
  border-radius:12px;
  padding:8px;
  box-shadow:0 0 12px rgba(214,168,0,.35);
}

.label{font-size:11px;color:#fff2b2}
.value{font-size:20px;font-weight:bold;color:#fff}

canvas{
  width:100%;
  max-width:520px;
  aspect-ratio:1/1;
  background:#070707;
  border:3px solid #d6a800;
  border-radius:18px;
  box-shadow:0 0 30px rgba(214,168,0,.55);
}


.joystick{
  margin-top:18px;
  width:160px;
  height:160px;
  border-radius:50%;
  border:2px solid #d6a800;
  background:radial-gradient(circle,#2b2106,#050505 70%);
  box-shadow:
    0 0 25px rgba(214,168,0,.75),
    inset 0 0 22px rgba(255,215,0,.35);
  position:relative;
  touch-action:none;
}

.stick{
  width:64px;
  height:64px;
  border-radius:50%;
  background:radial-gradient(circle,#fff8c7,#ffd700 45%,#b8860b);
  box-shadow:
    0 0 22px rgba(255,220,80,.95),
    0 0 38px rgba(0,229,255,.35);
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
}

.overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.82);
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding:20px;
  z-index:10;
}

.card{
  max-width:420px;
  width:100%;
  border:2px solid #d6a800;
  border-radius:22px;
  padding:24px;
  background:radial-gradient(circle at top,#3b2d08,#090909 65%);
  box-shadow:0 0 35px rgba(214,168,0,.75);
}

.card h2{
  font-size:30px;
  margin-bottom:10px;
}

.card p{
  color:#fff2b2;
  margin:8px 0;
}

.startBtn{
  margin-top:16px;
  padding:14px 24px;
  border-radius:999px;
  border:none;
  background:#d6a800;
  color:#080808;
  font-size:18px;
  font-weight:bold;
}

.hidden{display:none}

/* Player Name Overlay Polish */

.player-name-input{
  display:block;
  width:260px;
  margin:18px auto 16px;
  padding:10px 14px;
  text-align:center;
  font-size:22px;
  font-weight:bold;
  border-radius:10px;
  border:2px solid #d6a800;
  outline:none;
}

.player-name-input:focus{
  box-shadow:0 0 18px rgba(214,168,0,.9);
}

.maze-start-btn{
    display:block;
    margin:0 auto;
    width:280px;
}

/* ==========================================
   PLAYER RESULTS + LEADERBOARD
========================================== */

.hidden {
  display: none !important;
}

.player-results-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;

  display: flex;
  align-items: flex-start;
  justify-content: center;

  overflow-y: auto;
  padding:
    max(18px, env(safe-area-inset-top))
    14px
    max(24px, env(safe-area-inset-bottom));

  background:
    radial-gradient(
      circle at top,
      rgba(183, 136, 22, 0.26),
      rgba(5, 5, 5, 0.96) 44%
    ),
    rgba(0, 0, 0, 0.96);

  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.player-results-card {
  width: min(100%, 520px);
  margin: auto;

  padding: 22px 16px 24px;

  border: 1px solid rgba(247, 215, 116, 0.48);
  border-radius: 22px;

  background:
    linear-gradient(
      180deg,
      rgba(31, 24, 7, 0.98),
      rgba(7, 7, 7, 0.99)
    );

  box-shadow:
    0 0 0 1px rgba(255, 224, 132, 0.08),
    0 0 36px rgba(222, 166, 34, 0.26),
    0 22px 70px rgba(0, 0, 0, 0.68);

  color: #f7d774;
}

.results-header {
  text-align: center;
}

.results-eyebrow {
  margin-bottom: 7px;

  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;

  color: #c99d37;
}

.results-header h2 {
  margin: 0;

  font-size: clamp(28px, 8vw, 42px);
  line-height: 1;
  letter-spacing: 1px;

  color: #fff1b5;

  text-shadow:
    0 0 8px rgba(255, 217, 106, 0.72),
    0 0 24px rgba(218, 155, 24, 0.48);
}

.results-player-name {
  margin: 12px 0 0;

  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1.4px;

  color: #ffffff;
}

.official-result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;

  margin-top: 20px;
}

.result-stat {
  min-height: 102px;

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  padding: 14px 8px;

  border: 1px solid rgba(247, 215, 116, 0.36);
  border-radius: 16px;

  background:
    radial-gradient(
      circle at top,
      rgba(244, 190, 54, 0.19),
      rgba(16, 13, 5, 0.86)
    );

  box-shadow:
    inset 0 0 20px rgba(255, 204, 75, 0.05),
    0 0 18px rgba(199, 145, 21, 0.08);
}

.result-label {
  margin-bottom: 8px;

  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;

  color: #cfae5e;
}

.result-stat strong {
  font-size: clamp(25px, 7vw, 36px);
  line-height: 1;

  color: #ffffff;
}

.results-status {
  margin: 14px 0 18px;
  padding: 10px 12px;

  border-radius: 10px;

  background: rgba(255, 210, 87, 0.09);

  text-align: center;
  font-size: 13px;
  font-weight: 700;

  color: #f7d774;
}

.results-status.success {
  background: rgba(65, 194, 113, 0.13);
  color: #8df0b1;
}

.results-status.error {
  background: rgba(229, 76, 76, 0.13);
  color: #ff9e9e;
}

.leaderboard-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;

  margin-bottom: 12px;
}

.leaderboard-kicker {
  display: block;
  margin-bottom: 3px;

  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;

  color: #c79c3b;
}

.leaderboard-heading h3 {
  margin: 0;

  font-size: 20px;
  color: #fff2bc;
}

.leaderboard-refresh-button,
.player-search-row button {
  min-height: 42px;

  border: 1px solid rgba(247, 215, 116, 0.55);
  border-radius: 10px;

  background:
    linear-gradient(
      180deg,
      #f0cf70,
      #b57c11
    );

  padding: 0 14px;

  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.5px;

  color: #171006;
  cursor: pointer;
}

.leaderboard-refresh-button:active,
.player-search-row button:active {
  transform: scale(0.98);
}

.player-search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;

  margin-bottom: 12px;
}

.player-search-row input {
  min-width: 0;
  min-height: 44px;

  padding: 0 12px;

  border: 1px solid rgba(247, 215, 116, 0.32);
  border-radius: 10px;

  background: rgba(0, 0, 0, 0.58);

  font-size: 16px;
  color: #ffffff;

  outline: none;
}

.player-search-row input:focus {
  border-color: rgba(247, 215, 116, 0.8);

  box-shadow:
    0 0 0 3px rgba(247, 215, 116, 0.1);
}

.player-search-row input::placeholder {
  color: rgba(255, 255, 255, 0.48);
}

.player-search-result {
  width: 100%;
  margin-top: 10px;
  padding: 14px 16px;

  border: 1px solid rgba(212, 175, 55, 0.28);
  border-radius: 14px;

  background: rgba(255, 255, 255, 0.04);
  color: #ffffff;

  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;

  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-word;
}

.search-result-row {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  align-items: center;
  gap: 10px;
}

.search-result-rank {
  font-size: 16px;
  font-weight: 900;
  color: #f7d774;
}

.search-result-name {
  overflow: hidden;

  font-size: 14px;
  font-weight: 800;

  color: #ffffff;

  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result-time {
  font-size: 14px;
  font-weight: 900;

  color: #f7d774;
}

.player-leaderboard-table-wrap {
  overflow: hidden;

  border: 1px solid rgba(247, 215, 116, 0.27);
  border-radius: 14px;
}

.player-leaderboard-table {
  width: 100%;
  border-collapse: collapse;

  background: rgba(0, 0, 0, 0.38);
}

.player-leaderboard-table th,
.player-leaderboard-table td {
  padding: 11px 10px;
  border-bottom: 1px solid rgba(247, 215, 116, 0.12);
}

.player-leaderboard-table th {
  background: rgba(247, 215, 116, 0.08);

  font-size: 10px;
  letter-spacing: 1px;
  text-align: left;

  color: #c9a650;
}

.player-leaderboard-table th:first-child,
.player-leaderboard-table td:first-child {
  width: 58px;
  text-align: center;
}

.player-leaderboard-table th:last-child,
.player-leaderboard-table td:last-child {
  text-align: right;
}

.player-leaderboard-table td {
  font-size: 14px;
  color: #ffffff;
}

.player-leaderboard-table tbody tr:last-child td {
  border-bottom: 0;
}

.player-leaderboard-table tbody tr.current-player {
  background:
    linear-gradient(
      90deg,
      rgba(255, 210, 74, 0.23),
      rgba(255, 210, 74, 0.08)
    );

  box-shadow:
    inset 3px 0 0 #f7d774;
}

.leaderboard-rank {
  font-weight: 900;
  color: #f7d774 !important;
}

.leaderboard-name {
  max-width: 190px;
  overflow: hidden;

  font-weight: 800;

  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-time {
  font-weight: 900;
  color: #f7d774 !important;
}

.leaderboard-loading,
.leaderboard-empty,
.leaderboard-error {
  padding: 22px 10px !important;

  text-align: center !important;
  color: rgba(255, 255, 255, 0.66) !important;
}

.results-footer-message {
  margin: 16px 4px 0;

  text-align: center;
  font-size: 12px;
  line-height: 1.45;

  color: rgba(255, 255, 255, 0.67);
}

@media (max-width: 380px) {
  .player-results-card {
    padding-left: 12px;
    padding-right: 12px;
  }

  .official-result {
    gap: 8px;
  }

  .result-stat {
    min-height: 92px;
  }

  .player-leaderboard-table th,
  .player-leaderboard-table td {
    padding-left: 7px;
    padding-right: 7px;
  }

  .leaderboard-name {
    max-width: 135px;
  }
}

.player-reward-button {
  width: 100%;
  margin-top: 18px;
  padding: 16px 18px;

  border: 1px solid rgba(212, 175, 55, 0.5);
  border-radius: 14px;

  color: #080808;
  background: linear-gradient(
    180deg,
    #f4d97f,
    #d4af37
  );

  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;

  cursor: pointer;
}

.player-reward-button:hover {
  filter: brightness(1.08);
}

.player-reward-button:active {
  transform: translateY(1px);
}

.spectator-round-clock {
  margin: 14px 0 18px;
  padding: 14px 16px;
  border: 1px solid rgba(250, 204, 21, 0.45);
  border-radius: 14px;
  background: rgba(250, 204, 21, 0.08);
  text-align: center;
}

.spectator-round-clock-label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  opacity: 0.85;
}

#spectatorRoundTime {
  display: block;
  margin: 5px 0;
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}

#spectatorRoundMessage {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  opacity: 0.8;
}

@media (max-width: 700px) {
  #timer {
    font-size: 30px;
    font-weight: 900;
  }

  .statBox .label {
    font-size: 11px;
    font-weight: 800;
  }

  #spectatorRoundTime {
    font-size: 36px;
  }
}