:root {
    --rose: #b75b64;
    --blue: #80a5c1;
    --yellow: #f9d060;
    --cream: #f2e8d9;
    --rose-dark: #9a4a52;
    --blue-dark: #5d8aa8;
    --yellow-dark: #d4a830;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', 'Segoe UI', sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: url('../images/0-bg.png') center/cover no-repeat;
}
body.game-active::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('../images/0-bg.png') center/cover no-repeat;
    filter: blur(8px);
    z-index: -2;
    transform: scale(1.05);
}
body.game-active {
    background: transparent;
}

canvas {
    display: block;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* ============================================================
   加载页面
   ============================================================ */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#loading-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('../images/0-bg.png') center/cover no-repeat;
    filter: blur(10px);
    z-index: -1;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    position: relative;
    width: 50px;
    height: 50px;
    margin: 0 auto 20px;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-top-color: var(--yellow);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.loading-spinner::after {
    content: '';
    position: absolute;
    inset: 8px;
    border: 3px solid transparent;
    border-bottom-color: var(--yellow);
    border-radius: 50%;
    animation: spin 1.1s linear infinite reverse;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--cream);
    font-size: 22px;
    letter-spacing: 4px;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

/* ============================================================
   开始游戏页面
   ============================================================ */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1500;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, transform 0.5s ease;
    overflow: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#start-screen::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    background: url('../images/0-bg.png') center/cover no-repeat;
    z-index: -1;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#start-screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
}

.start-bg-deco {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 15% 20%, rgba(128,165,193,0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 75%, rgba(183,91,100,0.12) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(249,208,96,0.08) 0%, transparent 60%);
    pointer-events: none;
}

.start-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
    z-index: 1;
}

.title-text {
    font-size: 72px;
    color: #fff;
    letter-spacing: 10px;
    text-shadow:
        3px 3px 0 var(--rose-dark),
        0 0 30px rgba(249,208,96,0.4);
    line-height: 1.2;
}

#start-btn {
    padding: 18px 55px;
    width: 240px;
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 26px;
    color: #fff;
    background: var(--blue);
    border: 4px solid var(--blue-dark);
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 5px 5px 0 var(--blue-dark);
    letter-spacing: 4px;
    outline: none;
    transform: translateY(0);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

#start-btn:active {
    transform: translateY(4px);
    box-shadow: 1px 1px 0 var(--blue-dark);
}

/* ============================================================
   游戏结束弹窗
   ============================================================ */
#game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#game-over-modal::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    background: url('../images/0-bg.png') center/cover no-repeat;
    filter: blur(8px);
    z-index: -1;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

#game-over-modal::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    z-index: -1;
}

#game-over-modal.visible {
    opacity: 1;
    pointer-events: auto;
}

.modal-bg-deco {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 30% 40%, rgba(183,91,100,0.1) 0%, transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(128,165,193,0.1) 0%, transparent 40%);
    pointer-events: none;
}

.modal-content {
    position: relative;
    background: var(--cream);
    padding: 35px 45px 30px;
    border: 5px solid var(--rose);
    border-radius: 40px 15px 40px 15px;
    text-align: center;
    box-shadow:
        8px 8px 0 var(--rose-dark),
        0 0 0 10px var(--cream),
        0 0 0 15px var(--blue);
    min-width: 280px;
    transform: scale(0.5) rotate(-2deg);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#game-over-modal.visible .modal-content {
    transform: scale(1) rotate(0deg);
}

.modal-stamp {
    position: absolute;
    top: -18px;
    right: -10px;
    padding: 6px 18px;
    background: var(--rose);
    color: var(--cream);
    font-size: 16px;
    letter-spacing: 3px;
    border: 3px solid var(--cream);
    border-radius: 8px 20px 8px 20px;
    transform: rotate(8deg);
    box-shadow: 2px 2px 0 rgba(0,0,0,0.2);
}

.modal-content h1 {
    color: var(--rose-dark);
    font-size: 32px;
    margin-bottom: 8px;
    letter-spacing: 4px;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.1);
}

.score-label {
    color: var(--blue-dark);
    font-size: 16px;
    margin-bottom: 4px;
    letter-spacing: 3px;
}

.score-display {
    font-size: 68px;
    color: var(--rose);
    font-weight: bold;
    margin: 10px 0;
    text-shadow:
        3px 3px 0 var(--rose-dark),
        0 0 15px rgba(249,208,96,0.6);
    letter-spacing: 2px;
    line-height: 1;
}

.score-stars {
    height: 8px;
    margin: 8px 0 20px;
    background: repeating-linear-gradient(
        90deg,
        var(--yellow) 0px,
        var(--yellow) 10px,
        transparent 10px,
        transparent 16px
    );
    border-radius: 4px;
}

#restart-btn {
    position: relative;
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 22px;
    color: var(--cream);
    background: var(--rose);
    border: 4px solid var(--rose-dark);
    padding: 14px 38px;
    border-radius: 50px 18px 50px 18px;
    cursor: pointer;
    letter-spacing: 3px;
    box-shadow:
        4px 4px 0 var(--rose-dark),
        0 0 0 5px var(--cream),
        0 0 0 9px var(--yellow);
    transition: all 0.15s ease;
    outline: none;
}

#restart-btn:hover {
    background: #c76b74;
    transform: translateY(-2px);
    box-shadow:
        6px 6px 0 var(--rose-dark),
        0 0 0 5px var(--cream),
        0 0 0 9px var(--yellow);
}

#restart-btn:active {
    transform: translateY(2px);
    box-shadow:
        2px 2px 0 var(--rose-dark),
        0 0 0 5px var(--cream),
        0 0 0 9px var(--yellow);
}

/* ============================================================
   暂停页面
   ============================================================ */
#pause-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
#pause-screen::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    background: url('../images/0-bg.png') center/cover no-repeat;
    filter: blur(8px);
    z-index: -1;
}
#pause-screen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    z-index: -1;
}
#pause-screen:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}
#pause-screen.hidden {
    opacity: 0;
    pointer-events: none;
}
#pause-screen:not(.hidden) .modal-content {
    transform: scale(1) rotate(0deg);
}
#pause-screen .modal-content {
    transform: scale(0.5) rotate(-2deg);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#pause-screen .modal-content h1 {
    color: var(--blue-dark);
    margin-bottom: 4px;
}
.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}
#resume-btn {
    position: relative;
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 22px;
    color: var(--cream);
    background: var(--rose);
    border: 4px solid var(--rose-dark);
    padding: 14px 38px;
    border-radius: 50px 18px 50px 18px;
    cursor: pointer;
    letter-spacing: 3px;
    box-shadow: 4px 4px 0 var(--rose-dark),
                0 0 0 5px var(--cream),
                0 0 0 9px var(--yellow);
    transition: all 0.15s ease;
    outline: none;
}
#resume-btn:hover {
    background: #c76b74;
    transform: translateY(-2px);
    box-shadow: 6px 6px 0 var(--rose-dark),
                0 0 0 5px var(--cream),
                0 0 0 9px var(--yellow);
}
#resume-btn:active {
    transform: translateY(2px);
    box-shadow: 2px 2px 0 var(--rose-dark),
                0 0 0 5px var(--cream),
                0 0 0 9px var(--yellow);
}
#pause-restart-btn {
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 18px;
    color: var(--cream);
    background: var(--blue);
    border: 4px solid var(--blue-dark);
    padding: 10px 28px;
    border-radius: 10px;
    cursor: pointer;
    letter-spacing: 2px;
    box-shadow: 3px 3px 0 var(--blue-dark);
    transition: all 0.15s ease;
    outline: none;
}
#pause-restart-btn:hover {
    background: #5d95b8;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0 var(--blue-dark);
}
#pause-restart-btn:active {
    transform: translateY(2px);
    box-shadow: 1px 1px 0 var(--blue-dark);
}

/* ============================================================
   排行榜页面
   ============================================================ */
#records-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
#records-screen::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    width: calc(100% + 20px);
    height: calc(100% + 20px);
    background: url('../images/0-bg.png') center/cover no-repeat;
    filter: blur(8px);
    z-index: -1;
}
#records-screen::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    z-index: -1;
}
#records-screen:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}
#records-screen.hidden {
    opacity: 0;
    pointer-events: none;
}
#records-screen:not(.hidden) .modal-content {
    transform: scale(1) rotate(0deg);
}
#records-screen .modal-content {
    transform: scale(0.5) rotate(-2deg);
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.records-content {
    min-width: 310px;
    max-width: 400px;
    font-size: 17px;
}
.records-content h1 {
    color: var(--yellow-dark);
    margin-bottom: 16px;
    font-size: 32px;
}
.records-table-wrap {
    max-height: 340px;
    overflow-y: auto;
    margin-bottom: 18px;
}
#records-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--rose-dark);
    font-size: 17px;
}
#records-table th {
    color: var(--blue-dark);
    font-size: 14px;
    padding: 7px 10px;
    border-bottom: 2px solid var(--rose);
    letter-spacing: 1px;
}
#records-table td {
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid rgba(183,91,100,0.15);
}
#records-table tr.top-record td {
    color: var(--rose);
    font-weight: bold;
    font-size: 18px;
    background: rgba(249,208,96,0.12);
}
#records-table .empty-records {
    color: #999;
    font-size: 16px;
    padding: 20px 0;
}

/* ============================================================
   通用控件
   ============================================================ */

.btn-secondary {
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 17px;
    color: var(--blue-dark);
    background: rgba(128,165,193,0.15);
    border: 2px solid var(--blue-dark);
    border-radius: 10px;
    padding: 8px 24px;
    cursor: pointer;
    letter-spacing: 2px;
    outline: none;
    transition: all 0.15s ease;
    margin-top: 4px;
}
.btn-secondary:hover {
    background: rgba(128,165,193,0.25);
}
.btn-secondary:active {
    transform: translateY(2px);
}

.game-stats {
    margin: 6px 0;
    font-size: 15px;
    color: var(--blue-dark);
}
.stat-item {
    margin: 0 6px;
}

.new-record-badge {
    background: linear-gradient(135deg, #ffd700, #ff8c00);
    color: #fff;
    font-size: 18px;
    padding: 4px 20px;
    border-radius: 20px;
    margin: 8px auto;
    display: inline-block;
    animation: pulse-badge 1s ease-in-out infinite alternate;
    letter-spacing: 2px;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}
.new-record-badge.hidden {
    display: none !important;
}
@keyframes pulse-badge {
    from { transform: scale(1); }
    to { transform: scale(1.08); }
}

.score-rank {
    font-size: 16px;
    color: var(--rose);
    margin: 4px 0 8px;
    letter-spacing: 2px;
}

#records-btn {
    padding: 18px 55px;
    font-family: 'ZCOOL KuaiLe', 'Comic Sans MS', sans-serif;
    font-size: 26px;
    color: var(--cream);
    background: var(--yellow-dark);
    border: 4px solid #b89220;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 5px 5px 0 #b89220;
    letter-spacing: 4px;
    outline: none;
    transition: all 0.1s ease;
    width: 240px;
}
#records-btn:active {
    transform: translateY(4px);
    box-shadow: 1px 1px 0 #b89220;
}