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

html,
body {
  height: 100%;
}

body {
  background: #1d2430;
  color: #ecf0f1;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

header {
  width: 100%;
  max-width: 560px;
  padding: 8px 12px 4px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

header h1 {
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  color: #f1c40f;
}

header .tagline {
  font-size: 0.72rem;
  color: #95a5a6;
  text-align: right;
}

#hud {
  width: 100%;
  max-width: 560px;
  padding: 2px 12px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

#hud-score {
  font-weight: 700;
  color: #f1c40f;
}

#hud-best {
  color: #95a5a6;
}

.heart {
  color: #e74c3c;
  font-size: 1.05rem;
  margin-left: 2px;
}

.heart.lost {
  color: #4a5568;
}

#stage {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0 8px;
  min-height: 0;
}

#frame {
  position: relative;
  width: min(100%, 480px, calc((100dvh - 140px) * 0.75));
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

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

#banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 92%;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.2s;
}

#banner.danger {
  background: rgba(192, 57, 43, 0.92);
  color: #fff;
}

#banner.good {
  background: rgba(39, 174, 96, 0.92);
  color: #fff;
}

#banner.hidden {
  opacity: 0;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 28, 0.88);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  font-size: 1.4rem;
  color: #f1c40f;
}

.overlay p {
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 340px;
  color: #d5dbe1;
}

.overlay .rules {
  text-align: left;
  font-size: 0.8rem;
  line-height: 1.6;
  max-width: 340px;
  color: #bdc3c7;
  list-style: none;
}

.overlay .rules li::before {
  content: "\2022";
  color: #f1c40f;
  margin-right: 8px;
}

.overlay button {
  font: inherit;
  font-weight: 700;
  padding: 10px 26px;
  border: none;
  border-radius: 8px;
  background: #f1c40f;
  color: #1d2430;
  cursor: pointer;
}

.overlay button:hover {
  background: #f4d03f;
}

#over-record {
  color: #2ecc71;
  font-weight: 700;
}

#over-record.hidden {
  display: none;
}

#controls {
  width: 100%;
  max-width: 560px;
  padding: 8px 12px 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
}

#controls button {
  font: inherit;
  font-size: 0.8rem;
  padding: 8px 14px;
  border: 1px solid #4a5568;
  border-radius: 8px;
  background: #2a3444;
  color: #ecf0f1;
  cursor: pointer;
}

#controls button:hover {
  background: #35415a;
}

#controls button.hidden {
  display: none;
}

@media (max-width: 360px) {
  header h1 {
    font-size: 1rem;
  }

  header .tagline {
    display: none;
  }

  #hud {
    font-size: 0.78rem;
  }
}
