:root {
    --ui-bg: #f5f7f9;
    --ui-surface: #ffffff;
    --ui-primary: #1a4d8f;
    --ui-primary-dark: #133a6e;
    --ui-accent: #00a8a8;
    --ui-text: #1a2332;
    --ui-text-muted: #5a6b80;
    --ui-border: #d8e0ea;
    --ui-border-light: #e8edf3;
    --canvas-bg: #0d1b2a;
    --radius-sm: 4px;
    --radius-md: 6px;
    --base-A: #ff5470;
    --base-T: #4dabf7;
    --base-G: #ffd43b;
    --base-C: #69db7c;
    --ligase: #44ff88;
    --rna-primer: #ff4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* 通用隐藏类：必须 !important 才能压过 .two-player-controls 等元素的 display:flex/具体 display。
   之前只有 .screen.hidden / .scene-screen.hidden 有 display:none，导致非 screen 元素加 .hidden 不生效。 */
.hidden { display: none !important; }

html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: var(--ui-bg);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: var(--ui-text);
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
}

#game-container {
    position: relative; width: 100%; height: 100%;
    display: flex; flex-direction: column;
    max-width: 520px; margin: 0 auto;
    background: var(--ui-bg);
}

#hud {
    display: grid; grid-template-columns: 1.4fr 1.4fr 0.8fr 0.8fr;
    gap: 10px; padding: 12px 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 249, 250, 0.95) 100%);
    border-bottom: 1px solid rgba(102, 126, 234, 0.2);
    z-index: 10;
    backdrop-filter: blur(10px);
}
.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    padding: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 12px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease;
}
.hud-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.hud-label {
    font-size: 11px;
    color: var(--ui-text-muted);
    margin-bottom: 5px;
    white-space: nowrap;
    letter-spacing: 0.5px;
    font-weight: 500;
}
#progress-bar, #integrity-bar {
    width: 100%;
    height: 10px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid rgba(102, 126, 234, 0.2);
}
#progress-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
    border-radius: 5px;
}
#integrity-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #48bb78 0%, #38a169 100%);
    transition: width 0.3s ease;
    border-radius: 5px;
}
#progress-text, #integrity-text, #bp-count, #okazaki-status { font-size: 12px; font-weight: bold; color: var(--ui-text); margin-top: 2px; }

#helicase-bar-container {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.8) 0%, rgba(248, 249, 250, 0.8) 100%);
    border-radius: 12px;
    border: 1px solid rgba(102, 126, 234, 0.2);
    margin: 0 16px 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.helicase-label {
    font-size: 11px;
    color: var(--ui-text-muted);
    font-weight: 600;
    white-space: nowrap;
}
#helicase-bar {
    flex: 1;
    height: 10px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 5px;
    overflow: hidden;
    border: 1px solid rgba(102, 126, 234, 0.2);
}
#helicase-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #48bb78 0%, #38a169 100%);
    transition: width 0.3s ease;
    border-radius: 5px;
}

#game-canvas { flex: 1; display: block; width: 100%; touch-action: none; background: var(--canvas-bg); }

#controls {
    display: flex; flex-direction: column; gap: 12px; padding: 16px 20px 20px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 249, 250, 0.95) 100%);
    border-top: 1px solid rgba(102, 126, 234, 0.2);
    z-index: 10;
    backdrop-filter: blur(10px);
}
.single-controls, .two-player-controls {
    width: 100%;
    padding: 12px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.control-group { display: flex; align-items: center; gap: 12px; }
.group-label { font-size: 11px; color: var(--ui-text-muted); writing-mode: vertical-rl; text-orientation: upright; letter-spacing: 2px; min-width: 16px; font-weight: 600; }
.two-player-controls {
    display: flex;
    flex-direction: column;   /* 上下分屏：P1 上 P2 下 */
    align-items: stretch;
    gap: 8px;
}
.player-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.player1 .group-label { color: var(--ui-primary); }
.player2 .group-label { color: #f97316; }
/* 分隔线代替大圆球，防溢出 */
.vs-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--ui-text-muted);
    letter-spacing: 3px;
    height: 14px;
    position: relative;
}
.vs-divider::before,
.vs-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(102, 126, 234, 0.25);
}
.vs-divider::before { margin-right: 8px; }
.vs-divider::after { margin-left: 8px; }
.player-controls .control-group {
    display: flex; align-items: center; gap: 6px;
}
.player-controls .group-label {
    font-size: 10px; color: var(--ui-text-muted); letter-spacing: 1px; min-width: 14px; font-weight: 600;
    writing-mode: horizontal-tb; text-orientation: upright;
}
.player-controls .base-buttons { flex: 1; }
.base-buttons, .enzyme-buttons { flex: 1; display: flex; justify-content: space-around; gap: 6px; }

.lane-btn, .enzyme-btn {
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0%, rgba(248, 249, 250, 0.9) 100%);
    color: var(--ui-text); font-weight: bold; cursor: pointer;
    transition: all 0.2s ease;
    user-select: none; -webkit-tap-highlight-color: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.lane-btn {
    width: 56px; height: 56px;
    font-size: 24px;
    position: relative;
    overflow: hidden;
}
.lane-btn:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.3) 0%, transparent 70%);
    transition: all 0.3s ease;
    transform: translate(-50%, -50%);
    border-radius: 50%;
}
.lane-btn:active:before {
    width: 100%;
    height: 100%;
}
.lane-btn .base-label {
    font-size: 22px;
    font-weight: bold;
    line-height: 1.1;
    z-index: 1;
}
.lane-btn .key-hint {
    font-size: 10px;
    font-weight: normal;
    opacity: 0.6;
    line-height: 1;
    margin-top: -2px;
    z-index: 1;
}
.lane-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}
.lane-btn:active, .lane-btn.pressed {
    transform: scale(0.95);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
}
.lane-btn[data-base="A"] {
    border-color: var(--base-A);
    color: var(--base-A);
    background: linear-gradient(135deg, rgba(255, 84, 112, 0.1) 0%, rgba(255, 84, 112, 0.05) 100%);
}
.lane-btn[data-base="A"]:hover {
    border-color: var(--base-A);
    box-shadow: 0 6px 16px rgba(255, 84, 112, 0.3);
}
.lane-btn[data-base="T"] {
    border-color: var(--base-T);
    color: var(--base-T);
    background: linear-gradient(135deg, rgba(77, 171, 247, 0.1) 0%, rgba(77, 171, 247, 0.05) 100%);
}
.lane-btn[data-base="T"]:hover {
    border-color: var(--base-T);
    box-shadow: 0 6px 16px rgba(77, 171, 247, 0.3);
}
.lane-btn[data-base="G"] {
    border-color: var(--base-G);
    color: var(--base-G);
    background: linear-gradient(135deg, rgba(255, 212, 59, 0.1) 0%, rgba(255, 212, 59, 0.05) 100%);
}
.lane-btn[data-base="G"]:hover {
    border-color: var(--base-G);
    box-shadow: 0 6px 16px rgba(255, 212, 59, 0.3);
}
.lane-btn[data-base="C"] {
    border-color: var(--base-C);
    color: var(--base-C);
    background: linear-gradient(135deg, rgba(105, 219, 124, 0.1) 0%, rgba(105, 219, 124, 0.05) 100%);
}
.lane-btn[data-base="C"]:hover {
    border-color: var(--base-C);
    box-shadow: 0 6px 16px rgba(105, 219, 124, 0.3);
}
.enzyme-btn[data-enzyme="helicase"] {
    border-color: var(--ui-primary);
    color: var(--ui-primary);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(102, 126, 234, 0.05) 100%);
}
.enzyme-btn[data-enzyme="helicase"]:hover {
    border-color: var(--ui-primary);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3);
}
.enzyme-btn[data-enzyme="ligase"] {
    border-color: #f97316;
    color: #f97316;
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.1) 0%, rgba(249, 115, 22, 0.05) 100%);
}
.enzyme-btn[data-enzyme="ligase"]:hover {
    border-color: #f97316;
    box-shadow: 0 6px 16px rgba(249, 115, 22, 0.3);
}
.enzyme-btn[data-enzyme="ssb"] {
    border-color: var(--ui-accent);
    color: var(--ui-accent);
    background: linear-gradient(135deg, rgba(0, 168, 168, 0.1) 0%, rgba(0, 168, 168, 0.05) 100%);
}
.enzyme-btn[data-enzyme="ssb"]:hover {
    border-color: var(--ui-accent);
    box-shadow: 0 6px 16px rgba(0, 168, 168, 0.3);
}
.enzyme-btn[data-enzyme="repair"] {
    border-color: #e8505b;
    color: #e8505b;
    background: linear-gradient(135deg, rgba(232, 80, 91, 0.1) 0%, rgba(232, 80, 91, 0.05) 100%);
}
.enzyme-btn[data-enzyme="repair"]:hover {
    border-color: #e8505b;
    box-shadow: 0 6px 16px rgba(232, 80, 91, 0.3);
}
.enzyme-btn.ready { animation: pulse 0.8s infinite alternate; background: rgba(249, 115, 22, 0.12); }
.enzyme-btn.cooldown { opacity: 0.5; }
@keyframes pulse { from { box-shadow: 0 0 0 rgba(249, 115, 22, 0.3); } to { box-shadow: 0 0 10px rgba(249, 115, 22, 0.6); } }

.screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex; justify-content: center; align-items: center;
    z-index: 100; overflow-y: auto;
}
.screen.hidden { display: none; }
.screen-content {
    text-align: center; padding: 40px 30px;
    max-width: 450px; width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.screen h1 {
    font-size: 42px;
    color: var(--ui-primary);
    margin-bottom: 8px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.screen h2 {
    font-size: 20px;
    color: var(--ui-text-muted);
    margin-bottom: 25px;
    font-weight: 400;
}
.subtitle {
    font-size: 17px;
    color: var(--ui-text);
    margin-bottom: 16px;
    line-height: 1.6;
    font-weight: 500;
}
.description {
    font-size: 14px;
    color: var(--ui-text-muted);
    margin-bottom: 30px;
    line-height: 1.8;
}
.key-reference {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 20px;
    margin-bottom: 28px;
    font-size: 12px;
}
.key-reference kbd {
    display: inline-block;
    padding: 3px 8px;
    font-size: 11px;
    font-family: inherit;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    color: var(--ui-text);
    margin: 0 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}
.key-reference kbd:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.briefing-body, .report-body, .knowledge-panel {
    text-align: left;
    font-size: 14px;
    color: var(--ui-text);
    line-height: 1.8;
    margin-bottom: 28px;
    padding: 22px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 16px;
    border: 1px solid rgba(102, 126, 234, 0.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    max-height: 50vh;
    overflow-y: auto;
}
.briefing-body::-webkit-scrollbar, .report-body::-webkit-scrollbar, .knowledge-panel::-webkit-scrollbar {
    width: 6px;
}
.briefing-body::-webkit-scrollbar-track, .report-body::-webkit-scrollbar-track, .knowledge-panel::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}
.briefing-body::-webkit-scrollbar-thumb, .report-body::-webkit-scrollbar-thumb, .knowledge-panel::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.3);
    border-radius: 3px;
}
.briefing-body h3, .report-body h3, .knowledge-panel h3 {
    color: var(--ui-primary);
    font-size: 16px;
    margin: 16px 0 10px;
    font-weight: 700;
    position: relative;
    padding-left: 20px;
}
.briefing-body h3:before, .report-body h3:before, .knowledge-panel h3:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 2px;
}
.briefing-body h3:first-child, .report-body h3:first-child, .knowledge-panel h3:first-child {
    margin-top: 0;
}
.briefing-body p, .report-body p, .knowledge-panel p {
    margin-bottom: 12px;
}
.briefing-body ul, .report-body ul, .knowledge-panel ul {
    margin-left: 20px;
    margin-bottom: 12px;
}
.report-body .stat {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
    font-size: 15px;
}
.report-body .stat-value {
    color: var(--ui-primary);
    font-weight: bold;
}

.ach-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ach { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; font-size: 12px; border: 1px solid var(--ui-border-light); }
.ach-ico { font-size: 16px; }
.ach-name { font-weight: bold; min-width: 88px; color: var(--ui-text); }
.ach-desc { color: var(--ui-text-muted); font-size: 11px; }
.ach-done { background: rgba(0, 168, 168, 0.08); border-color: rgba(0, 168, 168, 0.3); }
.ach-new { background: rgba(255, 215, 0, 0.15); border-color: #ffd43b; animation: achpop 0.5s ease; }
.ach-locked { opacity: 0.45; }
@keyframes achpop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.primary-btn, .secondary-btn {
    padding: 15px 36px; font-size: 18px; border: none; border-radius: 12px;
    cursor: pointer; transition: all 0.3s ease;
    margin: 8px; min-width: 160px; font-weight: 600;
    position: relative;
    overflow: hidden;
}
.primary-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.primary-btn:before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.5s;
}
.primary-btn:hover:before {
    left: 100%;
}
.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}
.primary-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.4);
}
.secondary-btn {
    background: var(--ui-surface);
    color: var(--ui-primary);
    border: 2px solid var(--ui-primary);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.secondary-btn:hover {
    background: rgba(102, 126, 234, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}
.secondary-btn:active {
    background: var(--ui-bg);
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ===== 关卡列表 ===== */
.level-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px;
}
.level-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--ui-surface);
    border: 2px solid var(--ui-border-light);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.18s ease;
    text-align: left;
}
.level-item:hover:not(.locked) {
    border-color: var(--ui-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 168, 168, 0.15);
}
.level-item.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--ui-bg);
}
.level-item.cleared {
    border-color: rgba(105, 219, 124, 0.5);
    background: linear-gradient(135deg, rgba(255,255,255,1) 0%, rgba(236,253,240,0.6) 100%);
}
.level-icon {
    font-size: 22px;
    width: 32px;
    text-align: center;
    flex-shrink: 0;
}
.level-info { flex: 1; min-width: 0; }
.level-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--ui-text);
    margin-bottom: 2px;
}
.level-sub {
    font-size: 11px;
    color: var(--ui-text-muted);
}

#mode-selector {
    margin: 30px 0;
    padding: 20px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-radius: 16px;
    border: 1px solid rgba(102, 126, 234, 0.2);
}
#mode-selector p {
    font-size: 14px;
    color: var(--ui-text-muted);
    margin-bottom: 15px;
    font-weight: 500;
}
#mode-selector .secondary-btn {
    flex: 1;
    max-width: 160px;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 10px;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
}
#mode-selector .secondary-btn:first-child {
    margin-right: 15px;
}
#mode-description {
    font-size: 12px;
    color: var(--ui-text-muted);
    margin-top: 12px;
    text-align: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    font-style: italic;
}

@media (min-width: 521px) { #game-container { border-left: 1px solid var(--ui-border); border-right: 1px solid var(--ui-border); } }
@media (max-height: 640px) { .lane-btn { width: 46px; height: 46px; font-size: 20px; } .enzyme-btn { width: 58px; height: 40px; font-size: 12px; } #controls { padding: 8px 10px 12px; gap: 8px; } }

[data-feature]:not([data-feature-active="true"]) { display: none !important; }

.scene-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--ui-bg); z-index: 100; display: flex; flex-direction: column; }
.scene-screen.hidden { display: none; }
.scene-stage { width: 100%; height: 100%; max-width: 520px; margin: 0 auto; display: flex; flex-direction: column; background: var(--ui-surface); }
.scene-hud { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--ui-surface); border-bottom: 1px solid var(--ui-border); min-height: 52px; }
.scene-progress { font-size: 14px; color: var(--ui-primary); font-weight: bold; }
.scene-bubble { font-size: 12px; color: var(--ui-primary); background: rgba(0, 168, 168, 0.1); border: 1px solid var(--ui-accent); border-radius: 14px; padding: 4px 10px; transition: opacity 0.3s; max-width: 70%; text-align: right; }
.scene-bubble.hidden { opacity: 0; }
.scene-canvas { flex: 1; display: block; width: 100%; touch-action: none; background: var(--canvas-bg); }
.scene-controls { display: flex; justify-content: space-around; gap: 12px; padding: 16px; background: var(--ui-surface); border-top: 1px solid var(--ui-border); }
.scene-btn { width: 64px; height: 64px; font-size: 24px; }
