:root {
  --primary: #2563eb;
  --secondary: #666;
  --bg: #fafaf8;
  --white: #fff;
  --dark: #1a1a1a;
  --muted: #888;
  --border: #e5e5e5;
  --radius: 4px;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --serif: Georgia, 'Times New Roman', serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--serif); background: var(--bg); color: #333; line-height: 1.7; font-size: 17px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

@media (min-width: 600px) {
  body { font-size: 18px; }
}

/* Wrapper */
.tree-wrapper { max-width: 680px; margin: 0 auto; padding: 0 1.5rem; transition: max-width 0.2s; }
.tree-wrapper.map-active { max-width: 960px; }

/* Header */
.tree-header { padding: 2rem 0 0; }
.back-link { font-family: var(--sans); font-size: 0.85rem; color: var(--secondary); text-decoration: none; }
.back-link:hover { color: var(--primary); text-decoration: none; }
.tree-header h1 { font-family: var(--sans); font-size: 1.5rem; font-weight: 600; color: var(--dark); margin: 0.5rem 0 0; line-height: 1.3; }

/* View toggle */
.view-toggle { display: flex; gap: 0; margin-top: 0.8rem; }
.toggle-btn { font-family: var(--sans); font-size: 0.8rem; padding: 0.35rem 1rem; border: 1px solid var(--border); background: var(--white); color: var(--secondary); cursor: pointer; transition: all 0.15s; }
.toggle-btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.toggle-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.toggle-btn.active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.toggle-btn:hover:not(.active) { background: var(--bg); color: var(--dark); }

/* Map view */
#map-view { position: relative; }
#map-canvas { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); display: block; }
.map-hint { text-align: center; font-family: var(--sans); font-size: 0.75rem; color: var(--muted); margin-top: 0.5rem; }
.map-on-person { display: inline-block; font-family: var(--sans); font-size: 0.8rem; color: var(--primary); cursor: pointer; margin-top: 0.3rem; }
.map-on-person:hover { text-decoration: underline; }

/* Explorer */
.explorer { padding: 1.5rem 0; }

/* Search */
.search-wrap { position: relative; margin-bottom: 1.5rem; }
.search-box { width: 100%; padding: 0.7rem 1rem; font-family: var(--sans); font-size: 0.95rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--white); color: var(--dark); outline: none; }
.search-box:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.search-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--white); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); max-height: 280px; overflow-y: auto; z-index: 200; display: none; box-shadow: 0 8px 24px rgba(0,0,0,0.08); }
.search-item { padding: 0.55rem 1rem; cursor: pointer; border-bottom: 1px solid var(--bg); font-family: var(--sans); }
.search-item:hover { background: var(--bg); }
.search-item:last-child { border-bottom: none; }
.si-name { font-weight: 600; font-size: 0.9rem; }
.si-detail { font-size: 0.8rem; color: var(--muted); }

/* Mini family diagram */
.family-diagram { text-align: center; margin-bottom: 1.5rem; }
.fd-row { display: flex; justify-content: center; align-items: stretch; gap: 0.5rem; flex-wrap: wrap; }
.fd-line { width: 1px; height: 1.2rem; background: var(--border); margin: 0 auto; }
.fd-node { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; padding: 0.4rem 0.8rem; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 0.8rem; line-height: 1.3; transition: all 0.15s; width: 140px; min-height: 52px; text-align: center; font-family: var(--sans); }
.fd-node:hover { border-color: var(--primary); background: var(--bg); }
.fd-node.active { border-color: var(--primary); background: var(--primary); color: var(--white); }
.fd-node.active .fd-dates { color: rgba(255,255,255,0.8); }
.fd-name { font-weight: 600; font-size: 0.78rem; }
.fd-dates { font-size: 0.7rem; color: var(--muted); }
.fd-couple { display: inline-flex; align-items: stretch; gap: 0; }
.fd-couple .fd-node { border-radius: var(--radius) 0 0 var(--radius); }
.fd-couple .fd-node:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.fd-children-row { display: flex; justify-content: center; align-items: stretch; gap: 0.4rem; flex-wrap: wrap; }
.fd-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin: 0.3rem 0; font-family: var(--sans); }

/* Person card */
.person-card { background: var(--white); border-radius: var(--radius); padding: 1.8rem; margin-bottom: 1.5rem; border: 1px solid var(--border); }
.person-card h2 { font-family: var(--sans); font-size: 1.3rem; color: var(--dark); margin: 0 0 0.15rem; font-weight: 600; line-height: 1.3; }
.person-nicknames { font-style: italic; color: var(--muted); margin-bottom: 0.6rem; font-size: 0.9rem; }
.person-relation { display: inline-block; font-size: 0.75rem; background: var(--bg); color: var(--secondary); padding: 0.2rem 0.6rem; border-radius: 100px; margin-bottom: 0.8rem; font-family: var(--sans); }
.person-meta { margin-bottom: 0.8rem; }
.meta-row { display: flex; gap: 0.4rem; margin-bottom: 0.2rem; font-size: 0.9rem; }
.meta-label { color: var(--muted); min-width: 4rem; flex-shrink: 0; font-family: var(--sans); }
.meta-value { color: var(--dark); }
.spouse-link { color: var(--primary); cursor: pointer; }
.spouse-link:hover { text-decoration: underline; }
.person-notes { border-top: 1px solid var(--border); padding-top: 0.8rem; margin-top: 0.5rem; color: var(--muted); font-size: 0.9rem; line-height: 1.7; }

/* Siblings */
.siblings-section { margin-bottom: 1.5rem; }
.siblings-section h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.4rem; font-family: var(--sans); }
.siblings-section .pills { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.sib-pill { padding: 0.3rem 0.7rem; background: var(--white); border: 1px solid var(--border); border-radius: 100px; cursor: pointer; font-size: 0.8rem; color: var(--secondary); transition: all 0.15s; font-family: var(--sans); }
.sib-pill:hover { border-color: var(--primary); color: var(--primary); }

/* Footer */
.tree-footer { text-align: center; padding: 2rem 0; color: var(--muted); font-size: 0.8rem; border-top: 1px solid var(--border); font-family: var(--sans); }
.tree-footer a { color: var(--muted); text-decoration: none; }
.tree-footer a:hover { color: var(--primary); }

@media (max-width: 600px) {
  .tree-wrapper { padding: 0 1rem; }
  .tree-header h1 { font-size: 1.3rem; }
  .explorer { padding: 1rem 0; }
  .person-card { padding: 1.2rem; }
  .person-card h2 { font-size: 1.15rem; }
  .meta-row { flex-direction: column; gap: 0; }
  .meta-label { min-width: auto; }
  .fd-node { width: 110px; min-height: 46px; padding: 0.3rem 0.5rem; }
  .fd-name { font-size: 0.72rem; }
}
