/* ==========================================================================
   STAGE 5: COMM (100% 独立解耦架构 · 分布式系统协同握手)
   上下紧贴10px极佳画幅 · 全局随点随停 · 8阶协议通讯 · 3次沉稳高亮闪烁
   ========================================================================== */

#stage5-viewport {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: none;
    z-index: 100;
    background: transparent;
    opacity: 1;
    container-type: size;
    transition: opacity 2.0s cubic-bezier(0.16, 1, 0.3, 1);
}

#stage5-viewport.active {
    display: block !important;
}

#stage5-viewport.fading-out {
    opacity: 0 !important;
    pointer-events: none;
}

/* ==========================================================================
   [全局随点随停] 暂停时所有动画在当前毫秒原地彻底冻结
   ========================================================================== */

body.engine-paused *,
body.engine-paused *::before,
body.engine-paused *::after,
#app-frame.engine-paused * {
    animation-play-state: paused !important;
}

/* ==========================================================================
   [台阶 1：哲学锚点]
   ========================================================================== */

#s5-anchor-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    z-index: 120;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#s5-anchor-layer.visible {
    opacity: 1;
}

#s5-anchor-text {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 24px;
    font-weight: 500;
    color: #141418;
    letter-spacing: -0.01em;
    text-align: center;
    line-height: 1.4;
}

#s5-anchor-sub {
    font-family: 'SF Mono', Consolas, monospace;
    font-size: clamp(11px, 1.0vw, 12.5px);
    color: rgba(20, 20, 24, 0.48);
    letter-spacing: 0.12em;
    text-align: center;
}

/* ==========================================================================
   [核心舞台：双雄竞技场 最大化自适应排版]
   距上方分割线约 10px，距下方导轨约 10px，自适应所有分辨率
   ========================================================================== */

#s5-arena-layout {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 1560px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    box-sizing: border-box;
    padding: 0 16px;
    z-index: 110;
}

/* 左右工位容器：高度反推宽度公式，保证上下各 10px 且绝不越界 */
.s5-station {
    width: min(calc(48cqw - 45px), calc((100cqh - 176px) * 1.4));
    max-width: 680px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    box-sizing: border-box;
    transition: transform 1.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 1.2s ease;
}

/* 右工位 (章鱼) 率先滑入浮现 */
.s5-station-right {
    transform: translateY(32px);
    opacity: 0;
}

.s5-station-right.entered {
    transform: translateY(0);
    opacity: 1;
}

/* 左工位 (海妖) 自左滑入归位 */
.s5-station-left {
    transform: translateX(-45px);
    opacity: 0;
}

.s5-station-left.entered {
    transform: translateX(0);
    opacity: 1;
}

/* ==========================================================================
   两端 7:5 画幅卡片 (自适应饱满大画幅)
   ========================================================================== */

.s5-card-box {
    width: 100%;
    aspect-ratio: 7 / 5;
    position: relative;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
    background: transparent;
    box-sizing: border-box;
}

#s5-chassis-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
    transition: filter 1.2s ease;
}

#s5-chassis-img.standby-sleep {
    filter: brightness(0.42) contrast(0.92) !important;
}

.s5-octo-viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #141418;
}

#s5-console-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    user-select: none;
    pointer-events: none;
}

/* NODE B 遮罩层：根据新裁切 7:5 原图实测精确锁定至 90.9%，底色严格匹配 #262626 */
.s5-node-b-mask {
    position: absolute;
    left: 90.9%;
    top: 6.6%;
    width: 6.3%;
    height: 6.0%;
    background: #262626;
    border-radius: 2px;
    pointer-events: none;
    z-index: 15;
    transition: opacity 0.3s ease;
    opacity: 1;
}

.s5-node-b-mask.unmasked {
    opacity: 0;
}

/* NODE B 注册成功时：向外扩散 3 次的强力脉冲同心光环 */
.s5-node-b-ping {
    position: absolute;
    left: 94.1%;
    top: 8.7%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    z-index: 20;
    display: none;
}

.s5-node-b-ping.active {
    display: block;
}

.ping-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid #00AEEF;
    opacity: 0;
}

.s5-node-b-ping.active .r1 {
    animation: nodeBPing 1.8s 0.0s cubic-bezier(0.2, 0.8, 0.3, 1) 3 forwards;
}

.s5-node-b-ping.active .r2 {
    animation: nodeBPing 1.8s 0.2s cubic-bezier(0.2, 0.8, 0.3, 1) 3 forwards;
}

.s5-node-b-ping.active .r3 {
    animation: nodeBPing 1.8s 0.4s cubic-bezier(0.2, 0.8, 0.3, 1) 3 forwards;
}

@keyframes nodeBPing {
    0% { transform: scale(0.6); opacity: 1; border-color: #FFFFFF; }
    50% { opacity: 0.95; border-color: #00AEEF; }
    100% { transform: scale(4.4); opacity: 0; border-color: #00AEEF; }
}

/* ==========================================================================
   顶置独立工控通信 HUD：5行可见窗口 (105px) + 向上平滑滚动
   米白底色 + 浅灰线框 + 13px 纯黑等宽大字号 (永不缩小)
   ========================================================================== */

.s5-terminal-box {
    width: 100%;
    height: 148px;
    background: rgba(244, 244, 240, 0.98);
    border: 1px solid rgba(20, 20, 24, 0.18);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    padding: 8px 14px;
    margin-bottom: 10px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.9s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.4s ease, box-shadow 0.4s ease, background-color 0.4s ease;
    display: flex;
    flex-direction: column;
}

.s5-terminal-box.visible {
    opacity: 1;
}

/* 握手圆满达成时：两端终端同时沉稳高亮闪烁 3 次 (放慢至 0.95s/次) */
.s5-terminal-box.handshake-success {
    animation: pairedSuccessBlink 0.95s ease-in-out 3;
}

@keyframes pairedSuccessBlink {
    0%, 100% {
        border-color: rgba(20, 20, 24, 0.18);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
        background: rgba(244, 244, 240, 0.98);
    }
    50% {
        border-color: #00AEEF;
        box-shadow: 0 0 24px rgba(0, 174, 239, 0.5), inset 0 0 12px rgba(0, 174, 239, 0.12);
        background: #FFFFFF;
    }
}

.s5-term-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(20, 20, 24, 0.1);
    padding-bottom: 4px;
    margin-bottom: 5px;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}

.s5-term-title { color: #141418; }
.s5-term-title.octo { color: #00AEEF; }

.s5-term-badge {
    font-size: 9.5px;
    padding: 2px 7px;
    border: 1px solid rgba(20, 20, 24, 0.25);
    color: #141418;
    letter-spacing: 0.05em;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.s5-term-badge.bound {
    border-color: #00AEEF;
    color: #00AEEF;
    background: rgba(0, 174, 239, 0.08);
    font-weight: 700;
}

/* 5行视口屏幕：固定高度 105px (5 * 21px)，overflow: hidden 裁切多余行 */
.s5-term-screen {
    height: 105px;
    overflow: hidden;
    position: relative;
    font-family: 'SF Mono', Consolas, monospace;
    font-size: 13px;
    line-height: 21px;
    text-align: left;
    box-sizing: border-box;
}

/* 向上平滑跳动的流容器 */
.s5-screen-stream {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    transform: translateY(0);
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.s5-screen-row {
    color: #141418;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 21px;
    line-height: 21px;
    font-weight: 500;
}

/* ==========================================================================
   中央水平雷达声纳走廊 (精准锚定在两对话窗屏幕正中间)
   ========================================================================== */

.s5-radio-corridor {
    width: 76px;
    align-self: flex-start;
    margin-top: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.s5-radio-corridor.active {
    opacity: 1;
}

.s5-sonar-svg {
    width: 76px;
    height: 48px;
    overflow: visible;
}

.s5-pulse-arc {
    fill: none;
    stroke: #141418;
    stroke-width: 2.2px;
    stroke-linecap: round;
    opacity: 0;
}

.s5-carrier-dot {
    fill: #141418;
    opacity: 0;
}

/* 向右定向发射脉冲 (Siren -> Octo) */
.s5-corridor-firing-right .arc-r1 {
    animation: sonarPingRight 0.8s 0.0s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-right .arc-r2 {
    animation: sonarPingRight 0.8s 0.14s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-right .arc-r3 {
    animation: sonarPingRight 0.8s 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-right .dot-r {
    animation: carrierFlyRight 0.8s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}

@keyframes sonarPingRight {
    0% { opacity: 0; transform: translateX(-12px); }
    30% { opacity: 0.95; }
    100% { opacity: 0; transform: translateX(24px); }
}

@keyframes carrierFlyRight {
    0% { opacity: 0; transform: translateX(0); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateX(52px); }
}

/* 向左定向发射脉冲 (Octo -> Siren) */
.s5-corridor-firing-left .arc-l1 {
    animation: sonarPingLeft 0.8s 0.0s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-left .arc-l2 {
    animation: sonarPingLeft 0.8s 0.14s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-left .arc-l3 {
    animation: sonarPingLeft 0.8s 0.28s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}
.s5-corridor-firing-left .dot-l {
    animation: carrierFlyLeft 0.8s cubic-bezier(0.2, 0.8, 0.3, 1) infinite;
}

@keyframes sonarPingLeft {
    0% { opacity: 0; transform: translateX(12px); }
    30% { opacity: 0.95; }
    100% { opacity: 0; transform: translateX(-24px); }
}

@keyframes carrierFlyLeft {
    0% { opacity: 0; transform: translateX(0); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateX(-52px); }
}