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

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --border: #e3e1d8;
  --text: #26251f;
  --muted: #8b897e;
  --accent: #2f5d50;
  --accent-dark: #234a3f;
  --line: #c2beb0;
  --danger: #a94442;
  --male: #9db4c9;
  --female: #c9a3ae;
  --other: #b8b6a4;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #f1efe9; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { background: var(--accent-dark); }

button.wide { width: 100%; }

button.linklike {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
button.linklike:hover { background: none; color: var(--accent-dark); }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ============ Language switch ============ */
.lang-switch {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.lang-switch button {
  border: none;
  border-radius: 0;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--muted);
}
.lang-switch button.active {
  background: var(--accent);
  color: #fff;
}
.lang-switch button:not(.active):hover { background: #f1efe9; color: var(--text); }

.login-lang {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
}

/* ============ Settings menu ============ */
.settings-wrap { position: relative; }
#settingsBtn { font-size: 15px; padding: 7px 11px; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 170px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(40, 38, 30, 0.14);
  z-index: 60;
}
.menu button {
  border: none;
  border-radius: 6px;
  text-align: left;
  padding: 8px 10px;
  font-size: 14px;
}

/* ============ Login ============ */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(40, 38, 30, 0.06);
}

.login-card .crest { font-size: 40px; margin-bottom: 12px; }

.login-card h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 24px;
  margin-bottom: 6px;
}

.login-card .sub { color: var(--muted); margin-bottom: 22px; }
.login-card input { margin-bottom: 12px; text-align: center; }

.error { color: var(--danger); margin-top: 14px; font-size: 14px; }

.shake { animation: shake 0.35s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ============ App layout ============ */
#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 600;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============ Canvas ============ */
#canvas {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
#canvas.panning { cursor: grabbing; }

#world {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

#lines { position: absolute; top: 0; left: 0; overflow: visible; }

#lines path, #lines line {
  stroke: var(--line);
  stroke-width: 1.5;
  fill: none;
}
#lines .distant { stroke-dasharray: 5 4; }
#lines line.divorced { stroke-dasharray: 6 4; }
#lines line.distant.divorced { stroke: #c4a5a3; }

/* Overlay layer (wedding rings etc.) — painted above the cards. */
#overlays {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}
#overlays .rings circle {
  stroke: #b08a3e;
  stroke-width: 1.5;
  fill: var(--surface);
}
#overlays .rings.divorced circle { stroke: var(--muted); }
#overlays .divorce-slash {
  stroke: var(--danger);
  stroke-width: 1.5;
}

#cards { position: absolute; top: 0; left: 0; }

.card {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--other);
  border-radius: 10px;
  padding: 9px 6px 6px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(40, 38, 30, 0.05);
  transition: box-shadow 0.15s, border-color 0.15s;
  /* no overflow:hidden — the chips sit on the card's edges */
}
.card:hover { box-shadow: 0 3px 10px rgba(40, 38, 30, 0.12); }
.card.m { border-top-color: var(--male); }
.card.f { border-top-color: var(--female); }
.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}
.card.deceased .name-first,
.card.deceased .name-last { color: #5c5a50; }

.card-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  text-align: center;
  min-width: 0;
}
.card-col .avatar { width: 44px; height: 44px; margin-bottom: 5px; }

.card .name-first,
.card .name-last {
  width: 100%;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .years {
  width: 100%;
  color: var(--muted);
  font-size: 10.5px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Avatars ============ */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.avatar.generic svg { width: 72%; height: 72%; margin-top: 12%; }
.avatar.generic.m { background: #e3ebf3; }
.avatar.generic.m svg { fill: #90a9c2; }
.avatar.generic.f { background: #f4e8ec; }
.avatar.generic.f svg { fill: #bd8e9c; }
.avatar.generic.o { background: #ecebdd; }
.avatar.generic.o svg { fill: #a3a189; }
.avatar.avatar-md { width: 44px; height: 44px; }
.avatar.avatar-lg { width: 84px; height: 84px; }

/* ============ Card chips ============ */
.collapse-chip, .quickadd-chip {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  z-index: 2;
}
.collapse-chip { top: -12px; }
.quickadd-chip { bottom: -12px; }
.collapse-chip:hover, .quickadd-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface);
}
.collapse-chip.collapsed {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.collapse-chip.collapsed:hover { background: var(--accent-dark); color: #fff; }

/* ============ Empty state ============ */
#emptyState {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text);
  font-size: 18px;
  pointer-events: none;
}
#emptyState .sub { color: var(--muted); font-size: 15px; }

/* ============ Zoom controls ============ */
.zoom-controls {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 6px;
  z-index: 10;
}
.zoom-controls button {
  min-width: 38px;
  padding: 7px 10px;
  box-shadow: 0 1px 4px rgba(40, 38, 30, 0.1);
}

/* Keep the zoom controls visible when the detail panel overlays the right edge. */
#app:has(#panel:not(.hidden)) .zoom-controls { right: 316px; }

/* ============ Detail panel ============ */
#panel {
  position: absolute;
  top: 61px;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  z-index: 15;
  box-shadow: -4px 0 18px rgba(40, 38, 30, 0.05);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.panel-id {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.panel-id-text { min-width: 0; }
.panel-head h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.nee {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  margin-top: 1px;
}
.panel-close {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--muted);
  padding: 0 4px;
  line-height: 1;
}
.panel-close:hover { background: none; color: var(--text); }

.panel-meta { color: var(--muted); font-size: 14px; margin-bottom: 12px; }

.panel-details {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  margin-bottom: 14px;
}
.panel-details p {
  font-size: 13.5px;
  margin: 3px 0;
  overflow-wrap: anywhere;
}
.panel-details p span {
  color: var(--muted);
  margin-right: 7px;
}

.panel-section { margin-bottom: 14px; }
.panel-section h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}
.panel-section .none { color: var(--muted); font-size: 13.5px; }

.rel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 0;
}
.rel-row .jump {
  border: none;
  background: none;
  padding: 2px 0;
  color: var(--text);
  text-align: left;
  flex: 1;
  overflow-wrap: anywhere;
}
.rel-row .jump:hover { background: none; color: var(--accent); text-decoration: underline; }
.rel-row .unlink {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 5px;
}
.rel-row .unlink:hover { background: none; color: var(--danger); }

.rel-row .divorce-toggle {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 15px;
  padding: 0 5px;
  line-height: 1;
}
.rel-row .divorce-toggle:hover { background: none; color: var(--accent); }

.divorced-tag {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

.panel-add-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0; }
.panel-add-btns button { font-size: 13.5px; padding: 6px 10px; }

.panel-footer {
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
button.danger { color: var(--danger); }
button.danger:hover { background: #f9eded; border-color: #dcbcbc; }

/* ============ Modal ============ */
#modalBackdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 28, 22, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

#modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 26px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 50px rgba(20, 18, 12, 0.25);
}

#modal h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 19px;
  font-weight: 600;
  margin-bottom: 18px;
  overflow-wrap: anywhere;
}

#modal label {
  display: block;
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 12px;
}
#modal label input, #modal label select { margin-top: 5px; }

#modal label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
}
#modal label.check input { width: auto; margin: 0; }

.row2 { display: flex; gap: 10px; }
.row2 label { flex: 1; min-width: 0; }

.field-label {
  display: block;
  font-size: 13.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.photo-block { margin-bottom: 12px; }
.photo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.photo-row button { font-size: 13.5px; padding: 6px 10px; }

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.quick-btn { padding: 10px 8px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.modal-alt {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.modal-note { color: var(--muted); font-size: 14px; margin-bottom: 14px; }

/* ============ Small screens ============ */
@media (max-width: 640px) {
  header { padding: 10px 12px; }
  #panel { top: auto; height: 55vh; width: 100%; max-width: none; border-top: 1px solid var(--border); }
  /* On small screens the panel is a bottom sheet covering the controls; hide them while it is open. */
  #app:has(#panel:not(.hidden)) .zoom-controls { display: none; }
}
