:root {
    --root-color: #e74c3c;
    --ancestor-color: #e67e22;
    --branch-color: #27ae60;
    --current-gen-color: #3498db;
    --highlight-color: #9b59b6;
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --text-light: #ffffff;
    --text-muted: #a0a0a0;
    --line-color: #4a5568;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Vazirmatn', sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #0f0f23 100%);
    min-height: 100vh;
    color: var(--text-light);
    overflow-x: hidden;
}

.container {
    max-width: 100%;
    padding: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

header {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(180deg, rgba(231, 76, 60, 0.2) 0%, transparent 100%);
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--root-color);
    text-shadow: 0 0 30px rgba(231, 76, 60, 0.5);
    margin-bottom: 10px;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    margin-bottom: 40px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.tree-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    width: 100%;
}

.generation {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 10px;
    position: relative;
}

.gen-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.1);
    padding: 3px 12px;
    border-radius: 10px;
}

.members {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    position: relative;
}

.person {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.person-node {
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: 600;
    font-size: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 2;
    min-width: 80px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.person-node:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

.person-node.root {
    background: linear-gradient(135deg, var(--root-color), #c0392b);
    font-size: 1.2rem;
    padding: 15px 30px;
}

.person-node.ancestor {
    background: linear-gradient(135deg, var(--ancestor-color), #d35400);
}

.person-node.branch {
    background: linear-gradient(135deg, var(--branch-color), #1e8449);
}

.person-node.current {
    background: linear-gradient(135deg, var(--current-gen-color), #2980b9);
}

.person-node.highlight {
    background: linear-gradient(135deg, var(--highlight-color), #8e44ad);
    animation: pulse 2s infinite;
}

.person-node.you {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    animation: glow 2s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(155, 89, 182, 0.4); }
    50% { box-shadow: 0 4px 30px rgba(155, 89, 182, 0.8); }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 4px 30px rgba(231, 76, 60, 0.8); }
}

.connector {
    position: relative;
    width: 2px;
    height: 30px;
    background: var(--line-color);
    margin: 0 auto;
}

.connector::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: var(--line-color);
    border-radius: 50%;
}

/* Family branch styling */
.family-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    margin: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.branch-title {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 15px;
    padding: 5px 15px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.children-container {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    position: relative;
    padding-top: 20px;
}

.children-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: var(--line-color);
}

.child-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.child-connector {
    width: 2px;
    height: 20px;
    background: var(--line-color);
}

/* Horizontal tree section */
.horizontal-section {
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-wrap: wrap;
    margin-top: 30px;
}

.sub-tree {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 20px;
    padding: 25px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    min-width: 200px;
}

.sub-tree-title {
    text-align: center;
    margin-bottom: 20px;
}

.grandchildren {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.grandchild-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 15px;
}

.great-grandchildren {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 15px;
}

/* Tooltip */
.tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.person-node:hover + .tooltip,
.person-node:hover .tooltip {
    opacity: 1;
    visibility: visible;
}

/* Footer */
footer {
    text-align: center;
    padding: 40px 20px;
    margin-top: 60px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

footer p {
    margin-bottom: 10px;
}

.family-crest {
    font-size: 3rem;
    margin-bottom: 20px;
}

/* Responsive - Tablet */
@media (max-width: 900px) {
    .gen-box {
        max-width: 100%;
    }

    .gen-box-groups {
        flex-wrap: wrap;
    }

    .gen-box-members {
        flex-wrap: wrap;
    }

    .horizontal-section {
        flex-direction: column;
        align-items: center;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    header {
        padding: 25px 15px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    header p {
        font-size: 0.95rem;
    }

    .family-crest {
        font-size: 2.5rem;
    }

    .container {
        padding: 10px;
    }

    .legend {
        gap: 12px;
        padding: 15px;
        margin-bottom: 25px;
    }

    .main-lineage {
        padding: 15px 10px;
        border-radius: 20px;
        margin-bottom: 25px;
    }

    .person-node {
        padding: 8px 14px;
        font-size: 0.85rem;
        min-width: 60px;
    }

    .person-node.root {
        font-size: 1rem;
        padding: 10px 20px;
    }

    /* Gen-box: stack label on top instead of side */
    .gen-box {
        flex-direction: column;
        max-width: 100%;
    }

    .gen-box-label {
        writing-mode: horizontal-tb;
        text-orientation: initial;
        border-radius: 12px 12px 0 0;
        padding: 8px 15px;
        min-width: unset;
        width: 100%;
        text-align: center;
    }

    .gen-box-content {
        border-radius: 0 0 15px 15px;
        border-right: 1px solid rgba(255, 255, 255, 0.12);
        border-top: none;
        padding: 15px 10px;
    }

    .gen-box-groups {
        flex-direction: column;
        flex-wrap: wrap;
        gap: 10px;
        align-items: stretch;
    }

    .gen-box-members {
        flex-wrap: wrap;
        gap: 8px;
    }

    .gen-inner-box {
        padding: 10px 12px;
        min-width: unset;
    }

    .connector {
        height: 20px;
    }

    .members {
        gap: 10px;
    }

    .generation {
        margin-bottom: 5px;
    }

    footer {
        padding: 25px 15px;
        margin-top: 30px;
    }

    footer p {
        font-size: 0.85rem;
    }
}

/* Responsive - Small phones */
@media (max-width: 400px) {
    header h1 {
        font-size: 1.4rem;
    }

    header p {
        font-size: 0.85rem;
    }

    .legend {
        gap: 8px;
        padding: 10px;
        flex-direction: column;
        align-items: center;
    }

    .person-node {
        padding: 6px 10px;
        font-size: 0.75rem;
        min-width: 50px;
        border-radius: 18px;
    }

    .person-node.root {
        font-size: 0.9rem;
        padding: 8px 16px;
    }

    .main-lineage {
        padding: 10px 6px;
    }

    .gen-box-content {
        padding: 10px 6px;
    }

    .gen-inner-box {
        padding: 8px 6px;
    }

    .gen-box-members {
        gap: 6px;
    }

    .gen-label {
        font-size: 0.65rem;
        padding: 2px 8px;
    }

    .gen-inner-title {
        font-size: 0.6rem;
    }

    .gen-box-title {
        font-size: 0.7rem;
    }
}

/* Special styling for main lineage */
.main-lineage {
    background: linear-gradient(180deg, rgba(231, 76, 60, 0.1) 0%, rgba(39, 174, 96, 0.1) 50%, rgba(52, 152, 219, 0.1) 100%);
    padding: 30px;
    border-radius: 30px;
    margin-bottom: 40px;
}

.section-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin: 40px 0;
    color: var(--text-muted);
}

.section-divider::before,
.section-divider::after {
    content: '';
    flex: 1;
    max-width: 200px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line-color), transparent);
}

.scroll-hint {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    z-index: 1000;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-10px); }
}

/* Generation Box Layout */
.gen-box {
    display: flex;
    align-items: stretch;
    gap: 0;
    width: 100%;
    max-width: 900px;
}

.gen-box-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    padding: 15px 8px;
    border-radius: 12px 0 0 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 35px;
    letter-spacing: 1px;
}

.gen-box-content {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-right: none;
    border-radius: 0 15px 15px 0;
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.gen-box-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 5px;
}

.gen-box-members {
    display: flex;
    gap: 12px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}

.gen-box-groups {
    display: flex;
    gap: 15px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: stretch;
    width: 100%;
}

/* Inner box for grouping children of a specific father */
.gen-inner-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 15px 20px;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    min-width: 120px;
}

.gen-inner-box--highlight {
    border-color: rgba(155, 89, 182, 0.3);
    background: rgba(155, 89, 182, 0.05);
}

.gen-inner-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 10px;
    border-radius: 8px;
    white-space: nowrap;
}
