/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap");

:root {
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --card-shadow-hover:
        0 8px 24px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
    --border: #e8ecf1;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --accent: #6366f1;
    --accent-light: #eef2ff;
    --male-accent: #3b82f6;
    --male-bg: #f0f7ff;
    --male-border: #bfdbfe;
    --female-accent: #ec4899;
    --female-bg: #fdf2f8;
    --female-border: #fbcfe8;
    --couple-connector: #e879a0;
    --connector: #94a3b8;
    --connector-width: 2px;
    --font:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
        sans-serif;
    --radius: 12px;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Header */
header {
    text-align: center;
    padding: 1.5rem 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.92);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text);
}

header p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Scroll wrapper */
.tree-scroll {
    overflow-x: auto;
    overflow-y: visible;
    padding: 2.5rem 2rem 3rem;
    position: relative;
}

#tree-container {
    display: inline-flex;
    justify-content: center;
    min-width: 100%;
    position: relative;
}

/* SVG connector overlay */
#connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 0;
}

#connector-svg line {
    stroke: var(--connector);
    stroke-width: 2;
}

#connector-svg line.couple-line {
    stroke: var(--couple-connector);
    stroke-width: 2;
}

/* Family unit */
.family-unit {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

/* Couple row */
.couple {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

/* Person card */
.person {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0.75rem 0.6rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--card-bg);
    width: 100px;
    text-align: center;
    position: relative;
    box-shadow: var(--card-shadow);
    transition:
        box-shadow 0.2s ease,
        transform 0.2s ease;
    cursor: default;
}

.person:hover {
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-2px);
}

.person.male {
    background: var(--male-bg);
    border-color: var(--male-border);
}

.person.female {
    background: var(--female-bg);
    border-color: var(--female-border);
}

/* Gender accent bar at top of card */
.person::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 28px;
    height: 3px;
    border-radius: 0 0 3px 3px;
}

.person.male::before {
    background: var(--male-accent);
}

.person.female::before {
    background: var(--female-accent);
}

/* Photo */
.person-photo {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e2e8f0, #f1f5f9);
    margin-bottom: 0.4rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.person.male .person-photo {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

.person.female .person-photo {
    background: linear-gradient(135deg, #fce7f3, #fdf2f8);
}

.person-photo .initials {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.person.male .person-photo .initials {
    color: var(--male-accent);
}

.person.female .person-photo .initials {
    color: var(--female-accent);
}

.person-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-name {
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
    word-break: break-word;
}

.person-dob {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
    font-weight: 400;
}

/* Children container */
.children-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin-top: 50px;
    gap: 0.3rem;
}

/* Each child branch */
.child-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Expand/collapse button */
.expand-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: var(--connector-width) solid var(--connector);
    background: var(--card-bg);
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 8px;
    line-height: 1;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    position: relative;
    z-index: 1;
}

.expand-btn:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    transform: scale(1.1);
}

/* Indicator that couple has expandable children */
.couple.has-hidden-children .person {
    cursor: pointer;
}

.couple.has-hidden-children .person::after {
    content: "double-click to expand";
    position: absolute;
    bottom: -14px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.5rem;
    color: var(--text-muted);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.couple.has-hidden-children .person:hover::after {
    opacity: 1;
}

.couple.has-hidden-children.expanded .person::after {
    content: "double-click to collapse";
}

/* ======= PERSON DETAIL MODAL ======= */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    animation: fadeIn 0.15s ease;
}

.modal-overlay[hidden] {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-card {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.15),
        0 4px 16px rgba(0, 0, 0, 0.08);
    padding: 2.5rem 2rem 1.75rem;
    max-width: 400px;
    width: 100%;
    position: relative;
    text-align: center;
    animation: slideUp 0.2s ease;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    font-size: 1.2rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    line-height: 1;
}

.modal-close:hover {
    background: var(--border);
    color: var(--text);
}

.modal-photo {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 1.25rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.modal-photo.male {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

.modal-photo.female {
    background: linear-gradient(135deg, #fce7f3, #fdf2f8);
}

.modal-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-photo .initials {
    font-size: 2rem;
    font-weight: 600;
}

.modal-photo.male .initials {
    color: var(--male-accent);
}

.modal-photo.female .initials {
    color: var(--female-accent);
}

.modal-name {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
}

.modal-details {
    text-align: left;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.modal-details .detail-row {
    display: flex;
    gap: 0.5rem;
}

.modal-details .detail-label {
    color: var(--text-muted);
    min-width: 70px;
    flex-shrink: 0;
    font-weight: 500;
}

.modal-details .detail-value {
    color: var(--text);
    font-weight: 500;
}

.modal-details .detail-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
}

.modal-details .detail-link:hover {
    color: var(--male-accent);
    text-decoration: underline;
}

/* ======= SEARCH ======= */
.search-wrapper {
    position: relative;
    max-width: 280px;
    margin: 0.75rem auto 0;
}

#search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font);
    font-size: 0.8rem;
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition:
        border-color 0.15s,
        box-shadow 0.15s;
}

#search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

#search-input::placeholder {
    color: var(--text-muted);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    max-height: 240px;
    overflow-y: auto;
    z-index: 20;
}

.search-results[hidden] {
    display: none;
}

.search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.1s;
}

.search-result-item:hover,
.search-result-item.active {
    background: var(--accent-light);
}

.search-result-item .result-gender {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.search-result-item .result-gender.male {
    background: var(--male-accent);
}

.search-result-item .result-gender.female {
    background: var(--female-accent);
}

/* Highlight effect on the card when searched */
.person.search-highlight {
    animation: highlightPulse 1.5s ease;
    box-shadow:
        0 0 0 3px var(--accent),
        var(--card-shadow-hover);
    z-index: 5;
}

@keyframes highlightPulse {
    0% {
        box-shadow:
            0 0 0 6px rgba(99, 102, 241, 0.4),
            var(--card-shadow-hover);
    }
    100% {
        box-shadow:
            0 0 0 3px var(--accent),
            var(--card-shadow-hover);
    }
}

/* ======= BIRTHDAYS SECTION ======= */
.birthdays-section {
    padding: 1.25rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.birthdays-section[hidden] {
    display: none;
}

.birthdays-section h2 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.birthdays-section h2::before {
    content: "\1F382";
    font-size: 1rem;
}

.birthdays-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 320px;
}

.birthday-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: var(--card-bg);
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    flex-shrink: 0;
    cursor: pointer;
    transition:
        box-shadow 0.15s,
        transform 0.15s;
}

.birthday-card:hover {
    box-shadow: var(--card-shadow-hover);
    transform: translateY(-1px);
}

.birthday-card .bday-photo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

.birthday-card .bday-photo.male {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

.birthday-card .bday-photo.female {
    background: linear-gradient(135deg, #fce7f3, #fdf2f8);
}

.birthday-card .bday-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.birthday-card .bday-photo .initials {
    font-size: 0.75rem;
    font-weight: 600;
}

.birthday-card .bday-photo.male .initials {
    color: var(--male-accent);
}

.birthday-card .bday-photo.female .initials {
    color: var(--female-accent);
}

.birthday-card .bday-info {
    display: flex;
    flex-direction: column;
}

.birthday-card .bday-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
}

.birthday-card .bday-date {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 0.1rem;
}

/* ======= MOBILE: vertical list layout ======= */
@media (max-width: 768px) {
    header {
        padding: 1.25rem 1rem;
    }

    .tree-scroll {
        padding: 1rem 0.75rem;
        overflow-x: visible;
    }

    #tree-container {
        display: block;
        min-width: unset;
    }

    #connector-svg {
        display: none;
    }

    .family-unit {
        align-items: flex-start;
        width: 100%;
    }

    .couple {
        display: inline-flex;
        flex-wrap: nowrap;
        gap: 8px;
    }

    .children-row {
        flex-direction: column;
        align-items: flex-start;
        padding-left: 1.25rem;
        border-left: var(--connector-width) solid var(--connector);
        margin-left: 1.25rem;
        margin-top: 0.75rem;
        gap: 0.6rem;
    }

    .child-branch {
        align-items: flex-start;
        padding: 0;
        position: relative;
    }

    .child-branch::before {
        content: "";
        position: absolute;
        top: 50%;
        left: -1.25rem;
        width: 1.25rem;
        border-top: var(--connector-width) solid var(--connector);
    }

    .person {
        width: auto;
        flex-direction: row;
        gap: 0.6rem;
        padding: 0.5rem 0.75rem;
        text-align: left;
    }

    .person::before {
        display: none;
    }

    .person-photo {
        width: 40px;
        height: 40px;
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .person-info {
        display: flex;
        flex-direction: column;
    }

    .expand-btn {
        margin-top: 0.3rem;
        margin-left: 1.25rem;
        width: 26px;
        height: 26px;
    }
}

@media (max-width: 480px) {
    .person {
        padding: 0.4rem 0.6rem;
        gap: 0.5rem;
    }

    .person-photo {
        width: 36px;
        height: 36px;
    }

    .person-name {
        font-size: 0.68rem;
    }
}
