/* style.css - 2D半挂停车模拟器视觉设计系统 */

:root {
    --bg-dark: #0a0c10;
    --bg-card: rgba(18, 22, 32, 0.75);
    --border-light: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 255, 204, 0.25);
    
    /* Neon Palette */
    --neon-cyan: #00ffcc;
    --neon-cyan-glow: rgba(0, 255, 204, 0.4);
    --neon-magenta: #ff0055;
    --neon-magenta-glow: rgba(255, 0, 85, 0.4);
    --neon-yellow: #ffff00;
    --neon-yellow-glow: rgba(255, 255, 0, 0.4);
    --neon-green: #39ff14;
    --neon-green-glow: rgba(57, 255, 20, 0.4);

    --text-main: #f0f2f5;
    --text-muted: #8e9cae;
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    --safe-bottom: env(safe-area-inset-bottom, 16px);
    --safe-top: env(safe-area-inset-top, 12px);
    --safe-left: env(safe-area-inset-left, 16px);
    --safe-right: env(safe-area-inset-right, 16px);
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-family);
    color: var(--text-main);
    position: fixed;
    touch-action: none; /* 禁用系统手势，如下拉刷新 */
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* 游戏画布 */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
}

/* 顶部 HUD 工具栏 */
.hud-header {
    position: absolute;
    top: var(--safe-top);
    left: var(--safe-left);
    right: var(--safe-right);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none; /* 让鼠标/触控事件穿透到下方的Canvas，只有按钮可以响应 */
}

.level-info {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 8px 16px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
}

.level-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    font-weight: 600;
}

.level-value {
    font-size: 15px;
    font-weight: 800;
    color: var(--neon-cyan);
    text-shadow: 0 0 8px var(--neon-cyan-glow);
}

.action-buttons {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.hud-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.hud-btn svg {
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.hud-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.05);
}

.hud-btn.active {
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px var(--neon-cyan-glow), inset 0 0 4px var(--neon-cyan-glow);
    color: var(--neon-cyan);
}

.hud-btn.active svg {
    opacity: 1;
}

/* 警报提示框 */
#warning-banner {
    position: absolute;
    top: calc(var(--safe-top) + 60px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(255, 0, 85, 0.15);
    border: 1px solid var(--neon-magenta);
    box-shadow: 0 0 15px var(--neon-magenta-glow);
    color: #ff3366;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 1px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.warning-blink {
    animation: blink 0.8s infinite alternate;
}

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

.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Toast 提示 */
.hud-toast {
    position: absolute;
    bottom: 24%;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 10;
    background: rgba(10, 12, 16, 0.9);
    border: 1px solid var(--border-light);
    color: var(--text-main);
    padding: 10px 24px;
    border-radius: 30px;
    font-size: 13px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 0;
}

.hud-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 关卡教学层 */
.hud-tutorial {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 15;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 24px;
    border-radius: 20px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: zoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hud-tutorial h3 {
    font-size: 20px;
    font-weight: 800;
    color: var(--neon-cyan);
    text-shadow: 0 0 10px var(--neon-cyan-glow);
}

.hud-tutorial p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-muted);
}

.btn-primary {
    background: var(--neon-cyan);
    color: #000;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 0 15px var(--neon-cyan-glow);
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.97);
    box-shadow: 0 0 5px var(--neon-cyan-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 12px 24px;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-secondary:active {
    background: rgba(255,255,255,0.05);
}

/* 移动端操作手柄区 */
.mobile-controls {
    position: absolute;
    bottom: var(--safe-bottom);
    left: var(--safe-left);
    right: var(--safe-right);
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none; /* 穿透 */
    height: 160px;
}

.pedal-section, .steering-section {
    pointer-events: auto; /* 响应触控 */
}

/* 左侧动力控制区 */
.pedal-section {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    height: 100%;
}

/* 挡位拨杆 */
.gear-selector-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.gear-label {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.gear-selector {
    background: rgba(10, 12, 16, 0.8);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 3px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.8);
}

.gear-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gear-btn.active {
    background: var(--text-main);
    color: #000;
    box-shadow: 0 4px 10px rgba(255,255,255,0.2);
}

#gear-r.active {
    background: var(--neon-magenta);
    color: #000;
    box-shadow: 0 0 10px var(--neon-magenta-glow);
}

/* 油门与刹车踏板 */
.pedals {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.pedal {
    border-radius: 8px;
    position: relative;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0,0,0,0.5), inset 0 2px 3px rgba(255,255,255,0.05);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 12px 6px;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.pedal-b {
    width: 60px;
    height: 100px;
    background: linear-gradient(180deg, #1b202c 0%, #11141c 100%);
    border-bottom: 4px solid #000;
}

.pedal-g {
    width: 50px;
    height: 115px;
    background: linear-gradient(180deg, #162423 0%, #0d1615 100%);
    border-bottom: 4px solid #000;
}

.pedal:active, .pedal.pressed {
    transform: scaleY(0.94) translateY(4px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.8);
}

.pedal-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.pedal-b .pedal-label {
    color: rgba(255, 255, 255, 0.4);
}

.pedal-g .pedal-label {
    color: var(--neon-cyan);
    text-shadow: 0 0 5px rgba(0,255,204,0.3);
}

.pedal-grooves {
    width: 70%;
    height: 60%;
    background-image: repeating-linear-gradient(0deg, transparent, transparent 6px, rgba(0,0,0,0.4) 6px, rgba(0,0,0,0.4) 10px);
    border-radius: 4px;
    border-left: 1px solid rgba(0,0,0,0.2);
    border-right: 1px solid rgba(255,255,255,0.02);
}

/* 右侧方向盘区 */
.steering-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.steering-wheel-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.steering-wheel {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    position: relative;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    background: radial-gradient(circle, #1a1e27 40%, #0c0e12 90%);
    border: 3px solid #14171f;
    transition: transform 0.05s linear;
}

.steering-wheel:active {
    cursor: grabbing;
}

.wheel-rim {
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border-radius: 50%;
    border: 8px solid #222836;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8), 0 0 4px rgba(255,255,255,0.05);
}

.wheel-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1b202c 0%, #0f121a 100%);
    border: 3px solid #333d52;
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

.wheel-logo {
    font-size: 7px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.wheel-spoke {
    position: absolute;
    background: linear-gradient(90deg, #1f2533 0%, #151a24 100%);
    border: 1px solid #2d364a;
    z-index: 2;
}

.spoke-left {
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    width: 45px;
    height: 12px;
}

.spoke-right {
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    width: 45px;
    height: 12px;
}

.spoke-bottom {
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 45px;
}

.wheel-indicator {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 8px;
    color: var(--neon-cyan);
    text-shadow: 0 0 5px var(--neon-cyan-glow);
    z-index: 4;
}

.steering-angle-display {
    background: rgba(10,12,16,0.8);
    border: 1px solid var(--border-light);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

#steering-val {
    color: var(--text-main);
    font-weight: 800;
}

/* 弹窗样式 */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 7, 10, 0.75);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    width: 90%;
    max-width: 480px;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 30px 70px rgba(0,0,0,0.8);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: zoomIn 0.25s ease-out;
}

.modal h2 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0.5px;
}

/* 关卡选择网格 */
.levels-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 10px 0;
}

.level-card {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--border-light);
    padding: 16px;
    border-radius: 16px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.level-card:active {
    transform: scale(0.96);
}

.level-card.completed {
    border-color: rgba(57, 255, 20, 0.3);
    background: rgba(57, 255, 20, 0.02);
}

.level-card.active {
    border-color: var(--neon-cyan);
    background: rgba(0, 255, 204, 0.04);
}

.level-card-num {
    font-size: 10px;
    font-weight: 800;
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.level-card.active .level-card-num {
    color: var(--neon-cyan);
}

.level-card-title {
    font-size: 15px;
    font-weight: 800;
}

.level-card-desc {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* 结算弹窗 */
.result-content {
    max-width: 380px;
}

.result-icon {
    font-size: 48px;
    animation: bounce 0.6s infinite alternate;
}

.result-stats {
    display: flex;
    background: rgba(0,0,0,0.3);
    border-radius: 16px;
    padding: 14px;
    border: 1px solid var(--border-light);
}

.stat-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-item:first-child {
    border-right: 1px solid var(--border-light);
}

.stat-val {
    font-size: 24px;
    font-weight: 800;
    color: var(--neon-cyan);
}

.stat-lbl {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-actions button {
    width: 100%;
}

/* 桌面操作悬浮框 */
.desktop-tips {
    position: absolute;
    bottom: var(--safe-bottom);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 12px 18px;
    border-radius: 16px;
    z-index: 10;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    display: none; /* 默认隐藏，在检测到非触摸屏/宽屏时通过JS显示，或者靠CSS显示 */
    pointer-events: none;
}

.desktop-tips h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--neon-cyan);
    margin-bottom: 6px;
    font-weight: 800;
    letter-spacing: 0.5px;
    text-align: center;
}

.desktop-tips ul {
    list-style: none;
    font-size: 10px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

.desktop-tips kbd {
    background: #252b3a;
    border: 1px solid #3c465d;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 9px;
    color: var(--text-main);
    box-shadow: 0 2px 0 rgba(0,0,0,0.5);
}

/* 动画效果 */
@keyframes zoomIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

/* 针对非移动端大屏幕，显示按键提示 */
@media (min-width: 992px) {
    .desktop-tips {
        display: block;
    }
}

/* 移动端 Header 适配：避免按钮文字纵向折行 */
@media (max-width: 720px) {
    .hud-header {
        gap: 6px;
    }
    .level-info {
        padding: 6px 10px;
        gap: 6px;
        max-width: 55%;
        min-width: 0;
        flex: 0 1 auto;
        overflow: hidden;
    }
    .level-label {
        font-size: 10px;
        letter-spacing: 1px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .level-value {
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
    }
    .action-buttons {
        gap: 6px;
        flex-shrink: 0;
    }
    .hud-btn {
        padding: 8px;
        border-radius: 10px;
    }
    .hud-btn span {
        display: none;
    }
    .hud-btn svg {
        width: 20px;
        height: 20px;
        opacity: 1;
    }
}

@media (max-width: 380px) {
    .level-info {
        padding: 5px 8px;
        max-width: 50%;
    }
    .level-label {
        display: none;
    }
    .level-value {
        font-size: 12px;
    }
    .action-buttons {
        gap: 4px;
    }
    .hud-btn {
        padding: 7px;
    }
    .hud-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* 强制横屏友好布局或纵向适配的逻辑 */
@media (orientation: portrait) {
    /* 如果是竖屏移动端，需要重新编排控制器位置，使画幅保持在上方 */
    .mobile-controls {
        height: 200px;
        flex-direction: row;
        align-items: center;
    }
    .steering-wheel {
        width: 120px;
        height: 120px;
    }
    .hud-toast {
        bottom: 30%;
    }
}
