/* ════════════════════════════════════════════════════════════════════════
   ProjectRoots — Free-Canvas Family Tree Editor Styles
   ────────────────────────────────────────────────────────────────────────
   These styles only apply when a `#roots-canvas` element is present and
   pair with the editor JS in `tree.js`. Variables come from the parent
   `style.css` (--bg-color, --text-primary, --accent-primary, etc.) so
   the canvas inherits the site's light/dark/rainbow themes.
   ════════════════════════════════════════════════════════════════════════ */

.tree-page {
    /* Let the editor span the full viewport rather than fight the floating
       header padding the rest of the marketing site uses. */
    padding: 0 !important;
    background: var(--bg-color);
}

.tree-page-shell {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
    width: 100%;
}

.tree-page-banner {
    padding: 24px clamp(20px, 4vw, 48px) 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-color);
}

.tree-page-banner-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tree-breadcrumb {
    font-size: 0.72rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.tree-breadcrumb:hover {
    color: var(--text-primary);
}

.tree-page-banner-title {
    font-family: var(--font-heading);
    font-size: clamp(1rem, 2vw, 1.2rem);
    margin: 0;
    color: var(--text-primary);
}

.tree-page-banner-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0;
}

.tree-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.tree-status-pill-demo {
    background: rgba(244, 169, 62, 0.12);
    border-color: rgba(244, 169, 62, 0.35);
    color: #f4a93e;
}

/* ──────────────── Editor mount ──────────────── */

#roots-canvas {
    position: relative;
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: calc(100vh - 90px);
    /* Leave room for the bottom-nav floating pill so cards never sit
       under it. The padding is *inside* the viewport so pan/zoom math
       still uses the full width. */
    padding-bottom: 0;
    background: var(--bg-color);
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
}

/* ──────────────── Toolbar ──────────────── */

.roots-toolbar {
    position: relative;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 12px clamp(16px, 3vw, 32px);
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

[data-theme="light"] .roots-toolbar {
    background: rgba(255, 255, 255, 0.6);
}

.roots-toolbar-section {
    display: flex;
    align-items: center;
    gap: 10px;
}

.roots-toolbar-title {
    flex: 1 1 220px;
    min-width: 220px;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
}

.roots-toolbar-center {
    flex: 2 1 320px;
    justify-content: center;
    flex-wrap: wrap;
}

.roots-toolbar-right {
    flex: 1 1 220px;
    justify-content: flex-end;
}

.roots-title-input,
.roots-subtitle-input {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-heading);
    padding: 2px 4px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.roots-title-input {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.roots-subtitle-input {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-family: var(--font-main);
}

.roots-title-input:hover,
.roots-subtitle-input:hover,
.roots-title-input:focus,
.roots-subtitle-input:focus {
    background: rgba(255, 255, 255, 0.05);
    outline: none;
}

[data-theme="light"] .roots-title-input:hover,
[data-theme="light"] .roots-subtitle-input:hover,
[data-theme="light"] .roots-title-input:focus,
[data-theme="light"] .roots-subtitle-input:focus {
    background: rgba(0, 0, 0, 0.04);
}

.roots-search-wrap {
    flex: 1 1 180px;
    max-width: 280px;
}

.roots-search-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 9px 14px;
    font-family: var(--font-main);
    font-size: 0.85rem;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.roots-search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .roots-search-input {
    background: rgba(0, 0, 0, 0.04);
}

.roots-search-input::placeholder {
    color: var(--text-secondary);
}

.roots-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease, border-color 0.2s ease;
}

.roots-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

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

.roots-btn-primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: #fff;
}

.roots-btn-primary:hover {
    background: var(--accent-primary);
    filter: brightness(1.08);
}

.roots-btn-plus {
    font-size: 1.1rem;
    line-height: 1;
}

.roots-btn-danger {
    color: #ef6464;
    border-color: rgba(239, 100, 100, 0.35);
    background: rgba(239, 100, 100, 0.08);
}

.roots-btn-danger:hover {
    background: rgba(239, 100, 100, 0.16);
}

.roots-icon-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.roots-icon-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.18);
}

.roots-icon-btn-danger {
    color: #ef6464;
    border-color: rgba(239, 100, 100, 0.3);
}

.roots-icon-btn-danger:hover {
    background: rgba(239, 100, 100, 0.16);
}

.roots-zoom-readout {
    min-width: 48px;
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* ──────────────── Viewport (pan/zoom canvas) ──────────────── */

.roots-viewport {
    position: relative;
    overflow: hidden;
    /* A subtle dotted grid that pans with content gives the user a
       visual reference for movement. */
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 24px 24px;
    background-position: 0 0;
    cursor: grab;
    touch-action: none;
}

[data-theme="light"] .roots-viewport {
    background-image:
        radial-gradient(circle, rgba(0, 0, 0, 0.07) 1px, transparent 1px);
}

.roots-viewport.is-panning {
    cursor: grabbing;
}

.roots-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.roots-links-layer {
    position: absolute;
    pointer-events: none;
    overflow: visible;
}

.roots-link {
    stroke: var(--accent-primary);
    stroke-width: 2;
    stroke-linecap: round;
    opacity: 0.8;
}

.roots-link-spouse {
    stroke: var(--accent-primary);
    stroke-width: 3;
}

.roots-link-parent {
    stroke: var(--text-secondary);
    stroke-width: 2;
}

.roots-link-ghost {
    stroke: var(--accent-primary);
    stroke-width: 2;
    opacity: 0.6;
}

.roots-people-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
}

/* ──────────────── Person card ──────────────── */

.roots-card {
    --card-accent: var(--accent-primary);
    position: absolute;
    width: 208px;
    min-height: 104px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--card-accent);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    cursor: grab;
    transition:
        box-shadow 0.2s ease,
        transform 0.15s ease,
        opacity 0.2s ease,
        border-color 0.2s ease;
    user-select: none;
}

[data-theme="light"] .roots-card {
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
}

.roots-card:hover {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
    transform: translateY(-1px);
}

[data-theme="light"] .roots-card:hover {
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
}

.roots-card.is-selected {
    border-color: var(--card-accent);
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.32),
        0 0 0 2px var(--card-accent);
}

.roots-card.is-faded {
    opacity: 0.25;
}

.roots-card.is-match {
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.28),
        0 0 0 2px var(--card-accent);
}

.roots-card-avatar {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--card-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.04em;
}

.roots-card-body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.roots-card-name {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.roots-card-dates {
    margin: 0;
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.roots-card-note {
    margin: 2px 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.roots-card-link-handle {
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--card-accent);
    border: 2px solid var(--card-bg);
    cursor: crosshair;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.15s ease;
    padding: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.roots-card:hover .roots-card-link-handle,
.roots-card.is-selected .roots-card-link-handle {
    opacity: 1;
}

.roots-card-link-handle:hover {
    transform: translateY(-50%) scale(1.25);
}

/* ──────────────── Empty state & hint ──────────────── */

.roots-empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    pointer-events: none;
    text-align: center;
    padding: 32px;
}

.roots-empty-icon {
    font-size: 2.4rem;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 2px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.roots-hint {
    position: absolute;
    bottom: clamp(96px, 14vh, 140px);
    left: 50%;
    transform: translateX(-50%);
    max-width: min(640px, calc(100% - 48px));
    padding: 10px 18px;
    background: rgba(15, 15, 15, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.78rem;
    text-align: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: none;
    line-height: 1.5;
}

[data-theme="light"] .roots-hint {
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-secondary);
}

.roots-hint strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ──────────────── Edit popover ──────────────── */

.roots-editor {
    position: fixed;
    top: 50%;
    right: clamp(16px, 3vw, 32px);
    transform: translateY(-50%);
    width: min(360px, calc(100vw - 32px));
    max-height: min(80vh, 720px);
    z-index: 50;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    animation: roots-editor-in 0.24s ease;
}

@keyframes roots-editor-in {
    from {
        opacity: 0;
        transform: translate(8px, -50%);
    }
    to {
        opacity: 1;
        transform: translate(0, -50%);
    }
}

[data-theme="light"] .roots-editor {
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.18);
}

.roots-editor[hidden] {
    display: none;
}

.roots-editor-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-color);
}

.roots-editor-title {
    margin: 0;
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.roots-editor-body {
    padding: 16px 18px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.roots-editor-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .roots-editor-foot {
    background: rgba(0, 0, 0, 0.02);
}

.roots-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.roots-field > span {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    font-weight: 500;
}

.roots-field input,
.roots-field textarea {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: var(--font-main);
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s ease, background 0.2s ease;
    resize: vertical;
}

[data-theme="light"] .roots-field input,
[data-theme="light"] .roots-field textarea {
    background: rgba(0, 0, 0, 0.03);
}

.roots-field input:focus,
.roots-field textarea:focus {
    border-color: var(--accent-primary);
    background: rgba(255, 255, 255, 0.08);
}

.roots-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.roots-color-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.roots-color-chip {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease;
    padding: 0;
}

.roots-color-chip:hover {
    transform: scale(1.1);
}

.roots-color-chip.is-active {
    border-color: var(--text-primary);
    transform: scale(1.1);
}

.roots-editor-relations {
    border-top: 1px solid var(--border-color);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.roots-relations-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-secondary);
    font-weight: 500;
}

.roots-relations-empty {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.roots-relations-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.roots-relations-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

[data-theme="light"] .roots-relations-item {
    background: rgba(0, 0, 0, 0.03);
}

.roots-relations-name {
    font-size: 0.84rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.roots-relations-item select {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 0.78rem;
    cursor: pointer;
}

.roots-relations-remove {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: rgba(239, 100, 100, 0.12);
    color: #ef6464;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}

.roots-relations-remove:hover {
    background: rgba(239, 100, 100, 0.22);
}

/* ──────────────── Demo CTA + footer ──────────────── */

.tree-demo-cta {
    padding: 32px clamp(20px, 4vw, 48px) 120px;
    text-align: center;
}

.tree-page-footer {
    padding: 24px clamp(20px, 4vw, 48px) 120px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.tree-page-footer p {
    margin: 4px 0;
}

/* ──────────────── Responsive ──────────────── */

@media (max-width: 720px) {
    .roots-toolbar {
        gap: 10px;
        padding: 10px 16px;
    }

    .roots-toolbar-section {
        flex: 1 1 100%;
        justify-content: flex-start;
    }

    .roots-toolbar-center {
        justify-content: space-between;
    }

    .roots-toolbar-right {
        justify-content: center;
    }

    .roots-search-wrap {
        max-width: 100%;
    }

    .roots-editor {
        right: 12px;
        left: 12px;
        top: auto;
        bottom: clamp(120px, 20vh, 200px);
        transform: none;
        width: auto;
        max-height: 60vh;
        animation: roots-editor-in-mobile 0.24s ease;
    }

    @keyframes roots-editor-in-mobile {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .roots-hint {
        bottom: clamp(120px, 18vh, 160px);
        font-size: 0.72rem;
        padding: 8px 14px;
    }

    .roots-card-link-handle {
        opacity: 1;
        width: 18px;
        height: 18px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .roots-card,
    .roots-btn,
    .roots-icon-btn,
    .roots-color-chip {
        transition: none;
    }

    .roots-editor {
        animation: none;
    }
}
