:root {
  --arcade: 'Press Start 2P', 'Courier New', monospace;
  --ink: #1d2530;
  --paper: #fdf6e3;
  --accent: #ffcf3f;
  --accent-dark: #e6a817;
}

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

html, body {
  height: 100%;
  background: #10141c;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: var(--arcade);
  -webkit-user-select: none;
  user-select: none;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 0.65625)); /* 420/640 */
  aspect-ratio: 420 / 640;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  overflow: hidden;
}

@supports (height: 100dvh) {
  #stage { width: min(100vw, calc(100dvh * 0.65625)); }
}

/* Phones: fill the whole screen; canvas adapts its logical height */
@media (max-width: 500px) {
  #stage {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
  }
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

button, .overlay { touch-action: manipulation; }

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
}

.overlay.hidden { display: none; }

#title {
  background: linear-gradient(180deg, #1e2a1c 0%, #2c3f28 55%, #3a5232 100%);
  gap: 16px;
}

#title > :first-child { margin-top: auto; }
#title > :last-child { margin-bottom: auto; }

#title-face {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  animation: hopIdle 1.1s ease-in-out infinite;
}

@keyframes hopIdle {
  0%, 100% { transform: translateY(0) scale(1, 0.96); }
  30% { transform: translateY(-14px) scale(0.96, 1.04); }
  60% { transform: translateY(0) scale(1.04, 0.94); }
}

.title {
  color: var(--accent);
  text-align: center;
  font-size: 27px;
  line-height: 1.3;
  text-shadow: 3px 3px 0 #1d2530, 5px 5px 0 rgba(0, 0, 0, 0.35);
  letter-spacing: 2px;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #d7e6cf;
  font-size: 9px;
}

#player-name {
  font-family: var(--arcade);
  font-size: 10px;
  padding: 8px 10px;
  width: 150px;
  border: 3px solid #1d2530;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  text-transform: uppercase;
  outline: none;
}

.howto {
  text-align: center;
  color: #b9d3ae;
  font-size: 8px;
  line-height: 2.1;
}

/* ---------- Map cards ---------- */

#map-cards {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: 300px;
}

.map-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 11px;
  border: 3px solid #1d2530;
  border-radius: 8px;
  cursor: pointer;
  background: var(--paper);
  transition: transform 0.08s ease;
}

.map-card:active { transform: scale(0.98); }

.map-card.selected {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.map-card.locked {
  background: #39424e;
  cursor: not-allowed;
}

.map-card .swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid #1d2530;
  flex: none;
}

.map-card .info { flex: 1; min-width: 0; }

.map-card .map-name {
  font-size: 9px;
  color: var(--ink);
  margin-bottom: 4px;
}

.map-card.locked .map-name { color: #cfd8e2; }

.map-card .map-sub {
  font-size: 7px;
  color: #5a6673;
  line-height: 1.5;
}

.map-card.locked .map-sub { color: #8d99a7; }

.map-card .lock-icon { font-size: 14px; }

.home-link {
  color: #8fb383;
  font-size: 8px;
  text-decoration: none;
  margin-top: 6px;
}

/* ---------- Buttons ---------- */

.menu-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  font-family: var(--arcade);
  font-size: 11px;
  padding: 12px 18px;
  border: 3px solid #1d2530;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 #1d2530;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1d2530;
}

.btn-primary { background: var(--accent); }

/* ---------- Game over ---------- */

#over { background: rgba(10, 14, 20, 0.55); }

.panel {
  margin: auto 0;
  background: var(--paper);
  border: 4px solid #1d2530;
  border-radius: 12px;
  padding: 20px 18px;
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.subtitle {
  color: #d9534f;
  font-size: 16px;
  text-shadow: 2px 2px 0 rgba(29, 37, 48, 0.25);
}

.cause {
  font-size: 8px;
  color: #5a6673;
  text-align: center;
  line-height: 1.6;
}

.score-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 12px;
  color: var(--ink);
}

.score-row span:last-child { color: var(--accent-dark); }

.submit-status {
  font-size: 8px;
  color: #5a6673;
  text-align: center;
  line-height: 1.6;
  min-height: 13px;
}

.unlock-banner {
  background: var(--accent);
  border: 2px solid #1d2530;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 8px;
  color: var(--ink);
  text-align: center;
  line-height: 1.6;
  animation: pulse 0.9s ease-in-out infinite;
}

.unlock-banner.hidden { display: none; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

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

#board {
  background: linear-gradient(180deg, #141a26 0%, #1f2a3d 100%);
  gap: 14px;
}

#board > :first-child { margin-top: auto; }
#board > :last-child { margin-bottom: auto; }

.board-title {
  color: var(--accent);
  font-size: 16px;
  text-shadow: 2px 2px 0 #1d2530;
  text-align: center;
}

#board-tabs {
  display: flex;
  gap: 6px;
}

.board-tab {
  font-family: var(--arcade);
  font-size: 8px;
  padding: 8px 9px;
  border: 2px solid #1d2530;
  border-radius: 6px;
  background: #39424e;
  color: #cfd8e2;
  cursor: pointer;
}

.board-tab.active {
  background: var(--accent);
  color: var(--ink);
}

#board-list {
  list-style: none;
  width: 100%;
  max-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 200px;
}

#board-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(253, 246, 227, 0.08);
  border-radius: 6px;
  padding: 8px 10px;
  color: #e8eef7;
  font-size: 9px;
}

#board-list li .rank {
  color: var(--accent);
  width: 26px;
  flex: none;
}

#board-list li .bname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#board-list li .bscore { color: var(--accent); }

#board-status {
  color: #8d99a7;
  font-size: 8px;
  text-align: center;
  line-height: 1.6;
  min-height: 13px;
}
