* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: #14161f;
  color: #eef1f8;
  font-family: "Segoe UI", Arial, sans-serif;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  overscroll-behavior: none;
  overflow: hidden;
}
.screen { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ---------- SCREEN 1: MENU ---------- */
#menuScreen {
  overflow-y: auto;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  touch-action: pan-y;
}
#menuHead { text-align: center; margin: 10px 0 4px; }
#menuTitle { font-size: 44px; font-weight: 900; letter-spacing: 4px; }
#menuSub { color: #9aa3b8; font-size: 14px; margin-bottom: 8px; }
#maxChip {
  display: inline-block; background: #3a2f5e; border: 2px solid #8a6fff;
  color: #d9ccff; font-weight: 800; font-size: 14px;
  padding: 6px 16px; border-radius: 20px;
}
#installBtn {
  display: block; margin: 10px auto 0;
  font-size: 16px; font-weight: 800; color: #fff; font-family: inherit;
  background: #37b24d; border: none; border-radius: 12px; padding: 12px 30px; cursor: pointer;
}
#installBtn:active { transform: scale(.96); }
#iosHint {
  margin: 10px auto 0; max-width: 420px;
  background: #222839; border: 1px solid #343c55; color: #c9d1e6;
  font-size: 13.5px; padding: 10px 16px; border-radius: 12px; text-align: center;
}
#chapters { width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; margin-top: 10px; }
.chBlock {
  background: #1b2133; border: 2px solid #343c55; border-radius: 16px; padding: 12px;
}
.chBlock.done { border-color: #ffd23e; }
.chBlockHead { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.chBlockName { font-size: 17px; font-weight: 800; }
.chBlockSub { font-size: 12px; color: #9aa3b8; }
.chStarBar { height: 10px; background: #10131d; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.chStarFill { height: 100%; background: linear-gradient(90deg, #ffd23e, #ff9f1c); }
.chStarText { font-size: 13px; color: #ffd23e; font-weight: 700; }
.chNeed { font-size: 12px; color: #8b94ad; margin-top: 2px; }
.lvlGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.lvlCard {
  background: #222839; border: 2px solid #57e389; color: #eef1f8;
  border-radius: 12px; padding: 12px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit; min-height: 76px;
}
.lvlCard:active { transform: scale(.96); }
.lvlCard .num { font-size: 22px; font-weight: 900; }
.lvlCard .nm { font-size: 10.5px; color: #9aa3b8; text-align: center; line-height: 1.2; }
.lvlCard .st { font-size: 12px; color: #ffd23e; letter-spacing: 1px; }
.lvlCard.locked { border-color: #343c55; opacity: .5; cursor: not-allowed; }
.lvlCard.boss { border-color: #ff5d5d; }
#menuFoot { margin: 14px 0 6px; color: #5a6378; font-size: 12px; text-align: center; }

/* ---------- SCREEN 2: GAME (true fullscreen, HUD floats over canvas) ---------- */
#gameScreen { padding: 0; position: relative; overflow: hidden; background: #0b0e17; }
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: max(8px, env(safe-area-inset-top)) 10px 26px;
  background: linear-gradient(rgba(8,10,18,.62), rgba(8,10,18,0));
  pointer-events: none;
}
#topbar button { pointer-events: auto; }
#topLeft { display: flex; gap: 8px; align-items: center; }
#backBtn, #fsBtn {
  background: #222839; border: 2px solid #343c55; color: #eef1f8;
  font-size: 17px; font-weight: 800; border-radius: 10px;
  width: 42px; height: 38px; cursor: pointer; font-family: inherit;
}
#backBtn:active, #fsBtn:active { transform: scale(.94); }
#levelTag { font-size: 15px; font-weight: 800; letter-spacing: .5px; }
#hud { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#chStars {
  background: #3a2f14; border: 2px solid #ffd23e; color: #ffd23e;
  padding: 5px 12px; border-radius: 10px; font-weight: 800; font-size: 14px;
  white-space: nowrap;
}
#stars, #time {
  background: #222839; border: 1px solid #343c55;
  padding: 6px 12px; border-radius: 10px; font-weight: 700; font-size: 14px;
  white-space: nowrap;
}
#sizeMeter {
  position: relative; width: 130px; height: 30px;
  background: #222839; border: 1px solid #343c55; border-radius: 10px; overflow: hidden;
}
#sizeFill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, #38d977, #ffb02e, #ff5d5d);
}
#sizeLabel {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff; text-shadow: 0 1px 3px #000;
}
#game-holder {
  position: relative; flex: 1; min-height: 0; width: 100%;
  overflow: hidden; background: #0b0e17;
}
#game { width: 100%; height: 100%; display: block; cursor: pointer; }
/* portrait phones: 16:9 strip (game is landscape-first), rotate tip shown */
@media (orientation: portrait) {
  #gameScreen { justify-content: center; }
  #game-holder { flex: none; width: 100%; aspect-ratio: 16/9; }
}
#rotateTip {
  display: none; position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.6); padding: 6px 14px; border-radius: 16px;
  font-size: 12.5px; font-weight: 600; pointer-events: none; white-space: nowrap;
}
@media (orientation: portrait) and (max-width: 700px) {
  #rotateTip { display: block; }
}
#hint {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.55); padding: 8px 16px; border-radius: 20px;
  font-size: 15px; font-weight: 600; pointer-events: none; white-space: nowrap;
  max-width: 94%; overflow: hidden; text-overflow: ellipsis;
}
#holdBadge {
  position: absolute; bottom: 12px; right: 12px;
  background: rgba(0,0,0,.45); border: 2px solid #4a5470; color: #8b94ad;
  font-weight: 800; font-size: 13px; letter-spacing: 1px;
  padding: 8px 14px; border-radius: 20px; pointer-events: none;
  transition: all .08s;
}
#holdBadge.on {
  background: #ff5d5d; border-color: #ff8a8a; color: #fff;
  transform: scale(1.12);
  box-shadow: 0 0 18px rgba(255,93,93,.8);
}
#overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: rgba(10,12,20,.78); text-align: center; padding: 20px;
}
#overlay.gold { background: rgba(30,22,6,.85); }
#overlay.gold #overlayTitle { color: #ffd23e; text-shadow: 0 0 24px rgba(255,210,62,.6); }
#overlayTitle { font-size: clamp(28px, 6vw, 42px); font-weight: 900; }
#overlayText { font-size: clamp(13px, 2.6vw, 16px); color: #c9d1e6; max-width: 520px; }
#overlayBtns { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
#retryBtn {
  font-size: 17px; font-weight: 800; color: #14161f;
  background: #ffd23e; border: none; border-radius: 12px; padding: 12px 30px; cursor: pointer; font-family: inherit;
}
#nextBtn {
  font-size: 17px; font-weight: 800; color: #fff;
  background: #37b24d; border: none; border-radius: 12px; padding: 12px 28px; cursor: pointer; font-family: inherit;
}
#menuBtn {
  font-size: 17px; font-weight: 800; color: #eef1f8;
  background: #343c55; border: none; border-radius: 12px; padding: 12px 28px; cursor: pointer; font-family: inherit;
}
#retryBtn:active, #nextBtn:active, #menuBtn:active { transform: scale(.96); }

/* landscape phones: app mode, chrome slim, canvas owns every pixel */
@media (orientation: landscape) and (max-height: 500px) {
  #levelTag { font-size: 13px; }
  #stars, #time, #chStars { font-size: 12px; padding: 4px 10px; }
  #sizeMeter { width: 100px; height: 26px; }
  #backBtn, #fsBtn { width: 38px; height: 32px; font-size: 15px; }
  #hint { font-size: 12.5px; padding: 5px 12px; top: 44px; }
  #holdBadge { display: none; }
}
