* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, sans-serif;
  background: #2a2a2a;
  color: #eee;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: #333;
  border-bottom: 1px solid #444;
  z-index: 10;
}

#search-modal {
  position: fixed;
  inset: 0;
  background: #0008;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem 1rem;
  z-index: 30;
}

#search-modal.open { display: flex; }

.search-dialog {
  background: #383838;
  border: 1px solid #ff8c00;
  border-radius: 8px;
  width: min(640px, 100%);
  max-height: calc(100vh - 5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#search-bar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  border-bottom: 1px solid #5c4020;
}

#search-bar input {
  flex: 1;
  background: #4a3520;
  color: #eee;
  border: 1px solid #ff8c00;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
}

#search-bar input[type="number"] { flex: 0 0 110px; }

#search-results {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  overflow-y: auto;
}

.search-result {
  background: #404040;
  border: 2px solid #ff8c00;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.search-result:hover { border-color: #ffa333; background: #4a4a4a; }

.search-result .name { font-weight: 600; }
.search-result .dates { font-size: 0.85rem; color: #aaa; margin-top: 0.25rem; }

.search-empty { color: #888; padding: 0.5rem 0; }

#search-btn, #add-btn, #edit-btn {
  background: #ff8c00;
  color: #1a1a1a;
  border: 1px solid #e67e00;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

#search-btn:hover, #add-btn:hover, #edit-btn:hover { background: #ffa333; border-color: #ffb347; }

.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.story-header h2 { margin-bottom: 0; }

#human-modal {
  position: fixed;
  inset: 0;
  background: #0008;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 4rem 1rem 1rem;
  z-index: 30;
}

#human-modal.open { display: flex; }

.human-dialog {
  background: #333;
  border: 1px solid #444;
  border-radius: 8px;
  width: min(420px, 100%);
  padding: 1rem;
}

.human-dialog h3 { margin-bottom: 1rem; }

#human-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#human-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

#human-form label.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

#human-form label.checkbox-label input {
  width: auto;
  margin: 0;
}

.parent-picker {
  position: relative;
}

.parent-picker input {
  width: 100%;
  padding-right: 1.75rem;
}

.parent-clear {
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.parent-clear:hover { color: #eee; }

.parent-results {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 180px;
  overflow-y: auto;
  background: #333;
  border: 1px solid #555;
  border-radius: 4px;
  z-index: 5;
}

.parent-results.open { display: flex; flex-direction: column; }

.parent-result {
  background: transparent;
  border: none;
  border-bottom: 1px solid #444;
  color: #eee;
  cursor: pointer;
  padding: 0.5rem 0.6rem;
  text-align: left;
}

.parent-result:last-child { border-bottom: none; }
.parent-result:hover { background: #4a4a4a; }
.parent-result .dates { font-size: 0.8rem; color: #aaa; margin-top: 0.15rem; }
.parent-empty { color: #888; padding: 0.5rem 0.6rem; font-size: 0.85rem; }

#human-form input,
#human-form select,
#human-form textarea {
  background: #404040;
  color: #eee;
  border: 1px solid #555;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.5rem;
}

.form-actions-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

#human-delete {
  background: #404040;
  border-color: #dc2626;
  color: #fca5a5;
  font-weight: 600;
}

#human-delete:hover { background: #4a4a4a; border-color: #ef4444; }

.form-actions button {
  background: #ff8c00;
  color: #1a1a1a;
  border: 1px solid #e67e00;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

.form-actions button:hover { background: #ffa333; border-color: #ffb347; }

.form-actions button[type="submit"] { background: #e67e00; border-color: #cc7000; }
.form-actions button[type="submit"]:hover { background: #ff8c00; border-color: #e67e00; }

.form-error { color: #f87171; font-size: 0.85rem; min-height: 1.2em; }

.main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#viewport {
  flex: 1;
  overflow: hidden;
  cursor: grab;
  position: relative;
  background: #2a2a2a;
}

#viewport.dragging { cursor: grabbing; }

#canvas {
  position: absolute;
  transform-origin: 0 0;
}

#timeline-axis {
  position: absolute;
  top: 0;
  width: 2px;
  background: #ff8c00;
  pointer-events: none;
}

.timeline-label {
  position: absolute;
  right: 12px;
  font-size: 11px;
  color: #ff8c00;
  transform: translateY(-50%);
  white-space: nowrap;
}

#links {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

#links .tree-link {
  fill: none;
  stroke: #ff8c00;
  stroke-width: 2;
}

#links .now-line {
  stroke: #ff8c00;
  stroke-width: 2;
  stroke-dasharray: 8 6;
  opacity: 0.9;
}

.card-wrap {
  position: absolute;
  width: 180px;
  overflow: visible;
}

.card-wrap.adds-visible .card-add { opacity: 1; pointer-events: auto; }

.card {
  position: relative;
  width: 100%;
  background: #404040;
  border: 2px solid #888;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
  overflow: hidden;
}

.card-add {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #e67e00;
  background: #ff8c00;
  color: #1a1a1a;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 2;
  font-weight: 700;
}

.card-add:hover { border-color: #ffb347; background: #ffa333; color: #1a1a1a; }

.card-add-top { top: -28px; }
.card-add-bottom { bottom: -28px; }

.card.male { border-color: #38bdf8; }
.card.female { border-color: #ec4899; }

.card.male:hover, .card.male.focus { border-color: #7dd3fc; box-shadow: 0 0 12px #38bdf899; }
.card.female:hover, .card.female.focus { border-color: #f472b6; box-shadow: 0 0 12px #ec489999; }

.card .name {
  font-weight: 600;
  font-size: 0.9rem;
  overflow-wrap: break-word;
  word-break: break-word;
}

.card .dates {
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 4px;
}

.card.sibling { border-style: dashed; opacity: 0.85; }

.card.alive { background: #525252; }

.card.dash-top { border-top-style: dashed; }
.card.dash-bottom { border-bottom-style: dashed; }

#story-panel {
  width: 360px;
  flex-shrink: 0;
  background: #333;
  border-left: 1px solid #444;
  padding: 1.5rem;
  overflow-y: auto;
}

#story-panel h2 { margin-bottom: 0.5rem; }
#story-panel #story-dates { color: #aaa; margin-bottom: 1rem; font-size: 0.9rem; }
#story-panel #story-text { line-height: 1.6; white-space: pre-wrap; }
