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

body {
  background-color: #060a0f;
  background-image: radial-gradient(ellipse at 50% 0%, rgba(74, 222, 128, 0.06) 0%, transparent 60%);
  color: #e0e0e0;
  font-family: 'Courier New', Courier, monospace;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 24px 16px 32px;
}

#container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 740px;
}

h1 {
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  letter-spacing: 0.5em;
  color: #4ade80;
  text-shadow:
    0 0 10px rgba(74, 222, 128, 0.8),
    0 0 30px rgba(74, 222, 128, 0.4),
    0 0 60px rgba(74, 222, 128, 0.15);
}

#score-board {
  display: flex;
  gap: 32px;
  font-size: clamp(0.7rem, 2.5vw, 0.82rem);
  letter-spacing: 0.1em;
  color: #4b5563;
  text-transform: uppercase;
}

#score-board strong {
  color: #4ade80;
  font-size: 1em;
}

/* ---- Layout principal ---- */

#game-area {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  width: 100%;
  justify-content: center;
}

#left-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

/* ---- Canvas ---- */

#canvas-wrapper {
  position: relative;
  width: min(520px, calc(100vw - 32px));
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow:
    0 0 0 1px rgba(74, 222, 128, 0.15),
    0 0 24px rgba(74, 222, 128, 0.12),
    0 0 60px rgba(74, 222, 128, 0.05);
  touch-action: none;
}

/* ---- Overlay ---- */

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  background-color: rgba(6, 10, 15, 0.88);
  backdrop-filter: blur(6px);
  border-radius: 8px;
  transition: opacity 0.25s ease;
  opacity: 0;
  pointer-events: none;
  padding: 24px;
}

#overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#overlay-title {
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  font-weight: bold;
  letter-spacing: 0.4em;
  color: #4ade80;
  text-shadow:
    0 0 10px rgba(74, 222, 128, 0.9),
    0 0 30px rgba(74, 222, 128, 0.4);
}

#overlay-message {
  font-size: clamp(0.72rem, 2.5vw, 0.82rem);
  color: #6b7280;
  letter-spacing: 0.05em;
  text-align: center;
}

/* Formulário de nome */
#name-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#name-form.hidden { display: none; }

#name-label {
  font-size: 0.75rem;
  color: #6b7280;
  letter-spacing: 0.05em;
}

#player-name {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(74, 222, 128, 0.25);
  border-radius: 5px;
  color: #e0e0e0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  padding: 9px 16px;
  text-align: center;
  width: min(200px, 80%);
  outline: none;
  transition: border-color 0.15s;
}

#player-name:focus { border-color: rgba(74, 222, 128, 0.55); }
#player-name::placeholder { color: #374151; }

#form-buttons {
  display: flex;
  gap: 10px;
}

#btn-save, #btn-skip {
  padding: 9px 22px;
  border-radius: 5px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid;
  touch-action: manipulation;
}

#btn-save {
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
  border-color: rgba(74, 222, 128, 0.35);
}
#btn-save:hover { background: rgba(74, 222, 128, 0.28); }

#btn-skip {
  background: transparent;
  color: #4b5563;
  border-color: rgba(255, 255, 255, 0.08);
}
#btn-skip:hover { color: #6b7280; }

/* Botão principal */
#btn-start {
  margin-top: 4px;
  padding: 12px 36px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #022c22;
  border: none;
  border-radius: 6px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  font-weight: bold;
  letter-spacing: 0.18em;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: 0 0 16px rgba(74, 222, 128, 0.3);
  transition: all 0.15s ease;
  touch-action: manipulation;
}
#btn-start:hover {
  background: linear-gradient(135deg, #4ade80, #22c55e);
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.55);
  transform: translateY(-1px);
}
#btn-start:active { transform: translateY(0); }

/* ---- D-pad ---- */

#dpad {
  display: none;
  grid-template-columns: repeat(3, 72px);
  grid-template-rows: repeat(3, 72px);
  gap: 8px;
}

[data-dir="up"]    { grid-column: 2; grid-row: 1; }
[data-dir="left"]  { grid-column: 1; grid-row: 2; }
[data-dir="pause"] { grid-column: 2; grid-row: 2; }
[data-dir="right"] { grid-column: 3; grid-row: 2; }
[data-dir="down"]  { grid-column: 2; grid-row: 3; }

.dpad-btn {
  width: 72px;
  height: 72px;
  background: rgba(74, 222, 128, 0.08);
  border: 1px solid rgba(74, 222, 128, 0.2);
  border-radius: 14px;
  color: #4ade80;
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.1s, transform 0.08s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dpad-btn:active,
.dpad-btn.pressed {
  background: rgba(74, 222, 128, 0.22);
  transform: scale(0.92);
}

.dpad-center {
  font-size: 1.2rem;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
  color: #6b7280;
}

.dpad-center:active { background: rgba(255, 255, 255, 0.1); }

/* ---- Leaderboard ---- */

#leaderboard {
  width: 195px;
  height: 520px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(74, 222, 128, 0.1);
  border-radius: 8px;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#leaderboard h2 {
  font-size: 0.72rem;
  letter-spacing: 0.3em;
  color: #4ade80;
  text-align: center;
  text-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
  flex-shrink: 0;
}

#rank-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

#rank-list::-webkit-scrollbar { width: 3px; }
#rank-list::-webkit-scrollbar-track { background: transparent; }
#rank-list::-webkit-scrollbar-thumb { background: rgba(74, 222, 128, 0.2); border-radius: 2px; }

.rank-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-radius: 5px;
  font-size: 0.75rem;
}

.rank-entry.destaque { background: rgba(74, 222, 128, 0.07); }

.rank-pos {
  width: 18px;
  text-align: center;
  font-weight: bold;
  font-size: 0.7rem;
  color: #4b5563;
  flex-shrink: 0;
}

.pos-1 .rank-pos { color: #fbbf24; }
.pos-2 .rank-pos { color: #94a3b8; }
.pos-3 .rank-pos { color: #cd7c2f; }

.rank-info { flex: 1; overflow: hidden; }

.rank-name {
  display: block;
  color: #d1d5db;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-date {
  display: block;
  font-size: 0.62rem;
  color: #374151;
  margin-top: 1px;
}

.rank-score {
  color: #4ade80;
  font-weight: bold;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.rank-empty {
  color: #374151;
  font-size: 0.72rem;
  text-align: center;
  padding: 32px 0;
}

/* ---- Rodapé ---- */

#controls-hint {
  display: flex;
  gap: 36px;
  font-size: 0.7rem;
  color: #374151;
  letter-spacing: 0.04em;
}

#credits {
  font-size: 0.65rem;
  color: #1f2937;
  letter-spacing: 0.08em;
}

/* ================================================================
   RESPONSIVO — tablet / mobile (< 760px)
   ================================================================ */

@media (max-width: 760px) {

  body {
    padding: 16px 12px 40px;
    align-items: flex-start;
  }

  #game-area {
    flex-direction: column;
    align-items: center;
    gap: 16px;
  }

  #left-col {
    width: 100%;
    gap: 14px;
  }

  #canvas-wrapper {
    width: min(520px, calc(100vw - 24px));
  }

  /* D-pad aparece no mobile */
  #dpad { display: grid; }

  /* Leaderboard vira faixa horizontal abaixo do jogo */
  #leaderboard {
    width: min(520px, calc(100vw - 24px));
    height: auto;
    min-height: unset;
    flex-direction: row;
    align-items: flex-start;
    padding: 14px;
    gap: 10px;
  }

  #leaderboard h2 {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    letter-spacing: 0.25em;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding-right: 10px;
    border-right: 1px solid rgba(74, 222, 128, 0.1);
    font-size: 0.65rem;
  }

  #rank-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 160px;
    overflow-y: auto;
  }

  .rank-entry {
    width: calc(50% - 2px);
    padding: 5px 6px;
  }

  .rank-date { display: none; }

  /* Oculta hint de teclado, substituído pelo dpad */
  #controls-hint { display: none; }
}

/* ---- Telas muito pequenas (< 380px) ---- */
@media (max-width: 380px) {
  .dpad-btn {
    width: 62px;
    height: 62px;
    font-size: 1.3rem;
    border-radius: 12px;
  }

  #dpad {
    grid-template-columns: repeat(3, 62px);
    grid-template-rows: repeat(3, 62px);
    gap: 6px;
  }
}
