html.embed,
body.embed {
  overflow: hidden;
}

body.embed .game-viewport,
body.embed .game-shell {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

.player-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  margin-top: 10px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 248, 223, 0.82);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.player-badge.is-user {
  border-color: rgba(76, 175, 80, 0.45);
  background: rgba(76, 175, 80, 0.14);
  color: #d7f5da;
  text-transform: none;
}

.player-badge.is-guest {
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 248, 223, 0.72);
}

.leaderboard-hint {
  margin: 0 0 10px;
  color: rgba(255, 248, 223, 0.72);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: center;
}

.leaderboard-hint a {
  color: #9fd4ff;
  text-decoration: underline;
  text-underline-offset: 3px;
}

:root {
  --sky: #83d8ff;
  --sky-dark: #4fb8ee;
  --grass: #43c86f;
  --grass-dark: #20844a;
  --yellow: #ffd34f;
  --red: #ff5b5b;
  --purple: #9257d8;
  --ink: #17324d;
  --white: #fffaf2;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #80d8ff;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-shell.assets-loading,
.game-shell.assets-loading .canvas-wrap {
  background: #000000;
}

.game-shell.assets-loading .hud,
.game-shell.assets-loading .runner-controls,
.game-shell.assets-loading .overlay {
  visibility: hidden;
  pointer-events: none;
}

/* Full-screen game stage — extract this block later as a dedicated game screen */
.game-viewport,
.game-shell {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: #80d8ff;
}

.canvas-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #80d8ff;
}

.game-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  top: calc(10px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  pointer-events: none;
}

.stats {
  display: flex;
  justify-content: start;
  gap: 8px;
  min-width: 0;
}

.stats span,
.icon-button {
  min-width: 88px;
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(8, 14, 24, 0.55);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  color: #fff8df;
  font-size: clamp(13px, 2.2vw, 17px);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 8px 0;
  pointer-events: auto;
}

.overlay {
  z-index: 6;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background:
    radial-gradient(circle at 25% 18%, rgba(255, 118, 199, 0.22), transparent 28%),
    radial-gradient(circle at 80% 75%, rgba(95, 210, 255, 0.2), transparent 28%),
    rgba(8, 12, 22, 0.72);
  backdrop-filter: blur(6px);
}

.menu-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}

.menu-overlay > * {
  pointer-events: auto;
}

.menu-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(22px, 4vh, 36px);
  width: min(380px, 92vw);
}

.menu-title-block {
  margin: 0;
  text-align: center;
  color: #fff8df;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.55);
}

.menu-title-block h1 {
  width: max-content;
  max-width: none;
  white-space: nowrap;
}

.menu-tagline {
  margin-top: 10px;
  font-size: clamp(14px, 2.4vw, 18px);
  font-weight: 700;
  color: rgba(255, 248, 223, 0.88);
}

.menu-actions {
  display: grid;
  gap: 12px;
  width: 100%;
}

.menu-button {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid rgba(255, 255, 255, 0.38);
  border-radius: 14px;
  background: rgba(8, 14, 24, 0.28);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  font-size: clamp(16px, 2.8vw, 20px);
  font-weight: 900;
  color: #fff8df;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.menu-button:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.58);
}

.menu-button:active {
  transform: scale(0.98);
}

.menu-button-primary {
  border-color: rgba(255, 211, 79, 0.62);
  background: rgba(255, 211, 79, 0.1);
}

.menu-button-primary:hover {
  background: rgba(255, 211, 79, 0.18);
  border-color: rgba(255, 211, 79, 0.82);
}

.menu-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: min(420px, 92vw);
  margin: 0;
  padding: 18px 20px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  background: rgba(18, 24, 38, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  color: #fff8df;
  text-align: center;
  transform: translate(-50%, -50%);
}

.menu-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(24px, 5vw, 34px);
}

.menu-panel p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 700;
  color: rgba(255, 248, 223, 0.9);
}

.leaderboard-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: min(42vh, 280px);
  overflow-y: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 800;
}

.leaderboard-list li + li {
  margin-top: 8px;
}

.leaderboard-rank {
  color: #ffd34f;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 248, 223, 0.92);
  font-size: 14px;
}

.leaderboard-score {
  text-align: right;
  font-size: 18px;
  color: #ffffff;
}

.leaderboard-date {
  display: none;
}

.leaderboard-empty {
  display: block;
  padding: 16px 8px;
  color: rgba(255, 248, 223, 0.75);
  font-weight: 700;
}

.game-shell[data-state="start"] .hud,
.game-shell[data-state="start"] .runner-controls {
  display: none;
}

.hidden {
  display: none;
}

.panel {
  width: min(420px, 92vw);
  padding: 24px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: rgba(18, 24, 38, 0.92);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  color: #fff8df;
  text-align: center;
}

.hero-preview {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: rgba(95, 210, 255, 0.15);
  box-shadow: 0 0 24px rgba(95, 210, 255, 0.25);
}

.hero-preview span {
  display: block;
  width: 76px;
  height: 84px;
  background-image: url("assets/hero_spritesheet.png");
  background-size: 1428px 1102px;
  background-position: -73px -39px;
  background-repeat: no-repeat;
}

.panel.small {
  width: min(320px, 90vw);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 100%;
  font-size: clamp(30px, 7vw, 58px);
  line-height: 1;
  color: #ffffff;
  white-space: nowrap;
}

h2 {
  font-size: clamp(28px, 7vw, 44px);
  color: #ffffff;
}

.panel p {
  margin-top: 12px;
  font-weight: 700;
  color: rgba(255, 248, 223, 0.88);
}

.primary-button,
.secondary-button,
.mini-button {
  width: 100%;
  margin-top: 16px;
  padding: 13px 18px;
  border-radius: 12px;
  font-weight: 900;
  color: var(--ink);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.28);
}

.primary-button {
  background: var(--yellow);
}

.secondary-button {
  background: #8df4ff;
}

.mini-button {
  width: auto;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff8df;
  box-shadow: none;
}

.menu-panel-wide:not(.hidden) {
  width: min(520px, 94vw);
  max-height: min(88vh, 640px);
  display: flex;
  flex-direction: column;
}

.howto-scroll {
  margin-top: 8px;
  overflow-y: auto;
  max-height: min(62vh, 480px);
  padding-right: 4px;
  text-align: left;
}

.howto-section {
  margin-bottom: 16px;
}

.howto-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 900;
  color: #ffd34f;
  letter-spacing: 0.02em;
}

.howto-section p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  font-weight: 600;
  color: rgba(255, 248, 223, 0.92);
}

.howto-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.howto-icon {
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.35));
}

.howto-icon-wide {
  width: 88px;
  height: 88px;
}

.howto-controls {
  justify-content: flex-start;
  margin-top: 0;
}

.howto-controls span {
  font-size: 12px;
}

.howto-collectibles {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.howto-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 8px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 800;
}

.howto-chip img {
  image-rendering: pixelated;
}

.howto-powerups {
  display: grid;
  gap: 10px;
}

.howto-power {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.howto-power img {
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.3));
}

.howto-power strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  color: #ffffff;
}

.howto-power p {
  font-size: 12px;
}

.howto-tip p {
  font-size: 12px;
  color: rgba(255, 211, 79, 0.92);
  font-style: italic;
}

.menu-panel-wide .mini-button {
  flex-shrink: 0;
  margin-top: 12px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.controls span {
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 13px;
  font-weight: 800;
  color: rgba(255, 248, 223, 0.85);
}

.new-best {
  color: var(--red);
  font-size: 22px;
  font-weight: 900;
}

.runner-controls {
  position: absolute;
  z-index: 4;
  left: var(--safe-left);
  right: var(--safe-right);
  bottom: calc(16px + var(--safe-bottom));
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(18px, 6vw, 76px);
  pointer-events: none;
}

.runner-button {
  display: grid;
  place-items: center;
  width: clamp(112px, 16vw, 168px);
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  background: rgba(8, 14, 24, 0.42);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: #ffffff;
  font-size: clamp(26px, 4.5vw, 46px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}

.runner-button:active {
  transform: scale(0.96);
  background: rgba(95, 210, 255, 0.22);
}

@media (hover: none) and (pointer: coarse) {
  .runner-controls {
    display: flex;
  }
}

@media (max-width: 760px), (pointer: coarse) {
  .hud {
    grid-template-columns: 1fr auto;
  }

  .stats {
    justify-content: start;
    flex-wrap: wrap;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .stats::-webkit-scrollbar {
    display: none;
  }

  .stats span {
    min-width: 0;
    padding: 6px 10px;
    font-size: 11px;
  }

  .runner-controls {
    bottom: calc(10px + var(--safe-bottom));
    padding: 0 10px;
    gap: 8px;
  }

  .runner-button {
    width: clamp(72px, 20vw, 120px);
    font-size: clamp(20px, 5.5vw, 34px);
  }
}

@media (max-width: 420px) {
  #bestLabel,
  #heartLabel {
    display: none;
  }

  .stats span {
    font-size: 10px;
    padding: 5px 8px;
  }

  .panel {
    padding: 18px 16px;
  }

  h1 {
    font-size: clamp(26px, 9vw, 40px);
  }
}

@media (max-height: 520px) {
  .hud {
    top: calc(6px + var(--safe-top));
    min-height: 0;
  }

  .stats span {
    padding: 5px 8px;
    font-size: 10px;
  }

  .runner-controls {
    bottom: calc(6px + var(--safe-bottom));
  }

  .runner-button {
    width: clamp(64px, 14vh, 96px);
    font-size: clamp(18px, 4vh, 28px);
  }

  .overlay {
    padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
  }
}
