:root {
  --bg: #f0e8d8;
  --card: #fffdf8;
  --text: #2a1f12;
  --muted: #7a6450;
  --accent: #9b3520;
  --accent-dark: #7a2a18;
  --accent-soft: #f2e8e0;
  --gold: #b8893a;
  --gold-soft: #fdf4e4;
  --gold-border: #e0c88a;
  --line: #e2d0b8;
  --shadow: rgba(70, 40, 10, 0.10);
  --male-bar: linear-gradient(90deg, #5a82a0, #7aaac8);
  --female-bar: linear-gradient(90deg, #a06080, #c090a8);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 25% 0%, #fff8ea 0%, transparent 55%),
    radial-gradient(ellipse at 75% 100%, #e4d0b8 0%, transparent 55%);
  color: var(--text);
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 14px 100px;
}

/* ── Topbar ── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.topbar-title {
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.12em;
  color: var(--accent);
  flex-shrink: 0;
  white-space: nowrap;
}

#searchInput {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 16px;
  background: var(--card);
  font: inherit;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#searchInput:focus {
  border-color: var(--gold);
}

/* ── Card ── */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px 16px;
  margin-bottom: 12px;
  box-shadow: 0 3px 14px var(--shadow);
}

/* ── Person Card ── */

.person-card {
  padding: 0;
  overflow: hidden;
}

.person-card-header {
  background: linear-gradient(145deg, var(--accent-dark) 0%, var(--accent) 55%, #c0522e 100%);
  padding: 22px 20px 18px;
  position: relative;
}

/* subtle texture lines */
.person-card-header::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 12px,
    rgba(255, 255, 255, 0.03) 12px,
    rgba(255, 255, 255, 0.03) 13px
  );
  pointer-events: none;
}

.person-gen-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.person-gen-badge {
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 2px 10px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.90);
  letter-spacing: 0.06em;
}

.person-char-badge {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.70);
  letter-spacing: 0.05em;
}

.person-name {
  font-size: 42px;
  line-height: 1.1;
  margin: 0 0 12px;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 1;
}

.person-id-badge {
  font-family: "Courier New", "SF Mono", monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.08em;
  position: relative;
  z-index: 1;
}

.person-card-body {
  padding: 16px 20px 18px;
}

.person-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.6;
}

.person-branch {
  display: inline-block;
  font-size: 12px;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 8px;
  padding: 3px 10px;
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}

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

.btn-ghost {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 7px 16px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-ghost:active {
  background: var(--accent-soft);
  border-color: #c8a080;
}

.data-status {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  letter-spacing: 0.04em;
  margin-left: auto;
}

.data-status.ocr {
  background: #f0ede8;
  color: #9a8878;
}

.data-status.reviewed {
  background: #e8f2e8;
  color: #507850;
}

.data-status.verified {
  background: #e8eef6;
  color: #486898;
}

/* ── Family Grid ── */

.family-card-section {
  padding: 16px;
}

.family-section {
  margin-bottom: 18px;
}

.family-section:last-child {
  margin-bottom: 4px;
}

.family-section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.15em;
  margin-bottom: 10px;
}

.family-section-title::before,
.family-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

.family-section-title::before {
  max-width: 14px;
}

.family-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.family-group.cols-3 {
  grid-template-columns: repeat(3, 1fr);
}

.family-card {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px 10px;
  background: #fff;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  font: inherit;
  color: var(--text);
  transition: box-shadow 0.15s, transform 0.12s;
  box-shadow: 0 1px 4px rgba(80, 40, 10, 0.06);
}

.family-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--line);
}

.family-card.male::before {
  background: var(--male-bar);
}

.family-card.female::before {
  background: var(--female-bar);
}

.family-card:active {
  transform: scale(0.97);
  box-shadow: none;
}

.rel-label {
  display: inline-block;
  font-size: 11px;
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 5px;
  padding: 1px 6px;
  margin-bottom: 5px;
  letter-spacing: 0.04em;
}

.family-card-name {
  font-size: 20px;
  font-weight: 400;
  line-height: 1.2;
  margin: 0 0 5px;
  color: var(--text);
}

.family-card-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.family-empty {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  padding: 12px;
  font-style: italic;
}

/* ── Search ── */

.search-hint {
  font-size: 14px;
  margin: 0 0 10px;
}

.search-results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.search-results li {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.search-results button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  padding: 12px 14px 6px;
  font: inherit;
  font-size: 18px;
  border: none;
  cursor: pointer;
}

.search-meta {
  padding: 0 14px 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

/* ── Contribution Section ── */

.contrib-section {
  text-align: center;
}

.contrib-prompt {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 12px;
}

.contrib-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.contrib-btn {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px 18px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.contrib-btn:active,
.contrib-btn.active {
  background: var(--accent-soft);
  border-color: #c09870;
  color: var(--text);
}

.contrib-form-area {
  display: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  text-align: left;
}

.contrib-form-area.visible {
  display: block;
}

.contrib-form {
  display: grid;
  gap: 10px;
}

.contrib-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  resize: vertical;
  outline: none;
}

.contrib-form textarea:focus {
  border-color: var(--gold);
}

.btn-primary {
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  padding: 12px 20px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:active {
  background: var(--accent-dark);
}

.form-msg {
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* ── Tab Bar ── */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border-top: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 8px 6px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  gap: 2px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  padding: 6px 4px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  letter-spacing: 0.04em;
}

.tab-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* ── Utilities ── */

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

/* ── Responsive ── */

@media (min-width: 580px) {
  .app {
    padding-top: 28px;
  }

  .person-name {
    font-size: 48px;
  }
}
