/* ========================================================
   《回声行者》（Echo-Walker）- 样式系统
   极简主义声学声呐与深邃暗夜赛博美学
   跨平台排版对齐 · 响应式自适应 · 视网膜高清渲染
   ======================================================== */

:root {
    --bg-primary: #020406;
    --bg-surface: rgba(8, 14, 22, 0.94);
    --border-cyan: rgba(0, 195, 255, 0.22);
    --cyan-glow: #00d5ff;
    --cyan-text: #e2f5ff;
    --red-alert: #ff2a48;
    --amber-gold: #ffb822;
    --green-emerald: #00ffaa;
    --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, "Courier New", monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    background-color: var(--bg-primary);
    color: #c0d8ec;
    font-family: var(--font-ui);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    position: relative;
    padding: env(safe-area-inset-top, 8px) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 8px) env(safe-area-inset-left, 0);
}

/* 幽微的环境声呐扫描线覆层 */
body::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.2) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.015), rgba(0, 255, 0, 0.01), rgba(0, 255, 255, 0.015));
    z-index: 90;
    background-size: 100% 3px, 6px 100%;
    pointer-events: none;
    opacity: 0.55;
}

#gameContainer {
    position: relative;
    width: 1000px;
    max-width: 98vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 0 60px rgba(0, 170, 255, 0.14), 0 20px 40px rgba(0, 0, 0, 0.8);
    border-radius: 12px;
    background: #000000;
    border: 1px solid var(--border-cyan);
    overflow: hidden;
}

/* ---------------- 顶部 HUD 仪表栏 ---------------- */
header {
    width: 100%;
    padding: 10px 18px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-cyan);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    z-index: 20;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.logo-area {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-shrink: 0;
}

.logo-area h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--cyan-text);
    text-shadow: 0 0 14px rgba(0, 210, 255, 0.7);
    line-height: 1;
}

.logo-area .en-title {
    font-size: 0.72rem;
    color: var(--cyan-glow);
    letter-spacing: 1.5px;
    font-family: var(--font-mono);
    font-weight: 600;
    opacity: 0.9;
}

/* 核心遥测胶囊挂件（等高垂直居中，数字等宽排版） */
.hud-telemetry {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    flex-wrap: wrap;
}

.telemetry-pill {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 10px;
    border-radius: 14px;
    background: rgba(0, 180, 255, 0.08);
    border: 1px solid rgba(0, 180, 255, 0.22);
    color: #9cd8f7;
    line-height: 1;
    gap: 7px;
    transition: all 0.2s ease;
}

.pill-icon {
    font-size: 0.85rem;
    line-height: 1;
}

/* 声纳分贝条 */
.db-pill {
    min-width: 142px;
}

.db-meter-bg {
    width: 64px;
    height: 6px;
    background: #08121c;
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(0, 180, 255, 0.3);
}

#dbBar {
    width: 12%;
    height: 100%;
    background: var(--cyan-glow);
    border-radius: 3px;
    transition: width 0.08s ease-out, background 0.15s ease;
    box-shadow: 0 0 6px currentColor;
}

#dbValue {
    font-weight: 700;
    min-width: 42px;
    text-align: right;
    color: var(--cyan-glow);
    font-variant-numeric: tabular-nums;
}

/* 动态心率 ECG */
.ecg-pill {
    min-width: 86px;
}

#ecgMonitor {
    font-weight: 700;
    letter-spacing: 0.5px;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 8px currentColor;
    transition: color 0.25s ease;
}

/* 道具物资徽章 */
.item-pill {
    font-weight: 600;
    color: #8ce1ff;
    letter-spacing: 0.5px;
}

.crystal-pill {
    background: rgba(0, 255, 170, 0.1);
    border-color: rgba(0, 255, 170, 0.3);
    color: #00ffaa;
}

/* 顶部操作区（下拉框、重置、静音统一 28px 高度） */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

select, button {
    background: rgba(10, 20, 32, 0.9);
    color: #a4daf8;
    border: 1px solid rgba(0, 180, 255, 0.28);
    height: 28px;
    padding: 0 12px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    line-height: 1;
}

select {
    padding-right: 24px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2300d5ff' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}

select:hover, button:hover {
    background-color: rgba(0, 190, 255, 0.18);
    color: #ffffff;
    border-color: #00e5ff;
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.35);
}

select:focus, button:focus {
    border-color: var(--cyan-glow);
}

/* ---------------- 视口与画布容器 ---------------- */
#canvasWrapper {
    position: relative;
    width: 100%;
    max-width: calc(min(75vh, 750px) * (4 / 3));
    aspect-ratio: 4 / 3;
    max-height: 75vh;
    background: #000000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    touch-action: none;
}

#glCanvas {
    width: 100%;
    height: 100%;
    display: block;
    background: #000000;
    touch-action: none;
}

/* ---------------- 关卡悬浮战术简报（平滑渐隐） ---------------- */
#levelBanner {
    position: absolute;
    top: 14px;
    left: 18px;
    right: 18px;
    pointer-events: none;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 5px;
    transition: opacity 0.8s ease, transform 0.8s ease;
}

#levelBanner.fade-out {
    opacity: 0.12;
    transform: translateY(-4px);
}

#canvasWrapper:hover #levelBanner {
    opacity: 1;
    transform: translateY(0);
}

#levelTitle {
    font-size: 0.95rem;
    font-weight: 700;
    color: #eaf6ff;
    text-shadow: 0 0 10px rgba(0, 200, 255, 0.8);
    letter-spacing: 0.8px;
}

#levelHint {
    font-size: 0.78rem;
    color: #92d4ee;
    background: rgba(3, 8, 14, 0.78);
    padding: 6px 12px;
    border-radius: 4px;
    border-left: 3px solid #00d5ff;
    max-width: 540px;
    line-height: 1.45;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* ---------------- 移动端虚拟触控按键 ---------------- */
#mobileControls {
    display: none;
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    height: 120px;
    pointer-events: none;
    z-index: 30;
}

@media (pointer: coarse) {
    #mobileControls {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

@media (hover: none) and (max-width: 1024px) {
    #mobileControls {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

#mobileControls.touch-active {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
}

#virtualJoystick {
    width: 105px;
    height: 105px;
    border-radius: 50%;
    background: rgba(6, 18, 30, 0.55);
    border: 2px solid rgba(0, 210, 255, 0.4);
    position: relative;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    box-shadow: 0 0 20px rgba(0, 180, 255, 0.15);
}

#joystickKnob {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(0, 210, 255, 0.75);
    box-shadow: 0 0 14px #00d0ff;
    pointer-events: none;
    transition: transform 0.05s ease-out;
}

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

.btn-touch {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(6, 18, 28, 0.85);
    border: 2px solid rgba(0, 180, 255, 0.5);
    color: #ffffff;
    font-size: 0.72rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.15;
    box-shadow: 0 0 12px rgba(0, 180, 255, 0.25);
    touch-action: none;
    transition: all 0.1s ease;
}

.btn-touch.btn-tap {
    border-color: #00ffcc;
    box-shadow: 0 0 14px rgba(0, 255, 200, 0.35);
}

.btn-touch:active, .btn-touch.active {
    transform: scale(0.92);
    background: #00d5ff;
    color: #000000;
    box-shadow: 0 0 20px #00e5ff;
}

/* ---------------- 模态弹窗系统（玻璃拟态与居中排版） ---------------- */
.modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(2, 4, 7, 0.88);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-card {
    background: linear-gradient(160deg, #09131d 0%, #04080c 100%);
    border: 1px solid rgba(0, 200, 255, 0.4);
    box-shadow: 0 0 45px rgba(0, 170, 240, 0.25);
    border-radius: 12px;
    padding: 24px 28px;
    max-width: 520px;
    width: 95%;
    max-height: 90vh;
    max-height: 88dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    text-align: center;
    animation: modalPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-card h2 {
    font-size: 1.55rem;
    color: #ebf7ff;
    margin-bottom: 4px;
    letter-spacing: 2px;
    text-shadow: 0 0 14px rgba(0, 210, 255, 0.8);
    line-height: 1.2;
}

.modal-card .subtitle {
    font-size: 0.78rem;
    color: #00d0ff;
    font-family: var(--font-mono);
    letter-spacing: 1.5px;
    margin-bottom: 16px;
    opacity: 0.9;
}

.modal-body {
    text-align: left;
    margin-bottom: 20px;
    color: #b0d2e8;
    font-size: 0.84rem;
    line-height: 1.5;
}

.modal-tagline {
    text-align: center;
    margin-bottom: 14px;
    color: #92c5e5;
    font-size: 0.86rem;
    line-height: 1.5;
}

.modal-center {
    text-align: center;
}

.modal-subtext {
    margin-top: 8px;
    color: #72a8c9;
    font-size: 0.8rem;
}

/* 2x2 极简机制卡片网格 */
.mechanic-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 12px 0 16px 0;
}

.mechanic-card {
    background: rgba(0, 24, 42, 0.45);
    border: 1px solid rgba(0, 180, 255, 0.2);
    border-radius: 6px;
    padding: 9px 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.mechanic-card strong {
    color: #00e4ff;
    display: block;
    margin-bottom: 3px;
    font-size: 0.8rem;
    letter-spacing: 0.3px;
}

.mechanic-card p {
    font-size: 0.74rem;
    color: #88bad4;
    line-height: 1.4;
}

.danger-card {
    border-color: rgba(255, 40, 60, 0.35);
    background: rgba(45, 6, 12, 0.45);
}

.danger-card strong {
    color: #ff3858;
}

.danger-card p {
    color: #d18a94;
}

/* 危险与胜利模态定制 */
.modal-danger {
    border-color: rgba(255, 40, 60, 0.55);
    box-shadow: 0 0 50px rgba(255, 30, 50, 0.3);
}

.danger-title {
    color: #ff3355 !important;
    text-shadow: 0 0 15px rgba(255, 30, 60, 0.8) !important;
}

.danger-sub {
    color: #ff7788 !important;
}

.modal-victory {
    border-color: rgba(0, 255, 180, 0.55);
    box-shadow: 0 0 50px rgba(0, 255, 170, 0.3);
}

#victoryTitle {
    color: #00ffaa;
    text-shadow: 0 0 16px rgba(0, 255, 170, 0.85);
}

#victorySubtitle {
    color: #60ffcc;
}

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

/* 动作按钮 */
.btn-primary {
    background: linear-gradient(90deg, #0070a0, #00b0e0);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.92rem;
    padding: 10px 32px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(0, 190, 240, 0.45);
    transition: all 0.2s ease;
    height: auto;
    letter-spacing: 0.5px;
}

.btn-primary:hover {
    transform: scale(1.03);
    box-shadow: 0 0 30px rgba(0, 220, 255, 0.75);
}

.btn-danger {
    background: linear-gradient(90deg, #991122, #ee2244);
    box-shadow: 0 0 20px rgba(255, 30, 60, 0.45);
}

.btn-danger:hover {
    box-shadow: 0 0 30px rgba(255, 30, 60, 0.75);
}

/* ---------------- 底部极简键位指引 ---------------- */
footer {
    width: 100%;
    padding: 9px 18px;
    background: rgba(3, 6, 9, 0.95);
    border-top: 1px solid rgba(0, 180, 255, 0.14);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.75rem;
    color: #5c849e;
    font-family: var(--font-mono);
}

.controls-guide {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    line-height: 1.4;
}

.controls-guide .sep {
    color: #00d5ff;
    opacity: 0.5;
    font-weight: bold;
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 680px) {
    header {
        justify-content: center;
        gap: 8px;
        padding: 8px 12px;
    }
    .hud-telemetry {
        justify-content: center;
        width: 100%;
        gap: 8px;
    }
    .header-actions {
        width: 100%;
        justify-content: center;
    }
    select {
        font-size: 16px; /* 防止 iOS Safari 聚焦输入控件时强制全局缩放页面 */
    }
    .mechanic-grid {
        grid-template-columns: 1fr;
    }
    .controls-guide {
        font-size: 0.7rem;
    }
}

/* 平板设备优化 (iPad / Android Tablet / 768px-1024px) */
@media (min-width: 681px) and (max-width: 1024px) {
    header {
        padding: 8px 16px;
        gap: 10px;
    }
    .telemetry-pill {
        height: 30px;
        font-size: 0.82rem;
    }
    select, button {
        height: 30px;
        font-size: 0.82rem;
    }
    .btn-touch {
        width: 60px;
        height: 60px;
        font-size: 0.75rem;
    }
    #virtualJoystick {
        width: 110px;
        height: 110px;
    }
}

/* 手机超窄屏幕优化 (<= 480px) */
@media (max-width: 480px) {
    #mobileControls {
        bottom: 10px;
        left: 10px;
        right: 10px;
        height: 95px;
    }
    #virtualJoystick {
        width: 86px;
        height: 86px;
    }
    #joystickKnob {
        width: 34px;
        height: 34px;
    }
    .btn-touch {
        width: 46px;
        height: 46px;
        font-size: 0.65rem;
    }
    .action-buttons {
        gap: 6px;
    }
    .logo-area h1 {
        font-size: 1.05rem;
    }
}

/* 移动端横屏极致沉浸视口优化 (屏幕高度 <= 520px 且横屏) */
@media (max-height: 520px) and (orientation: landscape) {
    body {
        padding: 0;
    }
    header {
        padding: 3px 12px;
        gap: 8px;
    }
    .logo-area h1 {
        font-size: 0.95rem;
    }
    .logo-area .en-title {
        display: none;
    }
    .telemetry-pill {
        height: 24px;
        padding: 0 8px;
        font-size: 0.72rem;
    }
    select, button {
        height: 24px;
        font-size: 0.72rem;
        padding: 0 8px;
    }
    #canvasWrapper {
        max-height: calc(100dvh - 58px);
    }
    footer {
        display: none; /* 横屏时隐藏底部按键说明，为画布留出最大的垂直操作视野 */
    }
    #mobileControls {
        bottom: 8px;
        left: 12px;
        right: 12px;
        height: 80px;
    }
    #virtualJoystick {
        width: 78px;
        height: 78px;
    }
    #joystickKnob {
        width: 30px;
        height: 30px;
    }
    .btn-touch {
        width: 42px;
        height: 42px;
        font-size: 0.6rem;
    }
    .modal-card {
        padding: 12px 18px;
        max-height: 92dvh;
    }
    .modal-card h2 {
        font-size: 1.2rem;
        margin-bottom: 2px;
    }
    .modal-card .subtitle {
        margin-bottom: 6px;
    }
    .modal-body {
        margin-bottom: 8px;
    }
    .modal-tagline {
        margin-bottom: 6px;
    }
    .mechanic-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        margin: 6px 0 8px 0;
        gap: 6px;
    }
    .mechanic-card {
        padding: 4px 8px;
    }
    .btn-primary {
        padding: 6px 20px;
        font-size: 0.85rem;
    }
}
