/* FaceDB — dark "studio" theme.
   Refined, gallery-like: deep neutral ground, warm ink, a single amber accent. */

:root {
  /* Light "atelier" theme — default */
  --bg: #f5f2ec;
  --bg-soft: #fbf9f5;
  --surface: #ffffff;
  --surface-2: #efe9df;
  --line: #ddd5c7;
  --line-soft: #e8e2d6;
  --ink: #211d17;
  --ink-dim: #6c655b;
  --ink-faint: #a39b8d;
  --accent: #ec7aa3;        /* pig pink */
  --accent-hover: #f08fb3;
  --accent-ink: #2e0a16;
  --danger: #c0492f;
  --page-bg:
    radial-gradient(1100px 600px at 78% -8%, rgba(236, 122, 163, 0.10), transparent 60%),
    radial-gradient(900px 700px at 8% 110%, rgba(236, 122, 163, 0.06), transparent 55%),
    var(--bg);
  --topbar-bg: linear-gradient(to bottom, rgba(245, 242, 236, 0.9), rgba(245, 242, 236, 0.62));
  --scrim: rgba(43, 36, 25, 0.55);
  --grain-opacity: 0.05;
  --add-bg: #fdeef2;        /* super-light skin pink */
  --add-bg-hover: #fbe0e8;
  --add-border: #f1cdd8;

  --radius: 14px;
  --radius-sm: 9px;
  --btn-radius: 5px;        /* squared-off buttons, not pills */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  font-family: "Hanken Grotesk", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b0b0d;
  --bg-soft: #121215;
  --surface: #161619;
  --surface-2: #1d1d22;
  --line: #2a2a31;
  --line-soft: #232329;
  --ink: #ece8e1;
  --ink-dim: #9a958c;
  --ink-faint: #6a665f;
  --accent: #f291b3;        /* pig pink */
  --accent-hover: #f6a6c2;
  --accent-ink: #2e0a16;
  --danger: #e0654a;
  --page-bg:
    radial-gradient(1100px 600px at 78% -8%, rgba(242, 145, 179, 0.12), transparent 60%),
    radial-gradient(900px 700px at 8% 110%, rgba(242, 145, 179, 0.06), transparent 55%),
    var(--bg);
  --topbar-bg: linear-gradient(to bottom, rgba(11, 11, 13, 0.92), rgba(11, 11, 13, 0.72));
  --scrim: rgba(11, 11, 13, 0.82);
  --grain-opacity: 0.035;
  --add-bg: #1b1418;        /* faint pink-tinted dark */
  --add-bg-hover: #241a20;
  --add-border: #3a2630;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--page-bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle film grain over everything for atmosphere. */
.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 18px 32px;
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: baseline; gap: 12px; flex-shrink: 0; }

.brand-mark {
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 25px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.brand-db { color: var(--accent); font-style: italic; }

.brand-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.search {
  position: relative;
  flex: 1;
  max-width: 520px;
  margin: 0 auto;
}
.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  fill: none; stroke: var(--ink-faint); stroke-width: 2; stroke-linecap: round;
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 11px 16px 11px 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
#search::placeholder { color: var(--ink-faint); }
#search:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-soft);
  box-shadow: 0 0 0 4px rgba(236, 122, 163, 0.16);
}
#search::-webkit-search-cancel-button { -webkit-appearance: none; }

.actions { display: flex; gap: 10px; flex-shrink: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: var(--btn-radius);
  border: 1px solid transparent;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.2s, border-color 0.2s, color 0.2s;
}
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: scale(0.96); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--ink-dim); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); border-color: var(--ink-faint); background: var(--surface); }

.btn-icon { padding: 10px; }
.btn-icon svg { width: 17px; height: 17px; }
.theme-sun { display: none; }
.theme-moon { display: block; }
[data-theme="dark"] .theme-sun { display: block; }
[data-theme="dark"] .theme-moon { display: none; }

/* ---------- Gallery ---------- */

.gallery {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(208px, 1fr));
  gap: 20px;
  padding: 32px;
  max-width: 1500px;
  margin: 0 auto;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.28s var(--ease), border-color 0.28s, box-shadow 0.28s;
  animation: rise 0.5s var(--ease) backwards;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--line);
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.8);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
}

.card-img {
  aspect-ratio: 1;
  background: var(--bg-soft);
  overflow: hidden;
}
.card-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s var(--ease), filter 0.3s;
}
.card:hover .card-img img { transform: scale(1.04); }

.card-bar {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
}
.card-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  outline: none;
  border-radius: 4px;
}
.card-name[contenteditable="true"] {
  white-space: normal;
  background: var(--surface-2);
  box-shadow: 0 0 0 2px rgba(236, 122, 163, 0.5);
  padding: 2px 5px;
  margin: -2px -5px;
}

/* Hover overlay with the actions */
.card-overlay {
  position: absolute;
  inset: 0 0 auto 0;
  height: calc(100% - 49px); /* sit above the name bar */
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  background: linear-gradient(to bottom, rgba(8, 8, 10, 0.4), rgba(8, 8, 10, 0.78));
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
.card:hover .card-overlay,
.card:focus-within .card-overlay { opacity: 1; }

.ov-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 64px;
  padding: 10px 6px;
  background: rgba(22, 22, 25, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--btn-radius);
  color: #f4eee7; /* overlay glass is always dark, so labels stay light in both themes */
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: transform 0.15s var(--ease), background 0.2s, color 0.2s, border-color 0.2s;
}
.ov-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ov-btn:hover { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); transform: translateY(-2px); }
.ov-btn.ov-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.ov-btn.confirming,
.ov-btn.confirming:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.ov-btn:active { transform: scale(0.94); }

/* ---------- Add-faces tile (always first cell) ---------- */

.add-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 220px;
  align-self: stretch;
  background: var(--add-bg);
  border: 1.5px dashed var(--add-border);
  border-radius: var(--radius);
  color: var(--ink-dim);
  font: inherit;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, color 0.2s, background 0.2s, transform 0.2s var(--ease);
  animation: rise 0.5s var(--ease) backwards;
}
.add-tile:hover {
  border-color: var(--accent);
  background: var(--add-bg-hover);
  color: var(--accent);
  transform: translateY(-3px);
}
.add-tile:active { transform: scale(0.99); }
.add-plus {
  font-family: "Fraunces", serif;
  font-size: 40px;
  font-weight: 400;
  line-height: 0.8;
}
.add-title { font-size: 14.5px; font-weight: 600; color: var(--ink); transition: color 0.2s; }
.add-tile:hover .add-title { color: var(--accent); }
.add-sub { font-size: 11.5px; color: var(--ink-faint); padding: 0 18px; line-height: 1.45; }

.no-match {
  grid-column: 1 / -1;
  text-align: center;
  padding: 36px 0;
  font-size: 14px;
  color: var(--ink-faint);
}

/* ---------- Dropzone overlay ---------- */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--scrim);
  backdrop-filter: blur(3px);
}
.dropzone.show { display: flex; }
.dropzone-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 24px;
  font-family: "Fraunces", serif;
  font-style: italic;
  font-size: 32px;
  color: var(--accent);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 60;
  transform: translate(-50%, 24px);
  padding: 12px 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--btn-radius);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 16px 40px -16px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: var(--danger); }
.toast-accent { color: var(--accent); }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; padding: 14px 16px; gap: 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .brand { flex: 1; }
  .gallery { padding: 18px 16px; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .actions .btn-ghost { padding: 10px 12px; }
}
