/* ---- Design tokens ---- */
:root {
    --paper: #EAE6D9;
    --paper-card: #F8F6EF;
    --ink: #262A21;
    --ink-soft: #5B5C4E;
    --forest: #2F4438;
    --forest-dark: #223227;
    --brass: #A9793C;
    --brass-dark: #8C6330;
    --rosewood: #A85C56;
    --line: #C6BFA6;
    --danger: #A8433A;
    --radius: 10px;
    --shadow: 0 2px 10px rgba(38, 42, 33, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Inter', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

h1, h2 {
    font-family: 'Fraunces', serif;
    margin: 0;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 1rem;
}

/* ---- Header ---- */
.app-header {
    background: var(--forest);
    color: #F3F1E7;
    padding: 1rem 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark { font-size: 1.6rem; }
.brand h1 { font-size: 1.35rem; font-weight: 500; letter-spacing: 0.01em; }
.brand p { margin: 0.1rem 0 0; font-size: 0.8rem; color: #C9D2C4; }

.header-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

#search-input {
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.25);
    color: #F3F1E7;
    border-radius: 999px;
    padding: 0.5rem 1rem;
    width: 200px;
    max-width: 46vw;
}
#search-input::placeholder { color: #C9D2C4; }

/* ---- Buttons ---- */
.btn {
    border: none;
    border-radius: 999px;
    padding: 0.55rem 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--brass); color: #241804; }
.btn-primary:hover { background: var(--brass-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.icon-btn {
    background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer;
    color: var(--ink-soft); padding: 0.2rem 0.5rem;
}

/* ---- Zoom controls ---- */
.zoom-controls {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 15;
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: var(--shadow);
    display: flex;
    overflow: hidden;
}
.zoom-controls button {
    background: none; border: none; padding: 0.6rem 0.9rem; cursor: pointer;
    color: var(--forest); font-weight: 600; border-right: 1px solid var(--line);
}
.zoom-controls button:last-child { border-right: none; }
.zoom-controls button:hover { background: rgba(47,68,56,0.08); }

/* ---- Tree layout ---- */
.tree-viewport {
    overflow: auto;
    height: calc(100vh - 68px);
    padding: 2.5rem 1.5rem 4rem;
    -webkit-overflow-scrolling: touch;
}

.forest {
    display: flex;
    gap: 3.5rem;
    align-items: flex-start;
    width: max-content;
    transform-origin: top left;
    transition: transform 0.15s ease;
}

.tree ul {
    list-style: none;
    margin: 0;
    padding-top: 2.25rem;
    position: relative;
    display: flex;
}

.tree > ul { padding-top: 0; }

.tree li {
    list-style: none;
    position: relative;
    padding: 2.25rem 0.75rem 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tree > ul > li { padding-top: 0; }

.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: 2.25rem;
    border-top: 2px solid var(--line);
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--line); }
.tree li:only-child::before,
.tree li:only-child::after { 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: 2px solid var(--line); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree > ul > li::before,
.tree > ul > li::after { display: none; }

.tree ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    border-left: 2px solid var(--line);
    width: 0;
    height: 2.25rem;
}

/* ---- Person / couple cards ---- */
.couple {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

.person-card {
    background: var(--paper-card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 168px;
    padding: 0.7rem 0.75rem 0.8rem;
    cursor: pointer;
    text-align: left;
    border-left: 4px solid var(--forest);
    transition: box-shadow 0.15s ease, transform 0.1s ease;
}
.person-card:hover { box-shadow: 0 4px 16px rgba(38,42,33,0.18); transform: translateY(-1px); }
.person-card.gender-female { border-left-color: var(--rosewood); }
.person-card.gender-other { border-left-color: var(--brass); }
.person-card.deceased { opacity: 0.72; }
.person-card.highlight { outline: 2px solid var(--brass); outline-offset: 2px; }

.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--forest);
    color: #F3F1E7;
    display: flex; align-items: center; justify-content: center;
    font-family: 'Fraunces', serif; font-size: 0.95rem;
    margin-bottom: 0.5rem;
    object-fit: cover;
}
.person-card.gender-female .avatar { background: var(--rosewood); }
.person-card.gender-other .avatar { background: var(--brass); }

.person-name { font-family: 'Fraunces', serif; font-size: 0.98rem; line-height: 1.2; }
.person-dates { font-size: 0.75rem; color: var(--ink-soft); margin-top: 0.2rem; }
.person-place { font-size: 0.72rem; color: var(--ink-soft); margin-top: 0.1rem; }

.couple-connector {
    width: 0.4rem;
    align-self: center;
    border-top: 2px solid var(--line);
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 5rem 1.5rem;
    color: var(--ink-soft);
}
.empty-state p { font-family: 'Fraunces', serif; font-size: 1.25rem; color: var(--ink); margin-bottom: 1rem; }

/* ---- Drawer ---- */
.drawer-backdrop {
    position: fixed; inset: 0; background: rgba(34, 50, 39, 0.4);
    z-index: 30;
}
.drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(420px, 100vw);
    background: var(--paper-card);
    z-index: 31;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 24px rgba(0,0,0,0.15);
}
.drawer.open { transform: translateX(0); }

.drawer form { display: flex; flex-direction: column; height: 100%; }

.drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.drawer-body {
    padding: 1.1rem 1.25rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.drawer label {
    display: flex; flex-direction: column; gap: 0.35rem;
    font-size: 0.82rem; color: var(--ink-soft); font-weight: 600;
    flex: 1;
}

.drawer input, .drawer select, .drawer textarea {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    background: #fff;
    color: var(--ink);
    font-weight: 400;
}
.drawer input:focus, .drawer select:focus, .drawer textarea:focus {
    outline: 2px solid var(--brass);
    outline-offset: 1px;
}

.field-row { display: flex; gap: 0.75rem; }

.form-error {
    background: #F6E4E2;
    color: var(--danger);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.85rem;
}

.drawer-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--line);
}
.drawer-footer-right { display: flex; gap: 0.6rem; }

/* ---- Focus visibility ---- */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--brass);
    outline-offset: 2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
    .drawer, .forest, .person-card, .btn { transition: none; }
}

/* ---- Mobile ---- */
@media (max-width: 640px) {
    .app-header { padding: 0.85rem 1rem; }
    .brand p { display: none; }
    #search-input { width: 140px; }
    .tree-viewport { padding: 1.5rem 1rem 5rem; height: calc(100vh - 116px); }
    .person-card { width: 138px; }
    .drawer { width: 100vw; }
    .field-row { flex-direction: column; }
}
