/* Profile name font: Onest (Medium/500) — a free, Cyrillic-capable geometric
   grotesque close to TT Norms Pro, loaded from Google Fonts (see the <link> in
   index.html), so there's no font file to ship. Swappable free lookalikes with
   Cyrillic: Manrope, Golos Text. */
: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; }
/* white text caret everywhere (default browser blue looks off on the dark UI);
   inputs that deliberately hide the caret keep their own `caret-color: transparent`
   via more specific rules below */
input, textarea { caret-color: #ffffff; }
/* placeholder eases out when the field is focused (tapped), instead of only
   vanishing once you start typing */
input::placeholder, textarea::placeholder { opacity: 1; transition: opacity .22s ease; }
input:focus::placeholder, textarea:focus::placeholder { opacity: 0; }
/* stop iOS Safari from auto-inflating text in wide blocks (e.g. the update
   banner rendered with a huge font on some iPhones) */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
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; padding-right: 44px;
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: 14px; line-height: 1.4; outline: none;
  /* grows with dictated text (auto-sized in JS), scrolls past a cap */
  display: block; resize: none; overflow-y: auto; max-height: 40vh;
}
#search:focus { border-color: var(--lav-dim); }
/* mic / clear both anchor to the bottom-right so they stay put as the
   textarea grows; only one is shown at a time */
#mic, #clear {
  position: absolute; right: 4px; bottom: 7px;
  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;
}
#clear { color: var(--muted); }
#clear:hover { color: var(--text); }
#search::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 15px; height: 15px;
  margin-right: -6px;
  cursor: pointer;
  background-color: #ffffff;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6L18 18M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6L18 18M18 6L6 18' stroke='black' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}
#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); }
}

/* error/info toast — replaces alert(), which is a silent no-op in an iOS
   home-screen PWA (no browser chrome to host the native dialog) */
.toast {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
  font-weight: 600; font-size: 14px; text-align: center;
  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);
  cursor: pointer;
}
.toast.error { background: var(--danger); color: #2a0a0a; }
.toast.info { background: #ffffff; color: #111111; }

/* saving state: pulse the button so a slow request never looks like nothing
   is happening */
@keyframes btn-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
button.saving { animation: btn-pulse .9s ease-in-out infinite; pointer-events: none; }

.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; font-size: 16.8px; }
.results .r-reason {
  font-size: 13.8px; color: var(--muted);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* round icon buttons in the bottom-left row */
#add-btn, #names-btn {
  position: fixed; 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: 26px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  transition: transform .15s;
}
#add-btn { left: 68px; }
#names-btn { left: 184px; }
/* hide the hide-surnames (eye) button — functionality kept, button hidden */
#names-btn { display: none; }
#add-btn:active, #names-btn:active { transform: scale(0.94); }
/* logout: small bare icon in the top-right corner (no background/rounding) */
/* same grey circle as the profile avatar button (top-left), mirrored to the right */
#faq-btn {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 14px; z-index: 15;
  width: 30px; height: 30px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: #33343a; border: 1px solid rgba(255, 255, 255, .1);
  color: #8f8f98; cursor: pointer;
  font: 700 19px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
#faq-btn:active { transform: scale(0.92); }

/* one-shot sonar ping on app open: faint blurred rings expanding from the
   centre out to the screen edges, like a sonar sweep.
   z-index -1 puts it BEHIND the transparent graph canvas, so the wave animates
   under the avatars and names (and under the top bar) instead of over them */
#sonar-ping { position: fixed; inset: 0; z-index: -1; pointer-events: none; display: none; }
#sonar-ping.ping { display: block; }
#sonar-ping i {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0;
  /* thick, heavily-blurred band → a soft foggy/hazy wave rather than a crisp ring.
     near-white band with a soft violet/blue halo, so it reads white with a gentle
     dark-violet gradient rather than pure white */
  border-radius: 50%; border: 22px solid rgba(224, 219, 250, .4);
  transform: translate(-50%, -50%); filter: blur(24px); opacity: 0;
  box-shadow: 0 0 80px rgba(126, 110, 224, .2);
}
/* slow, languid sweep */
#sonar-ping.ping i { animation: sonar-wave 5s cubic-bezier(.3, .5, .2, 1) forwards; border-color: rgba(224, 219, 250, .42); }
@keyframes sonar-wave {
  0% { width: 0; height: 0; opacity: 0; }
  10% { opacity: .6; }
  70% { opacity: .34; }
  100% { width: 240vmax; height: 240vmax; opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { #sonar-ping { display: none !important; } }

/* FAQ — full-screen story cards (Instagram-stories style) */
#faq { background: #000000; backdrop-filter: none; opacity: 0; transition: opacity .2s ease; }
#faq.open { opacity: 1; }
.faq-card {
  position: relative; width: 100%; max-width: 560px; height: 100%; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: calc(20px + env(safe-area-inset-top)) 26px calc(30px + env(safe-area-inset-bottom));
  /* soft purple glow spilling from the top centre, like the glow behind the
     landing logo, layered over a dark base */
  background:
    radial-gradient(76% 42% at 50% -5%, rgba(150, 140, 225, .22), transparent 70%),
    radial-gradient(120% 80% at 50% 0%, #16171d 0%, #0b0b0e 60%, #000 100%);
}
.faq-bars { display: flex; gap: 5px; margin-bottom: 22px; }
.faq-bar { position: relative; flex: 1; height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .18); overflow: hidden; }
.faq-bar-fill {
  position: absolute; inset: 0; border-radius: 2px; background: rgba(255, 255, 255, .95);
  transform: scaleX(0); transform-origin: left center;
}
.faq-bar.done .faq-bar-fill { transform: scaleX(1); }           /* already watched */
.faq-bar.on .faq-bar-fill { animation: faq-fill linear forwards; } /* fills left→right over FAQ_SECONDS */
@keyframes faq-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .faq-bar.on .faq-bar-fill { animation: none; transform: scaleX(1); }
}
.faq-close {
  position: absolute; z-index: 3; top: calc(14px + env(safe-area-inset-top)); right: 16px;
  border: none; background: none; cursor: pointer; padding: 4px; color: #fff; font-size: 28px; line-height: 1;
}
.faq-body {
  position: relative; z-index: 2; flex: 1;
  display: flex; flex-direction: column; justify-content: flex-start; pointer-events: none;
  padding-top: 8vh; /* sit in the upper third, not centred */
}
.faq-kicker { font-size: 13px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: #8f7bff; margin-bottom: 16px; }
.faq-q {
  font-family: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 30px; font-weight: 700; line-height: 1.12; letter-spacing: -0.02em; color: #ffffff; margin-bottom: 18px;
}
.faq-a { font-size: 17px; line-height: 1.55; color: #c3c3cb; max-width: 30ch; }
/* no double-tap / pinch zoom on the story cards (manipulation kills the
   double-tap-to-zoom; pinch is additionally blocked in JS) */
#faq, .faq-card, .faq-zone, .faq-close { touch-action: manipulation; }
/* transparent tap zones: left third = prev, right two-thirds = next */
.faq-zone { position: absolute; top: 64px; bottom: 0; z-index: 1; border: none; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.faq-zone.prev { left: 0; width: 33%; }
.faq-zone.next { right: 0; width: 67%; }
/* profile avatar: grey person placeholder in the top-left → opens the profile */
#profile-btn {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); left: 14px; z-index: 15;
  width: 30px; height: 30px; border-radius: 50%; padding: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #33343a; border: 1px solid rgba(255, 255, 255, .1);
  color: #8f8f98; cursor: pointer;
}
#profile-btn svg { width: 21px; height: 21px; }
#profile-btn img { width: 100%; height: 100%; object-fit: cover; }
#profile-btn:active { transform: scale(0.92); }

/* profile page: full-width square avatar filling the top, plan badge over it,
   name centred below, three icon actions at the bottom */
#profile {
  background: #000000; backdrop-filter: none;
  flex-direction: column; align-items: center; justify-content: flex-start;
  overflow-y: auto; opacity: 0; transition: opacity .2s ease;
}
#profile.open { opacity: 1; }
.pf-card {
  position: relative; width: 100%; max-width: 520px; min-height: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding-top: 120px; /* black gap above the avatar */
  padding-bottom: calc(30px + env(safe-area-inset-bottom));
}
.pf-close {
  position: absolute; z-index: 3; top: calc(12px + env(safe-area-inset-top)); right: 14px;
  border: none; background: none; cursor: pointer; padding: 4px;
  color: #ffffff; display: flex; align-items: center; justify-content: center;
}
.pf-close svg { width: 35px; height: 35px; } /* thin strokes */
/* the square avatar — occupies the top of the screen, fades into black */
.pf-hero {
  position: relative; flex: none; width: 100%; aspect-ratio: 1 / 1;
  background: #26272c; overflow: hidden;
}
.pf-photo { width: 100%; height: 100%; object-fit: cover; display: block; }
.pf-ph {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: #54555c; background: #26272c;
}
.pf-ph svg { width: 44%; height: 44%; }
.pf-fade {
  position: absolute; left: 0; right: 0; bottom: 0; height: 40%; pointer-events: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), #000000 96%);
}
/* top fade: black at the very top → transparent lower down, so the avatar
   melts into the black gap above it */
.pf-hero::before {
  content: ""; position: absolute; z-index: 1; left: 0; right: 0; top: 0; height: 38%; pointer-events: none;
  background: linear-gradient(to bottom, #000000, rgba(0, 0, 0, 0));
}
.pf-badge {
  position: absolute; z-index: 2; top: calc(22px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  padding: 5px 18px; border-radius: 999px; white-space: nowrap; line-height: 1;
  font-size: 14px; font-weight: 600; color: #0a0a0a;
  /* solid white badge with black text */
  background: #ffffff;
  border: 1px solid rgba(255, 255, 255, .28);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
}
/* slide the badge down from the top as the profile opens */
#profile.open .pf-badge { animation: pf-badge-in .5s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes pf-badge-in {
  from { transform: translateX(-50%) translateY(-46px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
.pf-name {
  position: relative; z-index: 1; /* paint above .pf-hero, which it overlaps via the negative margin */
  margin: -8px 0 0; padding: 4px 22px 0; text-align: center; cursor: pointer;
  /* Archivo Expanded (bold) — a free, Cyrillic-capable expanded grotesque close
     to TT Norms Pro Expanded; falls back to Onest if a glyph is missing */
  font-family: "Archivo", "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 35px; font-weight: 700; font-stretch: 125%; letter-spacing: -0.005em; text-transform: uppercase;
  color: #ffffff; word-break: break-word; line-height: 1.1;
}
.pf-actions { margin-top: 12px; display: flex; flex-direction: column; align-items: center; gap: 0; }
.pf-act {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  background: none; border: none; padding: 2px 4px; text-align: left;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 14px; color: #e6e6ea;
}
.pf-act .pf-ico { flex: none; width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; color: #c4c4cd; }
.pf-act .pf-ico svg { width: 18px; height: 18px; }
.pf-act.danger, .pf-act.danger .pf-ico { color: #e5533f; }
.pf-act:active { opacity: .55; }

/* "Как вас зовут?" — asked on first login (Resend aesthetic) */
#name-ask {
  background: #000000; backdrop-filter: none; z-index: 40;
  align-items: center; justify-content: center;
  opacity: 0; transition: opacity .25s ease;
}
#name-ask.open { opacity: 1; }
.na-card { width: 100%; max-width: 360px; padding: 0 26px; text-align: center; }
.na-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 30px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; margin-bottom: 26px;
  background: linear-gradient(180deg, #ffffff 30%, #9b9ba4 130%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.na-input {
  width: 100%; text-align: center; font-size: 17px; padding: 14px 16px;
  background: rgba(255, 255, 255, .03); color: var(--text);
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 11px; outline: none;
  margin-bottom: 12px;
}
.na-input:focus { border-color: rgba(255, 255, 255, .28); }
.na-cta {
  display: block; width: 100%;
  background: #ffffff; color: #0a0a0a; border: none; border-radius: 11px;
  padding: 14px; font-size: 15.5px; font-weight: 600; cursor: pointer;
  transition: transform .12s, filter .15s;
}
.na-cta:hover { filter: brightness(0.92); }
.na-cta:active { transform: scale(0.985); }
.na-cta:disabled { opacity: .6; }
.na-skip { display: block; margin: 16px auto 0; font-size: 13px; }
/* admin: round style, only visible for the super-admin */
#admin-btn {
  position: fixed; left: 126px; 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(--lav); border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  transition: transform .15s;
}
#admin-btn:active { transform: scale(0.94); }
/* admin user list */
.adm-list { display: flex; flex-direction: column; margin-top: 6px; }
.adm-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.adm-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.adm-email { font-size: 14px; color: var(--text); word-break: break-all; }
.adm-tag {
  font-size: 10px; font-weight: 700; color: var(--lav);
  border: 1px solid var(--lav-dim); border-radius: 6px; padding: 0 4px; margin-left: 4px;
}
.adm-meta { font-size: 12px; color: var(--muted); }
.adm-plan { display: flex; gap: 0; flex: none; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.adm-plan button {
  background: none; border: none; border-radius: 0; padding: 7px 12px;
  color: var(--muted); font-size: 13px;
}
.adm-plan button.on { background: var(--lav); color: #14121c; font-weight: 700; }
.adm-plan button:disabled { opacity: .5; }
/* the icon itself signals the state: open eye = surnames shown, closed = hidden */
#names-btn .eye-closed, #names-btn.on .eye-open { display: none; }
#names-btn.on .eye-closed { display: block; }
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: 31px; height: 31px; 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;
  /* light (off-white) button with a black plus */
  background: #e9e9ea; color: #111111; border: none;
  font-size: 26px; line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
#fab:active { transform: scale(0.94); }
/* ---------- avatar cropper ---------- */
/* above every other modal (esp. the full-screen profile) so the pan/zoom
   editor is usable when launched from the profile's "изменить аватарку" */
#cropper { z-index: 50; }
#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-hint {
  position: absolute; z-index: 2; left: 50%; bottom: 12px; transform: translateX(-50%);
  padding: 5px 12px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  font-size: 12px; color: #fff; background: rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#crop-hint::before {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px;
  border-radius: 50%; background: currentColor; vertical-align: middle;
  animation: gentag-dot 1s ease-in-out infinite;
}
/* custom zoom slider with an iOS-style thumb that grows while pressed/dragged */
#crop-zoom {
  -webkit-appearance: none; appearance: none;
  width: 100%; max-width: 320px; display: block; margin: 0 auto 6px;
  height: 30px; background: transparent; cursor: pointer;
}
#crop-zoom::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); }
#crop-zoom::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -9px; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 5px rgba(0, 0, 0, .45);
  transition: transform .15s ease;
}
#crop-zoom:active::-webkit-slider-thumb { transform: scale(1.28); }
#crop-zoom::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .22); }
#crop-zoom::-moz-range-thumb {
  width: 22px; height: 22px; border: none; border-radius: 50%;
  background: #ffffff; box-shadow: 0 1px 5px rgba(0, 0, 0, .45);
  transition: transform .15s ease;
}
#crop-zoom:active::-moz-range-thumb { transform: scale(1.28); }

.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: 56px 24px 28px; overflow-y: auto; z-index: 20;
  transform: translateX(105%);
  transition: transform .32s cubic-bezier(.32, .72, .33, 1);
  touch-action: pan-y; /* allow vertical scroll, block pinch-zoom of the card */
}
.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: 106px; height: 106px; 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); }
/* contact name: 20% larger, in SF Pro Text (system font on Apple devices) */
.detail h2 {
  font-size: 23px; margin-bottom: 14px;
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
}
.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-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.d-tag {
  display: inline-block; padding: 4px 10px; border-radius: 999px;
  background: var(--pill); color: var(--text); font-size: 13px;
}
.d-tag.is-empty { background: none; color: var(--lav-dim); padding-left: 0; font-style: italic; }
#d-gentag { display: inline-block; }
/* while generating a tag: a small pulsing dot next to the label makes the
   in-progress state obvious */
#d-gentag.saving { animation: none; } /* the dot signals progress, not a whole-button fade */
#d-gentag.saving::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px;
  border-radius: 50%; background: currentColor; vertical-align: middle;
  animation: gentag-dot 1s ease-in-out infinite;
}
@keyframes gentag-dot {
  0%, 100% { opacity: .25; transform: scale(.7); }
  50% { opacity: 1; transform: scale(1); }
}
/* "Последняя встреча" — the date plus the button that stamps a new one */
#d-touch { margin-bottom: 10px; }
#d-touch.is-stale { color: var(--lav-dim); font-style: italic; }
#d-touch-btn {
  background: var(--pill); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 14px; font-size: 14px; cursor: pointer;
}
#d-touch-btn:hover { background: var(--pill-active); }
#d-touch-btn:active { transform: scale(0.97); }
#d-touch-btn:disabled { opacity: .6; }
.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.is-empty { color: var(--lav-dim); font-style: italic; }
.modal-card.narrow { width: 320px; }
.modal-card h2 { font-size: 17px; margin-bottom: 16px; }
/* the add/edit contact title, 1.5x larger */
#m-title { font-size: 25px; }
.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); }
/* Autofill must never flash the native white/blue fill: the browser paints it
   over `background`, so we paint back with a huge inset shadow instead. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  border-color: var(--line);
  transition: background-color 9999999s ease-out; /* stalls the fill animation */
}
/* the person's name is the headline field: ~20% larger and centered */
.modal-card input[name="name"] { font-size: 17px; text-align: center; caret-color: transparent; }
.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 ---------- */
/* Resend-style: near-black with a soft glow spilling from the top centre */
#login {
  background:
    radial-gradient(72% 46% at 50% -6%, rgba(150, 140, 225, .14), transparent 72%),
    #000000;
  backdrop-filter: none;
  inset: 0; top: 0; left: 0; right: 0; bottom: 0; height: auto;
  align-items: flex-start; justify-content: center;
  overflow-y: auto; /* landing can be taller than the screen → scrolls cleanly */
}
#login .modal-card {
  position: relative; z-index: 1; /* above the animated glow blobs */
  width: 100%; max-width: 480px; height: auto; max-height: none;
  background: transparent; border: none; border-radius: 0; box-shadow: none;
  padding: calc(52px + env(safe-area-inset-top)) 26px calc(44px + env(safe-area-inset-bottom));
  display: block; margin: auto; /* centered when short, scrollable when tall */
}
#login .brand { font-size: 34px; margin-bottom: 26px; }

/* live background: two soft coloured glows slowly drifting behind the hero
   (GPU-composited transforms — smooth, subtle, Resend-like) */
#login::before, #login::after {
  content: ""; position: fixed; z-index: 0; pointer-events: none;
  width: 62vmax; height: 62vmax; border-radius: 50%;
  filter: blur(64px); opacity: .5; will-change: transform;
}
#login::before {
  top: -22vmax; left: -12vmax;
  background: radial-gradient(circle, rgba(140, 120, 255, .22), transparent 60%);
  animation: login-blob-a 17s ease-in-out infinite;
}
#login::after {
  bottom: -26vmax; right: -14vmax;
  background: radial-gradient(circle, rgba(80, 140, 255, .16), transparent 60%);
  animation: login-blob-b 21s ease-in-out infinite;
}
@keyframes login-blob-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(11vmax, 9vmax) scale(1.15); }
}
@keyframes login-blob-b {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-9vmax, -11vmax) scale(1.12); }
}
@media (prefers-reduced-motion: reduce) {
  #login::before, #login::after { animation: none; }
}
/* brand title: silver gradient over a classic serif, with a slow sheen
   sweeping across the letters (metallic, not flat white) */
#login .brand, #pwa-tutorial .brand {
  font-family: ui-serif, "New York", Georgia, "Times New Roman", serif;
  font-size: 46px;
  font-weight: 500;
  letter-spacing: -1px;
  text-align: center;
  margin-bottom: 16px;
  background: linear-gradient(
    105deg,
    #eceef2 0%, #9a9aa3 30%, #ffffff 48%, #8f8f98 66%, #e8e9ee 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: brand-sheen 5.5s ease-in-out infinite;
}
/* ---- landing hero (Resend aesthetic) ---- */
.hero-title {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  /* scales down on narrow phones so it always stays on one line; the wider card
     lets it reach full size on desktop */
  font-size: clamp(18px, 6.2vw, 28px); line-height: 1.08; font-weight: 600; letter-spacing: -0.035em;
  white-space: nowrap; text-align: center; margin: 2px 0 14px;
  /* subtle white→gray fade like Resend's headlines */
  background: linear-gradient(180deg, #ffffff 30%, #9b9ba4 130%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  font-size: 15px; line-height: 1.5; color: #8b8b93;
  text-align: center; margin: 0 auto 26px; max-width: 400px;
}
.hero-field { display: block; margin-bottom: 10px; }
.hero-field input {
  width: 100%; text-align: center; font-size: 16px; padding: 14px 16px;
  background: rgba(255, 255, 255, .03); color: var(--text);
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 11px; outline: none;
}
.hero-field input:focus { border-color: rgba(255, 255, 255, .28); }
.hero-cta {
  display: block; width: 100%; margin-top: 8px;
  background: #ffffff; color: #0a0a0a; border: none; border-radius: 11px;
  padding: 14px; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; cursor: pointer;
  transition: transform .12s, filter .15s;
}
.hero-cta:hover { filter: brightness(0.92); }
.hero-cta:active { transform: scale(0.985); }
.hero-cta:disabled { opacity: .6; }
.hero-note { text-align: center; font-size: 12px; color: #6a6a72; margin-top: 13px; }
.hero-points {
  list-style: none; margin: 34px auto 0; max-width: 330px;
  display: flex; flex-direction: column; gap: 2px;
  border-top: 1px solid rgba(255, 255, 255, .07);
}
.hero-points li {
  display: flex; align-items: center; gap: 13px;
  padding: 14px 2px; border-bottom: 1px solid rgba(255, 255, 255, .07);
  font-size: 14px; line-height: 1.35; color: #d7d7dd; text-align: left;
}
.hp-ico {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .09);
  color: #cfcfe6;
}
/* Desktop (ПК): scale the whole landing hero up ~20%; the wider card keeps the
   title on one line at the larger size. Phones (<=760px) are unaffected. */
@media (min-width: 761px) {
  #login .modal-card { max-width: 580px; }
  #login .brand { font-size: 57px; }
  .hero-title { font-size: 33px; }
  .hero-sub { font-size: 16px; max-width: 500px; }
  .hero-field input { font-size: 19px; padding: 17px 19px; }
  .hero-cta { font-size: 18.5px; padding: 17px; }
  .hero-note { font-size: 14px; }
  .hero-points { max-width: 396px; }
  .hero-points li { font-size: 17px; padding: 17px 2px; }
  .hp-ico { width: 41px; height: 41px; border-radius: 11px; }
}
@keyframes brand-sheen {
  0%, 100% { background-position: 100% 0; }
  50% { background-position: 0% 0; }
}

#login .modal-card input { transition: border-color .2s ease; }
/* autofilled login fields keep the dark fill (no browser white/blue) */
#login .modal-card input:-webkit-autofill,
#login .modal-card input:-webkit-autofill:hover,
#login .modal-card input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #0e0e10 inset;
  border-color: rgba(255, 255, 255, .12);
}
/* one-time code entry: big, centered, spaced like the email it came from */
#login .code-input {
  font-size: 22px; text-align: center; letter-spacing: 8px;
  caret-color: transparent; /* the dots are the affordance, a blinking caret just adds noise */
}
#login .resend { display: block; margin: 4px 0 4px; padding-left: 2px; text-align: left; font-size: 13px; }
#login .resend:disabled { color: var(--muted); cursor: default; }

/* small serif wordmark in the top-left once inside the app (same look as the
   login title, but static) */
.brand-mini {
  font-family: ui-serif, "New York", Georgia, "Times New Roman", serif;
  font-size: 32px; letter-spacing: -.6px; line-height: 1;
  margin: 0 0 17px; text-align: center;
  background: linear-gradient(105deg, #eceef2, #9a9aa3 42%, #ffffff 56%, #b6b6bf);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- add-to-home-screen tutorial ---------- */
#pwa-tutorial {
  background: #000000; backdrop-filter: none;
  align-items: center; justify-content: center;
}
#pwa-tutorial .brand { font-size: 32px; margin-bottom: 6px; }
.pwa-card {
  width: 100%; max-width: 380px;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
  text-align: center; overflow-y: auto; max-height: 100%;
}
/* keep the heading to a single line */
.pwa-title { font-size: 16px; margin: 6px 0 10px; color: var(--text); white-space: nowrap; }
.pwa-lead { font-size: 13.5px; line-height: 1.55; color: var(--muted); margin-bottom: 26px; }
.pwa-steps { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 16px; margin-bottom: 28px; }
.pwa-step { display: flex; align-items: center; gap: 12px; }
.pwa-num {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--lav); color: #14121c; font-size: 12px; font-weight: 700;
}
.pwa-ico {
  flex: none; width: 46px; height: 46px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-raise); border: 1px solid var(--line); color: var(--text);
}
.pwa-txt { font-size: 14px; line-height: 1.4; color: var(--text); }
.pwa-word { color: var(--lav); font-weight: 600; }
.pwa-done { width: 100%; padding: 13px; }

/* ---------- upgrade-to-Pro dialog ---------- */
.up-card { text-align: center; }
.up-badge {
  display: inline-block; margin-bottom: 12px;
  padding: 3px 12px; border-radius: 999px;
  background: linear-gradient(105deg, #cbb8ff, #8f7bff);
  color: #14121c; font-size: 12px; font-weight: 800; letter-spacing: 1px;
}
.up-title { font-size: 18px; margin-bottom: 10px; }
.up-lead { font-size: 13.5px; line-height: 1.55; color: var(--muted); margin-bottom: 16px; }
.up-perks {
  list-style: none; text-align: left; display: flex; flex-direction: column; gap: 8px;
  margin: 0 auto 20px; max-width: 240px;
}
.up-perks li { position: relative; padding-left: 24px; font-size: 14px; color: var(--text); }
.up-perks li::before {
  content: "✓"; position: absolute; left: 0; top: 0;
  color: var(--lav); font-weight: 700;
}
.up-go { width: 100%; padding: 13px; margin-bottom: 8px; }
.up-later { display: block; margin: 0 auto; }

/* ---------- launch splash ---------- */
#splash {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
/* loader: the "Sonar" wordmark fills with the silver colour from the bottom up,
   on a loop, while the app boots — a faint base layer with a rising fill on top */
.splash-brand {
  position: relative;
  font-family: ui-serif, "New York", Georgia, "Times New Roman", serif;
  font-size: 46px; font-weight: 500; letter-spacing: -1px; line-height: 1;
}
.splash-brand span { display: block; }
.sb-base { color: rgba(255, 255, 255, .15); } /* faint empty logo */
.sb-fill {
  position: absolute; inset: 0;
  background: linear-gradient(105deg, #eceef2 0%, #9a9aa3 40%, #ffffff 55%, #b6b6bf 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  clip-path: inset(100% 0 0 0); /* starts empty */
  animation: sb-fill 1.8s ease-in-out infinite;
  will-change: clip-path;
}
@keyframes sb-fill {
  0%   { clip-path: inset(100% 0 0 0); opacity: 1; } /* empty */
  55%  { clip-path: inset(0 0 0 0);    opacity: 1; } /* filled bottom → top */
  80%  { clip-path: inset(0 0 0 0);    opacity: 1; } /* hold full */
  100% { clip-path: inset(0 0 0 0);    opacity: 0; } /* fade out full → seamless restart from empty */
}

.hidden { display: none !important; }

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

  /* sidebar becomes a frosted-glass top bar floating over the graph, so
     avatars passing beneath it faintly show through (iOS-style liquid glass) */
  #sidebar {
    position: absolute; top: 0; left: 0; right: 0; z-index: 10;
    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 rgba(255, 255, 255, .07);
    overflow: visible;
    background: rgba(10, 10, 10, .5);
    -webkit-backdrop-filter: blur(24px) saturate(1.7);
    backdrop-filter: blur(24px) saturate(1.7);
  }
  #sidebar h1, #sidebar .sub, #add-btn { display: none; }
  /* mobile has no side column — keep the row in the bottom-left corner */
  #admin-btn { left: 18px; }
  /* translucent so the frosted bar (and the graph behind it) shows through;
     keep the 46px right padding so text wraps before the mic/clear icon */
  #search {
    padding: 12px 46px 12px 14px; font-size: 16px;
    background: rgba(24, 24, 24, .55); border-color: rgba(255, 255, 255, .09);
  }
  .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: 90vh;
    border-left: none; border-bottom: 1px solid var(--line);
    border-radius: 0 0 18px 18px;
    padding: calc(36px + 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: 84px; height: 84px; font-size: 31px; }
  .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; }

  /* iOS-17-style sheet for the add/edit contact modal: frosted material,
     softly rounded bottom, and a blurred dimmed backdrop */
  #modal { background: rgba(0, 0, 0, .62); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
  #modal .modal-card {
    border-radius: 0 0 24px 24px;
    padding-bottom: 22px;
    background: rgba(30, 30, 33, .9);
    -webkit-backdrop-filter: blur(30px) saturate(1.7);
    backdrop-filter: blur(30px) saturate(1.7);
    box-shadow: 0 16px 44px rgba(0, 0, 0, .55);
  }
  /* 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; }

  /* the login overlay is a centered full-screen sheet, NOT a slide-down
     top-sheet like #modal — cancel the transform so its card stays centered
     (otherwise the Sonar title is pushed off the top of the screen) */
  #login .modal-card {
    transform: none; max-height: 100%;
    padding: 24px; border-radius: 0;
  }
  /* mini wordmark sits just under the status bar on mobile */
  .brand-mini { font-size: 28px; margin-bottom: 14px; }
}
