@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=Lato:wght@400;700&display=swap');

:root {
    --bark-dark: #3E2723;
    --bark-mid: #5D4037;
    --bark-light: #8D6E63;
    --leaf-deep: #1B5E20;
    --leaf-mid: #388E3C;
    --leaf-light: #66BB6A;
    --canopy: #E8F5E9;
    --soil: #EFEBE9;
    --parchment: #FAFAF7;
    --highlight: #D84315;
    --gold: #F9A825;
    --shadow-soft: 0 8px 32px rgba(62, 39, 35, 0.14);
    --shadow-card: 0 2px 12px rgba(62, 39, 35, 0.10);
    --font-display: 'Playfair Display', serif;
    --font-body: 'Lato', sans-serif;
    --radius: 16px;
    --radius-sm: 10px;
}

/* ══════════════════════════════════
   BASE
══════════════════════════════════ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-body);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    background: var(--canopy);
}

/* ══════════════════════════════════
   VIEWPORT & CANVAS
══════════════════════════════════ */
#viewport {
    position: fixed;
    inset: 0;
    z-index: 1;
    cursor: grab;
}

#viewport:active {
    cursor: grabbing;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ══════════════════════════════════
   UI LAYER
══════════════════════════════════ */
#ui-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
}

/* ══════════════════════════════════
   PANEL  (wood-bark framed card)
══════════════════════════════════ */
.panel {
    position: absolute;
    background: var(--parchment);
    pointer-events: auto;
    box-sizing: border-box;
}

/* ── Info Panel (top-left) ── */
.top-left {
    top: 20px;
    left: 20px;
    width: 310px;
    max-height: calc(100dvh - 40px);
    /* overflow-y: auto;
    overflow-x: hidden; */
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    padding: 0;
    border: 2px solid rgba(93, 64, 55, 0.18);
    scrollbar-width: thin;
    scrollbar-color: var(--bark-light) transparent;
}

/* Bark-texture header strip */
.top-left::before {
    content: '';
    display: block;
    height: 6px;
    background: repeating-linear-gradient(90deg,
            var(--bark-dark) 0px, var(--bark-dark) 4px,
            var(--bark-mid) 4px, var(--bark-mid) 10px,
            #6D4C41 10px, #6D4C41 14px,
            var(--bark-light) 14px, var(--bark-light) 18px);
    border-radius: var(--radius) var(--radius) 0 0;
}

.panel-inner {
    padding: 18px 18px 20px;
}

/* ── Zoom Controls (bottom-right) ── */
.bottom-right {
    bottom: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    background: transparent;
    box-shadow: none;
    border: none;
    padding: 0;
}

/* ══════════════════════════════════
   TITLE
══════════════════════════════════ */
.panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 16px;
}

.panel-title .tree-icon {
    font-size: 2rem;
    line-height: 1;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.panel-title h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--bark-dark);
    line-height: 1.2;
}

.panel-title h1 small {
    display: block;
    font-size: 0.72rem;
    font-weight: 400;
    color: var(--bark-light);
    font-family: var(--font-body);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 1px;
}

/* ══════════════════════════════════
   SEARCH
══════════════════════════════════ */
.search-container {
    position: relative;
}

#search-input-1,
#search-input-2 {
    width: 100%;
    padding: 11px 14px 11px 40px;
    border: 1.5px solid rgba(93, 64, 55, 0.2);
    border-radius: var(--radius-sm);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238D6E63' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 12px center;
    font-size: 0.95rem;
    font-family: var(--font-body);
    color: var(--bark-dark);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* ══════════════════════════════════
   LOADER OVERLAY
══════════════════════════════════ */
#loader-overlay {
    position: fixed;
    inset: 0;
    background: var(--canopy);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

#loader-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(93, 64, 55, 0.15);
    /* Soft bark */
    border-top-color: var(--leaf-mid);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#loader-overlay p {
    font-family: var(--font-display);
    color: var(--bark-dark);
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.05em;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

#search-input:focus {
    border-color: var(--leaf-mid);
    outline: none;
    box-shadow: 0 0 0 3px rgba(56, 142, 60, 0.15);
}

#search-input::placeholder {
    color: var(--bark-light);
}

.suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border-radius: var(--radius-sm);
    box-shadow: 0 12px 35px rgba(62, 39, 35, 0.22);
    border: 1.5px solid rgba(93, 64, 55, 0.12);
    z-index: 2000;
    max-height: 55vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.suggestion-item {
    padding: 11px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(93, 64, 55, 0.08);
    transition: background 0.15s;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: #F1F8E9;
}

.sugg-main {
    font-weight: 700;
    color: var(--bark-dark);
    font-size: 0.95rem;
    font-family: var(--font-display);
}

.sugg-sub {
    font-size: 0.78rem;
    color: var(--bark-light);
    margin-top: 3px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* ══════════════════════════════════
   SELECTION INFO
══════════════════════════════════ */
.selection-info {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 2px dashed rgba(93, 64, 55, 0.2);
    animation: slideDown 0.25s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.sel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.sel-leaf-dot {
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, var(--leaf-light), var(--leaf-deep));
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    flex-shrink: 0;
}

.selection-info h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--highlight);
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1.2;
}

.lineage-text {
    font-size: 0.83rem;
    color: var(--bark-mid);
    line-height: 1.6;
    background: linear-gradient(135deg, #F1F8E9, #E8F5E9);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--leaf-mid);
    margin-bottom: 12px;
    word-break: break-word;
}

.partner-tag {
    font-size: 0.85rem;
    color: #BF360C;
    font-weight: 700;
    background: linear-gradient(135deg, #FFF3E0, #FFE0B2);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border-left: 3px solid #FF8F00;
    display: block;
    margin-bottom: 14px;
    text-align: left;
}

/* ══════════════════════════════════
   ACTION BUTTONS
══════════════════════════════════ */
.action-group {
    display: flex;
    gap: 8px;
    margin-top: 14px;
}

.btn-action {
    flex: 1;
    padding: 11px 10px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    font-size: 0.88rem;
    font-family: var(--font-body);
    transition: all 0.18s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    letter-spacing: 0.01em;
}

.btn-action:active {
    transform: scale(0.96);
}

/* Primary – dark bark */
.btn-action:not(.secondary) {
    background: linear-gradient(135deg, var(--bark-dark), var(--bark-mid));
    color: #fff;
    box-shadow: 0 3px 10px rgba(62, 39, 35, 0.3);
}

.btn-action:not(.secondary):hover {
    background: linear-gradient(135deg, #2d1b18, var(--bark-dark));
    box-shadow: 0 5px 14px rgba(62, 39, 35, 0.4);
}

/* Secondary – leaf */
.btn-action.secondary {
    background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
    color: var(--leaf-deep);
    border: 1.5px solid rgba(56, 142, 60, 0.3);
}

.btn-action.secondary:hover {
    background: linear-gradient(135deg, #C8E6C9, #A5D6A7);
}

/* ══════════════════════════════════
   ZOOM CONTROLS
══════════════════════════════════ */
.zoom-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.zoom-controls button {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--parchment);
    font-size: 1.3rem;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    color: var(--bark-dark);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1.5px solid rgba(93, 64, 55, 0.15);
    font-weight: 700;
}

.zoom-controls button:hover {
    background: var(--bark-dark);
    color: #fff;
    box-shadow: 0 6px 20px rgba(62, 39, 35, 0.4);
    transform: translateY(-1px);
}

.zoom-controls button:active {
    transform: scale(0.92);
}

/* ══════════════════════════════════
   MENU BUTTON (mobile FAB)
══════════════════════════════════ */
.menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, var(--bark-dark), var(--bark-mid));
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.4rem;
    box-shadow: 0 4px 16px rgba(62, 39, 35, 0.45);
    z-index: 200;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.2s;
}

.menu-btn:active {
    transform: scale(0.9);
}

.close-mobile-btn {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    font-size: 1.15rem;
    color: var(--bark-light);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: background 0.15s;
}

.close-mobile-btn:hover {
    background: rgba(93, 64, 55, 0.1);
}

/* ══════════════════════════════════
   MODALS
══════════════════════════════════ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(27, 18, 14, 0.55);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--parchment);
    padding: 0;
    border-radius: var(--radius);
    width: 90%;
    max-width: 360px;
    box-shadow: 0 24px 64px rgba(62, 39, 35, 0.4);
    overflow: hidden;
    border: 1.5px solid rgba(93, 64, 55, 0.15);
}

.modal-header {
    background: linear-gradient(135deg, var(--bark-dark), var(--bark-mid));
    padding: 18px 22px;
    color: #fff;
}

.modal-header h3 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-body {
    padding: 20px 22px;
}

.field-group {
    margin-bottom: 16px;
}

.field-group label {
    display: block;
    font-size: 0.78rem;
    color: var(--bark-mid);
    margin-bottom: 6px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.parent-tag {
    background: linear-gradient(135deg, #E0F2F1, #B2EBF2);
    color: #00695C;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-family: var(--font-display);
    display: inline-block;
    border: 1px solid rgba(0, 105, 92, 0.2);
}

.modal-content input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid rgba(93, 64, 55, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font-body);
    background: #fff;
    color: var(--bark-dark);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.modal-content input:focus {
    border-color: var(--leaf-mid);
    outline: none;
    box-shadow: 0 0 0 3px rgba(56, 142, 60, 0.15);
}

.modal-content input::placeholder {
    color: var(--bark-light);
}

.modal-actions {
    display: flex;
    gap: 10px;
    padding: 0 22px 20px;
    margin-top: 4px;
}

.modal-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.92rem;
    transition: all 0.18s ease;
}

.modal-actions button:active {
    transform: scale(0.96);
}

#btn-cancel-add,
#btn-cancel-edit {
    background: #EFEBE9;
    color: var(--bark-mid);
    border: 1.5px solid rgba(93, 64, 55, 0.15);
}

#btn-cancel-add:hover,
#btn-cancel-edit:hover {
    background: #E0D7D3;
}

#btn-save-add {
    background: linear-gradient(135deg, var(--leaf-mid), var(--leaf-deep));
    color: white;
    box-shadow: 0 3px 10px rgba(56, 142, 60, 0.35);
}

#btn-save-add:hover {
    box-shadow: 0 5px 15px rgba(56, 142, 60, 0.5);
}

#btn-save-edit {
    background: linear-gradient(135deg, var(--bark-mid), var(--bark-dark));
    color: white;
    box-shadow: 0 3px 10px rgba(62, 39, 35, 0.3);
}

#btn-save-edit:hover {
    box-shadow: 0 5px 15px rgba(62, 39, 35, 0.4);
}

/* ══════════════════════════════════
   UTILITY
══════════════════════════════════ */
.hidden {
    display: none !important;
}

/* ══════════════════════════════════
   RESPONSIVE – MOBILE
══════════════════════════════════ */
@media (max-width: 600px) {
    .top-left {
        display: none;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 92%;
        max-width: 360px;
        max-height: 80dvh;
        z-index: 1500;
        box-shadow: 0 28px 60px rgba(62, 39, 35, 0.5);
        animation: popIn 0.2s ease;
    }

    .top-left.show {
        display: block;
    }

    .menu-btn {
        display: flex;
    }

    .close-mobile-btn {
        display: block;
    }

    @keyframes popIn {
        from {
            opacity: 0;
            transform: translate(-50%, -47%);
        }

        to {
            opacity: 1;
            transform: translate(-50%, -50%);
        }
    }

    .bottom-right {
        bottom: 14px;
        right: 14px;
        gap: 8px;
    }

    .zoom-controls button {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
    }
}