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

:root {
  --green: #2f6f4f;
  --green-dark: #245840;
  --green-light: #eaf4ee;
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #26302b;
  --muted: #6b756f;
  --line: #b8c9be;
  --danger: #b23b3b;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 50, 40, 0.10);
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--green);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-size: 1.15rem; font-weight: 700; }
.auth-area { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; margin-left: auto; }
.auth-email { opacity: 0.9; max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lang-btn, .icon-btn {
  background: rgba(255,255,255,0.18);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  margin-left: 8px;
  white-space: nowrap;
}
.icon-btn { position: relative; font-size: 0.95rem; padding: 6px 9px; }
.badge {
  position: absolute;
  top: -5px; right: -5px;
  background: #d84545;
  color: #fff;
  border-radius: 999px;
  font-size: 0.62rem;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  padding: 0 3px;
}
.no-card-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fdf6e3;
  border: 1px solid #e8d9a8;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 16px 0;
  font-size: 0.9rem;
}
.conn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid #f0efe9;
}
.conn-row:last-child { border-bottom: none; }
.conn-x {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 8px;
}
.conn-add { text-align: left; margin-top: 6px; }
.rel-pick { display: flex; gap: 6px; margin-top: 6px; }
.rel-pick select { margin-top: 0; min-width: 0; flex: 1; }
.panel-item {
  padding: 10px 0;
  border-bottom: 1px solid #ecebe6;
  font-size: 0.92rem;
}
.panel-item:last-of-type { border-bottom: none; }
.prop-actions { display: flex; gap: 8px; margin-top: 8px; }
.hist-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.8rem;
}
@media (max-width: 480px) {
  .auth-email { display: none; }
}

main { flex: 1; display: flex; flex-direction: column; }

/* Welcome / add-yourself */
.welcome {
  max-width: 420px;
  margin: 8vh auto 0;
  padding: 24px 16px;
  text-align: center;
}
.welcome .big { font-size: 3rem; }
.welcome h1 { margin: 8px 0 6px; font-size: 1.5rem; }
.welcome p { color: var(--muted); margin-bottom: 20px; }
.welcome form { text-align: left; background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.welcome .login-hint { margin-top: 18px; font-size: 0.9rem; }
.invite-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin: 0 0 18px;
}
.invite-card .avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--green);
  color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.invite-card .p-name { font-weight: 600; }
.invite-card .p-birth { color: var(--muted); font-size: 0.85rem; word-break: break-all; }

/* Tree */
.tree-wrap {
  flex: 1;
  overflow: auto;
  padding: 16px 0 90px;
  -webkit-overflow-scrolling: touch;
}
.tree-inner {
  position: relative;
  width: max-content;
  min-width: 100%;
  padding: 8px 24px;
}
.tree-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
.gen-row {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-bottom: 56px;
  position: relative;
  z-index: 1;
}
.gen-row:last-child { margin-bottom: 12px; }

.person-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  min-width: 130px;
  max-width: 170px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.1s;
  text-align: center;
}
.person-card:active { transform: scale(0.97); }
.person-card.self { border-color: var(--green); background: var(--green-light); }
.person-card .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 8px;
  font-size: 1.05rem;
}
.person-card .p-name { font-weight: 600; font-size: 0.95rem; word-break: break-word; }
.person-card .p-rel { color: var(--green); font-size: 0.75rem; font-weight: 600; margin-top: 2px; }
.person-card .p-birth { color: var(--muted); font-size: 0.8rem; margin-top: 3px; }
.avatar.g-f { background: #b0567c !important; }
.avatar.g-m { background: #4a6f9e !important; }
.person-card.deceased { background: #f1efe9; }
.person-card.deceased .avatar { filter: grayscale(0.7) opacity(0.75); }
.person-card.deceased .p-name { color: #5a6059; }
.rel-detail { color: var(--green) !important; font-weight: 600; }
.person-card .p-you {
  display: inline-block;
  background: var(--green);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.secondary { background: #e7e9e6; color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 8px 14px; font-size: 0.85rem; }
.btn.ghost { background: rgba(255,255,255,0.18); color: #fff; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; }
.link-btn {
  background: none; border: none;
  color: var(--green);
  font-size: 0.9rem;
  margin-top: 14px;
  cursor: pointer;
  text-decoration: underline;
  display: block;
  width: 100%;
}

/* Forms */
label { display: block; margin-bottom: 14px; font-size: 0.9rem; font-weight: 600; }
input[type="text"], input[type="email"], input[type="date"], select {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1.5px solid #d5dbd6;
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  appearance: none;
  -webkit-appearance: none;
  min-height: 46px;
}
input:focus, select:focus { outline: none; border-color: var(--green); }
.date-select { display: flex; gap: 6px; margin-top: 6px; }
.date-select select {
  margin-top: 0;
  padding: 12px 6px;
  min-width: 0;
}
.date-select .ds-d { flex: 0 0 24%; }
.date-select .ds-m { flex: 1 1 auto; }
.date-select .ds-y { flex: 0 0 30%; }
.muted { color: var(--muted); font-weight: 400; }
.code-input {
  width: 100%;
  text-align: center;
  font-size: 1.8rem;
  letter-spacing: 10px;
  padding: 12px;
  border: 1.5px solid #d5dbd6;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.code-input:focus { outline: none; border-color: var(--green); }

/* Overlays, modal, sheet */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 25, 0.45);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.hidden { display: none !important; }
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal-x {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
  z-index: 1;
}
.modal-x:hover { color: var(--text); }
.modal h2 { margin-bottom: 8px; font-size: 1.2rem; }
.modal p { margin-bottom: 14px; }

#sheetOverlay { align-items: flex-end; padding: 0; }
.sheet {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}
.sheet .sheet-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.sheet .avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--green);
  color: #fff; font-weight: 700; font-size: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sheet h2 { font-size: 1.2rem; }
.sheet .detail { color: var(--muted); font-size: 0.9rem; margin: 2px 0; word-break: break-all; }
.sheet .section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 16px 0 8px;
}
.sheet .action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sheet .action-grid .btn { padding: 12px 6px; font-size: 0.85rem; }
.sheet .edit-row { display: flex; gap: 8px; margin-top: 10px; }
.sheet .edit-row .btn { flex: 1; }

/* Floating add hint + toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #26302b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}
.toast.error { background: var(--danger); }

.tree-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 10px 16px 0;
}
