* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.tree-container {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    position: relative;
    padding: 20px;
    height: 600px;
    background-color: #f9f9f9;
    border: 2px solid black;
}

@media screen and (max-width: 640px) {
    .tree-container {
        height: 400px;
    }
    
    .zoom-controls {
        top: 10px;
        bottom: auto !important;
    }
}

.grid-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(to right, rgba(200, 200, 200, 0.2) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(200, 200, 200, 0.2) 1px, transparent 1px);
    background-size: 50px 50px;
    z-index: 0;
    pointer-events: none;
}

.draggable-area {
    position: absolute;
    min-width: 4000px;
    min-height: 800px;
    cursor: grab;
    z-index: 1;
}

.draggable-area:active {
    cursor: grabbing;
}

.tree {
    min-width: 3800px;
    display: inline-block;
    padding: 20px;
}

.tree ul {
    padding-top: 20px; 
    position: relative;
    display: flex;
    justify-content: center;
    flex-wrap: nowrap;
    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}

.tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    list-style-type: none;
    position: relative;
    padding: 20px 5px 0 5px;
    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}

.tree li::before, .tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    border-top: 1px solid #ccc;
    width: 50%;
    height: 20px;
}

.tree li::after {
    right: auto;
    left: 50%;
    border-left: 1px solid #ccc;
}

.tree li:only-child::after, .tree li:only-child::before {
    display: none;
}

.tree li:only-child {
    padding-top: 0;
}

.tree li:first-child::before, .tree li:last-child::after {
    border: 0 none;
}

.tree li:last-child::before {
    border-right: 1px solid #ccc;
    border-radius: 0 5px 0 0;
    -webkit-border-radius: 0 5px 0 0;
    -moz-border-radius: 0 5px 0 0;
}

.tree li:first-child::after {
    border-radius: 5px 0 0 0;
    -webkit-border-radius: 5px 0 0 0;
    -moz-border-radius: 5px 0 0 0;
}

.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 1px solid #ccc;
    width: 0;
    height: 20px;
}

.tree li a {
    border: 1px solid #ccc;
    padding: 5px 10px;
    text-decoration: none;
    color: #666;
    font-size: 14px;
    display: inline-block;
    white-space: nowrap;
    background-color: white;
    
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    
    transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -moz-transition: all 0.5s;
}

.spouse {
    font-size: 12px;
    color: #666;
    display: block;
}

.divorced {
    font-size: 10px;
    color: #c44;
    display: block;
}

.dates {
    font-size: 12px;
    color: #888;
    display: block;
}

.toggle-btn {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: #ff0000;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 20px;
    text-align: center;
    margin-top: 5px;
    font-weight: bold;
}

.toggle-btn.collapsed {
    background: #4e6d43;
}

.tree li.collapsed > ul {
    display: none;
}

.tree li a:hover, .tree li a:hover+ul li a {
    background: #e8f4d9;
    color: #000;
    border: 1px solid #94a0b4;
}

.tree li a:hover+ul li::after, 
.tree li a:hover+ul li::before, 
.tree li a:hover+ul::before, 
.tree li a:hover+ul ul::before {
    border-color: #94a0b4;
}

.tree li a:hover ~ .toggle-btn ~ ul li a {
    background: #e8f4d9;
    color: #000;
    border: 1px solid #94a0b4;
}

.tree li a:hover ~ .toggle-btn ~ ul li::after,
.tree li a:hover ~ .toggle-btn ~ ul li::before,
.tree li a:hover ~ .toggle-btn ~ ul::before,
.tree li a:hover ~ .toggle-btn ~ ul ul::before {
    border-color: #94a0b4;
}

.zoom-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: white;
    padding: 5px;
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    z-index: 2;
    display: flex;
    align-items: center;
}

.zoom-controls button {
    width: 30px;
    height: 30px;
    margin: 0 2px;
    cursor: pointer;
    font-size: 16px;
    border: 1px solid #ccc;
    background: white;
    border-radius: 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.zoom-controls button:hover {
    background: #f0f0f0;
}

.tree > ul > li > ul {
    flex-wrap: nowrap;
    justify-content: flex-start;
}

.tree > ul > li > ul > li {
    padding: 20px 2px 0 2px;
}