:root {
  --bg: #f4f1ea;
  --bg-2: #ece7dc;
  --ink: #2b2722;
  --ink-soft: #6f675c;
  --card: #fffdf9;
  --line: #e4ddcf;
  --green: #2faa5a;
  --green-d: #1f8a47;
  --accent: #c4452f;
  --shadow: 0 10px 30px rgba(60, 48, 30, .12);
  --radius: 30px;
  font-size: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 100% -10%, #faf6ee 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #efe9dd 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(244, 241, 234, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto;
  padding: 18px 26px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 16px; }
.brand-mark {
  width: 54px; height: 54px; border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--green), var(--green-d));
  color: #fff; box-shadow: 0 6px 16px rgba(31,138,71,.35);
}
.brand h1 { margin: 0; font-size: 1.7rem; letter-spacing: -.02em; font-weight: 800; }
.subtitle { margin: 2px 0 0; color: var(--ink-soft); font-size: 1rem; }

.edit-toggle {
  display: flex; align-items: center; gap: 10px;
  border: 2px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 1.1rem; font-weight: 700;
  padding: 14px 22px; border-radius: 999px; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .12s, background .2s, color .2s;
}
.edit-toggle:active { transform: scale(.96); }
.edit-toggle .pencil { font-size: 1.2rem; }
.edit-toggle.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Board ---------- */
.board { max-width: 1280px; margin: 0 auto; padding: 28px 26px 140px; }

.group { margin-bottom: 40px; }
.group-head {
  display: flex; align-items: center; gap: 14px; margin: 0 4px 18px;
}
.group-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.group-head h2 { margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em; }
.group-line { flex: 1; height: 2px; background: var(--line); border-radius: 2px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 26px;
}

/* ---------- Contact card ---------- */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 18px 22px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .14s ease, box-shadow .2s ease;
}
.card:active { transform: scale(.97); box-shadow: 0 6px 16px rgba(60,48,30,.14); }

.avatar-wrap { position: relative; width: 150px; height: 150px; margin: 0 auto 16px; }
.avatar {
  width: 100%; height: 100%; border-radius: 50%;
  object-fit: cover; background: var(--bg-2);
  border: 5px solid #fff;
  box-shadow: 0 8px 22px rgba(60,48,30,.18);
}
.avatar.initials {
  display: grid; place-items: center;
  font-size: 3.2rem; font-weight: 800; color: #fff;
}
.badge {
  position: absolute; right: 8px; bottom: 8px;
  width: 50px; height: 50px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--green), var(--green-d));
  color: #fff; border: 4px solid var(--card);
  box-shadow: 0 4px 12px rgba(31,138,71,.4);
}
.badge svg { width: 24px; height: 24px; }

.card-name { font-size: 1.3rem; font-weight: 800; margin: 0 0 2px; letter-spacing: -.01em; }
.card-action { font-size: 1.05rem; color: var(--green-d); font-weight: 700; }

.card .edit-pin {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--ink); color: #fff; border: none;
  display: none; place-items: center; font-size: 1.2rem; cursor: pointer;
  box-shadow: var(--shadow);
}
body.editing .card .edit-pin { display: grid; }
body.editing .card { animation: wobble 2.4s ease-in-out infinite; }
@keyframes wobble {
  0%,100% { transform: rotate(-.5deg); }
  50% { transform: rotate(.5deg); }
}

/* ---------- Empty ---------- */
.empty {
  text-align: center; padding: 80px 20px; color: var(--ink-soft);
}
.empty h3 { font-size: 1.5rem; color: var(--ink); margin: 0 0 10px; }
.empty .btn { margin-top: 18px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 28px; bottom: 28px; z-index: 30;
  width: 78px; height: 78px; border-radius: 50%;
  border: none; cursor: pointer; color: #fff;
  background: linear-gradient(150deg, var(--accent), #9c321f);
  box-shadow: 0 12px 28px rgba(196,69,47,.45);
  display: grid; place-items: center;
  transition: transform .14s;
}
.fab:active { transform: scale(.92); }

/* ---------- Overlay / sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(43, 39, 34, .5);
  backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
}
.sheet {
  width: min(560px, 100%); max-height: 92vh; overflow: auto;
  background: var(--card); border-radius: 28px;
  box-shadow: 0 30px 70px rgba(0,0,0,.3);
  animation: pop .2s ease;
}
@keyframes pop { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.sheet-head {
  position: sticky; top: 0; background: var(--card);
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 24px 14px; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 1.5rem; font-weight: 800; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: var(--bg-2); color: var(--ink);
  font-size: 1.2rem; cursor: pointer;
}
.sheet-body { padding: 22px 24px 26px; display: flex; flex-direction: column; gap: 20px; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-weight: 700; font-size: 1.05rem; }
.field input[type=text], .field select {
  font-size: 1.15rem; padding: 16px 16px; border-radius: 16px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
  width: 100%; -webkit-user-select: text; user-select: text;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--green); }

.segmented { display: flex; gap: 10px; }
.segmented button {
  flex: 1; padding: 15px 10px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; color: var(--ink-soft);
  font-size: 1.1rem; font-weight: 700; cursor: pointer; transition: .15s;
}
.segmented button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* photo picker */
.photo-field { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.photo-drop {
  width: 150px; height: 150px; border-radius: 50%;
  border: 3px dashed var(--line); background: var(--bg-2);
  display: grid; place-items: center; cursor: pointer; overflow: hidden; position: relative;
}
.photo-drop img { width: 100%; height: 100%; object-fit: cover; display: none; }
.photo-drop img.show { display: block; }
.photo-placeholder { color: var(--ink-soft); font-weight: 700; font-size: .95rem; text-align: center; }
.text-btn { background: none; border: none; color: var(--accent); font-weight: 700; cursor: pointer; font-size: 1rem; }

.sheet-actions { display: flex; gap: 12px; margin-top: 6px; }
.btn {
  flex: 1; padding: 17px; border-radius: 16px; border: none;
  font-size: 1.2rem; font-weight: 800; cursor: pointer; transition: transform .12s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(150deg, var(--green), var(--green-d)); color: #fff; }
.btn.danger { background: #fbe9e6; color: var(--accent); flex: 0 0 auto; padding-left: 26px; padding-right: 26px; }

/* relations list */
.rel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.rel-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px;
}
.rel-list .rdot { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.rel-list .rname { flex: 1; font-weight: 700; font-size: 1.1rem; }
.rel-list .rdel { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 1.3rem; }
.rel-add { display: flex; gap: 10px; margin-top: 18px; align-items: center; }
.rel-add input[type=text] { flex: 1; font-size: 1.1rem; padding: 14px; border-radius: 14px; border: 2px solid var(--line); -webkit-user-select: text; user-select: text; }
.rel-add input[type=color] { width: 54px; height: 54px; border: none; border-radius: 14px; background: none; cursor: pointer; }
.rel-add .btn { flex: 0 0 auto; padding: 14px 22px; font-size: 1.05rem; }

.manage-link { display: block; text-align: center; margin: 4px auto 0; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 16px 26px; border-radius: 999px;
  font-size: 1.1rem; font-weight: 700; z-index: 60; box-shadow: var(--shadow);
}
.hidden { display: none !important; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
  .avatar-wrap { width: 120px; height: 120px; }
}
