/* ====== CSS 变量系统 ====== */
:root {
    /* 色彩 */
    --c-primary: #C62828;
    --c-primary-light: #FF6B6B;
    --c-primary-dark: #8E0000;
    --c-accent: #FDCB6E;
    --c-bg: #FFF8F0;
    --c-surface: #FFFFFF;
    --c-text: #2D3436;
    --c-text-secondary: #636E72;
    --c-text-tertiary: #B2BEC3;
    --c-success: #00B894;
    --c-warning: #E17055;
    --c-board-bg: rgba(255, 255, 255, 0.55);
    --c-tile-bg: #FFFFFF;
    --c-selected: #FF6B6B;
    --c-match: #00B894;
    --c-shadow: rgba(0, 0, 0, 0.08);
    --c-shadow-lg: rgba(0, 0, 0, 0.12);

    /* 缓动函数 */
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring-soft: cubic-bezier(0.25, 1.2, 0.5, 1.1);
    --ease-spring-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);
    --ease-match-pop: cubic-bezier(0.34, 1.8, 0.64, 1);
    --ease-shake: cubic-bezier(0.36, 0.07, 0.19, 0.97);

    /* 字体 */
    --font-display: 'Ma Shan Zheng', cursive;
    --font-body: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
    --font-mono: 'DIN Alternate', 'Helvetica Neue', sans-serif;

    /* 间距 */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-safe-bottom: env(safe-area-inset-bottom, 0px);

    /* 圆角 */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 999px;
}

/* ====== 全局重置 ====== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--c-bg);
    color: var(--c-text);
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
}

/* 隐藏滚动条 */
::-webkit-scrollbar { display: none; }

/* ====== 粒子背景层 ====== */
#particleCanvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* ====== 屏幕边缘警告 ====== */
.edge-warning {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    box-shadow: inset 0 0 80px rgba(225, 112, 85, 0);
    transition: opacity 0.3s, box-shadow 0.3s;
}
.edge-warning.active {
    opacity: 1;
    box-shadow: inset 0 0 80px rgba(225, 112, 85, 0.2);
    animation: edgePulse 0.8s ease infinite;
}
@keyframes edgePulse {
    0%, 100% { box-shadow: inset 0 0 60px rgba(225, 112, 85, 0.15); }
    50% { box-shadow: inset 0 0 100px rgba(225, 112, 85, 0.28); }
}

/* ====== 屏幕容器 ====== */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-width: 480px;
    margin: 0 auto;
    left: 50%;
    transform: translateX(-50%);
    transition: opacity 0.3s ease, transform 0.35s var(--ease-out-expo);
}
.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(20px);
}

/* ====== 顶部装饰条 ====== */
.top-deco-bar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 180px;
    background: linear-gradient(180deg, rgba(198, 40, 40, 0.08) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
}

/* ====== 按钮系统 ====== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 48px;
    padding: 0 28px;
    border: none;
    border-radius: var(--radius-full);
    font-family: var(--font-body);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
    touch-action: manipulation;
}
.btn:active {
    transform: scale(0.96);
}
.btn:disabled {
    opacity: 0.45;
    pointer-events: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--c-primary-light) 0%, var(--c-primary) 100%);
    color: #fff;
    box-shadow: 0 4px 16px rgba(198, 40, 40, 0.3);
}
.btn-primary:active {
    filter: brightness(0.92);
    box-shadow: 0 2px 8px rgba(198, 40, 40, 0.2);
}

.btn-secondary {
    background: var(--c-surface);
    color: var(--c-primary);
    border: 1.5px solid var(--c-primary);
    box-shadow: 0 1px 4px var(--c-shadow);
}
.btn-secondary:active {
    background: rgba(198, 40, 40, 0.06);
}

.btn-ghost {
    background: transparent;
    color: var(--c-text-secondary);
    font-weight: 500;
}
.btn-ghost:active {
    background: rgba(0, 0, 0, 0.04);
}

.btn-pulse {
    animation: btnPulse 2.2s ease infinite;
}
@keyframes btnPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 4px 16px rgba(198, 40, 40, 0.3); }
    50% { transform: scale(1.02); box-shadow: 0 6px 24px rgba(198, 40, 40, 0.38); }
}

.btn-svg-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ====== 图标按钮 ====== */
.icon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 64px;
    background: none;
    border: none;
    color: var(--c-primary);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.15s ease;
    touch-action: manipulation;
}
.icon-btn svg {
    width: 28px;
    height: 28px;
    stroke: var(--c-primary);
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.icon-btn:active {
    transform: scale(0.92);
}

/* ====== 导航栏 ====== */
.nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 var(--space-lg);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
    z-index: 20;
}
.nav-back {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--c-text);
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: background 0.15s;
    touch-action: manipulation;
}
.nav-back svg {
    width: 22px;
    height: 22px;
}
.nav-back:active {
    background: rgba(0, 0, 0, 0.06);
}
.nav-title {
    font-family: var(--font-display);
    font-size: 20px;
    color: var(--c-text);
    letter-spacing: 1px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.nav-extra {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: auto;
}
.nav-nickname {
    font-size: 13px;
    color: var(--c-text-secondary);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.score-pill {
    background: linear-gradient(135deg, var(--c-accent), #F0B04E);
    color: var(--c-primary-dark);
    font-size: 12px;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
}

/* ====== 工具按钮 ====== */
.tool-btn {
    position: relative;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--c-surface);
    border: 1.5px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-md);
    color: var(--c-text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
}
.tool-btn svg {
    width: 22px;
    height: 22px;
}
.tool-btn:active {
    transform: scale(0.93);
    background: rgba(198, 40, 40, 0.05);
    border-color: rgba(198, 40, 40, 0.2);
}
.tool-btn:disabled {
    opacity: 0.35;
    pointer-events: none;
}
.tool-count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--c-primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
}

/* ====== 暂停按钮 ====== */
.pause-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: var(--radius-full);
    color: var(--c-text-secondary);
    cursor: pointer;
    touch-action: manipulation;
}
.pause-btn svg {
    width: 16px;
    height: 16px;
}
.pause-btn:active {
    background: rgba(0, 0, 0, 0.08);
}

/* ====== 连击提示 ====== */
.combo-popup {
    position: absolute;
    top: 18%;
    left: 50%;
    transform: translateX(-50%) scale(0);
    z-index: 40;
    font-family: var(--font-display);
    font-size: 32px;
    color: var(--c-primary);
    text-shadow: 0 2px 8px rgba(198, 40, 40, 0.2);
    pointer-events: none;
    opacity: 0;
    white-space: nowrap;
}
.combo-popup.show {
    animation: comboIn 0.45s var(--ease-spring-bounce) forwards;
}
.combo-popup.hide {
    animation: comboOut 0.25s ease forwards;
}
@keyframes comboIn {
    0% { transform: translateX(-50%) scale(0.3); opacity: 0; }
    60% { transform: translateX(-50%) scale(1.12); opacity: 1; }
    100% { transform: translateX(-50%) scale(1); opacity: 1; }
}
@keyframes comboOut {
    0% { transform: translateX(-50%) scale(1) translateY(0); opacity: 1; }
    100% { transform: translateX(-50%) scale(0.8) translateY(-20px); opacity: 0; }
}

/* ====== Toast ====== */
.toast {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-30px);
    z-index: 300;
    background: rgba(45, 52, 54, 0.88);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 14px;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s var(--ease-spring-soft);
    max-width: 80vw;
    text-align: center;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ========== 页面1: 开始界面 ========== */
.start-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-xl);
    position: relative;
    z-index: 1;
    gap: var(--space-xl);
}

.logo-section {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.theme-badge {
    display: inline-block;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-dark));
    color: var(--c-accent);
    font-family: var(--font-display);
    font-size: 14px;
    padding: 4px 16px;
    border-radius: var(--radius-full);
    box-shadow: 0 2px 8px rgba(198, 40, 40, 0.25);
}

.game-title {
    font-family: var(--font-display);
    font-size: 38px;
    color: var(--c-text);
    letter-spacing: 3px;
    margin-top: 4px;
}

.game-subtitle {
    font-size: 13px;
    color: var(--c-text-secondary);
    letter-spacing: 2px;
}

.title-underline {
    width: 48px;
    height: 3px;
    background: linear-gradient(90deg, var(--c-primary), var(--c-primary-light));
    border-radius: 2px;
    margin-top: 4px;
}

/* 吉祥物/腊味环绕区域 - 自适应缩放，确保任何屏幕下图标不重叠 */
.mascot-area {
    /* 使用 vmin 确保在竖屏和横屏下都能合理缩放 */
    width: min(260px, 55vmin);
    height: min(260px, 55vmin);
    position: relative;
    animation: mascotFloat 3s ease-in-out infinite;
}
@keyframes mascotFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.mascot-ring {
    width: 100%;
    height: 100%;
    position: relative;
}

/* CSS 变量定义图标尺寸和轨道半径，便于响应式调整 */
:root {
    --mascot-size: 40px;
    --mascot-orbit: 92px;
}

.mascot-item {
    position: absolute;
    /* 图标尺寸使用 CSS 变量 */
    width: var(--mascot-size);
    height: var(--mascot-size);
    /* 动态角度：根据总数量均匀分布在圆周上 */
    top: 50%;
    left: 50%;
    /* 居中偏移 = 尺寸的一半 */
    margin: calc(var(--mascot-size) / -2) 0 0 calc(var(--mascot-size) / -2);
    transform: rotate(calc(var(--i) * var(--angle, 36deg))) translateY(calc(var(--mascot-orbit) * -1)) rotate(calc(var(--i) * var(--angle, -36deg)));
    animation: mascotItemFloat 2.5s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.12s);
}
.mascot-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.12));
}
@keyframes mascotItemFloat {
    0%, 100% { transform: rotate(calc(var(--i) * var(--angle, 36deg))) translateY(calc(var(--mascot-orbit) * -1)) rotate(calc(var(--i) * var(--angle, -36deg))) scale(1); }
    50% { transform: rotate(calc(var(--i) * var(--angle, 36deg))) translateY(calc(var(--mascot-orbit) * -1 - 4px)) rotate(calc(var(--i) * var(--angle, -36deg))) scale(1.06); }
}

/* 中等屏幕：适当缩小 */
@media (max-width: 400px) {
    :root {
        --mascot-size: 34px;
        --mascot-orbit: 78px;
    }
    .mascot-area {
        width: min(220px, 52vmin);
        height: min(220px, 52vmin);
    }
}

/* 小屏幕：进一步缩小 */
@media (max-width: 360px) {
    :root {
        --mascot-size: 30px;
        --mascot-orbit: 68px;
    }
    .mascot-area {
        width: min(190px, 50vmin);
        height: min(190px, 50vmin);
    }
}

/* 极小屏幕（如 iPhone SE / 320px） */
@media (max-width: 320px) {
    :root {
        --mascot-size: 26px;
        --mascot-orbit: 58px;
    }
    .mascot-area {
        width: min(165px, 48vmin);
        height: min(165px, 48vmin);
    }
}

/* 开始操作区 */
.start-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
}

.nickname-wrap {
    width: 100%;
    max-width: 280px;
}

.nickname-input {
    width: 100%;
    height: 44px;
    padding: 0 var(--space-lg);
    border: 1.5px solid rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-full);
    background: var(--c-surface);
    font-family: var(--font-body);
    font-size: 14px;
    text-align: center;
    color: var(--c-text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.nickname-input:focus {
    border-color: var(--c-primary-light);
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}
.nickname-input::placeholder {
    color: var(--c-text-tertiary);
}

#btnStart {
    width: 100%;
    max-width: 280px;
    height: 52px;
    font-size: 16px;
}

.secondary-actions {
    display: flex;
    gap: var(--space-lg);
}

.footer-safe {
    padding-bottom: calc(var(--space-lg) + var(--space-safe-bottom));
}

.compliance-text {
    font-size: 11px;
    color: var(--c-text-tertiary);
    text-align: center;
}

/* ========== 页面2: 关卡选择 ========== */
.level-container {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    padding-bottom: calc(var(--space-xl) + var(--space-safe-bottom));
}

.levels-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

.level-card {
    aspect-ratio: 1;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    transition: all 0.25s var(--ease-spring);
    position: relative;
    border: 2px solid transparent;
}
.level-card.unlocked {
    background: var(--c-surface);
    box-shadow: 0 2px 12px var(--c-shadow);
}
.level-card.unlocked:active {
    transform: scale(0.94);
}
.level-card.locked {
    background: #F5F5F5;
    opacity: 0.55;
    cursor: not-allowed;
}
.level-card.completed {
    border-color: var(--c-success);
    background: linear-gradient(135deg, #fff, #F0FFF9);
}
.level-card.completed::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 8px;
    height: 8px;
    background: var(--c-success);
    border-radius: 50%;
}

.level-num {
    font-family: var(--font-display);
    font-size: 30px;
    color: var(--c-primary);
    line-height: 1;
}
.level-name {
    font-size: 11px;
    color: var(--c-text-secondary);
}
.level-size {
    font-size: 10px;
    color: var(--c-text-tertiary);
    font-family: var(--font-mono);
}
.level-stars {
    display: flex;
    gap: 2px;
    margin-top: 2px;
}
.level-stars .star-icon {
    font-size: 12px;
    color: var(--c-text-tertiary);
}
.level-stars .star-icon.earned {
    color: var(--c-accent);
}

.lock-icon-wrap svg {
    width: 24px;
    height: 24px;
    stroke: var(--c-text-tertiary);
    fill: none;
    stroke-width: 2;
}

/* ========== 页面3: 游戏进行中 ========== */
.game-hud-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    padding-top: calc(var(--space-sm) + env(safe-area-inset-top, 0px));
    flex-shrink: 0;
    gap: var(--space-md);
}

.hud-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 56px;
}
.hud-label {
    font-size: 11px;
    color: var(--c-text-secondary);
    line-height: 1.3;
}
.hud-label span {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--c-text);
}
.hud-score-wrap {
    align-items: flex-end;
    flex: 1;
}
.hud-score {
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 900;
    color: var(--c-text);
    line-height: 1;
}

/* 倒计时环形 */
.hud-timer {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}
.timer-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}
.timer-ring-bg {
    fill: none;
    stroke: rgba(0, 0, 0, 0.06);
    stroke-width: 3;
}
.timer-ring-progress {
    fill: none;
    stroke: var(--c-primary);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 125.66;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-ring-progress.warning {
    stroke: var(--c-warning);
}
.timer-number {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--c-text);
    line-height: 1;
}
.timer-number.warning {
    color: var(--c-warning);
    animation: timerTick 1s ease infinite;
}
@keyframes timerTick {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.18); }
}

/* 游戏棋盘区 */
.game-board-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-lg);
    position: relative;
}

.board-outer {
    position: relative;
    background: var(--c-board-bg);
    border-radius: var(--radius-lg);
    padding: 10px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.game-board {
    display: grid;
    gap: var(--space-sm);
}

.fx-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 5;
    border-radius: var(--radius-lg);
}

/* 图块 */
.tile {
    background: var(--c-tile-bg);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--c-shadow);
    border: 2px solid transparent;
    touch-action: manipulation;
}
.tile::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 45%;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    pointer-events: none;
}
.tile img {
    width: 78%;
    height: 78%;
    object-fit: contain;
    pointer-events: none;
    position: relative;
    z-index: 1;
    transition: transform 0.15s ease;
}
.tile:active {
    transform: scale(0.95);
}
.tile.selected {
    border-color: var(--c-selected);
    box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
    animation: selectedPulse 0.9s ease infinite;
    transform: scale(1.05);
}
@keyframes selectedPulse {
    0%, 100% { box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3); }
    50% { box-shadow: 0 4px 22px rgba(255, 107, 107, 0.45); }
}
.tile.matching {
    border-color: var(--c-match);
    animation: matchPop 0.35s var(--ease-match-pop) forwards;
}
@keyframes matchPop {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.12); }
    100% { transform: scale(0); opacity: 0; }
}
.tile.hint {
    animation: hintPulse 0.8s ease infinite;
    border-color: var(--c-accent);
}
@keyframes hintPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(253, 203, 110, 0.5); }
    50% { box-shadow: 0 0 0 6px rgba(253, 203, 110, 0); }
}
.tile.error {
    animation: tileShake 0.4s var(--ease-shake);
    border-color: var(--c-warning);
}
@keyframes tileShake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-6px); }
    30% { transform: translateX(5px); }
    45% { transform: translateX(-4px); }
    60% { transform: translateX(3px); }
    75% { transform: translateX(-2px); }
}
.tile.empty {
    background: transparent;
    box-shadow: none;
    border-color: transparent;
    pointer-events: none;
    cursor: default;
}
.tile.empty::before { display: none; }

/* 底部 HUD */
.game-hud-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    padding-bottom: calc(var(--space-sm) + var(--space-safe-bottom));
    flex-shrink: 0;
}
.hud-bottom-left {
    font-size: 13px;
    color: var(--c-text-secondary);
}
.matches-num {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--c-text);
}
.hud-bottom-actions {
    display: flex;
    gap: var(--space-md);
}

/* ========== 遮罩层系统 ========== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* 移动端占满全宽，大屏居中限制最大宽度 */
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    left: 0;
    right: 0;
}
.overlay.hidden {
    pointer-events: none;
    visibility: hidden;
}
.overlay.hidden .overlay-backdrop {
    opacity: 0;
}
.overlay.hidden .overlay-card {
    transform: translateY(100%);
}
.overlay.hidden .overlay-sheet {
    transform: translateY(100%);
}

.overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 1;
    transition: opacity 0.25s ease;
}

/* 居中卡片 */
.overlay-card {
    position: relative;
    background: var(--c-surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--space-xl);
    padding-bottom: calc(var(--space-xl) + var(--space-safe-bottom));
    transform: translateY(0);
    transition: transform 0.4s var(--ease-spring-soft);
    z-index: 2;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    width: 100%;
    box-sizing: border-box;
}

/* 底部浮层 */
.overlay-sheet {
    position: relative;
    background: var(--c-surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(0);
    transition: transform 0.4s var(--ease-spring-soft);
    z-index: 2;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) var(--space-xl);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
}
.sheet-title {
    font-family: var(--font-display);
    font-size: 20px;
    color: var(--c-text);
    letter-spacing: 1px;
}
.sheet-close {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.04);
    border: none;
    border-radius: var(--radius-full);
    color: var(--c-text-secondary);
    cursor: pointer;
    touch-action: manipulation;
}
.sheet-close svg {
    width: 18px;
    height: 18px;
}
.sheet-close:active {
    background: rgba(0, 0, 0, 0.08);
}

.sheet-footer {
    padding: var(--space-lg) var(--space-xl);
    padding-bottom: calc(var(--space-lg) + var(--space-safe-bottom));
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
}

/* 结果头部 */
.result-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}
.result-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.result-icon svg {
    width: 28px;
    height: 28px;
    stroke-width: 2.5;
}
.result-success {
    background: linear-gradient(135deg, #E8F8F5, #D1F2EB);
    color: var(--c-success);
}
.result-fail {
    background: linear-gradient(135deg, #FEF2EF, #FADBD0);
    color: var(--c-warning);
}

.overlay-title {
    font-family: var(--font-display);
    font-size: 26px;
    letter-spacing: 1px;
}
.overlay-subtitle {
    font-size: 14px;
    color: var(--c-text-secondary);
    text-align: center;
}

/* 遮罩操作按钮 */
.overlay-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}
.overlay-actions .btn {
    width: 100%;
}

/* ====== 星级评分 ====== */
.star-rating {
    display: flex;
    gap: 8px;
}
.star {
    font-size: 40px;
    color: #E8E8E8;
    transition: color 0.2s;
    line-height: 1;
}
.star.earned {
    color: var(--c-accent);
    text-shadow: 0 0 12px rgba(253, 203, 110, 0.4);
    animation: starPop 0.45s var(--ease-spring-bounce);
}
@keyframes starPop {
    0% { transform: scale(0) rotate(-30deg); }
    60% { transform: scale(1.25) rotate(5deg); }
    100% { transform: scale(1) rotate(0); }
}

/* ====== 分数明细 ====== */
.score-detail {
    width: 100%;
    background: #FAFAFA;
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
}
.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    font-size: 14px;
    color: var(--c-text-secondary);
}
.score-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.06);
    margin: 6px 0;
}
.score-row.score-total {
    font-size: 16px;
    font-weight: 700;
    color: var(--c-text);
}
.score-num {
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--c-text);
}
.score-total .score-num {
    color: var(--c-primary);
    font-size: 20px;
}

/* ====== 通关商品推荐 ====== */
.product-recommend {
    margin-top: var(--space-md);
    animation: fadeInUp 0.5s var(--ease-out-expo) both;
}
.product-recommend.hidden {
    display: none !important;
}
.product-recommend-label {
    font-size: 12px;
    color: var(--c-text-secondary);
    text-align: center;
    margin-bottom: var(--space-xs);
    letter-spacing: 1px;
}
.product-recommend-card {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: linear-gradient(135deg, #FFF8F1, #FFF3E8);
    border: 1.5px solid var(--c-accent);
    border-radius: var(--radius-lg);
    padding: var(--space-sm) var(--space-md);
    position: relative;
    overflow: hidden;
    flex-wrap: wrap;
}
.product-recommend-card::before {
    content: '';
    position: absolute;
    top: -40px;
    right: -40px;
    width: 80px;
    height: 80px;
    background: radial-gradient(circle, rgba(200,150,62,0.12) 0%, transparent 70%);
    border-radius: 50%;
}
.product-recommend-card img {
    width: 52px;
    height: 52px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    background: white;
    padding: 3px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.product-recommend-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}
.product-recommend-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--c-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.product-recommend-price {
    font-size: 16px;
    font-weight: 700;
    color: var(--c-primary);
}
.product-recommend-price span {
    font-family: var(--font-mono);
    font-size: 18px;
}

/* 小屏幕下商品推荐卡片适配 */
@media (max-width: 380px) {
    .product-recommend-card {
        gap: 8px;
        padding: 10px 12px;
    }
    .product-recommend-card img {
        width: 44px;
        height: 44px;
    }
    .product-recommend-name {
        font-size: 13px;
    }
    .product-recommend-price {
        font-size: 14px;
    }
    .product-recommend-price span {
        font-size: 15px;
    }
    /* 确保按钮在极小屏幕下仍能正常显示和点击 */
    .product-recommend-card .btn-sm {
        margin-left: auto;
        min-width: 72px;
        padding: 6px 10px;
        font-size: 12px;
    }
}

/* 小型强调按钮 */
.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 13px;
    min-height: 34px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}
.btn-sm .btn-svg-icon {
    width: 14px;
    height: 14px;
}
.btn-accent {
    background: linear-gradient(135deg, #E8A838, #D4942A);
    color: white;
    box-shadow: 0 3px 10px rgba(212,148,42,0.28);
}
.btn-accent:active {
    transform: scale(0.96);
    box-shadow: 0 1px 5px rgba(212,148,42,0.2);
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
/* ====== 安慰奖 ====== */
.consolation-box {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: #E8F8F5;
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    font-size: 14px;
    color: var(--c-success);
    font-weight: 500;
}
.consolation-box svg {
    width: 20px;
    height: 20px;
    stroke: var(--c-success);
    fill: var(--c-success);
    stroke-width: 0;
}

/* ====== 最终得分 ====== */
.final-score-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-md) var(--space-xl);
    background: linear-gradient(135deg, #FFF8E1, #FFF3CD);
    border-radius: var(--radius-lg);
    min-width: 160px;
}
.final-score-label {
    font-size: 13px;
    color: var(--c-text-secondary);
}
.final-score-num {
    font-family: var(--font-mono);
    font-size: 36px;
    font-weight: 900;
    color: var(--c-primary);
    line-height: 1;
}

/* ====== 领奖台 ====== */
.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-lg) var(--space-xl);
    flex-shrink: 0;
    min-height: 140px;
}
.podium-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    flex: 1;
    max-width: 80px;
}
.podium-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}
.podium-bar {
    width: 100%;
    border-radius: 6px 6px 0 0;
    transition: height 0.5s var(--ease-spring-soft);
}
.podium-item.first .podium-avatar {
    background: linear-gradient(135deg, #FDCB6E, #F0B04E);
    width: 52px;
    height: 52px;
    font-size: 20px;
    box-shadow: 0 4px 12px rgba(253, 203, 110, 0.4);
}
.podium-item.first .podium-bar {
    height: 72px;
    background: linear-gradient(180deg, #FDCB6E, #F0B04E);
}
.podium-item.second .podium-avatar {
    background: linear-gradient(135deg, #B2BEC3, #95A5A6);
}
.podium-item.second .podium-bar {
    height: 50px;
    background: linear-gradient(180deg, #B2BEC3, #95A5A6);
}
.podium-item.third .podium-avatar {
    background: linear-gradient(135deg, #E17055, #D35400);
}
.podium-item.third .podium-bar {
    height: 36px;
    background: linear-gradient(180deg, #E17055, #D35400);
}

/* ====== 排行榜列表 ====== */
.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-lg);
}
.leaderboard-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-sm);
    border-radius: var(--radius-md);
    min-height: 52px;
}
.leaderboard-item.self {
    background: #FFF5F5;
    border-left: 3px solid var(--c-primary);
}
.lb-rank {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-mono);
    flex-shrink: 0;
}
.lb-rank.gold { background: linear-gradient(135deg, #FDCB6E, #F0B04E); color: #fff; }
.lb-rank.silver { background: linear-gradient(135deg, #B2BEC3, #95A5A6); color: #fff; }
.lb-rank.bronze { background: linear-gradient(135deg, #E17055, #D35400); color: #fff; }
.lb-rank.normal { background: #F0F0F0; color: var(--c-text-tertiary); }

.lb-name {
    flex: 1;
    font-size: 14px;
    color: var(--c-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lb-score {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--c-primary);
}
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--c-text-tertiary);
    font-size: 14px;
}

/* ====== 玩法说明内容 ====== */
.howto-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg) var(--space-xl);
}
.howto-section {
    margin-bottom: var(--space-xl);
}
.howto-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--c-text);
    margin-bottom: var(--space-md);
}

/* 连线图解 */
.path-examples {
    display: flex;
    gap: var(--space-md);
}
.path-example {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    font-size: 12px;
    color: var(--c-text-secondary);
}
.path-demo {
    width: 72px;
    height: 72px;
    background: #F8F8F8;
    border-radius: var(--radius-md);
    position: relative;
}
.pdot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--c-primary);
    z-index: 2;
}
.pdot.a { top: 16px; left: 16px; }
.pdot.b { bottom: 16px; right: 16px; }
.pline, .plinel, .pliner, .plinem {
    position: absolute;
    background: var(--c-primary-light);
    border-radius: 2px;
    z-index: 1;
}
/* 直线 */
.path-demo.straight .pline {
    width: 3px;
    height: 36px;
    top: 18px;
    left: 20px;
    transform: rotate(45deg);
    transform-origin: top center;
}
/* 一折 */
.path-demo.oneturn .plinel {
    width: 3px;
    height: 20px;
    top: 20px;
    left: 20px;
}
.path-demo.oneturn .pliner {
    width: 20px;
    height: 3px;
    bottom: 20px;
    left: 20px;
}
/* 两折 */
.path-demo.twoturns .plinel {
    width: 3px;
    height: 18px;
    top: 20px;
    left: 20px;
}
.path-demo.twoturns .plinem {
    width: 18px;
    height: 3px;
    top: 35px;
    left: 20px;
}
.path-demo.twoturns .pliner {
    width: 3px;
    height: 18px;
    bottom: 18px;
    right: 20px;
}

/* 规则列表 */
.rules-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
.rule-item {
    display: flex;
    gap: var(--space-md);
    align-items: flex-start;
    padding: var(--space-sm);
    background: #F8F8F8;
    border-radius: var(--radius-sm);
}
.rule-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--c-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}
.rule-item p {
    font-size: 13px;
    color: var(--c-text);
    line-height: 1.5;
    flex: 1;
}

/* ====== 奖励列表 ====== */
.rewards-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: center;
}
.reward-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #E8F8F5;
    border-radius: var(--radius-full);
    font-size: 13px;
    color: var(--c-text);
}
.reward-chip svg {
    width: 16px;
    height: 16px;
    stroke: var(--c-success);
}

/* ====== 分数弹出动画 ====== */
.score-float {
    position: absolute;
    font-family: var(--font-mono);
    font-weight: 900;
    font-size: 16px;
    color: var(--c-primary);
    pointer-events: none;
    z-index: 10;
    animation: scoreFloatUp 0.8s var(--ease-out-expo) forwards;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}
@keyframes scoreFloatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    50% { opacity: 1; transform: translateY(-24px) scale(1.15); }
    100% { opacity: 0; transform: translateY(-48px) scale(0.85); }
}

/* ====== 消除粒子 ====== */
.particle {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 6;
}

/* ====== 响应式: 平板横屏 ====== */
@media (min-width: 768px) {
    .screen {
        max-width: 480px;
    }
}

@media (max-height: 700px) {
    .mascot-area {
        width: 160px;
        height: 160px;
    }
    .mascot-item {
        width: 48px;
        height: 48px;
        margin: -24px 0 0 -24px;
        transform: rotate(calc(var(--i) * 60deg)) translateY(-58px) rotate(calc(var(--i) * -60deg));
    }
    @keyframes mascotItemFloat {
        0%, 100% { transform: rotate(calc(var(--i) * 60deg)) translateY(-58px) rotate(calc(var(--i) * -60deg)) scale(1); }
        50% { transform: rotate(calc(var(--i) * 60deg)) translateY(-62px) rotate(calc(var(--i) * -60deg)) scale(1.06); }
    }
    .start-content {
        gap: var(--space-lg);
    }
}

/* 桌面端 hover 效果 */
@media (hover: hover) {
    .tile:hover {
        transform: scale(1.04);
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    }
    .tile.selected:hover {
        transform: scale(1.08);
    }
    .btn:hover {
        filter: brightness(1.05);
    }
    .btn-primary:hover {
        box-shadow: 0 6px 20px rgba(198, 40, 40, 0.38);
    }
}

/* 通用隐藏类 */
.hidden {
    display: none !important;
}
