/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #050510;
    color: #e5e7eb;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* ========== Valorant 风格动态渐变背景 ========== */
body::before {
    content: '';
    position: fixed;
    inset: -50%;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 30% 40%, rgba(30, 64, 175, 0.13) 0%, transparent 65%),
        radial-gradient(ellipse at 70% 60%, rgba(88, 28, 135, 0.10) 0%, transparent 65%),
        radial-gradient(ellipse at 50% 50%, rgba(6, 182, 212, 0.05) 0%, transparent 55%),
        radial-gradient(ellipse at 60% 30%, rgba(15, 23, 42, 0.4) 0%, transparent 70%);
    animation: bgDrift 16s ease-in-out infinite alternate;
}

@keyframes bgDrift {
    0%   { transform: translate(0, 0) scale(1); }
    25%  { transform: translate(4%, -2%) scale(1.04); }
    50%  { transform: translate(-2%, 3%) scale(1.02); }
    75%  { transform: translate(1%, -4%) scale(1.05); }
    100% { transform: translate(-3%, 1%) scale(1); }
}



/* 闯关：关卡格子 */
.campaign-level-cell {
    height: 70px;
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(15, 23, 42, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
    gap: 2px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.campaign-level-cell:hover:not(.locked) {
    transform: scale(1.08);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.campaign-level-cell.locked {
    opacity: 0.35;
    cursor: not-allowed;
}

/* 闯关格子内的星星 */
.campaign-cell-stars {
    display: flex;
    gap: 1px;
    line-height: 1;
}
.campaign-cell-stars .star {
    width: 12px;
    height: 12px;
    color: rgba(255, 255, 255, 0.15);
}
.campaign-cell-stars .star path {
    fill: currentColor;
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 5;
    stroke-linejoin: round;
    stroke-linecap: round;
    paint-order: stroke fill;
}
.campaign-cell-stars .star.filled {
    color: #facc15;
    filter: drop-shadow(0 0 3px rgba(250, 204, 21, 0.4));
}

/* 闯关格子内的数字 */
.campaign-cell-number {
    font-size: 16px;
    font-weight: 700;
}

.campaign-level-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 8px;
}

.campaign-difficulty-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

@media (max-width: 1100px) {
    .campaign-difficulty-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    .campaign-level-grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .campaign-difficulty-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .campaign-level-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .campaign-difficulty-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .campaign-level-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.campaign-difficulty-grid,
.campaign-level-grid {
    grid-auto-flow: row dense;
}

.campaign-difficulty-grid .btn {
    min-height: 60px;
    aspect-ratio: 1.9 / 1;
    color: #fff;
    font-weight: 700;
}

#campaign-diff-easy { background: linear-gradient(135deg, #4d8c5e, #3d7a4a); }
#campaign-diff-normal { background: linear-gradient(135deg, #7a9e3a, #5c7d2e); }
#campaign-diff-hard { background: linear-gradient(135deg, #b8944a, #8c6e3a); }
#campaign-diff-expert { background: linear-gradient(135deg, #b87a4e, #9a5e38); }
#campaign-diff-unsolvable { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.campaign-level-badge.easy { color: #5b9e6e; }
.campaign-level-badge.normal { color: #7a9e3a; }
.campaign-level-badge.hard { color: #b8944a; }
.campaign-level-badge.expert { color: #b87a4e; }
.campaign-level-badge.unsolvable { color: #ef4444; }
.campaign-level-cell.easy { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.3); }
.campaign-level-cell.normal { background: rgba(132, 204, 22, 0.10); border-color: rgba(132, 204, 22, 0.3); }
.campaign-level-cell.hard { background: rgba(234, 179, 8, 0.10); border-color: rgba(234, 179, 8, 0.3); }
.campaign-level-cell.expert { background: rgba(249, 115, 22, 0.10); border-color: rgba(249, 115, 22, 0.3); }
.campaign-level-cell.unsolvable { background: rgba(239, 68, 68, 0.10); border-color: rgba(239, 68, 68, 0.3); }
.campaign-level-cell.cleared {
    box-shadow: 0 0 0 2px rgba(34,197,94,0.2) inset;
}

/* 顶部信息栏 */
.header {
    height: 60px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: env(safe-area-inset-top, 0) 30px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.bgm-float-btn {
    margin-left: 12px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.16);
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.22), rgba(255,255,255,0.08));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 22px rgba(0,0,0,0.22);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.start-top-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.start-bgm-btn {
    margin-left: auto;
}

.bgm-float-btn:hover {
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 10px 28px rgba(0,0,0,0.28);
}

.bgm-float-icon-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
}

.bgm-modal-content {
    max-width: 480px;
}

.bgm-modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 6px 0 18px;
}

.bgm-volume-row {
    display: grid;
    grid-template-columns: 52px 1fr 52px;
    gap: 10px;
    align-items: center;
}

.music-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    font-size: 15px;
}

.music-toggle-row input {
    width: 18px;
    height: 18px;
}

.music-volume-row input[type="range"] {
    width: 100%;
}

.bgm-hint {
    text-align: center;
    color: rgba(229,231,235,0.8);
    font-size: 13px;
}

.about-us-link {
    position: absolute;
    left: 24px;
    bottom: 18px;
    color: rgba(229, 231, 235, 0.72);
    font-size: 14px;
    text-decoration: none;
    letter-spacing: 0.5px;
    transition: color 0.18s ease, transform 0.18s ease, opacity 0.18s ease;
    z-index: 2;
}

.about-us-link:hover {
    color: #ffffff;
    transform: translateY(-1px);
    opacity: 1;
}

.campaign-level-badge {
    margin-left: auto;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    min-width: 90px;
    justify-content: center;
}

.campaign-level-badge.unsolvable {
    color: #ef4444 !important;
}

.campaign-level-value {
    font-size: 18px;
    line-height: 1;
}

.campaign-level-label {
    font-size: 13px;
    opacity: 0.88;
}

.campaign-victory-content {
    text-align: center;
    min-width: 340px;
}

.campaign-victory-text {
    margin: 12px 0 22px;
    font-size: 18px;
    color: #dbeafe;
    line-height: 1.6;
}

.campaign-victory-stars {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 8px 0 6px;
    line-height: 1;
}

.campaign-victory-stars .star {
    width: 40px;
    height: 40px;
    display: inline-block;
    color: rgba(255, 255, 255, 0.18);
    overflow: visible;
}

.campaign-victory-stars .star path {
    fill: currentColor;
    stroke: rgba(255, 255, 255, 0.95);
    stroke-width: 4.2;
    stroke-linejoin: round;
    stroke-linecap: round;
    paint-order: stroke fill;
}

.campaign-victory-stars .star.filled {
    color: #facc15;
    filter: drop-shadow(0 0 10px rgba(250, 204, 21, 0.25));
}

.campaign-star-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 220px;
}

.campaign-star-bar {
    position: relative;
    flex: 1;
    height: 12px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.18);
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.campaign-star-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, #c2a040, #d4c070, #b8943a);
    box-shadow: 0 0 10px rgba(200, 180, 80, 0.3);
}

.campaign-star-bar-glow {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255,255,255,0.28), rgba(255,255,255,0));
    mix-blend-mode: screen;
    pointer-events: none;
}

.campaign-star-progress .star-count {
    color: #f8fafc;
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.campaign-star-progress .star-count .star {
    width: 14px;
    height: 14px;
    display: inline-block;
    color: #facc15;
    overflow: visible;
    vertical-align: middle;
}

.campaign-star-progress .star-count .star path {
    fill: currentColor;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 4;
    stroke-linejoin: round;
    stroke-linecap: round;
    paint-order: stroke fill;
    filter: drop-shadow(0 0 2px rgba(250, 204, 21, 0.4));
}

/* LRΣ 显示样式 */
#campaign-lrsigma-container {
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding-left: 8px;
}

#campaign-lrsigma-display {
    font-family: 'Courier New', monospace;
    color: #a78bfa;
    font-weight: 600;
    font-size: 14px;
    line-height: 1;
}

#campaign-lrsigma-display .lrsigma-label {
    font-size: 22px;
    vertical-align: baseline;
}

#campaign-lrsigma-display .lrsigma-int {
    font-size: 22px;
    vertical-align: baseline;
}

#campaign-lrsigma-display .lrsigma-dec {
    font-size: 14px;
    vertical-align: baseline;
    position: relative;
    top: 1px;
}

.campaign-victory-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 130px;
}

.icon-btn .icon {
    font-size: 18px;
    line-height: 1;
}

.score-display {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 18px;
    font-weight: bold;
}

.score-display .player {
    color: #94a3b8;
}

.score-display .score {
    color: #5b9e6e;
    font-size: 24px;
}

.header.campaign-mode .score-display {
    display: none !important;
}

.header.campaign-mode .round-info {
    display: none !important;
}

.header.campaign-mode .player-display {
    display: none !important;
}

/* 分数变化气泡 */
.score-popup {
    position: fixed;
    font-size: 28px;
    font-weight: bold;
    pointer-events: none;
    z-index: 1000;
    animation: scorePopupFloat 1.5s ease-out forwards;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

@keyframes scorePopupFloat {
    0% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -30px) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -60px) scale(1);
    }
}

.game-title {
    font-size: 28px;
    font-weight: bold;
    background: linear-gradient(135deg, #4d8c5e, #5b7fa8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* 测试模式：标题居中 */
.header.test-mode {
    justify-content: center;
}

.header.test-mode .game-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.round-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    color: #94a3b8;
}

.round-info .current {
    color: #5b9e6e;
    font-size: 20px;
    font-weight: bold;
}

/* 主容器 */
.main-container {
    display: flex;
    padding: 80px 20px 20px;
    gap: 18px;
    height: calc(100vh - 140px);
}

/* 左侧 Canvas 区域 */
.canvas-section {
    flex: 0 0 70%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 18px;
    padding: 20px;
    position: relative;
    border: 1px solid rgba(59, 130, 246, 0.12);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

#game-canvas {
    background: #070d1a;
    border-radius: 16px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    max-width: 100%;
    max-height: 100%;
    touch-action: manipulation;
}

/* 测试模式：Canvas 支持滚轮缩放 */
.canvas-section.test-mode #game-canvas {
    cursor: grab;
}

.canvas-section.test-mode #game-canvas:active {
    cursor: grabbing;
}

/* 右侧控制面板 */
.control-panel {
    flex: 0 0 30%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 300px;
}

.panel-card {
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(10px);
    border-radius: 18px;
    padding: 18px 22px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.panel-card h3 {
    font-size: 14px;
    color: #94a3b8;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* 计时器 */
.timer-display {
    text-align: center;
}

.timer-value {
    font-size: 48px;
    font-weight: bold;
    color: #5b9e6e;
    font-family: 'Courier New', monospace;
}

.timer-value.warning {
    color: #ef4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* 当前玩家 */
.player-display {
    text-align: center;
}

.player-value {
    font-size: 22px;
    font-weight: bold;
    color: #5b7fa8;
}

/* 状态气泡：计时器 | 当前玩家 | 当前阶段 */
.status-bubble {
    padding: 10px 12px !important;
}
.status-bubble-inner {
    display: flex;
    align-items: center;
    gap: 0;
}
.bubble-item {
    flex: 1;
    text-align: center;
    min-width: 0;
}
.bubble-item h3 {
    margin-bottom: 2px;
    letter-spacing: 1.5px;
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
}
.bubble-item .timer-value {
    font-size: 34px;
    line-height: 1.2;
}
.bubble-item .player-value {
    font-size: 17px;
    line-height: 1.2;
}
.bubble-item .phase-hint-text {
    font-size: 12px;
    color: #e5e7eb;
    line-height: 1.4;
    padding: 0 4px;
    word-break: break-word;
}
.bubble-divider {
    width: 1px;
    height: 38px;
    background: rgba(255, 255, 255, 0.10);
    flex-shrink: 0;
}

/* 阶段提示 */
.phase-display {
    text-align: center;
}

.phase-hint {
    font-size: 16px;
    color: #b0bdd0;
    padding: 12px 14px;
    background: rgba(59, 130, 246, 0.12);
    border-radius: 14px;
    border: 1px solid rgba(59, 130, 246, 0.18);
}

/* 表达式显示区 */
.expression-display {
    min-height: 60px;
    max-height: 160px;
    background: rgba(2, 6, 23, 0.8);
    border-radius: 14px;
    padding: 14px 16px;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    color: #c8cdd5;
    display: flex;
    flex-wrap: wrap;
    gap: 8px; /* 增加间距，方便点击空隙 */
    align-items: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: text; /* 提示用户可以点击移动光标 */
    overflow-y: auto;
    overflow-x: hidden;
    white-space: normal;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.65) rgba(15, 23, 42, 0.25);
}

.expression-display .placeholder {
    color: #64748b;
    font-style: italic;
}

.expression-element {
    background: rgba(59, 130, 246, 0.3);
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(59, 130, 246, 0.5);
}

.expression-element:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.5);
}

/* 光标样式 */
.cursor {
    color: #ffffff;
    font-weight: bold;
    animation: blink 1s step-end infinite;
    margin: 0 2px;
}

/* 表达式前缀 "y =" */
.expression-prefix {
    color: #ffffff;
    font-weight: bold;
    margin-right: 6px;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5), 0 0 16px rgba(255, 255, 255, 0.3);
}

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

/* 按钮组 */
.button-group {
    display: flex;
    gap: 12px;
}

.header.campaign-mode .score-display,
.header.campaign-mode .round-info {
    display: none;
}

.btn {
    flex: 1;
    padding: 14px 20px;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

/* 按钮箭头（由 JS 注入） */
.btn-arrow {
    display: inline-block;
    margin-left: 8px;
    opacity: 0;
    transform: translateX(-6px);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-size: 16px;
    line-height: 1;
}
.btn:hover .btn-arrow {
    opacity: 1;
    transform: translateX(0);
}

.btn-primary {
    background: linear-gradient(135deg, #4d8c5e, #3d7a4a);
    color: #dce8e0;
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #3d7a4a, #356a3e);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(77, 140, 94, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
}

/* 退出按钮样式 - 白底黑字 */
.btn-exit {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 16px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #ffffff;
    color: #000000;
    position: relative;
    overflow: hidden;
}

.btn-exit:hover:not(:disabled) {
    background: #e5e7eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.3);
}

/* 退出确认气泡框 */
.exit-confirm-popover {
    position: absolute;
    bottom: 160px; /* 位于按钮组上方 */
    right: 20px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 18px;
    padding: 20px;
    min-width: 240px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: block; /* 始终渲染，用 opacity 控制可见性 */
    z-index: 200;
    opacity: 0;
    transform: scale(0.92) translateY(4px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.exit-confirm-popover.visible {
    display: block;
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.exit-confirm-popover p {
    margin: 0 0 15px 0;
    color: #e5e7eb;
    font-size: 14px;
    text-align: center;
}

.popover-buttons {
    display: flex;
    gap: 10px;
}

.btn-small {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
    border-radius: 999px;
}

.btn-cancel {
    background: rgba(255, 255, 255, 0.1);
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-confirm-exit {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn-confirm-exit:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden-cell {
    opacity: 0.2;
}

/* ═══════════════════════════════════════════════════
   Summa Character UI  —  全新动画版
   结构：#summa-root > #summa-body > #summa-face-wrap
              > summa-avatar (立绘底图)
              > .summa-eye (×2，精确覆盖在眼睛区域上)
                  > .summa-pupil
                  > .summa-eyelid
           > #summa-message (气泡框)
═══════════════════════════════════════════════════ */

/* 锁点：fixed 定位，初始居右侧 */
.summa-root {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;               /* 真实的瘦窄碰撞箱宽度 */
    height: 190px;             /* 真实碰撞箱高度 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    cursor: grab;
    pointer-events: none;      /* 禁用原始 root 的点击，防止飞天脱节时被隔空抓取 */
    /* 增加微弱底色防止纯透明 divs 在某些浏览器中不吃时间 */
    background: rgba(0, 0, 0, 0.01);
}
.summa-root.dragging {
    cursor: grabbing;
}

/* 真正的动态碰撞箱：随身体旋转、拉伸，永远死扣在身体躯干上 */
.summa-hitbox {
    position: absolute;
    width: 40px;
    height: 190px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;      /* 仅此处开启点击 */
    cursor: grab;
    z-index: 10;
}
.summa-root.dragging .summa-hitbox {
    cursor: grabbing;
}

/* 弹性物理层：transform 由 JS 控制 */
.summa-body {
    position: relative;           /* 为绝对定位的气泡提供定位上下文 */
    display: flex;
    flex-direction: column;
    align-items: center;
    will-change: transform;   /* GPU 加速 */
    transform-origin: center center;  /* 链式物理：绕角色中心旋转 */
    pointer-events: none;     /* 让超出 root 的部分不可点击 */
}

/* 立绘 + 眼部叠加容器 */
.summa-face-wrap {
    position: relative;
    width: 220px;
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 150ms ease-in-out;
    pointer-events: none;
}

/* 情绪立绘底图 */
.summa-avatar {
    width: 220px;
    height: 220px;
    object-fit: contain;
    filter: drop-shadow(0 0 18px rgba(167, 139, 250, 0.45));
    display: block;
    pointer-events: none;
    /* 移除旧的 CSS summaFloat 动画，交由 JS 弹算控制 */
}

/* 眼眼容器：绝对定位覆盖在立绘眼睛区域
   左眼 / 右眼的具体位置在下方单独调整 */
.summa-eye {
    position: absolute;
    width: 26px;
    height: 26px;
    overflow: hidden;
    border-radius: 50%;
    pointer-events: none;
    /* 调试时可开启轮序： outline: 1px dashed red; */
}
/* 左眼中心位置（以 220px 孚宽立绘为基准） */
.summa-eye-left  { left: 33%; top: 34%; transform: translate(-50%, -50%); }
/* 右眼中心 */
.summa-eye-right { left: 63%; top: 34%; transform: translate(-50%, -50%); }

/* 眼珠：深色圆，偏移由 JS translate 控制 */
.summa-pupil {
    position: absolute;
    width: 12px;
    height: 12px;
    background: rgba(30, 20, 60, 0.75);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    margin-top: -6px;
    margin-left: -6px;
    will-change: transform;
    pointer-events: none;
}

/* 眼皮：与眼眼同宽，从顶部向下盖下（scaleY 0=全开, 1=全闭） */
.summa-eyelid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 220, 200, 0.92); /* 肤色调到跟脚色近似 */
    border-radius: 50%;
    transform-origin: top center;
    transform: scaleY(0);   /* 初始全开眼 */
    will-change: transform;
    pointer-events: none;
}

/* 气泡框 */
.summa-message {
    background: rgba(255, 255, 255, 0.95);
    color: #1e1b4b;
    padding: 14px 18px;
    border-radius: 12px;
    border: 2px solid #a78bfa;
    font-size: 15px;
    font-weight: bold;
    width: 8em; /* 固定每行约 8 个汉字 */
    max-width: 8em;
    white-space: normal;
    word-break: break-all;
    overflow-wrap: anywhere;
    line-height: 1.35;
    opacity: 0;
    /* 绝对定位：脱离文档流，不影响 #summa-body 高度，避免气泡出现时 offsetHeight 变化导致闪现 */
    position: absolute;
    bottom: calc(100% - 16px);   /* 100% = face-wrap 高度(220px)，-16px 与立绘轻微重叠 */
    left: 50%;
    transform: translateX(-50%) scale(0.85) translateY(16px);
    transition: opacity 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275),
                transform 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    z-index: 2;
    pointer-events: none;
}
.summa-message::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: #a78bfa transparent transparent transparent;
}
.summa-message.visible {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
}

/* 消息提示容器 */
.message-panel {
    display: none; /* 普通模式下隐藏整个容器 */
}

.message-panel.visible {
    display: block; /* 测试模式下显示 */
}

/* 消息提示 */
.message {
    min-height: 40px;
    padding: 10px;
    border-radius: 14px;
    font-size: 14px;
    text-align: center;
}

.message.error {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.message.success {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* 底部元素拖拽区 */
.elements-section {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 140px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px 24px env(safe-area-inset-bottom, 15px);
    display: flex;
    gap: 24px;
    overflow-x: auto;
    overflow-y: scroll;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.55) rgba(15, 23, 42, 0.2);
}

.element-category {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-label {
    font-size: 12px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.element-items {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.element-btn {
    padding: 7px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.element-btn:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.18);
}

.element-btn.locked {
    background: rgba(107, 114, 128, 0.2);
    color: #6b7280;
    border-color: rgba(107, 114, 128, 0.3);
    cursor: not-allowed;
}

.lock-icon {
    font-size: 12px;
    filter: grayscale(100%) brightness(1.5);
}

/* ========== 启动界面（仅首次进入时显示） ========== */
#splash-screen {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.splash-content {
    text-align: center;
    animation: splashContentFadeIn 1.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.splash-title {
    font-size: clamp(42px, 8vw, 72px);
    font-weight: 900;
    color: #fff;
    letter-spacing: 0.15em;
    text-shadow:
        0 0 20px rgba(255, 255, 255, 0.5),
        0 0 60px rgba(99, 102, 241, 0.35),
        0 0 120px rgba(59, 130, 246, 0.2);
    margin-bottom: 48px;
}

.splash-hint {
    font-size: clamp(14px, 2.4vw, 18px);
    color: rgba(255, 255, 255, 0.55);
    letter-spacing: 0.3em;
    animation: splashHintPulse 2.4s ease-in-out infinite alternate;
}

@keyframes splashContentFadeIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes splashHintPulse {
    from { opacity: 0.35; text-shadow: 0 0 8px rgba(255,255,255,0.08); }
    to   { opacity: 0.85; text-shadow: 0 0 20px rgba(255,255,255,0.25); }
}

/* ── 转场动画：旋转 + 放大 + 虚化 → 纯白吞没 ── */
#splash-screen.splash-exit {
    animation: splashTransition 0.9s cubic-bezier(0.65, 0, 0.35, 1) forwards;
    pointer-events: none;
}
#splash-screen.splash-exit .splash-content {
    animation: splashContentExit 0.9s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes splashTransition {
    0%   { background: #000; }
    40%  { background: #000; }           /* 前段保持黑色，内容先飞走 */
    70%  { background: #111; }
    100% { background: #fff; filter: brightness(1.3); } /* 末端白闪 */
}

@keyframes splashContentExit {
    0%   { opacity: 1; transform: scale(1) rotate(0deg); filter: blur(0); }
    30%  { opacity: 1; transform: scale(1.6) rotate(12deg); filter: blur(2px); }
    60%  { opacity: 0.4; transform: scale(2.8) rotate(24deg); filter: blur(12px); }
    100% { opacity: 0; transform: scale(4) rotate(36deg); filter: blur(30px); display:none; }
}

/* 模态框 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 5, 16, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: none;
}

/* ========== Arknights 风格角落幽暗光晕 + 坐标轴十字线 ========== */
#start-modal::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        /* 左上角蓝光 */
        radial-gradient(circle 350px at 12% 12%, rgba(59, 130, 246, 0.07) 0%, transparent 100%),
        /* 右上角紫光 */
        radial-gradient(circle 280px at 88% 8%, rgba(139, 92, 246, 0.06) 0%, transparent 100%),
        /* 左下角青绿光 */
        radial-gradient(circle 220px at 8% 92%, rgba(6, 182, 212, 0.05) 0%, transparent 100%),
        /* 右下角绿光 */
        radial-gradient(circle 300px at 92% 88%, rgba(34, 197, 94, 0.04) 0%, transparent 100%),
        /* 顶部中央微光 */
        radial-gradient(ellipse 50% 30% at 50% 0%, rgba(59, 130, 246, 0.03) 0%, transparent 100%);
    animation: auraBreathe 8s ease-in-out infinite alternate;
}

/* 开始界面 - 叠加一层更亮的网格 */
#start-modal::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        );
    background-size: 30px 30px, 30px 30px, 150px 150px, 150px 150px;
    animation: crosshairBreathe 6s ease-in-out infinite alternate;
}

@keyframes crosshairBreathe {
    0% { opacity: 0.32; }
    50% { opacity: 0.45; }
    100% { opacity: 0.32; }
}

/* 闯关模式 - 不透明深色底 + 难度选择/关卡选择网格背景 */
#campaign-modal {
    background: rgba(5, 8, 20, 0.97);
}
#campaign-modal::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.55;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        );
    background-size: 30px 30px, 30px 30px, 150px 150px, 150px 150px;
    animation: crosshairBreathe 6s ease-in-out infinite alternate;
}

@keyframes auraBreathe {
    0% { opacity: 0.7; }
    100% { opacity: 1; }
}

.modal-content {
    background: transparent;
    position: relative;
    padding: 42px 46px;
    border-radius: 0;
    text-align: center;
    max-width: 560px;
    width: 92%;
    border: none;
    box-shadow: none;
}

#start-modal .modal-content {
    transform-origin: top center;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    padding: 28px 64px 32px;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-sizing: border-box;
}

.start-modal-title-image {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0;
    image-rendering: auto;
}

#start-modal .start-modal-title-image {
    width: 100%;
}

.start-image-btn {
    display: block;
    width: min(100%, 448px);
    max-width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    outline: none;
    animation: startButtonPulse 2.6s ease-in-out infinite;
    transform-origin: center;
    filter: none;
    box-shadow: none;
    position: relative;
}

#start-modal .start-image-btn {
    width: min(70%, 420px);
    margin-top: 8px;
}

.start-image-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% + 160px);
    height: calc(100% + 120px);
    background: 
        radial-gradient(ellipse at center, rgba(255, 255, 255, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at center, rgba(59, 130, 246, 0.18) 0%, rgba(59, 130, 246, 0.06) 50%, transparent 80%);
    filter: blur(40px);
    z-index: -1;
    pointer-events: none;
    border-radius: 16px;
}

.start-image-btn img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
    user-select: none;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.25));
    box-shadow: none;
}

.start-image-btn:hover {
    animation-duration: 4.4s;
}

.start-image-btn:active {
    transform: scale(0.995);
}

@keyframes startButtonPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

@keyframes selectorFlash {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(255,255,255,0); }
    50% { transform: scale(1.04); box-shadow: 0 0 18px rgba(255,255,255,0.18); }
    100% { transform: scale(1); box-shadow: 0 0 0 rgba(255,255,255,0); }
}

@keyframes selectorArrowPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.stepper-arrow.round-color-8,
.stepper-arrow.diff-color-easy { color: #6b9f6e; }
.stepper-arrow.round-color-12,
.stepper-arrow.diff-color-normal { color: #6b84a8; }
.stepper-arrow.round-color-16,
.stepper-arrow.diff-color-expert { color: #b8944a; }
.stepper-arrow.round-color-20,
.stepper-arrow.diff-color-test { color: #8b7bb0; }
.stepper-arrow.round-color-24 { color: #b06e6e; }

.modal-content h2 {
    font-size: 32px;
    margin-bottom: 24px;
    background: linear-gradient(135deg, #22c55e, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content p {
    color: #94a3b8;
    margin-bottom: 24px;
    line-height: 1.6;
}

/* 开始界面 */
.selector-row,
.mode-select {
    margin-bottom: 16px;
}

.start-left-column {
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
    justify-content: center;
    height: 100%;
    transform: translateY(-5%);
}

.start-right-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.start-selectors-left {
    width: 100%;
}

.start-selectors-left .round-select,
.start-selectors-left .difficulty-select {
    max-width: 100%;
}

#start-modal .start-selectors-left .round-select,
#start-modal .start-selectors-left .difficulty-select {
    max-width: 100%;
}

.start-selectors-left .stepper-selector {
    width: 100%;
}

.start-selectors-left .stepper-value {
    font-size: 17px;
    min-height: 50px;
}

#start-modal .start-selectors-left .stepper-value {
    font-size: 22px;
    min-height: 80px;
}

.start-selectors-left .stepper-arrow {
    width: 40px;
    height: 40px;
}

#start-modal .start-selectors-left .stepper-arrow {
    width: 52px;
    height: 52px;
    font-size: 38px;
    line-height: 1;
    border-radius: 50%;
    padding: 0;
}

.start-selectors-left .stepper-value {
    min-width: 0;
}

.start-selectors-left .stepper-arrow {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
}

.start-modes-right {
    min-width: 0;
    width: 100%;
}

#start-modal .start-modes-right {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.stepper-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

#start-modal .stepper-selector {
    gap: 14px;
}

.stepper-selector.selector-change .stepper-value {
    animation: selectorFlash 0.22s ease;
}

.stepper-selector.selector-change .stepper-arrow {
    animation: selectorArrowPop 0.22s ease;
}

.stepper-value {
    flex: 1;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(2, 6, 23, 0.8);
    color: #b0bdd0;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    text-shadow: 0 0 6px rgba(255,255,255,0.05);
}

#start-modal .stepper-value {
    padding: 20px 28px;
    border-radius: 28px;
    text-shadow: 0 0 12px rgba(255,255,255,0.08);
}

.stepper-arrow {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(59, 130, 246, 0.10);
    color: #8a9bb5;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

.stepper-arrow:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.20);
    transform: scale(1.06);
}

#start-modal .stepper-arrow:hover:not(:disabled) {
    transform: scale(1.12);
}

#start-modal .mode-toggle-vertical .mode-btn {
    text-align: center;
}

#start-modal .stepper-arrow:hover:not(:disabled) {
    transform: scale(1.12);
}

.stepper-arrow.round-color-8 { background: rgba(96, 165, 250, 0.14); box-shadow: 0 0 14px rgba(96,165,250,0.18); }
.stepper-arrow.round-color-12 { background: rgba(52, 211, 153, 0.14); box-shadow: 0 0 14px rgba(52,211,153,0.18); }
.stepper-arrow.round-color-16 { background: rgba(251, 191, 36, 0.14); box-shadow: 0 0 14px rgba(251,191,36,0.18); }
.stepper-arrow.round-color-20 { background: rgba(249, 115, 22, 0.14); box-shadow: 0 0 14px rgba(249,115,22,0.18); }
.stepper-arrow.round-color-24 { background: rgba(244, 63, 94, 0.14); box-shadow: 0 0 14px rgba(244,63,94,0.18); }
.stepper-arrow.diff-color-easy { background: rgba(34, 197, 94, 0.14); box-shadow: 0 0 14px rgba(34,197,94,0.18); }
.stepper-arrow.diff-color-normal { background: rgba(59, 130, 246, 0.14); box-shadow: 0 0 14px rgba(59,130,246,0.18); }
.stepper-arrow.diff-color-expert { background: rgba(245, 158, 11, 0.14); box-shadow: 0 0 14px rgba(245,158,11,0.18); }
.stepper-arrow.diff-color-test { background: rgba(168, 85, 247, 0.14); box-shadow: 0 0 14px rgba(168,85,247,0.18); }

.stepper-arrow:disabled,
.stepper-selector.disabled .stepper-arrow {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

#start-modal .stepper-arrow:disabled,
#start-modal .stepper-selector.disabled .stepper-arrow {
    opacity: 0.35;
    color: rgba(255,255,255,0.45) !important;
}

#start-modal .stepper-selector.disabled .stepper-value {
    opacity: 0.55;
}

.round-select,
.difficulty-select {
    margin-bottom: 16px;
}


#difficulty-hint {
    display: none;
}

#start-modal small {
    font-size: 15px;
}

.start-action-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 4px;
}

.start-enter-text {
    color: #e5e7eb;
    opacity: 0.85;
    margin-bottom: 6px;
    font-size: 18px;
}

.round-select label,
.difficulty-select label {
    display: block;
    margin-bottom: 10px;
    color: #e5e7eb;
    font-size: 16px;
}

.round-select select,
.difficulty-select select {
    display: none;
}

.round-select select:focus,
.difficulty-select select:focus {
    outline: none;
    border-color: #22c55e;
}

/* 游戏模式切换 */
.start-settings-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
    margin-top: 0;
    margin-bottom: 0;
}

#start-modal .start-settings-layout {
    grid-template-columns: 1fr 1.05fr;
    gap: 48px;
    margin-top: 0;
    margin-bottom: 0;
    align-items: stretch;
    flex: 1;
    display: grid;
}

.mode-select {
    margin-bottom: 0;
}

.mode-toggle {
    display: flex;
    gap: 12px;
}

.mode-toggle-vertical {
    flex-direction: column;
}

.mode-toggle .mode-btn {
    background: rgba(255,255,255,0.06);
    color: #e5e7eb;
    border: 1px solid rgba(255,255,255,0.12);
    width: 100%;
}

.mode-toggle .mode-btn[data-mode="local"] {
    border-color: rgba(99, 102, 241, 0.42);
    color: #b9bbd7;
    background: rgba(88, 92, 128, 0.24);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
}
.mode-toggle .mode-btn[data-mode="ai"] {
    border-color: rgba(59, 130, 246, 0.42);
    color: #b8c9e6;
    background: rgba(68, 88, 124, 0.24);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}
.mode-toggle .mode-btn[data-mode="campaign"] {
    border-color: rgba(34, 211, 238, 0.42);
    color: #b7d7dc;
    background: rgba(68, 102, 112, 0.24);
    box-shadow: 0 0 10px rgba(34, 211, 238, 0.2);
}

.mode-toggle .mode-btn.active[data-mode="local"] { background: rgba(99, 102, 241, 0.26); color: #d7d8ff; box-shadow: 0 0 24px rgba(99,102,241,0.4); }
.mode-toggle .mode-btn.active[data-mode="ai"] { background: rgba(59, 130, 246, 0.26); color: #dbeafe; box-shadow: 0 0 24px rgba(59,130,246,0.4); }
.mode-toggle .mode-btn.active[data-mode="campaign"] { background: rgba(34, 211, 238, 0.24); color: #d6fbff; box-shadow: 0 0 24px rgba(34,211,238,0.4); }

.mode-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    background: rgba(2, 6, 23, 0.6);
    color: #94a3b8;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-shadow: 0 0 6px rgba(255,255,255,0.04);
}

#start-modal .mode-btn {
    padding: 22px 24px;
    font-size: 28px;
    border-radius: 32px;
    width: 100%;
}

.mode-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
}

.mode-btn.active {
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
    color: #22c55e;
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

.difficulty-select select option[value="easy"] {
    color: #22c55e;
}

.difficulty-select select option[value="hard"] {
    color: #f59e0b;
}

.difficulty-select select option[value="expert"] {
    color: #ef4444;
}

.difficulty-select select option[value="test"] {
    color: #a78bfa;
}

/* 测试模式函数列表 */
.function-list {
    margin-top: 15px;
    padding: 10px;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 200px;
    overflow-y: auto;
    animation: fadeIn 0.3s ease-out;
}

.function-list-title {
    font-size: 12px;
    color: #94a3b8;
    margin-bottom: 8px;
    text-align: center;
}

.function-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border-left: 3px solid;
    transition: background 0.2s, opacity 0.3s ease-out;
    animation: fadeIn 0.3s ease-out;
}

.function-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.function-expr {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #e2e8f0;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.function-actions {
    display: flex;
    gap: 5px;
}

.function-actions button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 14px;
    opacity: 0.7;
    transition: opacity 0.2s;
    color: rgba(255, 255, 255, 0.8);
}

.function-actions button:hover {
    opacity: 1;
    color: #ffffff;
}

/* 渐显动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 缩放控制按钮 */
.zoom-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    padding: 8px 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
    animation: fadeIn 0.3s ease-out;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.8);
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.zoom-btn:hover {
    background: rgba(59, 130, 246, 1);
    transform: scale(1.05);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-btn:disabled {
    background: rgba(107, 114, 128, 0.5);
    cursor: not-allowed;
    transform: none;
}

.zoom-range {
    font-size: 14px;
    font-weight: bold;
    color: #e2e8f0;
    min-width: 40px;
    text-align: center;
    font-family: 'Courier New', monospace;
}

/* 游戏结束界面 - 叠加网格线 */
#game-over-modal::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.3;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.12) 29px,
            rgba(59, 130, 246, 0.12) 30px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.12) 29px,
            rgba(59, 130, 246, 0.12) 30px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.18) 149px,
            rgba(99, 102, 241, 0.18) 150px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.18) 149px,
            rgba(99, 102, 241, 0.18) 150px
        );
}

/* 报告弹窗 - 叠加网格线 */
#report-modal::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.3;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.12) 29px,
            rgba(59, 130, 246, 0.12) 30px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.12) 29px,
            rgba(59, 130, 246, 0.12) 30px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.18) 149px,
            rgba(99, 102, 241, 0.18) 150px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.18) 149px,
            rgba(99, 102, 241, 0.18) 150px
        );
}

.winner-text {
    font-size: 36px;
    font-weight: bold;
    color: #5b9e6e;
    margin-bottom: 20px;
}

.final-scores {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 30px;
    font-size: 20px;
}

.final-scores div {
    padding: 15px 30px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 游戏报告样式 */
.report-modal-content {
    max-width: 900px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#report-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.report-summary {
    text-align: left;
    margin-bottom: 20px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
}

.report-summary h3 {
    color: #5b9e6e;
    margin-bottom: 10px;
    font-size: 18px;
}

.report-summary p {
    margin: 5px 0;
    color: #e5e7eb;
    font-size: 14px;
}

.report-history {
    text-align: left;
}

.report-history h3 {
    color: #3b82f6;
    margin-bottom: 10px;
    font-size: 18px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 10px;
}

.report-table th,
.report-table td {
    padding: 8px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.report-table th {
    background: rgba(59, 130, 246, 0.2);
    color: #e5e7eb;
    font-weight: bold;
}

.report-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

/* ========== 界面切换过渡动效系统 ========== */

/* --- Modal 通用进场/退场 --- */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes modalFadeOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.96) translateY(8px);
    }
}

/* Modal 背景遮罩淡入 */
@keyframes overlayFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes overlayFadeOut {
    from { opacity: 1; }
    to   { opacity: 0; }
}

/* Modal 内容从下滑入（弹窗型） */
@keyframes slideUpIn {
    from {
        opacity: 0;
        transform: translateY(28px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideUpOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(28px) scale(0.97);
    }
}

/* 开始界面与闯关界面：横向平移切换 */
@keyframes slideInFromRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 游戏胜利弹窗：弹跳进场 */
@keyframes popIn {
    0%   { opacity: 0; transform: scale(0.7); }
    60%  { opacity: 1; transform: scale(1.05); }
    80%  { transform: scale(0.97); }
    100% { transform: scale(1); }
}

/* --- 各 Modal 进场状态类 --- */
.modal-entering {
    animation: modalFadeIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.modal-exiting {
    animation: modalFadeOut 0.22s ease-in both;
    pointer-events: none;
}

/* ── 全屏界面（主菜单 / 闯关）：动画只作用于内容，背景始终不透明 ── */

@keyframes startModalContentIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes startModalContentOut {
    from { opacity: 1; transform: scale(1) translateY(0); }
    to   { opacity: 0; transform: scale(0.96) translateY(8px); }
}

#start-modal.modal-entering {
    /* 整体不透明，只动画内部内容 */
    animation: none !important;
    opacity: 1 !important;
}
#start-modal.modal-entering > * {
    animation: startModalContentIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}

#start-modal.modal-exiting {
    animation: none !important;
    opacity: 1 !important;
}
#start-modal.modal-exiting > * {
    animation: startModalContentOut 0.22s ease-in both;
}

@keyframes campaignSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes campaignSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-30px); }
}

#campaign-modal.modal-entering {
    animation: none !important;
    opacity: 1 !important;
}
#campaign-modal.modal-entering > * {
    animation: campaignSlideIn 0.30s cubic-bezier(0.22, 1, 0.36, 1) both;
}

#campaign-modal.modal-exiting {
    animation: none !important;
    opacity: 1 !important;
}
#campaign-modal.modal-exiting > * {
    animation: campaignSlideOut 0.22s ease-in both;
}

/* 闯关界面内部步骤切换 */
#campaign-step-difficulty,
#campaign-step-levels {
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* 游戏结束弹窗 */
#game-over-modal.modal-entering > * {
    animation: slideUpIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* 闯关胜利弹窗 */
#campaign-victory-modal.modal-entering > * {
    animation: popIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* BGM 设置弹窗 */
#bgm-modal.modal-entering > * {
    animation: slideUpIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* 游戏报告弹窗 */
#report-modal.modal-entering > * {
    animation: slideUpIn 0.30s cubic-bezier(0.22, 1, 0.36, 1) both;
}

/* Summa训练对话框 */
#summa-train-dialog.modal-entering > * {
    animation: slideUpIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.report-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.08);
}

.expr-cell {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.coord-cell {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #94a3b8;
}

.elem-cell {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #f59e0b;
}

.score-positive {
    color: #5b9e6e;
    font-weight: bold;
}

.score-negative {
    color: #ef4444;
    font-weight: bold;
}

/* ============================================
   响应式布局 - 基于 JS 设备检测 + CSS 适配
   ============================================ */

/* 桌面布局 - 默认（宽屏）两栏 + 底部元素栏 */
@media (min-width: 1024px) {
    .main-container {
        display: flex !important;
        flex-direction: row !important;
        padding: 80px 20px 20px;
        gap: 14px;
        height: calc(100vh - 140px);
    }
    
    .canvas-section {
        flex: 0 0 58%;
        height: auto;
        padding: 12px;
    }
    
    .canvas-section #game-canvas {
        border-radius: 14px;
    }
    
    .control-panel {
        flex: 1;
        min-width: 290px;
    }
}

/* 平板布局（iPad 横屏 / 小笔记本） */

/* 平板布局（iPad 横屏 / 小笔记本） */
@media (min-width: 768px) and (max-width: 1023px) {
    .main-container {
        display: flex !important;
        flex-direction: row !important;
        padding: 70px 15px 15px;
        gap: 15px;
        height: calc(100vh - 120px);
    }
    
    .canvas-section {
        flex: 0 0 60%;
        height: auto;
        padding: 15px;
    }
    
    .control-panel {
        flex: 0 0 40%;
        min-width: 280px;
        max-width: 350px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .header {
        padding: 0 20px;
    }
    
    .game-title {
        font-size: 22px;
    }

    .campaign-difficulty-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .campaign-level-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}

/* 平板竖屏布局（iPad 竖屏等） */
@media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    .main-container {
        display: flex !important;
        flex-direction: column !important;
        padding: 70px 12px 155px;
        gap: 10px;
        height: auto;
        min-height: calc(100vh - 70px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .canvas-section {
        flex: none;
        width: 100%;
        height: 40vh;
        min-height: 280px;
        max-height: 450px;
        padding: 12px;
    }
    
    .control-panel {
        flex: 1;
        min-width: unset;
        max-width: unset;
        width: 100%;
        overflow-y: visible;
    }
    
    .game-title {
        font-size: 18px;
    }

    .header {
        padding: 0 12px;
        height: 55px;
    }

    .score-display {
        font-size: 13px;
        gap: 8px;
    }
    .score-display .score {
        font-size: 16px;
    }
    .round-info {
        font-size: 12px;
    }
    .round-info .current {
        font-size: 16px;
    }

    .elements-section {
        height: auto;
        max-height: 130px;
        padding: 10px 14px;
        overflow-y: scroll;
        overscroll-behavior: contain;
    }
}

/* 手机布局（竖屏优先） */
@media (max-width: 767px) {
    .header {
        height: 55px;
        padding: 0 10px;
    }
    
    .game-title {
        font-size: 16px;
    }

    #start-modal .modal-content {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        padding: 18px 20px 16px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        box-sizing: border-box;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .start-settings-layout {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    #start-modal .start-settings-layout {
        margin-top: 8px;
    }

    #start-modal .start-left-column {
        gap: 14px;
    }

    #start-modal .start-right-column {
        gap: 12px;
    }

    #start-modal .start-modes-right,
    .start-selectors-left {
        width: 100%;
    }

    #start-modal .mode-btn {
        font-size: 24px;
        padding: 16px 14px;
        border-radius: 22px;
    }

    #start-modal .start-selectors-left .stepper-value {
        font-size: 17px;
        min-height: 60px;
    }

    #start-modal .start-selectors-left .stepper-arrow {
        width: 40px;
        height: 40px;
        font-size: 28px;
    }

    #start-modal .start-image-btn {
        width: min(60%, 260px);
    }

    #start-modal small {
        font-size: 12px;
    }
    
    .campaign-difficulty-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .campaign-level-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
    
    .score-display {
        font-size: 12px;
        gap: 8px;
    }
    
    .score-display .player {
        display: none; /* 手机上隐藏玩家标签 */
    }
    
    .score-display .score {
        font-size: 16px;
    }
    
    .round-info {
        font-size: 11px;
    }
    
    /* 主容器垂直布局 */
    .main-container {
        display: flex !important;
        flex-direction: column !important;
        padding: 65px 8px 155px;
        gap: 8px;
        height: auto;
        min-height: calc(100vh - 65px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Canvas 区域 - 占上方空间 */
    .canvas-section {
        flex: none;
        width: 100%;
        height: 45vh;
        min-height: 250px;
        max-height: 400px;
        padding: 8px;
    }
    
    /* 控制面板 */
    .control-panel {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
        min-width: unset;
        max-width: unset;
        padding-bottom: 10px;
        overflow-y: visible;
    }
    
    .panel-card {
        padding: 12px 14px;
    }
    
    .panel-card h3 {
        font-size: 11px;
        margin-bottom: 6px;
        letter-spacing: 1.5px;
    }
    
    /* 计时器缩小 */
    .timer-value {
        font-size: 32px;
    }
    
    /* 玩家显示缩小 */
    .player-value {
        font-size: 14px;
    }
    
    /* 状态气泡手机版 */
    .status-bubble {
        padding: 8px 10px !important;
    }
    .bubble-item .timer-value {
        font-size: 26px;
    }
    .bubble-item .player-value {
        font-size: 14px;
    }
    .bubble-item .phase-hint-text {
        font-size: 11px;
    }
    .bubble-divider {
        height: 28px;
    }
    
    /* 阶段提示缩小 */
    .phase-hint {
        font-size: 12px;
    }
    
    /* 按钮组 */
    .button-group {
        display: flex;
        gap: 8px;
    }
    
    .button-group .btn {
        flex: 1;
        padding: 10px 12px;
        font-size: 13px;
    }

    /* 底部元素栏 - 移动端优化 */
    .elements-section {
        height: auto;
        max-height: 130px;
        padding: 10px 12px;
        gap: 14px;
        overflow-x: auto;
        overflow-y: scroll;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    /* 退出确认气泡 - 移动端适配 */
    .exit-confirm-popover {
        position: fixed;
        bottom: 160px;
        right: 8px;
        left: auto;
        min-width: 200px;
    }

    /* 模态框通用 - 移动端可滚动 */
    .modal-content {
        max-width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 24px 18px;
    }

    #campaign-modal .modal-content,
    #report-modal .modal-content,
    #bgm-modal .modal-content,
    #game-over-modal .modal-content,
    #campaign-victory-modal .modal-content {
        max-height: 85vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* 关于我们链接 */
    .about-us-link {
        position: relative;
        left: auto;
        bottom: auto;
        display: block;
        text-align: center;
        margin-top: 12px;
    }
}

/* 超小手机（< 400px） */
@media (max-width: 400px) {
    .header {
        padding: 0 5px;
    }
    
    .game-title {
        font-size: 14px;
    }
    
    .score-display {
        font-size: 11px;
        gap: 5px;
    }
    
    .score-display .score {
        font-size: 14px;
    }
    
    .round-info {
        display: none; /* 超小屏隐藏回合信息 */
    }
    
    .main-container {
        padding: 60px 5px 155px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .canvas-section {
        height: 35vh;
        min-height: 200px;
        max-height: 320px;
    }
    
    .panel-card {
        padding: 10px 12px;
    }
    
    .timer-value {
        font-size: 28px;
    }
    
    .phase-hint {
        font-size: 11px;
    }
    
    /* 状态气泡超小屏 */
    .status-bubble {
        padding: 6px 8px !important;
    }
    .bubble-item .timer-value {
        font-size: 22px;
    }
    .bubble-item .player-value {
        font-size: 12px;
    }
    .bubble-divider {
        height: 24px;
    }
    .phase-hint-text {
        font-size: 10px;
    }

    .elements-section {
        max-height: 110px;
        padding: 8px 10px;
        gap: 10px;
        overflow-y: scroll;
        overscroll-behavior: contain;
    }

    .element-btn {
        padding: 5px 10px;
        font-size: 12px;
    }

    .button-group .btn {
        padding: 8px 10px;
        font-size: 11px;
    }
    
    #start-modal .modal-content {
        padding: 14px 14px 12px;
    }
    
    #start-modal .start-settings-layout {
        gap: 10px;
    }
    
    #start-modal .mode-btn {
        font-size: 20px;
        padding: 14px 12px;
        border-radius: 18px;
    }
    
    #start-modal .start-selectors-left .stepper-value {
        font-size: 14px;
        min-height: 50px;
    }
    
    #start-modal .start-selectors-left .stepper-arrow {
        width: 34px;
        height: 34px;
        font-size: 24px;
    }
    
    #start-modal .start-image-btn {
        width: min(50%, 200px);
    }
}

/* ============================================
   JS 设备检测增强类
   ============================================ */
body.device-desktop {
    /* 桌面端额外样式 */
}

body.device-tablet {
    /* 平板端额外样式 */
}

body.device-mobile {
    /* 移动端额外样式 */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ============================================
   移动端/平板通用增强
   ============================================ */
@media (max-width: 1023px) {
    /* 表达式显示区 */
    .expression-display {
        max-height: 100px;
    }

    /* 闯关模式模态框内容可滚动 */
    #campaign-modal .modal-content {
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 24px 16px;
    }

    /* 闯关难度/关卡网格 - 更小间距 */
    .campaign-difficulty-grid {
        gap: 6px;
    }
    .campaign-level-grid {
        gap: 5px;
    }
    .campaign-level-cell {
        height: 58px;
        border-radius: 12px;
    }
    .campaign-cell-number {
        font-size: 13px;
    }

    /* Summa 角色 - 缩小并调整位置 */
    .summa-root {
        right: 4px;
        width: 32px;
        height: 140px;
    }
    .summa-hitbox {
        width: 32px;
        height: 140px;
    }
    .summa-face-wrap {
        width: 160px;
        height: 160px;
    }
    .summa-avatar {
        width: 160px;
        height: 160px;
    }
    .summa-eye {
        width: 20px;
        height: 20px;
    }
    .summa-pupil {
        width: 10px;
        height: 10px;
        margin-top: -5px;
        margin-left: -5px;
    }
    .summa-message {
        font-size: 12px;
        padding: 10px 14px;
        width: 7em;
        max-width: 7em;
    }
    
    /* Summa 对话框移动端优化 */
    .summa-dialog-content {
        max-width: 92vw;
        padding: 24px 18px;
        border-radius: 18px;
    }
    .summa-dialog-title {
        font-size: 20px !important;
    }
    .summa-dialog-message {
        font-size: 13px !important;
        padding: 12px 14px;
    }
    .summa-dialog-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    .summa-dialog-option-btn {
        font-size: 14px !important;
        padding: 12px 14px !important;
        min-height: 52px;
    }
    .summa-dialog-footer-actions {
        flex-direction: column;
        gap: 8px;
    }
    .summa-dialog-skip-btn,
    .summa-dialog-exit-btn {
        width: 100%;
        min-height: 48px;
        min-width: unset;
        padding: 0 18px !important;
    }

    /* 开始界面 - 平板也需滚动支持 */
    #start-modal .modal-content {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    /* BGM 弹窗 */
    #bgm-modal .modal-content {
        max-width: 88vw;
    }

    /* 闯关胜利弹窗 */
    .campaign-victory-content {
        min-width: unset;
        width: 100%;
    }
    .campaign-victory-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    .icon-btn {
        min-width: 100px;
        padding: 12px 14px;
        font-size: 13px;
    }
    
    /* 游戏结束弹窗 */
    #game-over-modal .modal-content {
        max-width: 90vw;
    }
    .final-scores {
        flex-direction: column;
        gap: 10px;
    }

    /* 游戏报告 */
    .report-modal-content {
        max-width: 95vw !important;
        max-height: 85vh !important;
    }
    .report-table {
        font-size: 10px;
    }
    .report-table th,
    .report-table td {
        padding: 5px 4px;
    }
}

/* 横屏模式适配 */
@media (max-height: 800px) and (orientation: landscape) {
    .main-container {
        flex-direction: row !important;
        /* 顶部 header 60px + 底部 elements 90px */
        padding: 60px 12px 0;
        height: calc(100vh - 150px);
        overflow-x: hidden;
        overflow-y: scroll;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(148, 163, 184, 0.55) rgba(15, 23, 42, 0.2);
    }
    
    .canvas-section {
        flex: 0 0 55%;
        height: auto;
        min-height: unset;
        max-height: unset;
    }
    
    .control-panel {
        flex: 0 0 45%;
        max-height: calc(100vh - 150px);
        overflow-y: scroll;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(148, 163, 184, 0.55) rgba(15, 23, 42, 0.2);
    }

    .elements-section {
        height: auto;
        max-height: 90px;
        padding: 8px 14px env(safe-area-inset-bottom, 8px);
        gap: 14px;
        overflow-y: scroll;
        overscroll-behavior: contain;
    }
}

/* iPad 横屏专用微调 */
@media (min-width: 1024px) and (max-height: 800px) and (orientation: landscape) {
    .main-container {
        padding: 70px 20px 0;
        height: calc(100vh - 160px);
    }
    
    .control-panel {
        max-height: calc(100vh - 160px);
        flex: 0 0 38%;
    }
    
    .canvas-section {
        flex: 0 0 62%;
    }
}

/* 滚动条样式 - 全局强制显示 */
::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
}

::-webkit-scrollbar-track:vertical {
    background: rgba(255, 255, 255, 0.08);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    min-height: 30px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

::-webkit-scrollbar-thumb:active {
    background: rgba(255, 255, 255, 0.45);
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-card {
    animation: fadeIn 0.3s ease-out;
}

/* 锁定元素特殊样式 */
.element-btn[data-locked="true"] {
    position: relative;
}

.element-btn[data-locked="true"]::after {
    content: '🔒';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 10px;
}

/* 简单难度保护状态 */
.element-btn.protected {
    background: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.5);
    position: relative;
}

.element-btn.protected::after {
    content: '🛡️';
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 10px;
    filter: grayscale(100%) brightness(1.5);
}

.element-btn.protected:hover {
    background: rgba(34, 197, 94, 0.3);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.3);
}

/* ============================================
   Summa 神经网络训练弹窗样式
   ============================================ */

/* Summa 训练弹窗网格背景 */
#summa-train-dialog::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 29px,
            rgba(59, 130, 246, 0.15) 29px,
            rgba(59, 130, 246, 0.15) 30px
        ),
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 149px,
            rgba(99, 102, 241, 0.22) 149px,
            rgba(99, 102, 241, 0.22) 150px
        );
    background-size: 30px 30px, 30px 30px, 150px 150px, 150px 150px;
    animation: crosshairBreathe 6s ease-in-out infinite alternate;
}

.summa-dialog-content {
    max-width: 480px;
    padding: 35px 30px;
    background: rgba(7, 13, 26, 0.92);
    border: 1px solid rgba(59, 130, 246, 0.15);
    border-radius: 24px;
    box-shadow:
        0 0 28px rgba(0, 0, 0, 0.65),
        0 16px 48px rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

@keyframes summaIconPulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.1); opacity: 1; }
}

.summa-dialog-title {
    font-size: 26px !important;
    margin-bottom: 15px !important;
    background: linear-gradient(135deg, #a78bfa, #818cf8, #5b9e6e) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
}

.summa-dialog-message {
    color: #d1d5db !important;
    font-size: 15px !important;
    line-height: 1.7 !important;
    margin-bottom: 25px !important;
    padding: 15px 18px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.summa-dialog-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.summa-dialog-option-btn {
    padding: 14px 18px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: 'Courier New', monospace;
}

.summa-dialog-option-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.summa-dialog-option-btn span {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
    font-weight: 400;
}

.summa-dialog-skip-btn {
    padding: 14px 20px;
    border: 2px solid rgba(167, 139, 250, 0.4);
    border-radius: 12px;
    background: rgba(167, 139, 250, 0.1);
    color: #c4b5fd;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    flex: 1;
}

.summa-dialog-skip-btn:hover {
    background: rgba(167, 139, 250, 0.25);
    border-color: rgba(167, 139, 250, 0.6);
    color: #e5e7eb;
    box-shadow: 0 0 20px rgba(167, 139, 250, 0.2);
    transform: translateY(-2px);
}

/* 跳过和退出按钮容器 */
.summa-dialog-secondary-buttons {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    grid-column: 1 / -1;
}

.summa-dialog-exit-btn {
    padding: 14px 24px;
    border: 2px solid rgba(248, 113, 113, 0.4);
    border-radius: 12px;
    background: rgba(248, 113, 113, 0.1);
    color: #fca5a5;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-top: 10px;
}

.summa-dialog-exit-btn:hover {
    background: rgba(248, 113, 113, 0.25);
    border-color: rgba(248, 113, 113, 0.6);
    color: #fef2f2;
    box-shadow: 0 0 20px rgba(248, 113, 113, 0.2);
    transform: translateY(-2px);
}

.summa-dialog-input-area {
    margin-top: 15px;
}

.summa-dialog-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid rgba(167, 139, 250, 0.3);
    border-radius: 10px;
    background: rgba(2, 6, 23, 0.8);
    color: #e5e7eb;
    font-size: 16px;
    font-family: 'Courier New', monospace;
    text-align: center;
    outline: none;
    transition: all 0.25s ease;
}

.summa-dialog-input:focus {
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.2);
}

.summa-dialog-input::placeholder {
    color: #475569;
}

.summa-dialog-input-buttons {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.summa-dialog-input-buttons .btn {
    flex: 1;
    padding: 12px;
}