@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #faf6f2;
  --card: #ffffff;
  --ink: #2e2a27;
  --muted: #93887e;
  --accent: #c1666b;
  --accent-dark: #a24f55;
  --accent-light: #d98e88;
  --accent-soft: #f6e3e2;
  --gold: #cc9a52;
  --border: #ece2da;
  --shadow: 0 2px 10px rgba(46, 42, 39, 0.05), 0 1px 2px rgba(46, 42, 39, 0.04);
  --shadow-lg: 0 10px 30px rgba(46, 42, 39, 0.08);
  --radius: 16px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 0%, #fdf1ea 0%, transparent 45%),
    radial-gradient(circle at 100% 20%, #f7e6e3 0%, transparent 40%),
    var(--bg);
  min-height: 100vh;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Fraunces', Georgia, serif; letter-spacing: -0.01em; }

.wrap { max-width: 920px; margin: 0 auto; padding: 8px 20px 90px; }

header.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 28px 20px 8px; max-width: 920px; margin: 0 auto;
}
header.top h1 {
  font-size: 1.6rem; margin: 0; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
header.top .who { color: var(--muted); font-size: 0.88rem; }

nav.tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 14px 20px 22px;
  max-width: 920px; margin: 0 auto; -ms-overflow-style: none; scrollbar-width: none;
}
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  font-size: 0.88rem; font-weight: 500; transition: all 0.15s ease; box-shadow: var(--shadow);
}
nav.tabs button:hover { color: var(--ink); border-color: var(--accent); transform: translateY(-1px); }
nav.tabs button.active { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: white; border-color: var(--accent-dark); box-shadow: 0 4px 14px rgba(162, 79, 85, 0.35); }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}

/* ---------- Buttons (custom design system, no framework needed) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; cursor: pointer; font-family: inherit; font-weight: 600;
  font-size: 0.92rem; padding: 11px 20px; border-radius: 12px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  line-height: 1.2; white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  color: #fff; box-shadow: 0 3px 10px rgba(162, 79, 85, 0.3), 0 1px 2px rgba(162,79,85,0.2);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 6px 18px rgba(162, 79, 85, 0.4); transform: translateY(-1px); }

.btn-ghost {
  background: #fff; border: 1.5px solid var(--border); color: var(--muted);
  box-shadow: var(--shadow);
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-dark); }

.btn-danger {
  background: #fff; border: 1.5px solid #e6c6c6; color: #b3474f;
}
.btn-danger:hover:not(:disabled) { background: #b3474f; border-color: #b3474f; color: #fff; }

.btn-sm { padding: 7px 13px; font-size: 0.8rem; border-radius: 9px; }
.danger-text { color: #b3474f; border-color: #e6c6c6; }
.file-btn { cursor: pointer; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }

/* legacy aliases so nothing old ever breaks */
button.primary { }
button.ghost { }

/* ---------- Forms ---------- */
.grid-photos {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px;
}
.grid-photos img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; cursor: pointer;
  display: block; transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.grid-photos img:hover { transform: scale(1.03); box-shadow: var(--shadow-lg); }
.grid-photos figure { margin: 0; position: relative; }
.grid-photos figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px 5px; border-radius: 0 0 12px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent); color: #fff; font-size: 0.72rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}

input, textarea, select {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  font-size: 0.95rem; margin-bottom: 12px; font-family: inherit; background: #fdfbf9; color: var(--ink);
  transition: border-color 0.15s ease, background 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); background: white;
}
label { font-size: 0.8rem; font-weight: 500; color: var(--muted); display: block; margin-bottom: 6px; letter-spacing: 0.01em; text-transform: uppercase; }
.check-label { text-transform: none; display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.check-label input { width: auto; margin: 0; }

/* ---------- Toolbars (search / sort / filter) ---------- */
.toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: 0 0 14px;
}
.toolbar input[type="search"] { flex: 1 1 220px; margin-bottom: 0; }
.toolbar select { flex: 0 1 180px; margin-bottom: 0; }

.zoom-control { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.zoom-control button {
  border: none; background: transparent; color: var(--muted); padding: 9px 14px; cursor: pointer;
  font-size: 0.82rem; font-weight: 600; font-family: inherit; border-right: 1px solid var(--border);
}
.zoom-control button:last-child { border-right: none; }
.zoom-control button.active { background: var(--accent-soft); color: var(--accent-dark); }
.zoom-control button:hover:not(.active) { background: #f8f3ef; }

/* ---------- Photo attach widget ---------- */
.photo-attach { margin-bottom: 14px; }
.photo-attach-preview {
  width: 100px; height: 100px; border-radius: 12px; border: 2px dashed var(--border); background: #fdfbf9;
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px; overflow: hidden;
}
.photo-attach-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-attach-preview .ph-empty { color: var(--muted); font-size: 0.72rem; text-align: center; padding: 6px; }
.photo-attach-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Timeline ---------- */
.timeline-group-header { color: var(--accent-dark); font-family: 'Fraunces', serif; font-size: 1.05rem; font-weight: 600; margin: 26px 0 12px; padding-left: 4px; }
.timeline-group-header:first-child { margin-top: 4px; }
.timeline-rail { position: relative; padding-left: 18px; border-left: 2px solid var(--accent-soft); }
.timeline-item { display: flex; gap: 16px; margin-bottom: 18px; position: relative; }
.timeline-item::before {
  content: ''; position: absolute; left: -25px; top: 6px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 2px var(--accent-soft);
}
.timeline-item.activity::before { background: var(--muted); box-shadow: 0 0 0 2px #efe9e3; }
.timeline-item .date {
  width: 78px; flex-shrink: 0; color: var(--accent-dark); font-weight: 600; font-size: 0.78rem; padding-top: 3px;
}
.timeline-item .content { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.timeline-item.activity .content { background: #fdfbf9; box-shadow: none; }
.timeline-item img { width: 100%; max-width: 240px; border-radius: 10px; margin-top: 10px; display: block; cursor: pointer; }
.timeline-item .kind-tag { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.timeline-item .item-actions { margin-top: 8px; display: flex; gap: 8px; }

/* ---------- Stories ---------- */
.story h3 { margin: 0 0 6px; font-size: 1.3rem; }
.story .meta { color: var(--muted); font-size: 0.78rem; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.story .body { white-space: pre-wrap; line-height: 1.65; }
.story .item-actions { margin-top: 14px; display: flex; gap: 8px; }

/* ---------- Moments ---------- */
.moment { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.moment img { width: 60px; height: 60px; object-fit: cover; border-radius: 10px; flex-shrink: 0; cursor: pointer; }
.moment .meta { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }
.moment .mood-badge { display: inline-block; background: var(--accent-soft); color: var(--accent-dark); font-size: 0.72rem; padding: 2px 9px; border-radius: 999px; margin-bottom: 4px; font-weight: 600; }
.moment .item-actions { margin-top: 8px; display: flex; gap: 8px; }

/* ---------- Family tree diagram ---------- */
.tree-hint { color: var(--muted); font-size: 0.85rem; text-align: center; margin: 0 0 18px; }
.tree-card { overflow-x: auto; }
.tree-diagram { position: relative; min-width: 560px; padding: 10px 10px 40px; }
.tree-diagram svg { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }
.tree-columns { display: flex; gap: 40px; justify-content: center; position: relative; z-index: 1; }
.tree-column { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 22px; min-width: 220px; }
.tree-column-title { font-family: 'Fraunces', serif; color: var(--accent-dark); font-size: 1.05rem; font-weight: 600; }
.tree-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; width: 100%; }
.tree-node {
  background: var(--card); border: 1.5px solid var(--border); border-radius: 14px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.15s ease, border-color 0.15s ease; min-width: 140px;
}
.tree-node:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent-light); }
.tree-node.dimmed { opacity: 0.32; }
.tree-node.matched { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tree-node img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--accent-soft); border: 2px solid var(--accent-soft); flex-shrink: 0; }
.tree-node .ph-fallback { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; }
.tree-node .name { font-weight: 600; font-size: 0.9rem; }
.tree-node .relation { color: var(--muted); font-size: 0.74rem; }
.tree-node.self-node { background: linear-gradient(135deg, var(--accent-soft), #fff); border-color: var(--accent-light); }
.tree-union {
  margin: 26px auto 0; width: fit-content; display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #fff;
  padding: 14px 26px; border-radius: 999px; box-shadow: 0 8px 24px rgba(162,79,85,0.35);
  font-family: 'Fraunces', serif; font-size: 1.1rem; font-weight: 600; position: relative; z-index: 1;
}
.tree-empty-side { color: var(--muted); font-style: italic; font-size: 0.85rem; padding: 10px 0; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 16, 14, 0.85); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal-backdrop img.plain { max-width: 100%; max-height: 90vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.4); }
.modal-box {
  background: var(--card); border-radius: var(--radius); padding: 22px; max-width: 480px; width: 100%;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.picker-grid { max-height: 340px; overflow-y: auto; margin-top: 4px; }
.photo-modal-box img { width: 100%; max-height: 320px; object-fit: cover; border-radius: 12px; margin-bottom: 14px; }

.empty { color: var(--muted); font-style: italic; padding: 30px 0; text-align: center; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card { max-width: 380px; width: 100%; text-align: center; padding: 40px 32px; box-shadow: var(--shadow-lg); }
.login-card h1 { margin-bottom: 6px; font-size: 2rem; }
.login-card p.sub { color: var(--muted); margin-top: 0; margin-bottom: 26px; font-size: 0.92rem; }
.error-msg { color: var(--accent-dark); font-size: 0.85rem; margin-bottom: 12px; min-height: 1.2em; font-weight: 500; }

@media (max-width: 640px) {
  .tree-columns { flex-direction: column; align-items: stretch; }
  .tree-diagram { min-width: 0; }
}
