/* ========== 容器样式 ========== */
.gradient-container {
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;

    /* 深色渐变背景 */
    background: linear-gradient(135deg,
            var(--secondary-dark) 0%,
            var(--primary-dark) 50%,
            var(--primary-medium) 100%);

    /* 添加一些视觉效果 */
    box-shadow:
        0 20px 60px rgba(81, 56, 90, 0.4),
        0 10px 30px rgba(81, 56, 90, 0.3);

    /* 使用容器查询以支持自动缩放 */
    container-type: size;
}


/* ========== 动画演示页面样式 ========== */
.animation-demo-section {
    width: 100%;
    height: calc(100vh - 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.animation-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 60px;
    position: relative;
    pointer-events: auto;

    /* 基准尺寸 - 实际内容宽度（包括所有元素和间距） */
    width: 900px;
    height: 450px;

    /* 使用 scale 自适应容器大小 */
    transform-origin: center center;
    transform: scale(var(--scale-factor, 1));

    /* 使用容器查询单位自动计算缩放比例 */
    --container-width: 100cqw;
    --container-height: 100cqh;
    --base-width: 900;
    --base-height: 450;
    --container-padding: 80;

    /* 计算缩放因子（取宽高中较小的比例），确保内容不超出 */
    --scale-x: calc((var(--container-width) - var(--container-padding)) / var(--base-width));
    --scale-y: calc((var(--container-height) - var(--container-padding)) / var(--base-height));
    --scale-factor: clamp(0.3, min(var(--scale-x), var(--scale-y)), 1.5);
}

/* 如果浏览器不支持容器查询，使用媒体查询作为后备 */
@supports not (width: 1cqw) {
    .animation-container {
        transform: scale(1.2);
    }

    @media (max-width: 1400px) {
        .animation-container {
            transform: scale(1.1);
        }
    }

    @media (max-width: 1200px) {
        .animation-container {
            transform: scale(1);
        }
    }

    @media (max-width: 900px) {
        .animation-container {
            transform: scale(0.85);
        }
    }

    @media (max-width: 768px) {
        .animation-container {
            transform: scale(0.7);
        }
    }
}

/* 培养皿容器，从540x360缩小到420x280（约0.78倍） */
.petri-container {
    position: relative;
    width: 420px;
    height: 280px;
    flex-shrink: 0;
}

/* 培养皿背景 */
.petri-dish {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/petri-dish.webp');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    z-index: 0;
    scale: 1.2;
}

/* 节点区域，按比例缩小 */
.demo-area {
    display: grid;
    grid-template-columns: repeat(3, 39px);
    /* 从50px缩小到39px（50*0.78） */
    grid-template-rows: repeat(4, 39px);
    gap: 16px;
    /* 从20px缩小到16px（20*0.78） */
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 149px;
    /* 从190px缩小到149px（190*0.78） */
    height: 203px;
    /* 从260px缩小到203px（260*0.78） */
    margin-top: -15px;
}

/* 节点大小按比例缩小 */
.node {
    width: 31px;
    /* 从40px缩小到31px（40*0.78） */
    height: 31px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease;
    position: relative;
    overflow: visible;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: brightness(0.9);
}

.node-1-2 {
    margin-top: -20px;
    margin-left: 15px;
}

.node-1-3 {
    margin-top: -20px;
    margin-left: 15px;
}

.node-2-4 {
    margin-top: -20px;
}

/* 输入节点图片 */
.input-node.node-a {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/an.webp');
}

.input-node.node-b {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/bn.webp');
}

.input-node.node-c {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/cn.webp');
}

.input-node.node-d {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/dn.webp');
}

/* 输出节点图片 */
.output-node.node-alpha {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/alphan.webp');
}

.output-node.node-beta {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/betan.webp');
}

.output-node.node-gamma {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/gamman.webp');
}

/* 处理器节点图片 */
.processor-node.node-half {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/half-addern.webp');
}

.processor-node.node-amp {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/amplifiern.webp');
}

.processor-node.node-full {
    background-image: url('https://static.igem.wiki/teams/5646/images/section3/full-addern.webp');
}

/* 激活状态 */
.input-node.active {
    filter: brightness(1.3);
    transform: scale(1.1);
}

.output-node.active {
    filter: brightness(1.3);
    transform: scale(1.1);
}

.processor-node.active {
    filter: brightness(1.3);
    transform: scale(1.1);
}

/* 零值描边效果 */
.input-node.zero-outline {
    border: 3px dashed rgba(76, 175, 80, 0.7);
    border-radius: 8px;
    animation: dash-pulse 2s ease-in-out infinite;
}

.output-node.zero-outline {
    border: 3px dashed rgba(255, 82, 82, 0.7);
    border-radius: 8px;
    animation: dash-pulse 2s ease-in-out infinite;
}

@keyframes dash-pulse {

    0%,
    100% {
        border-color: rgba(76, 175, 80, 0.7);
        transform: scale(1);
    }

    50% {
        border-color: rgba(76, 175, 80, 1);
        transform: scale(1.02);
    }
}

/* 涟漪效果，按比例调整 */
.processor-node .ripple:nth-child(1) {
    border: 3px solid #2196f3;
    animation: ripple-expand 1.5s ease-out infinite;
}

.processor-node .ripple:nth-child(2) {
    border: 3px solid #03a9f4;
    animation: ripple-expand 1.5s ease-out 0.2s infinite;
}

.processor-node .ripple:nth-child(3) {
    border: 3px solid #00bcd4;
    animation: ripple-expand 1.5s ease-out 0.4s infinite;
}

.input-node .ripple:nth-child(1) {
    border: 3px solid #4caf50;
    animation: ripple-expand 1.5s ease-out infinite;
}

.input-node .ripple:nth-child(2) {
    border: 3px solid #66bb6a;
    animation: ripple-expand 1.5s ease-out 0.2s infinite;
}

.input-node .ripple:nth-child(3) {
    border: 3px solid #81c784;
    animation: ripple-expand 1.5s ease-out 0.4s infinite;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    z-index: 10;
}

/* 涟漪动画，按比例缩小 */
@keyframes ripple-expand {
    0% {
        width: 31px;
        /* 从40px缩小到31px */
        height: 31px;
        top: 0;
        left: 0;
        opacity: 0.8;
        transform: scale(1);
        border-width: 3px;
    }

    50% {
        opacity: 0.4;
        border-width: 2px;
    }

    100% {
        width: 125px;
        /* 从160px缩小到125px（160*0.78） */
        height: 125px;
        top: -47px;
        /* 从-60px调整到-47px（60*0.78） */
        left: -47px;
        opacity: 0;
        transform: scale(1);
        border-width: 1px;
    }
}

/* 说明文字区域 */
.result-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    font-size: 24px;
    width: 320px;
    height: 350px;
    justify-content: space-between;
    flex-shrink: 0;
}

.binary-display {
    padding: 35px 40px;
    border-radius: 10px;
    border: 2px solid #666;
    color: #ffffff;
    text-align: right;
    line-height: 2;
    width: 100%;
    height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    font-size: 26px;
}

.step-indicator {
    font-family: var(--font-sans);
    font-size: 16px;
    color: #e0e0e0;
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
    width: 100%;
    height: auto;
    word-wrap: break-word;
    line-height: 1.6;
    overflow-y: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 300;
    padding: 0 10px;
}

.binary-display .highlight {
    color: #a5d6a7;
    animation: pulse 0.5s ease-in-out;
    font-weight: bold;
    background-color: transparent !important;
}

.placeholder {
    background-color: transparent;
    font-size: 18px;
}

.input-highlight {
    color: #a5d6a7;
    animation: pulse 0.5s ease-in-out;
    font-weight: bold;
}

.output-highlight {
    color: #ff8a80;
    animation: pulse 0.5s ease-in-out;
    font-weight: bold;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* ========== 图注区域样式 ========== */
.legend-area {
    display: flex;
    gap: 18px;
    font-size: 12px;
    color: #e0e0e0;
    flex-shrink: 0;
    width: 280px;
}

.legend-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.legend-column h3 {
    font-size: 14px;
    font-weight: bold;
    color: #ffffff;
    margin: 0 0 8px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid #555;
    text-align: center;
    white-space: nowrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}

.legend-item img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0.9);
    flex-shrink: 0;
}

.legend-item span {
    font-size: 11px;
    color: #e0e0e0;
    white-space: nowrap;
    line-height: 1.3;
}

/* 网格位置定位 */
.node-1-1 {
    grid-column: 1;
    grid-row: 1;
}

.node-3-1 {
    grid-column: 3;
    grid-row: 1;
}

.node-2-1 {
    grid-column: 2;
    grid-row: 1;
}

.node-1-2 {
    grid-column: 1;
    grid-row: 2;
}

.node-2-2 {
    grid-column: 2;
    grid-row: 2;
}

.node-1-3 {
    grid-column: 1;
    grid-row: 4;
}

.node-2-3 {
    grid-column: 2;
    grid-row: 3;
}

.node-3-3 {
    grid-column: 3;
    grid-row: 3;
}

.node-1-4 {
    grid-column: 1;
    grid-row: 3;
}

.node-2-4 {
    grid-column: 2;
    grid-row: 5;
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .animation-container {
        gap: 40px;
    }

    .result-area {
        width: 280px;
        height: 320px;
    }

    .petri-container {
        width: 380px;
        height: 253px;
    }

    /* 按比例调整节点区域 */
    .demo-area {
        grid-template-columns: repeat(3, 35px);
        grid-template-rows: repeat(4, 35px);
        gap: 14px;
        width: 135px;
        height: 183px;
    }

    .node {
        width: 28px;
        height: 28px;
    }

    .legend-area {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .animation-container {
        flex-direction: column;
        gap: 30px;
        height: auto;
    }

    .petri-container {
        width: 360px;
        height: 240px;
    }

    /* 按比例调整节点区域 */
    .demo-area {
        grid-template-columns: repeat(3, 33px);
        grid-template-rows: repeat(4, 33px);
        gap: 13px;
        width: 127px;
        height: 173px;
    }

    .node {
        width: 27px;
        height: 27px;
    }

    .result-area {
        width: 300px;
        height: 280px;
    }

    .legend-area {
        flex-direction: row;
        gap: 15px;
        width: 100%;
        max-width: 360px;
    }

    .binary-display {
        font-size: 22px;
        padding: 25px 30px;
    }
}