/* Familiar — app styles. Builds on motif tokens + Plex Sans
 * (loaded from /static/motif/{tokens,plex}.css ahead of this file)
 * AND on spakit/spa.css for the shared SPA chrome (banner / modal /
 * settings / landing / activating / flashbar / .icon / .link-btn).
 *
 * Anything below is familiar-specific: the photo annotation stage,
 * face markers, the multiple-choice session UI, the stats charts,
 * the welcome card, and the about-prose typography. */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: #f7f7f5;
  color: #222;
  line-height: 1.55;
  font-size: 16px;
  font-feature-settings: "kern" 1, "liga" 1;
}

.dropdown-menu .icon { width: 1rem; height: 1rem; opacity: 0.7; }

main {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}
h1, h2 { color: var(--color-primary-800); margin: 0 0 0.5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; margin-top: 1rem; }
p { margin: 0.6rem 0; }
.muted { color: #888; font-weight: 400; font-size: 0.9rem; }
.form-text { color: #777; font-size: 0.85rem; }
.empty { text-align: center; padding: 3rem 1rem; color: #888; }

button, .btn {
  font: inherit;
  padding: 0.55rem 1.1rem;
  background: var(--color-primary-600); color: #fff; border: 0; border-radius: 4px;
  cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 0.4rem;
}
button:hover, .btn:hover { background: var(--color-primary-700); }
button.btn-secondary, .btn.btn-secondary {
  background: #fff; color: var(--color-primary-600); border: 1px solid var(--color-primary-600);
}

.upload {
  margin: 0.75rem 0 1.25rem;
  display: flex; align-items: center; gap: 0.75rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  overflow: hidden;
}
.card img {
  width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  background: #eee;
  display: block;
}
.card-body { padding: 0.6rem 0.75rem; }
.card-label { font-weight: 500; }
.card-meta { color: #777; font-size: 0.85rem; margin-top: 0.15rem; }
.card-actions {
  display: flex; gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.card-actions a { color: var(--color-primary-600); }
.card-actions .delete { color: #b91c1c; }

.back-link { color: var(--color-primary-600); text-decoration: none; }

.card.photo-card { cursor: pointer; transition: transform 60ms ease; }
.card.photo-card:hover { transform: translateY(-1px); border-color: var(--color-primary-600); }
.card-body .card-meta { margin-top: 0.15rem; }

/* Photo annotation stage --------------------------------------------------- */
.photo-stage {
  position: relative;
  margin: 0.75rem 0 1rem;
  background: #1a1a1a;
  border-radius: 6px;
  overflow: hidden;
  max-width: 720px;
}
.photo-stage img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none; -webkit-user-drag: none;
}
.photo-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
.face-marker {
  position: absolute;
  /* width is set inline as % of image width; aspect-ratio + center
     anchor make the marker a true circle in pixels regardless of
     image aspect ratio. left/top are the center, not the top-left. */
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
  cursor: grab;
  background: transparent;
  transition: border-color 100ms ease;
  /* Prevent iOS/Android from intercepting drag as scroll/zoom. */
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.face-marker:active { cursor: grabbing; }
.face-marker:hover { transform: translate(-50%, -50%) scale(1.04); }
.face-marker.saved        { border-color: #fff; }
.face-marker.draft        { border-color: #ffd866; border-style: dashed; }
.face-marker.selected     { border-color: #4ade80; box-shadow: 0 0 0 2px rgba(0,0,0,0.5), 0 0 0 4px rgba(74,222,128,0.55); }
.face-tag {
  position: absolute;
  bottom: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
}

/* Session: highlight target, dim everything else via huge outset
   box-shadow that follows the round marker border-radius and is
   clipped to the photo bounds by .photo-stage overflow:hidden. */
.session-stage .face-marker.target {
  border-color: #4ade80;
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.4),
    0 0 0 9999px rgba(0, 0, 0, 0.55);
}

/* Caption row (annotation view) ------------------------------------------- */
.caption-row {
  display: flex; gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  max-width: 720px;
}
.caption-row input {
  flex: 1; padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db; border-radius: 4px;
  font: inherit;
}

/* Edit panel -------------------------------------------------------------- */
.edit-panel { max-width: 720px; }
.edit-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.85rem 1rem 1rem;
}
.size-row {
  display: flex; align-items: center; gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.size-row .size-label {
  font-size: 0.85rem; color: #555; margin-right: 0.4rem;
}
.size-row .spacer { flex: 1; }
.pill {
  font: inherit;
  background: #fff; color: #333;
  border: 1px solid #d1d5db; border-radius: 999px;
  padding: 0.4rem 0.95rem;
  cursor: pointer;
  min-width: 2.5rem;
  font-size: 0.9rem;
}
.pill.active {
  background: var(--color-primary-600); color: #fff; border-color: var(--color-primary-600);
}
.pill:hover:not(.active) { background: #f3f4f6; }
.pill.danger {
  border-color: #ef4444; color: #b91c1c;
}
.pill.danger:hover { background: #fee2e2; }
.pill.ghost {
  background: #f9fafb; border-color: #e5e7eb; color: #444;
  font-size: 0.85rem; padding: 0.3rem 0.7rem;
}

.field {
  display: block; margin-bottom: 0.7rem;
  position: relative;
}
.field > span {
  display: block; font-size: 0.85rem; color: #555;
  margin-bottom: 0.25rem;
}
.field .req { color: #b91c1c; }
.field input {
  width: 100%; padding: 0.55rem 0.7rem;
  border: 1px solid #d1d5db; border-radius: 4px;
  font: inherit;
}
.name-suggest {
  list-style: none; padding: 0; margin: 0.2rem 0 0;
  display: flex; gap: 0.3rem; flex-wrap: wrap;
}
.name-suggest .suggest {
  font: inherit;
  background: var(--color-primary-100); color: #365314; border: 1px solid #a3e635;
  border-radius: 999px; padding: 0.2rem 0.7rem;
  cursor: pointer; font-size: 0.85rem;
}
.name-suggest .suggest:hover { background: #d9f99d; }

.recent-row {
  display: flex; gap: 0.4rem; flex-wrap: wrap;
  margin-bottom: 0.7rem; align-items: center;
}

details summary { cursor: pointer; color: #555; font-size: 0.9rem; padding: 0.3rem 0; }
details[open] { margin-bottom: 0.5rem; }

.action-row {
  display: flex; gap: 0.5rem; margin-top: 0.6rem;
}

/* Session mode toggle (Name / Where) -------------------------------------- */
.mode-toggle {
  display: inline-flex;
  margin: 0.4rem 0 0.8rem;
  gap: 0;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  padding: 0.2rem;
  background: #fff;
}
.mode-chip {
  font: inherit;
  background: transparent;
  color: #555;
  padding: 0.4rem 0.85rem;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}
.mode-chip:hover { color: var(--color-primary-800); }
.mode-chip.active {
  background: var(--color-primary-600);
  color: #fff;
}

/* Where-mode wrong-tap marker (red ring on the face the user tapped). */
.face-marker.wrong-tap {
  border-color: #b91c1c;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.4), 0 0 0 4px rgba(185,28,28,0.55);
}

.where-stage { cursor: pointer; }

/* Session ----------------------------------------------------------------- */
.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  max-width: 32rem;
  margin: 1rem auto 0.5rem;
}
.choice {
  font: inherit;
  padding: 0.95rem 1rem;
  background: #fff; color: var(--color-primary-800);
  border: 2px solid var(--color-primary-600); border-radius: 8px;
  cursor: pointer;
  font-size: 1.05rem; font-weight: 500;
  min-height: 3rem;
}
.choice:hover:not(:disabled) { background: var(--color-primary-100); }
.choice.correct {
  background: #166534; color: #fff; border-color: #166534;
}
.choice.wrong {
  background: #fee2e2; color: #b91c1c; border-color: #b91c1c;
}
.choice:disabled { cursor: default; opacity: 0.95; }

.reveal-row {
  max-width: 32rem;
  margin: 0.6rem auto 0;
  text-align: center;
}

/* Welcome card (first-photo onboarding) ----------------------------------- */
.welcome-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-left: 4px solid var(--color-primary-600);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  margin-top: 0.5rem;
}
.welcome-card h3 {
  margin: 0 0 0.4rem;
  color: var(--color-primary-800);
  font-size: 1.1rem;
}
.welcome-card p { margin: 0.4rem 0; }

/* About prose ------------------------------------------------------------- */
.prose {
  max-width: 40rem;
  margin: 0 auto;
  font-size: 1rem;
  line-height: 1.65;
}
.prose h1 { margin-top: 0.5rem; }
.prose h2 { margin-top: 2rem; font-size: 1.15rem; }
.prose ul { padding-left: 1.2rem; }
.prose li { margin: 0.4rem 0; }
.prose hr {
  border: 0; border-top: 1px solid #e5e7eb;
  margin: 2rem 0 1rem;
}
.prose .footnotes {
  font-size: 0.85rem;
  color: #555;
  margin: 0.4rem 0;
}
.prose ul.caveats li strong { color: var(--color-primary-800); }
.prose sup a { color: var(--color-primary-600); text-decoration: none; }
.prose sup a:hover { text-decoration: underline; }

/* Stats ------------------------------------------------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0 1.5rem;
}
.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.9rem 1rem;
}
.stat-value {
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--color-primary-800);
  line-height: 1.1;
}
.stat-label {
  font-size: 0.85rem;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.2rem;
}
.stat-foot {
  font-size: 0.8rem;
  color: #777;
  margin-top: 0.4rem;
}

.chart-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin: 0.5rem 0 1rem;
}
.bar-chart {
  display: block;
  width: 100%;
  height: 90px;
}

.dist-bar {
  display: flex;
  height: 1.6rem;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  margin-top: 0.4rem;
}
.dist-seg { transition: width 200ms ease; }
.dist-legend {
  display: flex; gap: 0.9rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #555;
}
.dist-key { display: inline-flex; align-items: center; gap: 0.3rem; }
.dist-dot {
  width: 0.7rem; height: 0.7rem;
  border-radius: 2px;
  display: inline-block;
}

.needs-list {
  background: #fff7ed;
  border: 1px solid #fdba74;
  border-radius: 6px;
  padding: 0.6rem 1rem 0.6rem 2rem;
  list-style: disc;
}

.face-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.92rem;
}
.face-table th, .face-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #e5e7eb;
}
.face-table th { color: #555; font-weight: 500; }
.face-table .num { text-align: right; font-variant-numeric: tabular-nums; }
