* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #e9e9ee;
  --dim: #7a7a86;
  --yellow: #ffd23f;
  --blue: #3b6bff;
  --red: #e23b3b;
  --panel: rgba(255, 255, 255, 0.05);
}
html, body {
  height: 100%;
  background: #0f0f12;
  color: var(--ink);
  font-family: "Press Start 2P", system-ui, monospace;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.wrap {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px;
  background: radial-gradient(900px 500px at 50% -20%, #1a1a20 0%, #0d0d10 65%);
}

/* HUD — minimalist, matches LEVEL 1 / centered timer / small stats */
.hud {
  width: 100%; max-width: 960px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 12px 8px 14px; font-size: 12px; letter-spacing: 1px;
}
.hud-item { color: var(--ink); }
.hud-item.time { justify-self: center; grid-column: 2; font-size: 16px; }
.hud .lbl { display: none; }
.hud-item:nth-child(1) { grid-column: 1; justify-self: start; }
.hud-item.time b { color: var(--ink); font-weight: normal; }
/* right cluster: level is left, stack coins/deaths/best on the right */
#coins, #deaths, #best { color: var(--dim); font-size: 9px; }
.hud-side {
  grid-column: 3; justify-self: end;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}

.stage { position: relative; margin-top: 2px; line-height: 0; }
canvas {
  display: block; border: 2px solid rgba(255,255,255,0.08);
  box-shadow: 0 24px 70px rgba(0,0,0,0.6);
}

/* Overlays */
.overlay {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 16px; padding: 20px;
  background: rgba(8, 8, 11, 0.9);
}
.overlay.show { display: flex; }
.overlay h1 {
  font-size: clamp(20px, 5vw, 34px); line-height: 1.35; letter-spacing: 2px;
  color: var(--ink);
}
.overlay h1.win { color: var(--yellow); }
.overlay p { font-size: 10px; line-height: 1.9; color: var(--dim); }
.overlay .bigtime { font-size: clamp(22px, 6vw, 40px); color: var(--yellow); }
.stats { display: flex; gap: 18px; font-size: 10px; color: var(--dim); flex-wrap: wrap; justify-content: center; }
.stats b { color: var(--ink); }
.controls { display: flex; flex-direction: column; gap: 8px; font-size: 8px; color: var(--dim); margin-top: 6px; }

.btn {
  font-family: inherit; font-size: 13px; cursor: pointer;
  color: #0f0f12; background: var(--yellow);
  border: none; padding: 14px 26px;
  box-shadow: 0 5px 0 #c9a52f; transition: transform .05s, box-shadow .05s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #c9a52f; }

/* Touch controls */
.touch {
  width: 100%; max-width: 960px; margin-top: 12px;
  display: none; justify-content: space-between; align-items: center; gap: 10px;
}
.tpad { display: flex; gap: 10px; }
.tbtn {
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 2px solid rgba(255,255,255,0.14);
  width: 72px; height: 64px; cursor: pointer;
}
.tbtn.jump { width: 120px; color: #0f0f12; background: var(--yellow); border: none; }
.tbtn:active { filter: brightness(1.3); }

@media (hover: none) and (pointer: coarse) { .touch { display: flex; } }
@media (max-width: 640px) { .hud { font-size: 10px; } .hud-item.time { font-size: 13px; } }

/* ===================== Screens / menus ===================== */
.screen {
  position: fixed; inset: 0; display: none;
  padding: 40px 32px; overflow-y: auto;
}
.screen.show { display: block; }
.screen.play.show { display: flex; }

.screen .back {
  position: absolute; top: 26px; left: 28px;
  font-family: inherit; font-size: 20px; color: var(--ink);
  background: none; border: none; cursor: pointer; padding: 6px;
}
.screen .back:hover { color: var(--yellow); }
.screen-title {
  text-align: center; font-size: clamp(18px, 4vw, 28px);
  letter-spacing: 2px; margin: 6px 0 34px;
}

/* Title / cover */
.title { display: none; flex-direction: column; justify-content: center; padding-left: 8vw; }
.title.show { display: flex; }
.game-title {
  font-size: clamp(32px, 9vw, 84px); line-height: 1.05; letter-spacing: 2px;
  margin-bottom: 8px; color: var(--ink);
  text-shadow: 4px 4px 0 rgba(255,255,255,0.06);
}
.menu { display: flex; flex-direction: column; align-items: flex-start; gap: 22px; margin-top: 40px; }
.menu-item {
  font-family: inherit; font-size: clamp(15px, 3vw, 24px); letter-spacing: 2px;
  color: var(--dim); background: none; border: none; cursor: pointer; padding: 4px 0;
  transition: color .1s, transform .1s;
}
.menu-item:hover { color: var(--ink); transform: translateX(8px); }

/* Level list / leaderboard */
.level-list { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.level-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  font-family: inherit; font-size: 13px; color: var(--ink);
  background: var(--panel); border: 2px solid rgba(255,255,255,0.10);
  border-radius: 10px; padding: 16px 18px; cursor: pointer; text-align: left;
}
.level-row:hover { border-color: rgba(255,255,255,0.3); }
.level-row .lv-name { letter-spacing: 1px; }
.level-row .lv-time { color: var(--dim); font-size: 11px; }
.level-row.locked { opacity: .45; cursor: not-allowed; }
.level-row.locked:hover { border-color: rgba(255,255,255,0.10); }
.level-list.read .level-row { cursor: default; }
.level-list.read .level-row:hover { border-color: rgba(255,255,255,0.10); }

/* Settings */
.panel { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.panel .ctl { font-size: 10px; color: var(--dim); line-height: 1.8; }
.btn2 {
  align-self: flex-start; margin-top: 12px;
  font-family: inherit; font-size: 11px; color: var(--ink);
  background: var(--panel); border: 2px solid rgba(255,255,255,0.18);
  border-radius: 10px; padding: 12px 16px; cursor: pointer;
}
.btn2:hover { border-color: var(--red); color: var(--red); }

/* Cosmetics */
.hint { text-align: center; font-size: 10px; color: var(--dim); margin-bottom: 20px; }
.color-list { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; max-width: 520px; margin: 0 auto; }
.swatch2 { width: 46px; height: 46px; border: 3px solid transparent; border-radius: 8px; cursor: pointer; }
.swatch2.active { border-color: var(--yellow); }

/* Finish overlay buttons */
.finish-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn.ghost { background: none; color: var(--dim); box-shadow: none; border: 2px solid rgba(255,255,255,0.16); }
.btn.ghost:active { transform: translateY(2px); }
.play-back {
  position: absolute; top: 14px; left: 12px; font-size: 10px !important;
  color: var(--dim) !important; letter-spacing: 1px;
}
.play.play { align-items: center; }

/* Home stats panel */
.stats-panel { position: absolute; top: 38px; right: 40px; display: flex; gap: 12px; }
.sp-item {
  background: var(--panel); border: 2px solid rgba(255,255,255,0.10);
  border-radius: 10px; padding: 12px 16px; text-align: center; min-width: 96px;
}
.sp-item b { display: block; font-size: 20px; color: var(--ink); }
.sp-item span { font-size: 8px; color: var(--dim); letter-spacing: 1px; }
@media (max-width: 720px) {
  .stats-panel { position: static; margin: 0 0 24px; justify-content: flex-start; }
}
