* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-primary: #FFF8F0;
    --bg-card: rgba(255, 248, 240, 0.92);
    --bg-card-solid: #FFF0E0;
    --text-primary: #2C1810;
    --text-secondary: rgba(44, 24, 16, 0.5);
    --accent-orange: #E85D26;
    --accent-red: #D63030;
    --accent-warm: #CC7700;
    --accent-gold: #B8860B;
    --border-subtle: rgba(44, 24, 16, 0.15);
    --border-accent: rgba(232, 93, 38, 0.35);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
    width: 100%;
    height: 100%;
    height: -webkit-fill-available;
    overflow: hidden;
    background: var(--bg-primary);
    font-family: 'Inter', 'Noto Sans SC', sans-serif;
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
    -webkit-overflow-scrolling: none;
    touch-action: none;
    position: fixed;
    top: 0;
    left: 0;
}

/* 扫描线效果取消（浅色背景不需要） */
.scanlines {
    display: none;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    overflow: hidden;
}

.screen.active {
    display: flex;
}

/* ===== 主界面 ===== */
.home-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 16px;
    justify-content: center;
    align-items: center;
    overflow: auto;
    padding-top: calc(20px + var(--safe-top));
    padding-bottom: calc(20px + var(--safe-bottom));
    background:
        radial-gradient(circle at 20% 30%, rgba(255, 200, 160, 0.35) 0%, transparent 45%),
        radial-gradient(circle at 80% 20%, rgba(255, 170, 120, 0.30) 0%, transparent 50%),
        radial-gradient(circle at 60% 80%, rgba(255, 210, 170, 0.32) 0%, transparent 55%),
        radial-gradient(circle at 10% 85%, rgba(255, 180, 130, 0.25) 0%, transparent 45%),
        linear-gradient(180deg, #FFF8F0 0%, #FFEEDF 50%, #FFF4E8 100%);
}

.title-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.game-title {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: clamp(32px, 8vw, 72px);
    font-weight: 900;
    color: #CC5500;
    letter-spacing: 4px;
    text-shadow:
        0 1px 2px rgba(204, 85, 0, 0.3),
        0 2px 8px rgba(232, 93, 38, 0.15);
}

.game-subtitle {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: clamp(14px, 3vw, 22px);
    color: var(--accent-warm);
    opacity: 0.85;
}

/* 主内容区（单列居中） */
.content-area {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* 排行榜按钮 */
.leaderboard-btn {
    width: 100%;
    padding: 14px 24px;
    min-height: 48px;
    background: var(--bg-card-solid);
    border: 2px solid var(--border-accent);
    color: var(--accent-orange);
    font-family: 'Noto Sans SC', sans-serif;
    font-size: clamp(16px, 3vw, 20px);
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: 2px;
}

.leaderboard-btn:active {
    background: var(--accent-orange);
    color: #FFFFFF;
}

/* 排行榜弹窗 */
.leaderboard-modal-box {
    max-width: 480px;
    max-height: 80vh;
    padding: 20px 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.leaderboard-modal-box .modal-title {
    text-align: center;
    white-space: nowrap;
    align-self: center;
}

.leaderboard-table {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.leaderboard-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    padding: 40px 12px;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 8px;
}

.leaderboard-row:nth-child(even) {
    background: rgba(232, 93, 38, 0.06);
}

.leaderboard-row.top3 .rank,
.leaderboard-row.top3 .score {
    color: var(--accent-orange);
}

.leaderboard-row.self {
    background: rgba(232, 93, 38, 0.12) !important;
    border: 1px solid var(--border-accent);
}

.rank {
    font-family: 'Roboto Mono', monospace;
    font-size: clamp(12px, 2vw, 16px);
    font-weight: 700;
    color: var(--text-primary);
    width: 48px;
    text-align: center;
    flex-shrink: 0;
}

.player-name {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: clamp(12px, 2vw, 16px);
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.score {
    font-family: 'Roboto Mono', monospace;
    font-size: clamp(12px, 2vw, 16px);
    font-weight: 700;
    color: var(--accent-orange);
    width: 80px;
    text-align: right;
    flex-shrink: 0;
}

.leaderboard-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    gap: 8px;
    background: rgba(232, 93, 38, 0.08);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    flex-shrink: 0;
}

/* 右侧面板 */
.right-panel {
    width: 100%;
    background: var(--bg-card);
    border: 2px solid var(--border-accent);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    justify-content: center;
    align-items: stretch;
    overflow-y: auto;
    backdrop-filter: blur(8px);
}

.online-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.online-dot {
    width: 8px;
    height: 8px;
    background: #00CC55;
    animation: blink 0.8s steps(2) infinite;
    flex-shrink: 0;
}

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

.input-label {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

.input-frame {
    background: #FFFFFF;
    border: 2px solid var(--border-accent);
    padding: 10px;
}

.name-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    -webkit-appearance: none;
}

.name-input::placeholder {
    color: rgba(44, 24, 16, 0.3);
}

.rules-box {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid var(--border-accent);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rules-title {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-orange);
}

.rules-item {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 11px;
    color: var(--text-primary);
}

.rules-item.danger {
    color: var(--accent-red);
}

.rules-item.warn {
    color: var(--accent-warm);
}

/* 开始游戏画布（划开水果） */
.start-canvas-wrapper {
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border-accent);
    overflow: hidden;
    min-height: 160px;
    flex-shrink: 0;
}

.start-canvas {
    width: 100%;
    height: 160px;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

.footer {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    flex-shrink: 0;
}

/* ===== 游戏界面 ===== */
#gameScreen {
    flex-direction: column;
    background:
        radial-gradient(circle at 20% 30%, rgba(255, 200, 160, 0.35) 0%, transparent 45%),
        radial-gradient(circle at 80% 20%, rgba(255, 170, 120, 0.30) 0%, transparent 50%),
        radial-gradient(circle at 60% 80%, rgba(255, 210, 170, 0.32) 0%, transparent 55%),
        radial-gradient(circle at 10% 85%, rgba(255, 180, 130, 0.25) 0%, transparent 45%),
        linear-gradient(180deg, #FFF8F0 0%, #FFEEDF 50%, #FFF4E8 100%);
    padding-top: var(--safe-top);
}

.hud {
    height: clamp(56px, 10vh, 80px);
    background: var(--bg-card);
    border-bottom: 2px solid var(--border-accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    position: relative;
    z-index: 10;
    flex-shrink: 0;
    backdrop-filter: blur(8px);
}

.hud-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.hud-group.center {
    align-items: center;
}

.hud-group.right {
    align-items: flex-end;
    margin-right: 50px;
}

.hud-label {
    font-family: 'Inter', sans-serif;
    font-size: clamp(9px, 1.5vw, 12px);
    font-weight: 700;
    color: var(--text-secondary);
}

.hud-value {
    font-family: 'Roboto Mono', monospace;
    font-size: clamp(20px, 5vw, 32px);
    font-weight: 700;
    color: var(--text-primary);
}

.hud-value.lives {
    color: var(--accent-red);
}

.hud-value.combo {
    color: var(--accent-orange);
}

.pause-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    background: rgba(255, 255, 255, 0.5);
    border: 2px solid var(--border-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#gameCanvas {
    flex: 1;
    display: block;
    touch-action: none;
    width: 100%;
    background: transparent;
}

/* 弹窗 */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 248, 240, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-box {
    background: var(--bg-card-solid);
    border: 2px solid var(--accent-orange);
    padding: 32px 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: calc(100% - 48px);
    max-width: 360px;
    box-shadow: 0 4px 20px rgba(232, 93, 38, 0.15);
}

.modal-title {
    font-family: 'Noto Sans SC', sans-serif;
    font-size: clamp(24px, 6vw, 36px);
    font-weight: 900;
    color: var(--accent-orange);
    text-shadow: none;
}

.final-score, .final-rank {
    font-family: 'Roboto Mono', monospace;
    font-size: clamp(16px, 3vw, 20px);
    color: var(--text-primary);
}

.modal-btn {
    width: 100%;
    padding: 14px 24px;
    min-height: 48px;
    background: transparent;
    border: 2px solid var(--accent-orange);
    color: var(--accent-orange);
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.modal-btn:active {
    background: var(--accent-orange);
    color: #FFFFFF;
}

/* ==================== 响应式 ==================== */

/* 平板 */
@media (max-width: 900px) {
    .home-container {
        padding: 16px;
    }

    .right-panel {
        padding: 20px;
        gap: 14px;
    }

    .content-area {
        max-width: 360px;
    }
}

/* 手机 — 纵向堆叠 */
@media (max-width: 640px) {
    .home-container {
        padding: 12px;
        gap: 10px;
        justify-content: flex-start;
        padding-top: calc(12px + var(--safe-top));
        padding-bottom: calc(12px + var(--safe-bottom));
    }

    .content-area {
        gap: 10px;
        flex: 1;
    }

    .right-panel {
        padding: 14px;
        gap: 10px;
        justify-content: flex-start;
    }

    .game-title {
        letter-spacing: 2px;
        font-size: clamp(28px, 9vw, 48px);
    }

    .start-canvas {
        height: 140px;
    }

    .start-canvas-wrapper {
        min-height: 140px;
    }

    .hud {
        padding: 0 8px;
    }

    .hud-group.right {
        margin-right: 44px;
    }

    .modal-box {
        padding: 24px 20px;
        width: calc(100% - 32px);
        gap: 12px;
    }

    .leaderboard-modal-box {
        max-height: 75vh;
    }
}

/* 超小屏 */
@media (max-width: 360px) {
    .right-panel {
        padding: 10px;
        gap: 8px;
    }

    .start-canvas {
        height: 120px;
    }

    .start-canvas-wrapper {
        min-height: 120px;
    }
}

/* 横屏手机 */
@media (max-width: 900px) and (orientation: landscape) {
    .home-container {
        padding: 8px 12px;
        gap: 8px;
    }

    .game-title {
        font-size: clamp(24px, 5vw, 48px);
    }

    .game-subtitle {
        font-size: 13px;
    }

    .start-canvas {
        height: 100px;
    }

    .start-canvas-wrapper {
        min-height: 100px;
    }

    .content-area {
        max-width: 320px;
    }
}

/* 桌面端 hover */
@media (hover: hover) {
    .leaderboard-btn:hover {
        background: var(--accent-orange);
        color: #FFFFFF;
    }

    .leaderboard-row:hover {
        background: rgba(232, 93, 38, 0.08);
    }

    .pause-btn:hover {
        background: rgba(232, 93, 38, 0.1);
    }

    .modal-btn:hover {
        background: var(--accent-orange);
        color: #FFFFFF;
    }

    #gameCanvas {
        cursor: crosshair;
    }
}
