html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #fff;
    overscroll-behavior: none;
}

/* 与旧版一致：桌面 20px；触屏按短边/320*10 缩放，最大 30px */
html, body { font-size: 20px; }
@media (pointer: coarse) {
    html, body { font-size: 3.125vmin; font-size: min(30px, 3.125vmin); }
}

* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

input {
    -webkit-user-select: text;
    user-select: text;
}

.SHADE {
    top: 0;
    left: 0;
    width: 100%;
    bottom: 0;
    z-index: 11;
}

/* 桌面端游戏区居中 640px，触屏设备铺满屏幕 */
#gameBody {
    position: relative;
    width: 640px;
    max-width: 100%;
    height: 100%;
    margin: 0 auto;
    overflow: hidden;
}
@media (pointer: coarse) {
    #gameBody { width: 100%; }
}

#welcome, #GameTimeLayer, #GameLayerBG, #GameScoreLayer { position: absolute; }
#GameLayerBG { touch-action: none; }

#GameTimeLayer {
    top: 1em;
    left: 0;
    width: 100%;
    text-align: center;
    color: rgb(233, 138, 131);
    font-size: 4em;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff;
    overflow: hidden;
    pointer-events: none;
    z-index: 2;
}

#GameLayerBG {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    background: #fff;
}

/* 尺寸由 JS 设为正好包住 40 个方块；不要加 will-change，
   否则 Safari 每次方块换图都会整层重绘，出现全屏闪白 */
.GameLayer {
    position: absolute;
    bottom: 0;
    left: 0;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.block {
    position: absolute;
    box-sizing: border-box;
    border-top: 1px solid #b8dfe6;
    background-repeat: no-repeat;
    background-position: center;
}

.bl { border-left: 1px solid #b8dfe6; }

.t1, .t2, .t3, .t4, .t5 {
    background-size: auto 100%;
    background-image: url(./image/ClickBefore.png);
}

.tt1, .tt2, .tt3, .tt4, .tt5 {
    background-size: auto 86%;
    background-image: url(./image/AfterClicking.png);
}

@-webkit-keyframes flash { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }
@keyframes flash { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }

.flash { -webkit-animation: flash .2s 3; animation: flash .2s 3; }

.bad {
    background-color: rgb(211, 91, 91);
    -webkit-animation: flash .2s 3;
    animation: flash .2s 3;
}

/* ---------- 浮层（开始、设置、结算）：尺寸用 px，与游戏区的缩放无关 ----------
   配色取自游戏本身：墨色是奏宝头发的深蓝，红色是泡面杯，黄色是点中后的星星，浅青是格线 */
#welcome, #GameScoreLayer {
    --ink: #233047;
    --muted: #5f6b7d;
    --red: #d9443a;
    --red-edge: #9e2d26;
    --star: #ffc53d;
    --line: #b8dfe6;
    --soft: #eef6f7;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
    overflow: auto;
    box-sizing: border-box;
}
/* 开始界面不遮住棋盘：透出底下排好的方块 */
#welcome {
    background: rgba(255, 255, 255, .5);
    padding-top: max(60px, env(safe-area-inset-top));
}
#GameScoreLayer { display: none; background: rgba(35, 48, 71, .45); }
#GameScoreLayer.show { display: flex; }

.card {
    width: 100%;
    max-width: 360px;
    margin: auto;
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 20px;
    padding: 26px 22px 20px;
    box-sizing: border-box;
    text-align: center;
    box-shadow: 0 6px 0 var(--ink);
}
#GameScoreLayer.show .card { animation: drop .22s cubic-bezier(.2, .9, .3, 1.15); }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #GameScoreLayer.show .card { animation: none; } }

.mascot {
    display: block;
    width: 104px;
    height: 104px;
    margin: -64px auto 10px;
    object-fit: cover;
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 18px;
    transform: rotate(-5deg);
}
.title {
    margin: 0;
    font-size: 34px;
    line-height: 1.2;
    font-weight: 900;
    letter-spacing: .04em;
}
.tagline { margin: 2px 0 0; font-size: 14px; font-weight: 700; color: var(--red); }
.intro { margin: 12px 0 20px; font-size: 16px; color: var(--muted); }
.hint { margin-top: 12px; font-size: 12px; color: var(--muted); }
@media (pointer: coarse) { .key-hint { display: none; } }
kbd {
    font: inherit;
    font-weight: 800;
    color: var(--ink);
    padding: 0 6px;
    border-radius: 6px;
    background: #fff;
    border: 1.5px solid var(--ink);
    box-shadow: 0 2px 0 var(--ink);
}

.btn {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-weight: 800;
    border: 2px solid var(--ink);
    border-radius: 14px;
    padding: 10px 16px;
    cursor: pointer;
    text-decoration: none;
    color: var(--ink);
    background: #fff;
    box-shadow: 0 4px 0 var(--ink);
    transition: transform .06s, box-shadow .06s;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--star); outline-offset: 3px; }
.btn:disabled { cursor: default; }
.btn-primary { color: #fff; background: var(--red); border-color: var(--red-edge); box-shadow: 0 4px 0 var(--red-edge); }
.btn-primary:hover { background: #e24f45; }
.btn-primary:active { box-shadow: 0 1px 0 var(--red-edge); }
.btn-big { width: 100%; padding: 13px 18px; font-size: 19px; letter-spacing: .1em; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; margin-top: 18px; }
.actions .btn { padding: 12px 10px; font-size: 16px; }

.btn-primary.loading {
    color: transparent;
    background-image: url("data:image/gif;base64,R0lGODlhJQAlAJECAL3L2AYrTv///wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgACACwAAAAAJQAlAAACi5SPqcvtDyGYIFpF690i8xUw3qJBwUlSadmcLqYmGQu6KDIeM13beGzYWWy3DlB4IYaMk+Dso2RWkFCfLPcRvFbZxFLUDTt21BW56TyjRep1e20+i+eYMR145W2eefj+6VFmgTQi+ECVY8iGxcg35phGo/iDFwlTyXWphwlm1imGRdcnuqhHeop6UAAAIfkEBQoAAgAsEAACAAQACwAAAgWMj6nLXAAh+QQFCgACACwVAAUACgALAAACFZQvgRi92dyJcVJlLobUdi8x4bIhBQAh+QQFCgACACwXABEADAADAAACBYyPqcsFACH5BAUKAAIALBUAFQAKAAsAAAITlGKZwWoMHYxqtmplxlNT7ixGAQAh+QQFCgACACwQABgABAALAAACBYyPqctcACH5BAUKAAIALAUAFQAKAAsAAAIVlC+BGL3Z3IlxUmUuhtR2LzHhsiEFACH5BAUKAAIALAEAEQAMAAMAAAIFjI+pywUAIfkEBQoAAgAsBQAFAAoACwAAAhOUYJnAagwdjGq2amXGU1PuLEYBACH5BAUKAAIALBAAAgAEAAsAAAIFhI+py1wAIfkEBQoAAgAsFQAFAAoACwAAAhWUL4AIvdnciXFSZS6G1HYvMeGyIQUAIfkEBQoAAgAsFwARAAwAAwAAAgWEj6nLBQAh+QQFCgACACwVABUACgALAAACE5RgmcBqDB2MarZqZcZTU+4sRgEAIfkEBQoAAgAsEAAYAAQACwAAAgWEj6nLXAAh+QQFCgACACwFABUACgALAAACFZQvgAi92dyJcVJlLobUdi8x4bIhBQAh+QQFCgACACwBABEADAADAAACBYSPqcsFADs=");
    background-repeat: no-repeat;
    background-position: center center;
    background-size: auto 60%;
}

.chip {
    display: inline-block;
    margin-top: 14px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 13px;
    color: var(--muted);
    background: var(--soft);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
}
.chip b { color: var(--ink); }
.chip.warn { color: #8a3a00; background: #fff1cc; }

#setting { display: none; text-align: left; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 800; margin: 0 0 4px 2px; }
.field input {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 16px; /* 不小于 16px，避免 iOS 聚焦时放大页面 */
    color: var(--ink);
    background: #fff;
    border: 2px solid var(--line);
    border-radius: 12px;
    padding: 9px 12px;
    outline: none;
}
.field input:focus { border-color: var(--ink); }
.field input::placeholder { color: var(--muted); opacity: .7; }

/* 结算 */
.score-line { display: flex; align-items: baseline; justify-content: center; gap: 4px; color: var(--red); }
.big-score {
    font-size: 84px;
    line-height: 1;
    font-weight: 900;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}
.unit { font-size: 22px; font-weight: 900; }
.big-score.invalid { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 4px; }
.comment { font-size: 20px; font-weight: 900; margin-top: 8px; min-height: 1.5em; }
.newbest {
    display: inline-block;
    margin-left: 8px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 13px;
    vertical-align: 3px;
    color: #5a4100;
    background: var(--star);
}
.facts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 16px;
    border-top: 2px dashed var(--line);
    border-bottom: 2px dashed var(--line);
    padding: 10px 0;
}
.facts div + div { border-left: 2px dashed var(--line); }
.facts span { display: block; font-size: 12px; color: var(--muted); }
.facts b { display: block; font-size: 24px; font-weight: 900; font-variant-numeric: tabular-nums; }
.status { font-size: 13px; color: var(--muted); min-height: 1.6em; margin-top: 10px; }
.status.ok { color: #1f8a4c; }
.status.err { color: var(--red); }
#setting .status { min-height: 0; margin: -4px 0 10px; text-align: center; }
