* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  height: 100%;
  background: #2c8a3e;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: none;
}

#game-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 480px;
  aspect-ratio: 400 / 700;
  margin: 0 auto;
  background: #8fd7ff;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.35);
}

@media (min-height: 700px) and (min-width: 480px) {
  #game-wrap { height: auto; top: 50%; position: relative; transform: translateY(-50%); }
}

canvas#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */

#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}

.hud-right {
  display: flex;
  gap: 6px;
}

.hud-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(30, 20, 10, 0.55);
  border: 2px solid rgba(255,255,255,0.55);
  border-radius: 999px;
  padding: 4px 10px 4px 6px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  min-height: 30px;
}

.hud-chip img {
  width: 20px;
  height: 20px;
  display: block;
}

#hud-hearts {
  gap: 3px;
}

#hud-hearts img {
  width: 22px;
  height: 22px;
}

.hud-pause {
  pointer-events: auto;
  border: 2px solid rgba(255,255,255,0.55);
  background: rgba(30, 20, 10, 0.55);
  color: #fff;
  border-radius: 999px;
  width: 30px;
  height: 30px;
  min-height: 30px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-pause:active {
  transform: translateY(1px);
}

/* ---------- Level banner & hit flash ---------- */

.banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  background: linear-gradient(180deg, #ffe066, #f2b100);
  border: 4px solid #7a4a00;
  border-radius: 16px;
  padding: 12px 26px;
  font-size: 26px;
  font-weight: 800;
  color: #4a2c00;
  text-shadow: 0 1px 0 rgba(255,255,255,0.4);
  z-index: 6;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}

.banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#hit-flash {
  position: absolute;
  inset: 0;
  background: rgba(220, 30, 30, 0.001);
  pointer-events: none;
  z-index: 4;
  transition: background 0.08s ease-out;
}

#hit-flash.flash {
  background: rgba(220, 30, 30, 0.45);
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 40, 15, 0.55);
  backdrop-filter: blur(2px);
}

.overlay.hidden {
  display: none;
}

.card {
  width: 84%;
  max-width: 340px;
  background: #fff8e6;
  border: 5px solid #3a7a2f;
  border-radius: 22px;
  padding: 22px 20px 26px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,0.2);
}

.card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  color: #2f5c22;
  text-shadow: 1px 1px 0 #fff;
}

.tagline {
  margin: 0 0 12px;
  color: #5a4a2a;
  font-weight: 600;
}

.rules {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  text-align: left;
  font-size: 14px;
  color: #3a3a3a;
  line-height: 1.7;
}

.rules li {
  padding: 4px 6px;
  background: rgba(139, 195, 74, 0.18);
  border-radius: 10px;
  margin-bottom: 6px;
}

.btn-primary {
  display: inline-block;
  border: none;
  background: linear-gradient(180deg, #9fe066, #6cb52e);
  color: #234a12;
  font-size: 19px;
  font-weight: 800;
  padding: 12px 34px;
  border-radius: 999px;
  box-shadow: 0 5px 0 #4a8a20, 0 8px 14px rgba(0,0,0,0.25);
  cursor: pointer;
  transition: transform 0.06s ease;
}

.btn-primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #4a8a20, 0 4px 8px rgba(0,0,0,0.2);
}

.actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn-secondary {
  display: inline-block;
  border: none;
  background: linear-gradient(180deg, #eee6c8, #dcd0a0);
  color: #5a4a2a;
  font-size: 16px;
  font-weight: 700;
  padding: 9px 26px;
  border-radius: 999px;
  box-shadow: 0 4px 0 #b6a565, 0 6px 10px rgba(0,0,0,0.18);
  cursor: pointer;
  transition: transform 0.06s ease;
}

.btn-secondary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #b6a565, 0 3px 6px rgba(0,0,0,0.15);
}

.hidden {
  display: none !important;
}

.hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: #7a7a7a;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 20px;
}

.stat {
  background: rgba(139, 195, 74, 0.18);
  border-radius: 14px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat img {
  width: 26px;
  height: 26px;
}

.stat-lvl {
  font-size: 22px;
}

.stat span {
  font-size: 20px;
  font-weight: 800;
  color: #2f5c22;
}

.stat label {
  font-size: 11px;
  color: #6a6a6a;
  font-weight: 600;
}

a.btn-primary,
a.btn-secondary {
  text-decoration: none;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  text-align: left;
  max-height: 46vh;
  overflow-y: auto;
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(139, 195, 74, 0.18);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14px;
  color: #3a3a3a;
}

.leaderboard-list .lb-rank {
  font-weight: 800;
  color: #2f5c22;
  min-width: 26px;
}

.leaderboard-list .lb-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .lb-score {
  font-weight: 800;
  color: #2f5c22;
}

.leaderboard-empty {
  color: #7a7a7a;
  font-size: 14px;
  margin: 0 0 18px;
}

#best-score-line {
  margin-top: -4px;
  font-weight: 700;
  color: #7a5a1a;
}

#fin-record-line {
  font-weight: 700;
}

#fin-record-line.is-new-record {
  color: #b6790a;
}

.abilities-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 0 0 16px;
}

.ability-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(139, 195, 74, 0.25);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #2f5c22;
}

.ability-chip-muted {
  background: rgba(120, 120, 120, 0.15);
  color: #7a7a7a;
  font-weight: 600;
}

.choice-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 6px;
}

.btn-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: linear-gradient(180deg, #9fe066, #6cb52e);
  color: #234a12;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 4px 0 #4a8a20, 0 6px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.06s ease;
}

.btn-choice:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #4a8a20, 0 3px 6px rgba(0,0,0,0.15);
}

.btn-choice .choice-icon {
  font-size: 22px;
  flex: none;
}
