* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0d0d1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Courier New", monospace;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-wrap {
  position: relative;
  width: 960px;
  height: 540px;
  max-width: 100vw;
  max-height: 100dvh;
  box-shadow: 0 0 0 4px #1a1a2e, 0 0 40px rgba(0,0,0,0.6);
  image-rendering: pixelated;
  touch-action: none;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: #7ec0ee;
}

#fireworks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  font-size: 22px;
  color: #fff;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  z-index: 5;
}

#hud-score {
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.3);
}

#hud-lives-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  pointer-events: none;
}

#hud-hero-name {
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #ffd23f;
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
  padding-right: 4px;
}

#hud-lives {
  display: flex;
  gap: 6px;
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.3);
}

.life-icon {
  width: 22px;
  height: 22px;
  background: #ff4d6d;
  clip-path: polygon(50% 15%, 61% 0%, 78% 0%, 100% 22%, 100% 40%, 50% 100%, 0% 40%, 0% 22%, 22% 0%, 39% 0%);
}

.life-icon.lost {
  background: #3a3a4a;
  opacity: 0.5;
}

#hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

#hud-level {
  pointer-events: none;
  background: rgba(0,0,0,0.35);
  padding: 6px 14px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.3);
  font-size: 16px;
  white-space: nowrap;
}

#btn-fullscreen, #btn-mute, #btn-restart {
  pointer-events: auto;
  background: rgba(0,0,0,0.35);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 8px;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 6px 12px;
  cursor: pointer;
}
#btn-fullscreen:active, #btn-mute:active, #btn-restart:active { transform: translateY(1px); }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(180deg, rgba(10,10,25,0.88), rgba(10,10,25,0.94));
  color: #fff;
  text-align: center;
  z-index: 10;
  padding: 20px;
  pointer-events: auto;
}

.screen.hidden { display: none; }

.screen h1 {
  font-size: 56px;
  margin: 0;
  letter-spacing: 4px;
  color: #ffd23f;
  text-shadow: 4px 4px 0 #d1495b, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.screen p {
  font-size: 16px;
  line-height: 1.6;
  max-width: 560px;
  color: #e8e8f0;
}

.screen p.flavor {
  font-size: 14px;
  color: #ff8fa3;
  font-style: italic;
  margin-top: -10px;
}

.controls {
  font-size: 14px;
  color: #bdbdd6;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.touch-hint {
  display: none;
  font-size: 12px;
  color: #8fd18f;
}

kbd {
  background: #2e2e42;
  border: 2px solid #565676;
  border-bottom-width: 4px;
  border-radius: 4px;
  padding: 3px 8px;
  margin: 0 2px;
  font-size: 13px;
  color: #fff;
}

.btn {
  font-family: inherit;
  font-size: 22px;
  letter-spacing: 2px;
  padding: 12px 36px;
  background: #ffd23f;
  border: none;
  border-bottom: 5px solid #c99b1e;
  border-radius: 8px;
  color: #3a2a00;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.08s ease;
}

.btn:hover { filter: brightness(1.08); }
.btn:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.btn-secondary {
  background: #3a3a52;
  border-bottom-color: #202030;
  color: #e8e8f0;
  font-size: 16px;
  padding: 10px 28px;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#gameover-score, #win-score {
  font-size: 20px;
  color: #ffd23f;
}

.scores-list {
  list-style: none;
  counter-reset: rank;
  padding: 0;
  margin: 0;
  width: 100%;
  max-width: 420px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scores-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 15px;
}

.scores-list li::before {
  content: counter(rank);
  font-weight: bold;
  color: #ffd23f;
  width: 20px;
  text-align: right;
}

.scores-list li:nth-child(1)::before { color: #ffd23f; }
.scores-list li .s-score {
  font-weight: bold;
  color: #ffd23f;
  min-width: 70px;
}
.scores-list li .s-donuts {
  color: #ff8fa3;
  flex: 1;
}
.scores-list li .s-date {
  color: #8f8fa8;
  font-size: 12px;
}

.scores-empty {
  color: #8f8fa8;
  font-size: 14px;
}

/* -------------------------------------------------------------------- */
/* Touch controls — shown around the screen edges on touch devices only */
/* -------------------------------------------------------------------- */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  display: none;
}

.touch-btn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(20, 20, 40, 0.55);
  border: 3px solid rgba(255,255,255,0.6);
  box-shadow: 0 4px 10px rgba(0,0,0,0.35), inset 0 2px 4px rgba(255,255,255,0.15);
  color: #fff;
  font-size: 30px;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.touch-btn.active {
  background: rgba(255, 210, 63, 0.65);
  border-color: #ffd23f;
  transform: scale(0.92);
}

#touch-left { left: 22px; bottom: 30px; }
#touch-right { left: 112px; bottom: 30px; }
#touch-jump {
  right: 28px;
  bottom: 30px;
  width: 96px;
  height: 96px;
  font-size: 36px;
  background: rgba(255, 77, 109, 0.4);
}
#touch-jump.active {
  background: rgba(255, 77, 109, 0.7);
}

html.touch-device #touch-controls { display: block; }
html.touch-device .touch-hint { display: block; }

@media (hover: none) and (pointer: coarse) {
  #touch-controls { display: block; }
  .touch-hint { display: block; }
}
