/* ===== 全屏 + 移动端适配 ===== */
/* 占满整屏、禁止页面滚动 / 下拉刷新 / 回弹，避免手机上游戏被顶走或露白边。
   游戏自带的 arcade-mode 会把画布缩放铺满，这里只做页面容器层面的加固。 */
html,
body {
    /* 触摸手势（滚动 / 双击缩放）全靠这里禁止，JS 里的触摸监听都是 passive，不做 preventDefault */
    touch-action: none;
    width: 100%;
    height: 100%;
    /* 用动态视口高度兜住手机地址栏收起/展开造成的高度跳变 */
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
    background: #fff;
}

/* 去掉 arcade 全屏缩放的过渡动画（index.css 里带 400ms 延迟 + 250ms 动画）。
   原版拿它当入场动效，但我们是「一打开就全屏」，留着会先出现一小块画面再放大，显得奇怪。
   去掉后缩放瞬间生效，加载即全屏态。 */
.arcade-mode .runner-container {
    transition: none !important;
}

/* 防止刷新时「闪一下」：引擎会先按原生尺寸画出小画面，接入层稍后才套上全屏缩放，
   中间那一帧未缩放的小画面会露出来。这里先把画布和引导藏起来（visibility 保留布局，
   不影响缩放计算），等接入层摆好全屏缩放后给 body 加 .yyg-ready 再一起显示。 */
body:not(.yyg-ready) .runner-container,
body:not(.yyg-ready) #main-content,
body:not(.yyg-ready) .yyg-hint {
    /* #main-content 是静态离线恐龙占位图（.icon-offline），引擎 init 前就显示，
       刷新时露出来就是那只「小恐龙」，一并藏掉。 */
    visibility: hidden;
}

/* 抢焦点后不要显示浏览器默认的黑色焦点框：
   接入层给容器（.runner-container）加了 tabindex 并 focus() 把键盘焦点拉回本 iframe，
   聚焦会触发默认 outline，这里统一去掉（焦点仍在，只是不画框）。
   同时覆盖 :focus-visible，避免部分浏览器用键盘焦点时仍画框。 */
body:focus,
body:focus-visible,
[tabindex]:focus,
[tabindex]:focus-visible,
.runner-container:focus,
.runner-container:focus-visible,
canvas:focus {
    outline: none;
}

body {
    /* 禁止触摸手势滚动/缩放，所有触摸交给游戏自身的触摸层处理 */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none; /* iOS 长按不弹系统菜单 */
    /* 适配刘海屏安全区 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
}

/* ===== 开局前操作引导（跳跃 / 下蹲）===== */
.yyg-hint {
    position: fixed;
    left: 50%;
    top: 34%;
    transform: translateX(-50%);
    z-index: 15;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    pointer-events: none; /* 不挡点击：点到引导上也能开始游戏 */
    font-family: "Open Sans", Arial, sans-serif;
    color: #535353;
    text-align: center;
}

.yyg-hint.hidden {
    display: none;
}

.yyg-hint-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* 鼠标左右键引导图标（纯 CSS、语言无关）：左键高亮=跳，右键高亮=蹲 */
.yyg-mouse {
    position: relative;
    width: 24px;
    height: 34px;
    border: 2px solid #535353;
    border-radius: 12px;
    box-sizing: border-box;
    flex: 0 0 auto;
}

.yyg-mouse::after {
    /* 两个键之间的竖向分隔线 */
    content: "";
    position: absolute;
    left: 50%;
    top: 2px;
    width: 2px;
    height: 10px;
    background: #535353;
    transform: translateX(-50%);
}

.yyg-mouse-btn {
    /* 高亮的那一侧按键 */
    position: absolute;
    top: 0;
    width: 9px;
    height: 12px;
    background: #535353;
}

.yyg-mouse-btn.left {
    left: 0;
    border-top-left-radius: 10px;
}

.yyg-mouse-btn.right {
    right: 0;
    border-top-right-radius: 10px;
}

/* 触摸设备不显示鼠标引导（手机用屏幕按钮） */
body.yyg-touch .yyg-mouse {
    display: none;
}

.yyg-hint-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(83, 83, 83, .12);
    font-size: 20px;
    line-height: 1;
}

.yyg-hint-label {
    font-size: 18px;
    font-weight: 600;
    min-width: 72px;
    text-align: left;
}

.yyg-hint-start {
    margin-top: 6px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .5px;
    animation: yyg-hint-blink 1.1s ease-in-out infinite;
}

@keyframes yyg-hint-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: .3; }
}

@media (max-height: 420px) {
    .yyg-hint {
        top: 28%;
        gap: 8px;
    }

    .yyg-hint-key {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .yyg-mouse {
        width: 20px;
        height: 28px;
    }

    .yyg-hint-label {
        font-size: 15px;
    }

    .yyg-hint-start {
        font-size: 14px;
    }
}

/* ===== 手机触摸操作按钮（跳 / 低头）===== */
/* 默认隐藏，只有触摸设备（body.yyg-touch）才显示；桌面用键盘。 */
.yyg-controls {
    display: none;
}

body.yyg-touch .yyg-controls {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    justify-content: space-between;
    align-items: flex-end;
    /* 左右内边距越大，两个按钮越往中间收（离屏幕左右边缘更远、更好按） */
    padding: 0 56px calc(24px + env(safe-area-inset-bottom)) 56px;
    pointer-events: none; /* 容器不挡，只有按钮可点 */
    box-sizing: border-box;
}

.yyg-ctrl-btn {
    pointer-events: auto;
    width: 84px;
    height: 84px;
    border: none;
    border-radius: 50%;
    background: rgba(83, 83, 83, .12);
    color: #535353;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none; /* 立即响应，不等待双击缩放判定 */
    display: flex;
    align-items: center;
    justify-content: center;
}

.yyg-ctrl-btn:active {
    background: rgba(83, 83, 83, .28);
}

/* 矮屏（手机横放）按钮小一点、离边近一点 */
@media (max-height: 420px) {
    .yyg-ctrl-btn {
        width: 64px;
        height: 64px;
        font-size: 24px;
    }

    body.yyg-touch .yyg-controls {
        padding: 0 40px calc(12px + env(safe-area-inset-bottom)) 40px;
    }
}

/* ===== 结算浮层样式：画布下方居中的分数卡片，沿用游戏的深灰像素风 ===== */

#yyg-overlay.hidden {
    display: none !important;
}

.yyg-overlay {
    position: fixed;
    left: 50%;
    /* 用视口百分比定位：全屏缩放后画布大致在上半屏，浮层落在下半屏，桌面/手机都能对齐 */
    top: 58%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none; /* 不挡点击：点到分数卡片上也能重开 */
}

.yyg-score-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 168px;
    padding: 12px 28px 14px;
    border-radius: 8px;
    background: #535353;
    color: #fff;
    box-shadow: 0 4px 0 rgba(0, 0, 0, .18);
    font-family: "Courier New", Courier, monospace;
    text-align: center;
    animation: yyg-score-pop .32s cubic-bezier(.2, 1.4, .4, 1) both;
}

.yyg-score-label {
    font-family: "Open Sans", Arial, sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 3px;
    opacity: .75;
}

.yyg-score {
    margin-top: 2px;
    font-size: 56px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 2px;
    font-variant-numeric: tabular-nums;
}

@keyframes yyg-score-pop {
    0% { opacity: 0; transform: scale(.6); }
    100% { opacity: 1; transform: scale(1); }
}

/* 横屏矮屏（手机横放）：画布占比更高，浮层再往下压一点、卡片缩小 */
@media (max-height: 420px) {
    .yyg-overlay {
        top: 64%;
    }

    .yyg-score-card {
        min-width: 128px;
        padding: 8px 20px 10px;
    }

    .yyg-score-label {
        font-size: 11px;
    }

    .yyg-score {
        font-size: 38px;
    }
}
