/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    width: 320px;
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

h1 {
    text-align: center;
    font-size: 20px;
    color: #333;
    padding: 20px 0;
    background-color: #fafafa;
    border-bottom: 1px solid #e0e0e0;
}

.display {
    padding: 20px;
    background-color: #f8f8f8;
    text-align: center;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin-bottom: 0;
}

.input {
    font-size: 24px;
    font-weight: 500;
    color: #333;
    margin-bottom: 10px;
    line-height: 1.4;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result {
    font-size: 32px;
    font-weight: 600;
    color: #ff6b6b;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.buttons {
    padding: 10px 20px 0;
}

.row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 8px;
}

.btn {
    width: 100%;
    height: 50px;
    border: none;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
    color: #333;
    background-color: #f0f0f0;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.btn:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-del {
    background-color: #ffcc00;
    color: #333;
}

.btn-del:hover {
    background-color: #ffb800;
}

.btn-ac {
    background-color: #ff6b6b;
    color: white;
}

.btn-ac:hover {
    background-color: #ff5252;
}

.btn-equal {
    background-color: #4caf50;
    color: white;
    grid-column: span 2;
    font-size: 24px;
}

.btn-equal:hover {
    background-color: #45a049;
}

.btn-special {
    background-color: #4ecdc4;
    color: white;
}

#relationChart {
    grid-column: 1 / 3;
}

#reverseCheck {
    grid-column: 3 / 5;
}

.btn-special:hover {
    background-color: #45b7aa;
}

/* 性别选择样式 */
.gender-selection {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    justify-items: center;
}

.gender-label {
    font-size: 18px;
    color: #666;
    grid-column: 1 / 3;
    text-align: center;
    padding-right: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 20px;
}

.gender-btn {
    background-color: #f0f0f0;
    color: #333;
    font-size: 18px;
    padding: 8px 16px;
    margin: 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 50px;
    width: 100%;
}

.gender-selection .gender-btn:nth-child(2) {
    grid-column: 3;
}

.gender-selection .gender-btn:nth-child(3) {
    grid-column: 4;
}

.gender-btn:hover {
    background-color: #e0e0e0;
}

.gender-btn.active {
    background-color: #4ecdc4;
    color: white;
    border-color: #4ecdc4;
}

@media (max-width: 400px) {
    .container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    
    .display {
        padding: 40px 20px;
        flex: 1;
    }
    
    .input {
        font-size: 22px;
    }
    
    .result {
        font-size: 28px;
    }
    
    .buttons {
        padding: 20px 20px 0;
    }
    
    .btn {
        height: 60px;
        font-size: 20px;
    }
}

/* 关系图样式 */
.relation-chart-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    overflow-y: auto;
}

.relation-chart-container.show {
    display: flex;
}

.relation-chart {
    background-color: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 1400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    text-align: center;
    position: relative;
}

.relation-chart h3 {
    font-size: 24px;
    color: #333;
    margin-bottom: 30px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

/* 家族树样式 - 思维导图样式 */
.family-tree {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 60px;
    padding: 30px 0 0 0;
    overflow-x: auto;
    margin: 0;
    width: 100%;
    min-height: 500px;
}

/* 层级样式 - 使用Grid布局确保对齐 */
.tree-level {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    position: relative;
    min-height: 100px;
    width: 100%;
    margin: 0;
    max-width: 1200px;
    margin: 0 auto;
}

/* 确保所有层级的分支数量一致，以便水平对齐 */
.level-1, .level-2, .level-4, .level-5 {
    grid-template-columns: repeat(7, 1fr);
}

/* 调整各个层级的分支数量和对齐 */
.level-1 {
    min-height: 40px;
}

.level-4 {
    min-height: 50px;
}

.level-5 {
    min-height: 50px;
}

/* 节点样式 */
.tree-node {
    background-color: white;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 8px 12px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    position: relative;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    min-width: 100px;
    text-align: center;
    z-index: 3;
    margin: 0;
    line-height: 1.4;
    white-space: pre-line;
}

/* 中心节点 */
.tree-node.center {
    background-color: #f0f0f0;
    font-weight: 600;
}

/* 自己节点 */
.tree-node.main {
    background-color: #4caf50;
    color: white;
    border-color: #388e3c;
    font-weight: 600;
    transform: scale(1.1);
    min-width: 140px;
}

/* 分支样式 */
.tree-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: 120px;
    z-index: 2;
}

/* SVG连接线样式 */
.connection-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* 分支样式 - 确保对齐 */
.tree-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    min-width: 120px;
    z-index: 2;
    grid-column: span 1;
}

/* 特定分支的网格列定位，确保对齐 */
/* 祖辈层级 - 祖父祖母和外祖父外祖母 */
.level-1 .tree-branch:nth-child(2) {
    grid-column: 2;
}

.level-1 .tree-branch:nth-child(6) {
    grid-column: 6;
}

/* 父辈层级 - 确保与子辈对齐 */
.level-2 .tree-branch:nth-child(1) {
    grid-column: 1;
}

.level-2 .tree-branch:nth-child(2) {
    grid-column: 2;
}

.level-2 .tree-branch:nth-child(3) {
    grid-column: 4;
}

.level-2 .tree-branch:nth-child(4) {
    grid-column: 6;
}

.level-2 .tree-branch:nth-child(5) {
    grid-column: 7;
}

/* 同辈层级 - 确保与父辈和子辈对齐 */
.level-3 .tree-branch:nth-child(1) {
    grid-column: 1;
}

.level-3 .tree-branch:nth-child(2) {
    grid-column: 2;
}

.level-3 .tree-branch:nth-child(3) {
    grid-column: 3;
}

.level-3 .tree-branch:nth-child(4) {
    grid-column: 4;
}

.level-3 .tree-branch:nth-child(5) {
    grid-column: 5;
}

.level-3 .tree-branch:nth-child(6) {
    grid-column: 6;
}

.level-3 .tree-branch:nth-child(7) {
    grid-column: 7;
}

/* 子辈层级 */
.level-4 .tree-branch:nth-child(1) {
    grid-column: 1;
}

.level-4 .tree-branch:nth-child(2) {
    grid-column: 1;
}

.level-4 .tree-branch:nth-child(3) {
    grid-column: 2;
}

.level-4 .tree-branch:nth-child(4) {
    grid-column: 3;
}

.level-4 .tree-branch:nth-child(5) {
    grid-column: 4;
}

.level-4 .tree-branch:nth-child(6) {
    grid-column: 5;
}

.level-4 .tree-branch:nth-child(7) {
    grid-column: 7;
}

/* 孙辈层级 */
.level-5 .tree-branch:nth-child(1) {
    grid-column: 1;
}

.level-5 .tree-branch:nth-child(2) {
    grid-column: 1;
}

.level-5 .tree-branch:nth-child(3) {
    grid-column: 2;
}

.level-5 .tree-branch:nth-child(4) {
    grid-column: 3;
}

.level-5 .tree-branch:nth-child(5) {
    grid-column: 4;
}

.level-5 .tree-branch:nth-child(6) {
    grid-column: 6;
}

.level-5 .tree-branch:nth-child(7) {
    grid-column: 7;
}

/* 确保节点和分支有相对定位 */
.tree-level,
.tree-branch,
.tree-node {
    position: relative;
}

/* 祖父祖母节点向下移动 */
#gp1 {
    transform: translateY(-20px);
}

/* 外祖父外祖母节点单独往上移 */
#gp2 {
    transform: translateY(-20px);
}

/* 子辈节点整体往右移半列 */
.level-4 .tree-branch:nth-child(3),
.level-4 .tree-branch:nth-child(4),
.level-4 .tree-branch:nth-child(5),
.level-4 .tree-branch:nth-child(6) {
    transform: translateX(50%);
}

/* 孙辈节点同步往右移半列，与子辈保持对齐 */
.level-5 .tree-branch:nth-child(4),
.level-5 .tree-branch:nth-child(5) {
    transform: translateX(50%);
}

/* 关闭按钮 */
.btn-close {
    margin-top: 20px;
    background-color: #ff6b6b;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-close:hover {
    background-color: #ff5252;
    transform: translateY(-1px);
}

.btn-close:active {
    transform: translateY(0);
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .tree-level {
        gap: 15px;
    }
    
    .tree-node {
        min-width: 100px;
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .tree-node.main {
        min-width: 120px;
    }
}

@media (max-width: 992px) {
    .tree-level {
        gap: 10px;
    }
    
    .tree-node {
        min-width: 80px;
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .tree-node.main {
        min-width: 100px;
        transform: scale(1.05);
    }
}

@media (max-width: 768px) {
    .relation-chart {
        margin: 10px;
        padding: 20px;
        border-radius: 8px;
    }
    
    .family-tree {
        gap: 30px;
    }
    
    .tree-level {
        gap: 8px;
    }
    
    .tree-node {
        min-width: 70px;
        padding: 5px 8px;
        font-size: 11px;
        margin-bottom: 30px;
    }
    
    .tree-node.main {
        min-width: 90px;
    }
    
    .tree-branch::before {
        bottom: 30px;
    }
    
    .level-1 .tree-branch::before,
    .level-2 .tree-branch::before,
    .level-3 .tree-branch::before,
    .level-4 .tree-branch::before {
        height: 30px;
    }
}

@media (max-width: 480px) {
    .relation-chart {
        padding: 15px;
    }
    
    .tree-level {
        gap: 5px;
    }
    
    .tree-node {
        min-width: 60px;
        padding: 4px 6px;
        font-size: 10px;
        margin-bottom: 20px;
    }
    
    .tree-node.main {
        min-width: 80px;
    }
    
    .family-tree {
        gap: 20px;
    }
    
    .tree-branch::before {
        bottom: 20px;
        height: 20px;
    }
    
    .level-1 .tree-branch::before,
    .level-2 .tree-branch::before,
    .level-3 .tree-branch::before,
    .level-4 .tree-branch::before {
        height: 20px;
    }
}

/* 页脚样式 */
.footer {
    text-align: center;
    padding: 15px 20px;
    background-color: #fafafa;
    border-top: 1px solid #e0e0e0;
    margin-top: 0;
}

.footer a {
    font-size: 16px;
    font-weight: 500;
    color: #666;
    text-decoration: none;
    transition: all 0.2s ease;
}

.footer a:hover {
    color: #333;
    text-decoration: none;
}