:root {
  --bg: #0a0a0a;
  --bg-raise: #161616;
  --pill: #222222;
  --pill-active: #2e2e2e;
  --lav: #ffffff;
  --lav-dim: #6e6e6e;
  --text: #f3f3f3;
  --muted: #8a8a8a;
  --line: #2a2a2a;
  --danger: #e57373;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  overflow: hidden;
}
#app { display: flex; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 300px; min-width: 300px;
  padding: 28px 22px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}
#sidebar h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
#sidebar .sub { color: var(--muted); font-size: 13px; margin: 8px 0 18px; }

.searchbox { position: relative; }
#search {
  width: 100%; padding: 10px 12px;
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none;
}
#search:focus { border-color: var(--lav-dim); }
#search { padding-right: 44px; }
#mic {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; background: none; border-radius: 50%;
  color: #ffffff; cursor: pointer;
}
#mic:hover { background: var(--pill); }
#mic.rec { background: var(--danger); animation: mic-pulse 1.1s ease-in-out infinite; }
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 80, 80, .45); }
  50% { box-shadow: 0 0 0 8px rgba(255, 80, 80, 0); }
}
.update {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  background: #ffffff; color: #111111; font-weight: 600; font-size: 14px;
  border: none; border-radius: 0 0 14px 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .5);
  animation: update-in .35s cubic-bezier(.32, .72, .33, 1);
}
@keyframes update-in {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

.ai-summary {
  padding: 8px 8px 10px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line); margin-bottom: 6px;
}
.results .r-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.results .r-body .r-name { flex: none; }
.results .r-reason {
  font-size: 11.5px; color: var(--muted);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

#add-btn { width: 100%; margin-top: 10px; }
button {
  font: inherit; cursor: pointer;
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px;
}
button:hover { border-color: var(--lav-dim); }
button.primary { background: #ffffff; border-color: #ffffff; color: #111111; font-weight: 600; }
button.primary:hover { filter: brightness(0.88); }
button.danger { color: var(--danger); }
button.linklike { background: none; border: none; padding: 0; color: var(--lav-dim); font-size: 12px; }
button.linklike:hover { color: var(--lav); }

.results { margin-top: 14px; }
.results .r-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
}
.results .r-item:hover { background: var(--bg-raise); }
.results .r-ava {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--pill) center/cover;
  flex: none;
}
.results .r-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-score { color: var(--lav-dim); font-size: 11px; }

/* ---------- stage ---------- */
#stage { flex: 1; position: relative; }
#graph { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* floating add button (mobile) */
#fab {
  display: none;
  position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 48px; height: 48px; border-radius: 50%;
  align-items: center; justify-content: center; padding: 0;
  background: var(--bg-raise); color: var(--text); border: 1px solid var(--line);
  font-size: 26px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
/* ---------- avatar cropper ---------- */
#crop-stage {
  position: relative; width: 100%; max-width: 320px; aspect-ratio: 1;
  margin: 4px auto 14px; border-radius: 12px; overflow: hidden;
  background: #000; touch-action: none;
}
#crop-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#crop-frame {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .5);
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85);
}
#crop-zoom { width: 100%; max-width: 320px; display: block; margin: 0 auto 6px; }

/* floating refresh button — bottom-left, always visible */
#refresh {
  position: fixed; left: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; padding: 0;
  background: var(--bg-raise); color: var(--text); border: 1px solid var(--line);
  font-size: 22px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  transition: transform .15s;
}
#refresh:active { transform: scale(0.94); }
#refresh.spinning { animation: refresh-spin .8s linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
.empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--muted); text-align: center; pointer-events: none;
}
.empty .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--lav); opacity: .7; }

/* ---------- detail panel ---------- */
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; width: 340px;
  background: var(--bg-raise); border-left: 1px solid var(--line);
  padding: 28px 24px; overflow-y: auto; z-index: 20;
  transform: translateX(105%);
  transition: transform .32s cubic-bezier(.32, .72, .33, 1);
}
.detail.open { transform: translate(0, 0); }
.detail .close {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; color: var(--muted); font-size: 22px; padding: 4px 8px;
}
.d-photo {
  width: 96px; height: 96px; border-radius: 50%;
  background: var(--pill) center/cover;
  margin-bottom: 14px;
  display: flex; align-items: center; justify-content: center;
  color: var(--lav); font-size: 34px; font-weight: 600;
  border: none; padding: 0; cursor: pointer; font-family: inherit;
  transition: filter .15s;
}
.d-photo:hover { filter: brightness(1.15); }
.d-photo:active { filter: brightness(0.9); }
.detail h2 { font-size: 19px; margin-bottom: 14px; }
.d-block { margin-bottom: 16px; }
.d-block h3 {
  font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .08em; margin-bottom: 5px;
}
.d-block p { white-space: pre-wrap; }
#d-reach a {
  display: block; color: var(--lav); text-decoration: none; margin-bottom: 4px;
  font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#d-reach a:hover { text-decoration: underline; }
.d-actions { display: flex; gap: 10px; margin-top: 22px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(5, 4, 8, .7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  position: relative;
  width: 460px; max-width: calc(100vw - 32px); max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: 16px;
  padding: 26px;
}
.modal-card .close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none; color: var(--muted); font-size: 24px; padding: 4px 10px;
}

/* wizard steps: one field at a time */
#steps .step { display: none; }
#steps .step.active { display: block; }
.dots { display: flex; gap: 7px; justify-content: center; margin: 6px 0 16px; }
.dots .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--pill-active); }
.dots .dot.on { background: var(--lav); }
input.invalid, textarea.invalid { border-color: var(--danger) !important; }

/* summary step */
.sum-hint { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.sum-row {
  display: flex; gap: 12px; align-items: baseline;
  padding: 13px 10px; cursor: pointer;
  border-bottom: 1px solid var(--line); border-radius: 8px;
}
.sum-row:hover { background: var(--bg); }
.sum-label { color: var(--muted); font-size: 13px; width: 80px; flex: none; }
.sum-val { flex: 1; white-space: pre-wrap; word-break: break-word; }
.sum-val.empty { color: var(--lav-dim); font-style: italic; }
.modal-card.narrow { width: 320px; }
.modal-card h2 { font-size: 17px; margin-bottom: 16px; }
.modal-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.modal-card .hint { font-size: 11px; color: var(--lav-dim); }
.modal-card input, .modal-card textarea {
  width: 100%; margin-top: 4px; padding: 8px 10px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; outline: none; resize: vertical;
}
.modal-card input:focus, .modal-card textarea:focus { border-color: var(--lav-dim); }
/* the person's name is the headline field: ~20% larger and centered */
.modal-card input[name="name"] { font-size: 17px; text-align: center; }
.modal-card input[type=file] { border: none; padding-left: 0; background: none; }
.row2 { display: flex; gap: 10px; }
.row2 label { flex: 1; }
.m-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.err { color: var(--danger); font-size: 13px; margin-bottom: 8px; }

/* ---------- login screen: solid black, edge to edge ---------- */
#login {
  background: #000000;
  backdrop-filter: none;
  inset: 0; top: 0; left: 0; right: 0; bottom: 0; height: auto;
  align-items: center; justify-content: center;
}
#login .modal-card {
  width: 100%; max-width: 340px; height: auto; max-height: none;
  background: transparent; border: none; border-radius: 0; box-shadow: none;
  padding: 24px; display: block;
}

.hidden { display: none !important; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #app { flex-direction: column; }

  /* sidebar becomes a slim top bar: just the search */
  #sidebar {
    width: 100%; min-width: 0;
    /* top inset keeps the search below the iPhone status bar / notch in standalone PWA mode */
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    border-right: none; border-bottom: 1px solid var(--line);
    overflow: visible;
  }
  #sidebar h1, #sidebar .sub, #add-btn { display: none; }
  #search { padding: 12px 14px; font-size: 16px; }
  .results { max-height: 40vh; overflow-y: auto; }

  #fab { display: flex; }

  /* detail panel drops down from the top like a popup */
  .detail {
    bottom: auto; left: 0; width: 100%; max-height: 78vh;
    border-left: none; border-bottom: 1px solid var(--line);
    border-radius: 0 0 18px 18px;
    padding: calc(18px + env(safe-area-inset-top)) 18px 24px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    transform: translateY(-105%);
  }
  .detail .close { top: calc(14px + env(safe-area-inset-top)); }
  .d-photo { width: 76px; height: 76px; font-size: 28px; }
  .d-actions button { flex: 1; padding: 13px 14px; }

  /* add / edit form drops down from the top like the detail popup */
  .modal { align-items: flex-start; justify-content: center; }
  .modal-card {
    width: 100%; max-width: 100%; height: auto; max-height: 88vh;
    border: none; border-radius: 0 0 18px 18px;
    padding: calc(18px + env(safe-area-inset-top)) 18px 22px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    transform: translateY(-105%);
    transition: transform .32s cubic-bezier(.32, .72, .33, 1);
    display: flex; flex-direction: column; overflow-y: auto;
  }
  .modal.open .modal-card { transform: translateY(0); }
  .modal-card .close { top: calc(10px + env(safe-area-inset-top)); }
  .modal-card form { display: flex; flex-direction: column; }
  /* 16px inputs stop iOS from auto-zooming on focus */
  .modal-card input, .modal-card textarea { font-size: 16px; padding: 12px; }
  .modal-card label { font-size: 14px; margin-bottom: 14px; }
  /* the person's name is the headline field: bigger and centered */
  .modal-card input[name="name"] { font-size: 19px; text-align: center; }
  .m-actions { gap: 12px; margin-top: 10px; }
  .m-actions button { flex: 1; padding: 13px 14px; }
}
