* {
    box-sizing: border-box;
    /* WebKit：移除点击任意元素时的高亮方框 */
    -webkit-tap-highlight-color: transparent;
    /* 禁止滚动穿透（overscroll chaining） */
    overscroll-behavior: none;
}

html, body {
    margin: 0;
    height: 100%;
    background: #000;
    color: #ddd;
    font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    touch-action: manipulation;
    /* iOS 刘海屏安全区：顶部由菜单栏的灰色背景延伸进状态栏区域，
       底部导航条（Home 指示条）处保持黑色背景 */
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
}

/* ---------- 顶部菜单（Win95 风格） ---------- */
#menubar {
    position: relative;
    z-index: 100;
    display: flex;
    align-items: center;
    min-height: 34px;
    padding-top: env(safe-area-inset-top);
    background: #c0c0c0;
    color: #000;
    border-bottom: 1px solid #808080;
    font-family: "MS Sans Serif", "MS Shell Dlg", "SimSun", "Microsoft YaHei", sans-serif;
}

.brand {
    padding: 0 14px;
    font-weight: bold;
    letter-spacing: .5px;
    color: #000;
    white-space: nowrap;
}

.menu { display: flex; flex: 1; }

.menuitem { position: relative; }

.menu-label {
    background: transparent;
    border: 0;
    color: #000;
    font: inherit;
    padding: 0 10px;
    height: 34px;
    line-height: 34px;
    cursor: pointer;
    white-space: nowrap;
}
.menuitem.open > .menu-label { background: #000080; color: #fff; }
.menu-label:active { background: #000080; color: #fff; }

.dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 190px;
    background: #c0c0c0;
    border: 1px solid #000;
    box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #808080;
    padding: 2px 0;
}
.menuitem.open > .dropdown { display: block; }
.dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: #000;
    font: inherit;
    padding: 5px 26px 5px 22px;
    cursor: pointer;
    white-space: nowrap;
}
.dropdown button:active { background: #000080; color: #fff; }
.dropdown hr { border: 0; border-top: 1px solid #808080; margin: 3px 4px; }

#stage {
    position: relative;
    overflow: hidden;
    background: #000;
}

#board {
    position: absolute;
    touch-action: none;
    display: block;
    transform-origin: 0 0;
    /* 显示缩放一律最近邻（紧邻），避免模糊/重影；旧 WebKit 用 -webkit-optimize-contrast */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
}

/* ---------- 对话框 ---------- */
#dialog-root { pointer-events: none; }
.overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,.65);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    pointer-events: auto;
}
.dialog {
    background: #232529;
    border: 1px solid #4a4e55;
    border-radius: 6px;
    min-width: 280px;
    max-width: 94vw;
    box-shadow: 0 10px 30px rgba(0,0,0,.6);
    overflow: hidden;
}
.dlg-title {
    background: #2e3137;
    padding: 10px 14px;
    font-weight: bold;
    border-bottom: 1px solid #111;
}
.dlg-body {
    padding: 14px;
    font-size: 14px;
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
}
.dlg-body p { margin: 4px 0; }
.dlg-body a { color: #66aaff; }
.dlg-btns {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #111;
    background: #1d1f23;
}
.dlg-btn {
    min-width: 72px;
    padding: 7px 14px;
    background: #4a4e55;
    color: #eee;
    border: 1px solid #000;
    border-radius: 4px;
    font: inherit;
    cursor: pointer;
}
.dlg-btn:hover { background: #5a5f68; }
.dlg-btn:focus { outline: 2px solid #7aa; }

.over-title { font-size: 20px; font-weight: bold; color: #ff6b6b; text-align: center; }
.record { color: #ffd76a; }
.name-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.name-row label { white-space: nowrap; }
.name-row input {
    flex: 1;
    min-width: 0;
    background: #12141a;
    color: #eee;
    border: 1px solid #5a5f68;
    border-radius: 4px;
    padding: 6px 8px;
    font: inherit;
}
.name-row input:focus { outline: 2px solid #7aa; }

table.scores { width: 100%; border-collapse: collapse; margin: 6px 0; }
.scores th, .scores td {
    padding: 4px 8px;
    text-align: center;
    border-bottom: 1px solid #333;
    font-size: 13px;
}
.scores th { color: #9aa0a8; font-weight: normal; }
.scores tr.top td { color: #ffd76a; font-weight: bold; }
.stats { color: #9aa0a8; font-size: 12px; }

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30,30,34,.92);
    color: #eee;
    border: 1px solid #4a4e55;
    border-radius: 4px;
    padding: 9px 18px;
    font-size: 13px;
    opacity: 0;
    transition: opacity .2s ease, transform .2s ease;
    pointer-events: none;
    z-index: 300;
    max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
