:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #2b2621;
  --text-muted: #6b6258;
  --border: #e4ddd3;
  --accent: #5b7553;
  --accent-contrast: #ffffff;
  --danger: #a8402f;
  --radius: 10px;
  --max-width: 640px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

h1 { font-size: 1.6rem; margin: 0.6rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }

a { color: var(--accent); }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

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

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  font-size: 1.1rem;
}

/* --- side menu (pure CSS, no JS: checkbox-driven slide-out) --- */

.menu-toggle-input { display: none; }

.menu-button {
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.2rem 0.3rem;
}

.menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 90;
}

.side-menu {
  position: fixed;
  top: 0;
  left: -280px;
  width: 260px;
  max-width: 80vw;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 6px 0 16px rgba(0, 0, 0, 0.12);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 100;
  transition: left 0.2s ease;
}

.menu-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 0.65rem 0.25rem;
  flex-shrink: 0;
}

.side-menu a {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.6rem 0.65rem;
  border-radius: 8px;
}

.side-menu a:hover,
.side-menu a:active {
  background: var(--bg);
}

.menu-icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-close {
  align-self: flex-end;
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

/* --- edit-mode switch (looks like a toggle, not a nav link) --- */

.switch-row-label { flex: 1; }

.switch {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: left 0.15s ease;
}

.switch-on { background: var(--accent); }
.switch-on .switch-thumb { left: 22px; }


.menu-toggle-input:checked ~ .menu-overlay { display: block; }
.menu-toggle-input:checked ~ .side-menu { left: 0; }

.site-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 2rem 1rem;
}

.breadcrumb { margin-bottom: 0.5rem; }
.breadcrumb a { text-decoration: none; }

.hint { color: var(--text-muted); }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* --- person list --- */

.person-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.person-item + .person-item { border-top: 1px solid var(--border); }

.person-item {
  display: flex;
  align-items: center;
}

.generation-group { margin-bottom: 1.25rem; }

.person-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.person-link:active { background: var(--bg); }

.avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border);
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
}

.avatar-large {
  width: 7rem;
  height: 7rem;
  font-size: 2.2rem;
  margin-bottom: 0.75rem;
}

.person-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.person-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person-dates { color: var(--text-muted); font-size: 0.9rem; }

.chevron { color: var(--text-muted); font-size: 1.5rem; }

/* --- person detail --- */

.person-detail { text-align: center; }

.photo-large-link { display: inline-block; cursor: zoom-in; }

.photo-large {
  width: 9rem;
  height: 9rem;
  object-fit: cover;
  border-radius: 50%;
  margin-bottom: 0.75rem;
}

.photo-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
  z-index: 1000;
}

.photo-lightbox:target { display: flex; }

.photo-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 0;
  margin: 0;
}

.dates, .parents, .notes { color: var(--text-muted); }
.notes { text-align: left; margin-top: 1rem; white-space: pre-wrap; }

/* --- forms & buttons --- */

form { display: flex; flex-direction: column; gap: 0.9rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 0.95rem;
}

label.checkbox {
  flex-direction: row;
  align-items: center;
  font-weight: normal;
}

input[type="text"],
input[type="date"],
input[type="file"],
select,
textarea {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

textarea { resize: vertical; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.person-detail .actions { justify-content: center; }
form.actions { flex-direction: row; }

.button {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  min-height: 2.75rem;
}

.button-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.button-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }

.form-errors {
  background: #fbeceb;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  margin: 0 0 1rem;
}

.notice {
  background: #eef3ec;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.token-link {
  word-break: break-all;
  background: var(--surface);
  padding: 0.5rem;
  border-radius: 6px;
}

.token-list { list-style: none; margin: 0; padding: 0; }
.token-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
}
.token-meta { min-width: 0; }

.unlink-form { padding: 0 0.85rem; flex-shrink: 0; }
.button-unlink {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.5rem 0;
}
.button-unlink:hover { color: var(--danger); }

/* --- person picker (search-and-link widget) --- */

.person-picker {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.picker-form { gap: 0.6rem; }
.picker-label { position: relative; }

.picker-results {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  max-height: 12rem;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.picker-result {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-weight: normal;
}
.picker-result + .picker-result { border-top: 1px solid var(--border); }
.picker-result-highlighted, .picker-result:hover { background: var(--bg); }

.picker-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- chat / log feed --- */

.name-form {
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.name-form label { font-size: 0.9rem; }

.chat-form { margin-bottom: 1.5rem; }
.chat-form textarea { resize: vertical; }

.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.log-entry {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.log-entry-system {
  background: transparent;
  border-style: dashed;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.log-entry-system .log-meta { display: inline; }
.log-entry-system .log-message { display: inline; }

.log-entry-chat .log-message { white-space: pre-wrap; margin-top: 0.2rem; }

.log-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.log-entry-chat .log-meta strong { color: var(--text); }

/* --- family tree diagram --- */

main.main-wide {
  max-width: none;
  padding: 1rem 0.75rem 4rem;
}

.tree-scroll {
  overflow: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.tree-couple-bar,
.tree-drop,
.tree-bus,
.tree-child-drop {
  stroke: var(--border);
  stroke-width: 2;
}

.tree-node {
  cursor: pointer;
}

.tree-avatar-placeholder {
  fill: var(--accent);
}

.tree-avatar-initial {
  fill: var(--accent-contrast);
  font-weight: 600;
  font-size: 20px;
  text-anchor: middle;
}

.tree-name {
  fill: var(--text);
  font-weight: 600;
  font-size: 13px;
  text-anchor: middle;
}

.tree-year {
  fill: var(--text-muted);
  font-size: 12px;
  text-anchor: middle;
}

.tree-node image {
  clip-path: url(#avatarClip);
}

@media (min-width: 600px) {
  body { font-size: 17px; }
  .person-form, .token-form { max-width: 420px; }
}
