:root {
    --ink: #2f2a2a;
    --paper: #fffdf7;
    --sky: #bfe7f6;
    --red: #e52521;
    --green: #4caf50;
    --font: 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--sky);
}

body {
    margin: 0;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    background: var(--sky);
    color: var(--ink);
    font-family: var(--font);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button {
    font-family: inherit;
    color: inherit;
}

.page {
    max-width: 840px;
    margin: 0 auto;
}

h1 {
    margin: 4px 0 10px;
    text-align: center;
    color: var(--red);
    font-size: 30px;
    text-shadow: 3px 3px 0 #fff;
}

h1 small {
    margin-left: 10px;
    font-size: 18px;
    color: var(--ink);
    text-shadow: none;
}

/* ---------- 状态栏 ---------- */
.hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-around;
    gap: 8px 18px;
    margin-bottom: 10px;
    padding: 10px 14px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 16px;
    box-shadow: 4px 4px 0 var(--ink);
    font-size: 16px;
}

.hud strong {
    font-size: 22px;
    font-variant-numeric: tabular-nums;
}

.hud-icon {
    width: 24px;
    height: 24px;
    vertical-align: -6px;
}

.level {
    color: #f5b800;
    font-size: 18px;
    letter-spacing: 1px;
    text-shadow: 0 0 1px var(--ink), 0 0 1px var(--ink);
}

/* ---------- 画面 ---------- */
.stage {
    position: relative;
    border: 3px solid var(--ink);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 5px 5px 0 var(--ink);
    background: #8fd3e8;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 2 / 1;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    text-align: center;
}

.overlay[hidden] {
    display: none;
}

.cover-screen {
    padding: 0;
    background: #fff;
}

.cover {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cover-actions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 6%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.howto {
    margin: 0;
    padding: 2px 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.85);
    font-size: 14px;
}

.result {
    background: rgba(255, 253, 247, 0.9);
}

.result h2 {
    margin: 0;
    font-size: 32px;
    color: var(--red);
}

.result p {
    margin: 0;
    font-size: 17px;
}

.result strong {
    font-size: 22px;
    color: var(--red);
}

.new-record {
    font-weight: bold;
    color: #d98a00;
}

.big-button {
    padding: 10px 34px;
    border: 3px solid var(--ink);
    border-radius: 16px;
    background: var(--red);
    color: #fff;
    font-size: 22px;
    font-weight: bold;
    box-shadow: 4px 4px 0 var(--ink);
    cursor: pointer;
}

.big-button:active {
    transform: translate(3px, 3px);
    box-shadow: 1px 1px 0 var(--ink);
}

.big-button:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ---------- 触屏按钮：只在触屏设备上显示 ---------- */
.touch-controls {
    display: none;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

@media (pointer: coarse) {
    .touch-controls {
        display: grid;
    }
}

.touch-controls button {
    height: 72px;
    border: 3px solid var(--ink);
    border-radius: 18px;
    background: var(--paper);
    font-size: 26px;
    font-weight: bold;
    box-shadow: 3px 3px 0 var(--ink);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-controls button:active {
    background: #ffe3e3;
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--ink);
}

/* 缩壳按钮：冷却时从下往上慢慢填满 */
.shell-button {
    --ready: 1;
    font-size: 20px !important;
    background: linear-gradient(to top, #bde3ff calc(var(--ready) * 100%), var(--paper) calc(var(--ready) * 100%)) !important;
}

.shell-button.cooling {
    color: #8a8a8a;
}

/* ---------- 工具栏 ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 16px;
}

.toolbar button {
    padding: 8px 14px;
    border: 2px solid var(--ink);
    border-radius: 12px;
    background: var(--paper);
    font-size: 15px;
    box-shadow: 2px 2px 0 var(--ink);
    cursor: pointer;
}

.toolbar button:active {
    transform: translate(2px, 2px);
    box-shadow: none;
}

/* ---------- 关于弹窗 ---------- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(20, 40, 50, 0.45);
}

.modal[hidden] {
    display: none;
}

.modal-card {
    position: relative;
    width: min(100%, 480px);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 22px 20px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 18px;
    box-shadow: 6px 6px 0 var(--ink);
    line-height: 1.6;
}

.modal-card h2 {
    margin: 0 0 10px;
}

.modal-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 28px;
    cursor: pointer;
}

.rules {
    padding-left: 20px;
}

.credits {
    padding-top: 8px;
    border-top: 2px dashed #c9d9e0;
}

.credits p {
    margin: 4px 0;
}

@media (max-width: 520px) {
    h1 {
        font-size: 24px;
    }

    h1 small {
        display: block;
        margin: 0;
        font-size: 14px;
    }

    .hud {
        font-size: 13px;
    }

    .hud strong {
        font-size: 17px;
    }

    .big-button {
        font-size: 16px;
        padding: 6px 20px;
    }

    .howto {
        font-size: 11px;
    }

    .result h2 {
        font-size: 22px;
    }

    .result p {
        font-size: 13px;
    }

    .result strong {
        font-size: 16px;
    }
}
