:root {
    --paper: #f4ecd8;
    --ink: #2b2b2b;
    --accent: #e74c3c;
    --green: #27ae60;
    --blue: #2980b9;
    --orange: #e67e22;
    --purple: #8e44ad;
    --shadow: rgba(0,0,0,0.25);
    --touch-alpha: rgba(41,128,185,0.25);
    --touch-stick: rgba(41,128,185,0.6);
}

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

html, body {
    font-family: 'Marker Felt', 'Comic Sans MS', 'Chalkboard SE', cursive, sans-serif;
    background: #1a1a2e;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: none;
}

#app {
    position: relative;
    width: 1000px;
    max-width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ===== HUD ===== */
#hud {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 6px 0 var(--shadow);
    align-items: center;
    width: 100%;
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 70px;
}

.hud-item.health-item,
.hud-item.ammo-item { min-width: auto; flex: 1; max-width: 150px; }

.hud-label {
    font-size: 12px;
    color: #666;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.hud-value {
    font-size: 26px;
    font-weight: bold;
    color: var(--ink);
    line-height: 1;
}

.bar-wrap {
    width: 100%;
    min-width: 80px;
    height: 18px;
    background: rgba(0,0,0,0.1);
    border: 2px solid var(--ink);
    border-radius: 9px;
    overflow: hidden;
    position: relative;
}

.bar {
    height: 100%;
    width: 100%;
    transition: width 0.2s;
    border-radius: 7px;
}

.health-bar { background: var(--green); }
.ammo-bar { background: var(--orange); }
.skill-bar { background: var(--blue); }

.hud-sub {
    font-size: 11px;
    color: #666;
}

.mode-switch-item { margin-left: auto; }
.mode-btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: bold;
    padding: 6px 14px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    box-shadow: 2px 2px 0 var(--shadow);
}

.pause-item { margin-left: 8px; }
.pause-btn {
    font-family: inherit;
    font-size: 18px;
    width: 38px;
    height: 38px;
    border: 2px solid var(--ink);
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    box-shadow: 2px 2px 0 var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}
.pause-btn:active { transform: scale(0.92); }

/* ===== 暂停/设置/帧率 ===== */
.pause-title { color: var(--orange) !important; text-shadow: 4px 4px 0 var(--ink) !important; }
.pause-stats {
    display: flex;
    gap: 24px;
    justify-content: center;
    margin: 16px 0;
    font-size: 18px;
    color: var(--ink);
}
.pause-stats strong { color: var(--accent); }

.btn-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}
.btn-col .btn { margin-top: 0; width: 220px; }

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0;
    text-align: left;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
}

.setting-label {
    flex: 1;
    font-size: 15px;
    font-weight: bold;
    color: var(--ink);
}

.setting-row input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.switch-ui {
    width: 44px;
    height: 24px;
    background: #ccc;
    border: 2px solid var(--ink);
    border-radius: 12px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.switch-ui::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 1px;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 1px solid var(--ink);
    border-radius: 50%;
    transition: transform 0.2s;
}
.setting-row input:checked ~ .switch-ui { background: var(--green); }
.setting-row input:checked ~ .switch-ui::after { transform: translateX(20px); }

.best-score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border: 2px dashed var(--ink);
    border-radius: 10px;
    padding: 10px 14px;
    margin: 12px 0;
    font-size: 14px;
    color: var(--ink);
}
.best-score-row strong { color: var(--accent); font-size: 18px; }
.new-best {
    color: var(--orange);
    font-weight: bold;
    font-size: 20px;
    animation: bestPulse 0.6s ease-in-out infinite alternate;
}
@keyframes bestPulse { from { transform: scale(1); } to { transform: scale(1.08); } }

.btn-sm { font-size: 14px; padding: 6px 14px; margin: 0; }

#fpsCounter {
    position: fixed;
    top: 8px;
    left: 8px;
    background: rgba(0,0,0,0.7);
    color: #0f0;
    font-family: monospace;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 4px;
    z-index: 200;
    pointer-events: none;
}

/* ===== 舞台 ===== */
#stage {
    position: relative;
    border: 3px solid var(--ink);
    border-top: none;
    background: var(--paper);
    overflow: hidden;
    width: 100%;
}

#game {
    display: block;
    width: 100%;
    height: auto;
    touch-action: none;
}

#crosshair {
    position: absolute;
    width: 28px;
    height: 28px;
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 20;
    display: none;
}

#crosshair::before, #crosshair::after {
    content: '';
    position: absolute;
    background: var(--accent);
    border: 1px solid var(--ink);
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }

#toast {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 42px;
    font-weight: bold;
    color: var(--accent);
    text-shadow: 3px 3px 0 var(--ink);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 30;
    white-space: nowrap;
}

#reloadIndicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--orange);
    color: #fff;
    padding: 8px 24px;
    border: 2px solid var(--ink);
    border-radius: 20px;
    font-weight: bold;
    display: none;
    z-index: 20;
    pointer-events: none;
}

#killFeed {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
    pointer-events: none;
}

.kill-msg {
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 14px;
    animation: killFade 2s forwards;
}

@keyframes killFade {
    0% { opacity: 0; transform: translateX(20px); }
    15% { opacity: 1; transform: translateX(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* ===== 底部 ===== */
#controls {
    display: flex;
    gap: 18px;
    padding: 12px 16px;
    background: var(--paper);
    border: 3px solid var(--ink);
    border-top: none;
    border-radius: 0 0 14px 14px;
    box-shadow: 0 6px 0 var(--shadow);
    justify-content: center;
    flex-wrap: wrap;
    font-size: 14px;
    color: var(--ink);
    width: 100%;
}

kbd {
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 6px;
    padding: 2px 8px;
    font-family: inherit;
    font-weight: bold;
    margin: 0 2px;
    box-shadow: 2px 2px 0 var(--shadow);
    font-size: 12px;
    display: inline-block;
}

/* ===== 触屏控制层 ===== */
#touchControls {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: none;
    pointer-events: none;
}

.touch-pad {
    position: absolute;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3px solid rgba(43,43,43,0.4);
    background: var(--touch-alpha);
    pointer-events: auto;
    touch-action: none;
    transition: opacity 0.2s;
}

#movePad { bottom: 30px; left: 30px; }
#aimPad { bottom: 30px; right: 30px; }

.touch-stick {
    position: absolute;
    top: 50%; left: 50%;
    width: 56px; height: 56px;
    border-radius: 50%;
    background: var(--touch-stick);
    border: 2px solid var(--ink);
    transform: translate(-50%, -50%);
    transition: none;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

#actionButtons {
    position: absolute;
    top: 60px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: auto;
}

.action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 3px solid var(--ink);
    background: rgba(255,255,255,0.85);
    font-family: inherit;
    font-size: 22px;
    font-weight: bold;
    color: var(--ink);
    cursor: pointer;
    box-shadow: 3px 3px 0 var(--shadow);
    touch-action: none;
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:active {
    transform: scale(0.9);
    background: var(--accent);
    color: #fff;
}

.special-btn { background: var(--blue); color: #fff; }
.special-btn:active { background: var(--purple); }

.weapon-btn { font-size: 18px; }
.weapon-btn.active-wpn { background: var(--orange); color: #fff; }

/* ===== 覆盖层 ===== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(20,20,40,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    overflow-y: auto;
    padding: 20px;
}

.overlay-card {
    background: var(--paper);
    border: 4px solid var(--ink);
    border-radius: 20px;
    padding: 36px 44px;
    text-align: center;
    box-shadow: 10px 10px 0 var(--shadow);
    max-width: 620px;
    width: 100%;
    transform: rotate(-1deg);
}

.title {
    font-size: 56px;
    color: var(--ink);
    text-shadow: 4px 4px 0 var(--accent);
    margin-bottom: 8px;
    transform: rotate(1deg);
}

.subtitle {
    font-size: 16px;
    color: #888;
    letter-spacing: 3px;
    margin-bottom: 20px;
}

.story {
    background: #fff;
    border: 2px dashed var(--ink);
    border-radius: 12px;
    padding: 14px;
    margin: 16px 0;
    font-size: 15px;
    line-height: 1.8;
    color: #444;
}

.device-info {
    font-size: 14px;
    color: #666;
    margin: 12px 0;
    background: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    border: 2px solid var(--ink);
}

.device-info strong { color: var(--accent); }

.mode-select { margin: 16px 0; }

.mode-select-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--ink);
    margin-bottom: 10px;
}

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

.mode-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 12px 8px;
    border: 3px solid var(--ink);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    box-shadow: 3px 3px 0 var(--shadow);
    transition: all 0.15s;
    font-family: inherit;
}

.mode-option:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--shadow); }
.mode-option.selected {
    background: var(--green);
    color: #fff;
    transform: translate(2px,2px);
    box-shadow: 1px 1px 0 var(--shadow);
}

.mode-icon { font-size: 28px; }
.mode-name { font-size: 15px; font-weight: bold; }
.mode-desc { font-size: 11px; opacity: 0.8; }

.btn-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

.btn {
    font-family: inherit;
    font-size: 20px;
    font-weight: bold;
    padding: 12px 32px;
    border: 3px solid var(--ink);
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 5px 5px 0 var(--shadow);
    transition: transform 0.1s, box-shadow 0.1s;
    margin-top: 12px;
}

.btn:hover { transform: translate(-2px, -2px); box-shadow: 7px 7px 0 var(--shadow); }
.btn:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--shadow); }

.btn-primary { background: var(--green); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); }

.how-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin: 16px 0;
}

.how-item {
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 12px;
    padding: 12px;
    text-align: left;
}

.how-icon { font-size: 26px; margin-bottom: 4px; }
.how-item h3 { font-size: 15px; margin-bottom: 4px; color: var(--accent); }
.how-item p { font-size: 12px; color: #555; line-height: 1.5; }

.result-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 20px 0;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 2px solid var(--ink);
    border-radius: 12px;
    padding: 14px 20px;
    min-width: 90px;
}

.stat-num { font-size: 32px; font-weight: bold; color: var(--accent); }
.stat-label { font-size: 12px; color: #666; margin-top: 4px; }

/* ====================================================
   模式: 平板
   ==================================================== */
#app.mode-tablet #controls { display: none; }
#app.mode-tablet #touchControls { display: block; }
#app.mode-tablet #crosshair { display: none !important; }
#app.mode-tablet #stage { cursor: default; }

/* ====================================================
   模式: 横屏手机
   ==================================================== */
#app.mode-phone-landscape #controls { display: none; }
#app.mode-phone-landscape #touchControls { display: block; }
#app.mode-phone-landscape #crosshair { display: none !important; }
#app.mode-phone-landscape #stage { cursor: default; }
#app.mode-phone-landscape { width: 100vw; }
#app.mode-phone-landscape #hud { gap: 8px; padding: 6px 10px; flex-wrap: nowrap; overflow: hidden; }
#app.mode-phone-landscape .hud-value { font-size: 18px; }
#app.mode-phone-landscape .hud-label { font-size: 10px; }
#app.mode-phone-landscape .bar-wrap { height: 12px; min-width: 50px; }
#app.mode-phone-landscape .mode-switch-item { display: none; }
#app.mode-phone-landscape .touch-pad { width: 110px; height: 110px; }
#app.mode-phone-landscape .touch-stick { width: 46px; height: 46px; }
#app.mode-phone-landscape #movePad { bottom: 16px; left: 16px; }
#app.mode-phone-landscape #aimPad { bottom: 16px; right: 16px; }
#app.mode-phone-landscape .action-btn { width: 46px; height: 46px; font-size: 18px; }
#app.mode-phone-landscape #actionButtons { top: 50px; right: 12px; gap: 8px; }

/* ====================================================
   模式: 竖屏手机
   ==================================================== */
#app.mode-phone-portrait {
    width: 100vw;
    flex-direction: column;
}
#app.mode-phone-portrait #controls { display: none; }
#app.mode-phone-portrait #touchControls { display: block; }
#app.mode-phone-portrait #crosshair { display: none !important; }
#app.mode-phone-portrait #stage { cursor: default; }
#app.mode-phone-portrait #hud {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px;
    border-radius: 0;
}
#app.mode-phone-portrait .hud-item { min-width: 50px; }
#app.mode-phone-portrait .hud-value { font-size: 16px; }
#app.mode-phone-portrait .hud-label { font-size: 9px; }
#app.mode-phone-portrait .bar-wrap { height: 10px; min-width: 40px; }
#app.mode-phone-portrait .hud-sub { font-size: 9px; }
#app.mode-phone-portrait .mode-switch-item { display: none; }
/* 竖屏: 摇杆位置调整 - 避免挡视野 */
#app.mode-phone-portrait #movePad { width: 100px; height: 100px; bottom: 12px; left: 12px; }
#app.mode-phone-portrait #aimPad { width: 100px; height: 100px; bottom: 12px; right: 12px; }
#app.mode-phone-portrait .touch-stick { width: 42px; height: 42px; }
/* 竖屏: 动作按钮放右上方 */
#app.mode-phone-portrait #actionButtons {
    top: 50px;
    right: 10px;
    flex-direction: column;
    gap: 8px;
}
#app.mode-phone-portrait .action-btn { width: 42px; height: 42px; font-size: 16px; }
/* 竖屏: 覆盖层卡片缩小 */
#app.mode-phone-portrait .overlay-card { padding: 24px 20px; }
#app.mode-phone-portrait .title { font-size: 40px; }
#app.mode-phone-portrait .mode-options { grid-template-columns: 1fr 1fr; }
#app.mode-phone-portrait .how-grid { grid-template-columns: 1fr; }

/* ====================================================
   模式: 桌面（默认）
   ==================================================== */
#app.mode-desktop #touchControls { display: none; }
#app.mode-desktop #stage { cursor: none; }

/* ===== 响应式 ===== */
@media (max-width: 1020px) {
    #app { width: 100%; padding: 0; }
    .title { font-size: 40px; }
}

@media (max-width: 600px) {
    .overlay-card { padding: 24px 18px; }
    .title { font-size: 32px; }
    .mode-options { grid-template-columns: 1fr; }
}
