* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #140c33;
  touch-action: none;
  overscroll-behavior: none;
}
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #fff;
  --wl: 30vw; --wr: 70vw; --wt: 20px; --btn: min(17vmin, 84px);
}
/* 字号规范（移动端）：正文最小 12px；辅助文字（SCORE / NEXT 等标签、按键提示）最小 10px */
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#safe {
  position: fixed; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  margin: 0 2px;
  border: 1px solid rgba(255,255,255,.6);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: rgba(255,255,255,.08);
  font: bold .9em/1.5 Consolas, monospace;
  text-align: center;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud span {
  display: block;
  font: 800 12px/1 "Arial Black", "Segoe UI", sans-serif;
  letter-spacing: 2px;
  color: #9fb4ff;
}
#hud b {
  display: block;
  font: 800 26px/1.15 Consolas, "Courier New", monospace;
  color: #fff;
  text-shadow: 0 0 12px rgba(120,160,255,.6);
}
.stat, #nextWrap {
  background: rgba(20,14,60,.55);
  border: 2px solid rgba(140,160,255,.35);
  border-radius: 12px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.stat { padding: 8px 14px; }
.stat.hi b { color: #ffd23c; }
/* 预览方块画在画布上，这里不能模糊或压暗背后的画面 */
#nextWrap { background: rgba(20,14,60,.18); -webkit-backdrop-filter: none; backdrop-filter: none; }
#nextBox { width: 132px; height: 100px; }
#keys { margin-top: 8px; font-size: 12px; line-height: 2; color: #d8e0ff; }
body.touch #keys { display: none; }

/* 宽屏：信息面板贴在井的两侧 */
body.side #stats {
  position: absolute;
  right: calc(100% - var(--wl) + 18px);
  top: var(--wt);
  display: flex; flex-direction: column; gap: 10px;
  width: 150px;
}
body.side #nextWrap {
  position: absolute;
  left: calc(var(--wr) + 18px);
  top: var(--wt);
  padding: 10px 12px;
}
/* 竖屏：信息栏在顶部 */
body.top #stats {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 8px);
  right: calc(env(safe-area-inset-right) + 104px);
  top: calc(env(safe-area-inset-top) + 8px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
body.top .stat { padding: 5px 10px; border-radius: 10px; }
body.top #hud span { font-size: 10px; letter-spacing: 1px; }
body.top #hud b { font-size: 18px; }
@media (max-height: 560px) {
  body.side #stats { width: 118px; gap: 6px; }
  body.side .stat { padding: 4px 10px; }
  body.side #hud b { font-size: 19px; }
  body.side #hud span { font-size: 10px; }
  body.side #nextBox { width: 100px; height: 80px; }
}
body.top #nextWrap {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 8px);
  top: calc(env(safe-area-inset-top) + 8px);
  padding: 6px 8px;
  border-radius: 10px;
}
body.top #nextBox { width: 80px; height: 72px; }
body.top #keys { display: none; }

#topbtns {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 10px);
  display: flex; gap: 8px;
  z-index: 6;
}
body.top #topbtns { flex-direction: column; top: var(--wt); right: calc(env(safe-area-inset-right) + 6px); }
#topbtns button {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 2px solid rgba(160,180,255,.6);
  background: rgba(20,14,60,.55);
  color: #fff;
  font: bold 16px Consolas, monospace;
  cursor: pointer;
}
#topbtns button.off { opacity: .45; text-decoration: line-through; }
body.hideui #hud, body.hideui #topbtns, body.hideui #touch { visibility: hidden; }

/* ---------- 提示文字 ---------- */
#toast {
  position: fixed;
  left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  z-index: 8;
  pointer-events: none;
  text-align: center;
  font: 900 clamp(28px, 7vmin, 64px)/1.1 "Arial Black", "Segoe UI Black", sans-serif;
  letter-spacing: 2px;
  color: #fff;
  -webkit-text-stroke: 2px #1b1150;
  paint-order: stroke fill;
  text-shadow: 0 0 24px rgba(255,255,255,.7), 4px 5px 0 #1b1150;
  opacity: 0;
}
#toast small { display: block; font-size: .5em; color: #ffd23c; margin-top: 4px; }
#toast.show { animation: toast 1.1s ease-out forwards; }
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  25% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1); }
}

/* ---------- 覆盖层（标题 / 暂停 / 结束） ---------- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20,12,60,.35), rgba(8,4,30,.8));
  z-index: 10;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-y: auto;
}
#overlay.hidden { display: none; }
/* margin:auto 居中：内容比屏幕高时从顶部开始滚动，不会把标志裁掉 */
.card { text-align: center; padding: 20px; max-width: 94vw; margin: auto; }
.logo {
  font: 900 clamp(46px, 13vmin, 120px)/1 "Arial Black", "Segoe UI Black", sans-serif;
  letter-spacing: clamp(2px, 1vmin, 8px);
  -webkit-text-stroke: clamp(3px, .8vmin, 7px) #120a3a;
  paint-order: stroke fill;
}
.logo i { font-style: normal; }
.logo .d3 {
  display: inline-block; margin-left: .15em;
  color: #ffd23c;
  transform: rotate(-6deg);
}
.subtitle {
  margin-top: 12px;
  font-size: clamp(15px, 3.6vmin, 26px);
  font-weight: bold;
  letter-spacing: 6px;
  color: #e6ebff;
}
.big { font: 900 clamp(30px, 8vmin, 64px)/1.1 "Arial Black", sans-serif; letter-spacing: 3px; margin-bottom: 12px; }
.mid { font-size: clamp(16px, 3.4vmin, 24px); font-weight: bold; margin: 6px 0; }
.mid em { font-style: normal; color: #ffd23c; font-family: Consolas, monospace; }
.lvsel { margin-top: 22px; }
.lvsel p { font-size: 14px; color: #b9c6ff; letter-spacing: 2px; margin-bottom: 8px; }
.lvsel .row { display: inline-grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvsel button {
  width: clamp(36px, 9vmin, 48px); height: clamp(36px, 9vmin, 48px);
  border-radius: 10px;
  border: 2px solid rgba(160,180,255,.5);
  background: rgba(30,20,80,.6);
  color: #fff;
  font: bold 18px Consolas, monospace;
  cursor: pointer;
}
.lvsel button.on { background: #ffd23c; color: #1b1150; border-color: #fff; }
.bigbtn {
  margin: 22px 6px 0;
  padding: 12px 38px;
  font: bold clamp(17px, 3.2vmin, 24px) "Microsoft YaHei", sans-serif;
  color: #fff;
  background: linear-gradient(#a45cff, #7434e0);
  border: 3px solid #fff;
  border-radius: 14px;
  box-shadow: 0 5px 0 #3f1590, 0 0 24px rgba(164,92,255,.5);
  cursor: pointer;
}
.bigbtn.alt { background: linear-gradient(#3a3f7a, #262a5c); box-shadow: 0 5px 0 #14163a; }
.bigbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #3f1590; }
.help { margin-top: 20px; font-size: clamp(12px, 2.4vmin, 15px); line-height: 2; color: #d8e0ff; }
/* 横屏且高度较矮（手机横屏）：标志缩小，等级 0–9 排成一行，整体压紧 */
@media (orientation: landscape) and (max-height: 560px) {
  .card { padding: 10px 16px; }
  .logo { font-size: clamp(34px, 14vh, 72px); }
  .subtitle { margin-top: 6px; font-size: clamp(13px, 4.2vh, 20px); letter-spacing: 4px; }
  .lvsel { margin-top: 12px; }
  .lvsel p { font-size: 12px; margin-bottom: 6px; }
  .lvsel .row { grid-template-columns: repeat(10, 1fr); }
  .lvsel button { width: clamp(30px, 9vh, 42px); height: clamp(30px, 9vh, 42px); font-size: 16px; }
  .bigbtn { margin-top: 12px; padding: 9px 32px; }
  .big { font-size: clamp(26px, 10vh, 48px); margin-bottom: 6px; }
  .mid { margin: 4px 0; font-size: clamp(14px, 4vh, 20px); }
  .help { margin-top: 10px; line-height: 1.8; }
}
body.touch .help.pc { display: none; }
body:not(.touch) .help.mobile { display: none; }

/* ---------- 触屏按键（与超级玛丽 3D 统一） ---------- */
#touch { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 7; }
body.touch #touch { display: block; }
/* 经典十字方向键：半透明圆形底座 + 实心十字。
   整个圆形底座都是热区（不只是十字本身），按手指相对圆心的方向判定：
   左/右 = 移动，下 = 软降，上 = 不响应 */
#dpad {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  width: clamp(130px, 40vmin, 200px);
  height: clamp(130px, 40vmin, 200px);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,0,0,.16) 55%, rgba(0,0,0,.24));
  border: 2px solid rgba(255,255,255,.35);
  pointer-events: auto;
  touch-action: none;
}
/* 十字和图标只负责显示，不单独接收触摸 */
#dpad .arm, #dpad .hub {
  position: absolute;
  width: 27.34%;
  height: 27.34%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(25,25,30,.58);
  color: rgba(255,255,255,.82);
  pointer-events: none;
  transition: background .06s;
}
#dpad svg { width: 48%; height: 48%; display: block; }
#dpad svg path { fill: currentColor; }
#dpad .up    { left: 36.33%; top: 9%;      border-radius: 9px 9px 0 0; box-shadow: inset 0 3px 0 rgba(255,255,255,.18); }
#dpad .left  { left: 9%;      top: 36.33%; border-radius: 9px 0 0 9px; box-shadow: inset 3px 0 0 rgba(255,255,255,.18); }
#dpad .hub   { left: 36.33%; top: 36.33%; }
#dpad .right { left: 63.67%; top: 36.33%; border-radius: 0 9px 9px 0; box-shadow: inset -3px 0 0 rgba(0,0,0,.25); }
#dpad .down  { left: 36.33%; top: 63.67%; border-radius: 0 0 9px 9px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
#dpad .hub::after {
  content: "";
  position: absolute;
  left: 27%; top: 27%;
  width: 46%; height: 46%;
  border-radius: 50%;
  background: rgba(0,0,0,.28);
  box-shadow: inset 0 2px 3px rgba(0,0,0,.35);
}
#dpad .arm.on { background: rgba(255,255,255,.42); color: #fff; }
/* A / B 圆形动作键 */
.tbtn {
  position: absolute;
  width: min(19vmin, 96px);
  height: min(19vmin, 96px);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: bold min(7vmin, 34px) sans-serif;
  color: #fff;
  background: rgba(229,37,33,.55);
  border: 3px solid rgba(255,255,255,.7);
  pointer-events: auto;
  touch-action: none;
}
.tbtn.on { background: rgba(229,37,33,.9); transform: scale(.94); }
#btnA { right: calc(env(safe-area-inset-right) + 16px); bottom: calc(env(safe-area-inset-bottom) + min(14vmin, 70px)); }
#btnB { right: calc(env(safe-area-inset-right) + min(24vmin, 122px)); bottom: calc(env(safe-area-inset-bottom) + 14px); background: rgba(40,80,220,.55); }
#btnB.on { background: rgba(40,80,220,.9); }
