/* "My selfie journey" section on /profile (markup in profile.html, behaviour in
   selfie-journey.js). Scoped under .sj / sj- so it never touches the rest of the
   profile. Inside .sj the --pfx-* variables from profile-view.css are available;
   the popups are appended to <body>, so they use literal colours. */
.sj { --sj-ink: #1B1B3A; --sj-muted: #55557A; --sj-green: #22A55A; --sj-manual: #7A6BE6; position: relative; display: flex; flex-direction: column; gap: 16px; margin-top: 28px; padding: 22px; border-radius: 22px; border: 1px solid var(--pfx-line); background: linear-gradient(180deg, #F1EDFE 0%, #F7F5FF 42%, #FBFAFF 100%); }
.sj[hidden] { display: none; }
.sj [hidden] { display: none !important; }
.sj svg { display: block; flex-shrink: 0; }

/* Header */
.sj-head { position: relative; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.sj-trail { position: absolute; left: 32%; top: -6px; width: 40%; height: 100%; opacity: .9; pointer-events: none; }
.sj-head-plane { position: absolute; left: 73%; top: 4px; color: var(--pf-purple); transform: rotate(8deg); opacity: .8; pointer-events: none; }
.sj-head-title { position: relative; display: flex; align-items: center; gap: 12px; min-width: 0; }
.sj-head-pin { color: var(--pf-purple); }
.sj-head-title h2 { margin: 0; font-size: 27px; font-weight: 800; line-height: 1.1; color: #2E2496; }
.sj-head-title p { margin: 3px 0 0; font-size: 13px; color: var(--sj-muted); }
.sj-head-actions { position: relative; display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.sj-head-actions .pf-btn-primary, .sj-head-actions .pf-btn-outline { padding: 10px 18px; }

/* Stats row */
.sj-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sj-stat { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--pfx-line); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.sj-stat-icon { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sj-stat-num { font-size: 21px; font-weight: 800; color: var(--sj-ink); line-height: 1.1; }
.sj-stat-label { font-size: 12px; color: var(--sj-muted); }
.sj-stat .sj-chip { margin-left: auto; }

/* Cards */
.sj-card { background: #fff; border: 1px solid var(--pfx-line); border-radius: 16px; padding: 16px 18px; box-shadow: 0 1px 3px rgba(40,30,90,.05); min-width: 0; }
.sj-card-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 12px; }
.sj-card-head h3 { margin: 0; font-size: 15px; font-weight: 700; color: var(--sj-ink); }
.sj-card-head .sj-chip, .sj-card-head .sj-seg-wrap { margin-left: auto; }
.sj-card-icon { color: var(--pf-purple); display: inline-flex; }
.sj-card-sub { flex-basis: 100%; margin: -6px 0 0 29px; font-size: 12px; color: var(--sj-muted); }
.sj-card-foot { display: flex; justify-content: flex-end; margin-top: 10px; font-size: 12px; }
.sj-chip { display: inline-flex; align-items: center; white-space: nowrap; border-radius: 999px; padding: 3px 10px; font-size: 11px; font-weight: 600; background: #FEF0D2; color: #B26A00; }
.sj-chip--soft { background: #EFEBFC; color: var(--pf-purple); }
.sj-row { display: grid; gap: 16px; align-items: stretch; }
.sj-row-map { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
.sj-row-extras { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
.sj-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 18px 8px; color: var(--muted); font-size: 13px; }
.sj-empty svg { color: #CFC8EC; }
.sj-empty strong { color: var(--sj-ink); }
.sj-loading { padding: 18px 8px; text-align: center; font-size: 13px; color: var(--muted); }

/* Journey map */
.sj-map-card { display: flex; flex-direction: column; }
.sj-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-left: auto; font-size: 11.5px; color: var(--sj-muted); }
.sj-legend-item { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border: 1px solid var(--pfx-line); border-radius: 999px; background: #fff; font: inherit; font-size: 11.5px; color: var(--sj-ink); cursor: pointer; }
.sj-legend-item:hover { border-color: var(--pf-purple); }
.sj-legend-item[aria-pressed="false"] { color: var(--sj-muted); background: #F6F5FA; }
.sj-legend-item[aria-pressed="false"] .sj-legend-dot { visibility: hidden; }
.sj-legend-item[aria-pressed="false"] { text-decoration: line-through; }
.sj-legend-dot { width: 13px; height: 13px; border-radius: 50%; box-sizing: border-box; }
.sj-legend-verified { background: var(--sj-green); box-shadow: inset 0 0 0 3px #fff, 0 0 0 1px var(--sj-green); }
.sj-legend-manual { border: 1.5px dashed var(--sj-manual); background: radial-gradient(circle, var(--sj-green) 0 3px, transparent 3.5px); }
.sj-legend-count { font-weight: 700; margin-left: 2px; }
.sj-map-wrap { position: relative; flex: 1; min-height: 300px; border-radius: 12px; overflow: hidden; border: 1px solid var(--pfx-line); }
.sj-map { position: absolute; inset: 0; z-index: 0; }
.sj-map-empty { position: absolute; inset: 0; z-index: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 20px; background: rgba(247,245,255,.86); color: var(--sj-muted); font-size: 13px; pointer-events: none; }
.sj-map-empty svg { color: var(--pf-purple); }
.sj-map-empty strong { color: var(--sj-ink); font-size: 14px; }
.sj-pin-icon { background: none; border: none; }
.sj-pin { position: relative; width: 46px; height: 46px; cursor: pointer; }
.sj-pin-img { width: 100%; height: 100%; box-sizing: border-box; border-radius: 50%; border: 3px solid #fff; background: #DDD6F4 center / cover no-repeat; box-shadow: 0 2px 8px rgba(30,20,80,.38); }
.sj-pin--manual .sj-pin-img { outline: 2px dashed var(--sj-manual); outline-offset: 1px; }
.sj-pin-check { position: absolute; top: -3px; right: -3px; width: 18px; height: 18px; border-radius: 50%; background: var(--sj-green); border: 2px solid #fff; box-sizing: border-box; display: flex; align-items: center; justify-content: center; color: #fff; }
.sj-cluster { width: 44px; height: 44px; box-sizing: border-box; border-radius: 50%; background: linear-gradient(135deg, #6A55F0, #3B2FB8); color: #fff; font-size: 15px; font-weight: 800; display: flex; align-items: center; justify-content: center; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(30,20,80,.4); }

/* Recent memories */
.sj-memories-card { display: flex; flex-direction: column; }
.sj-mem-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.sj-mem { display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 0; border: none; background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.sj-mem-photo { position: relative; aspect-ratio: 4 / 3.3; border-radius: 12px; overflow: hidden; background: #ECE7FB; }
.sj-mem-photo img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.sj-mem:hover .sj-mem-photo img { transform: scale(1.04); }
.sj-mem-badge { position: absolute; top: 7px; right: 7px; width: 22px; height: 22px; border-radius: 50%; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; background: var(--sj-green); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.sj-mem-badge--manual { background: #fff; color: var(--sj-manual); border: 1.5px dashed var(--sj-manual); }
.sj-mem-place { margin-top: 3px; font-size: 12.5px; font-weight: 700; color: var(--sj-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-mem-date { font-size: 11.5px; color: var(--muted); }
.sj-mem-cap { font-size: 11.5px; color: var(--sj-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.sj-viewall-btn { margin-top: auto; align-self: stretch; padding: 10px; border: none; border-radius: 10px; background: #EFEBFC; color: var(--pf-purple); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; }
.sj-mem-grid + .sj-viewall-btn { margin-top: 14px; }
.sj-viewall-btn:hover { background: #E6E0FA; }

/* Places I collected */
.sj-places-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sj-place { border: 1px solid var(--pfx-line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.sj-place-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sj-place-flag { width: 34px; height: 24px; border-radius: 4px; object-fit: cover; box-shadow: 0 0 0 1px rgba(0,0,0,.08); flex-shrink: 0; }
.sj-place-flag--none { display: flex; align-items: center; justify-content: center; background: #ECE7FB; color: var(--pf-purple); font-size: 10px; font-weight: 700; }
.sj-place-name { font-size: 13.5px; font-weight: 700; color: var(--sj-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-place-sub { font-size: 11.5px; color: var(--muted); }
.sj-place-sub--link { display: block; padding: 0; border: none; background: none; font: inherit; font-size: 11.5px; color: var(--pf-purple); cursor: pointer; text-align: left; }
.sj-place-sub--link:hover { text-decoration: underline; }
.sj-cities-bar { display: flex; justify-content: flex-end; padding: 2px 0 10px; }
.sj-cities-bar label { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--sj-muted); }
.sj-cities { list-style: none; margin: 0; padding: 0 0 6px; }
.sj-cities li { border-top: 1px solid #F0EDF7; }
.sj-cities li:first-child { border-top: none; }
.sj-city { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 4px; border: none; background: none; font: inherit; text-align: left; cursor: pointer; border-radius: 10px; }
.sj-city:hover { background: #F6F3FE; }
.sj-city-thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: #ECE7FB; }
.sj-city-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sj-city-name { font-size: 14px; font-weight: 700; color: var(--sj-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-city-meta { font-size: 12px; color: var(--sj-muted); }
.sj-city-pop { font-size: 12.5px; font-weight: 600; color: var(--pf-purple); white-space: nowrap; }
.sj-place-goal { display: flex; justify-content: flex-end; font-size: 11px; color: var(--sj-muted); margin-bottom: 4px; }
.sj-place-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; font-size: 11.5px; color: var(--sj-muted); }
.sj-place-bottom b { color: #1E8449; font-weight: 700; }
.sj-more-btn { display: block; margin: 12px auto 0; padding: 0; border: none; background: none; font: inherit; font-size: 12px; font-weight: 600; color: var(--pf-purple); cursor: pointer; }
.sj-more-btn:hover { text-decoration: underline; }

/* Travel leaderboard */
.sj-seg-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sj-seg { display: inline-flex; padding: 3px; border-radius: 999px; border: 1px solid var(--pfx-line); background: #fff; }
.sj-seg button { border: none; background: none; padding: 6px 16px; border-radius: 999px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--sj-muted); cursor: pointer; }
.sj-seg button.active { background: var(--pf-purple); color: #fff; }
.sj-select { border: 1px solid var(--pfx-line); border-radius: 999px; background: #fff; padding: 6px 12px; font: inherit; font-size: 12.5px; color: var(--sj-ink); cursor: pointer; }
.sj-lb-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.sj-lb-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; padding: 16px 8px 12px; border: 1px solid var(--pfx-line); border-radius: 14px; background: #fff; color: inherit; text-decoration: none; min-width: 0; }
a.sj-lb-card:hover { border-color: #C9BEF0; }
.sj-lb-card.you { border: 2px solid var(--pf-purple); background: #F6F3FF; padding: 15px 7px 11px; }
.sj-lb-rank { position: absolute; top: 9px; left: 9px; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 800; background: #EEEBFA; color: var(--pf-purple); }
.sj-lb-rank.r1 { background: #FCEFC7; color: #B7791F; }
.sj-lb-rank.r2 { background: #E9EDF3; color: #5B6472; }
.sj-lb-rank.r3 { background: #F8E1CF; color: #A5602B; }
.sj-lb-card .friend-avatar { margin-bottom: 5px; border: 2px solid #E4DEF7; box-sizing: border-box; }
.sj-lb-name { max-width: 100%; font-size: 13px; font-weight: 700; color: var(--sj-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-lb-meta { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.sj-lb-pts { margin-top: 3px; font-size: 14px; font-weight: 800; color: var(--pf-purple); }
.sj-lb-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid #F0EDF7; font-size: 12px; color: var(--sj-muted); }
.sj-lb-note { display: inline-flex; align-items: center; gap: 7px; }
.sj-lb-foot a, .sj-lb-foot button { font: inherit; font-size: 12px; font-weight: 600; color: var(--pf-purple); background: none; border: none; padding: 0; cursor: pointer; text-decoration: none; }
.sj-lb-foot a:hover, .sj-lb-foot button:hover { text-decoration: underline; }

/* Next place ideas */
.sj-ideas-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.sj-idea { position: relative; aspect-ratio: 4 / 3.2; border-radius: 12px; overflow: hidden; background: linear-gradient(135deg, #8B7CF0, #4B3FD1); color: #fff; }
.sj-idea img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sj-idea::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20,15,60,0) 38%, rgba(20,15,60,.72) 100%); }
.sj-idea-body { position: absolute; left: 10px; right: 10px; bottom: 9px; z-index: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.sj-idea-name { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,.4); max-width: 100%; }
.sj-idea-name img { position: static; width: 16px; height: 11px; border-radius: 2px; flex-shrink: 0; }
.sj-idea-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-idea-chip { border: none; border-radius: 999px; padding: 4px 11px; background: rgba(255,255,255,.93); color: var(--pf-purple); font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
.sj-idea-chip:hover { background: #fff; }
.sj-idea-chip.saved { background: var(--pf-purple); color: #fff; }
.sj-idea-chip:disabled { opacity: .6; cursor: default; }

/* Friends' travel highlights */
.sj-hl { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-top: 1px solid #F0EDF7; color: inherit; text-decoration: none; }
.sj-hl:first-child { border-top: none; padding-top: 0; }
a.sj-hl:hover .sj-hl-name { text-decoration: underline; }
.sj-hl .friend-avatar { flex-shrink: 0; }
.sj-hl-text { flex: 1; min-width: 0; font-size: 12.5px; line-height: 1.35; color: var(--sj-muted); }
.sj-hl-name { display: block; font-weight: 700; color: var(--sj-ink); }
.sj-hl-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.sj-footnote { display: flex; align-items: center; justify-content: center; gap: 7px; margin: 2px 0 0; text-align: center; font-size: 11.5px; color: var(--muted); }

/* Popups (appended to <body>) */
.sj-modal { max-width: 520px; }
.sj-modal--wide { max-width: 680px; }
.sj-detail-photo { width: 100%; max-height: 52vh; object-fit: contain; border-radius: 12px; display: block; background: #ECE7FB; }
.sj-detail-place { display: flex; align-items: center; gap: 8px; margin: 14px 0 2px; font-size: 17px; font-weight: 800; color: #1B1B3A; }
.sj-detail-place img { width: 22px; height: 15px; border-radius: 2px; object-fit: cover; }
.sj-detail-date { font-size: 13px; color: #55557A; }
.sj-detail-caption { margin: 10px 0 0; font-size: 14px; color: #1B1B3A; overflow-wrap: anywhere; }
.sj-detail-caption.empty { color: #8A8AA5; font-style: italic; }
.sj-detail-source { display: inline-flex; align-items: center; gap: 6px; margin-top: 12px; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.sj-detail-source.verified { background: #E3F5EA; color: #1E8449; }
.sj-detail-source.manual { background: #EFEBFC; color: #4B3FD1; }
.sj-detail-points { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: #FEF6E6; font-size: 12.5px; color: #6B5417; }
.sj-detail-points strong { display: block; font-size: 14px; color: #1B1B3A; margin-bottom: 2px; }
.sj-detail-points.zero { background: #F1F0F7; color: #6E6E8C; }
.sj-mem-pts { position: absolute; right: 6px; bottom: 6px; padding: 2px 7px; border-radius: 999px; background: rgba(27,27,58,.72); color: #fff; font-size: 10.5px; font-weight: 700; }
.sj-detail-edit { display: flex; gap: 8px; margin-top: 10px; }
.sj-detail-edit[hidden] { display: none; }
.sj-detail-edit input { flex: 1; min-width: 0; box-sizing: border-box; padding: 9px 12px; border: 1px solid #DDD8EE; border-radius: 8px; font: inherit; font-size: 13.5px; }
.sj-detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 14px; }
.sj-detail-actions button { border-radius: 999px; padding: 9px 16px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid #DDD8EE; background: #fff; color: #1B1B3A; }
.sj-detail-actions button:hover { border-color: #1B1B3A; }
.sj-detail-actions .primary { background: #4B3FD1; border-color: #4B3FD1; color: #fff; }
.sj-detail-actions .danger { color: #C0392B; border-color: #F0C9C4; margin-left: auto; }
.sj-detail-actions .danger:hover { border-color: #C0392B; }
.sj-detail-msg { font-size: 12.5px; color: #C0392B; min-height: 16px; }
.sj-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; padding-bottom: 12px; }
.sj-gallery-tile { position: relative; aspect-ratio: 1; padding: 0; border: none; border-radius: 10px; overflow: hidden; background: #ECE7FB; cursor: pointer; }
.sj-gallery-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.sj-gallery-tile span { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 7px 5px; background: linear-gradient(180deg, transparent, rgba(20,15,60,.75)); color: #fff; font-size: 11px; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sj-rules { list-style: none; margin: 0; padding: 0 0 6px; }
.sj-rules li { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-top: 1px solid #F0EDF7; font-size: 14px; color: #1B1B3A; }
.sj-rules li:first-child { border-top: none; }
.sj-rules b { color: #4B3FD1; white-space: nowrap; }
.sj-rules-note { margin: 4px 0 14px; font-size: 12.5px; color: #55557A; line-height: 1.5; }

@media (max-width: 980px) {
  .sj-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sj-row-map, .sj-row-extras { grid-template-columns: minmax(0, 1fr); }
  .sj-places-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sj-mem-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sj .sj-trail, .sj-head-plane { display: none; }
}
@media (max-width: 720px) {
  .sj { padding: 16px; border-radius: 18px; }
  .sj-head-title h2 { font-size: 23px; }
  .sj-head-actions { margin-left: 0; width: 100%; }
  .sj-head-actions .pf-btn-primary, .sj-head-actions .pf-btn-outline { flex: 1; justify-content: center; }
  .sj-lb-grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .sj-ideas-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .sj-mem-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sj-map-wrap { min-height: 260px; }
  .sj-legend { margin-left: 0; flex-basis: 100%; }
  .sj-card-head .sj-seg-wrap { margin-left: 0; flex-basis: 100%; }
}
@media (max-width: 480px) {
  .sj-head-actions { gap: 8px; }
  .sj-head-actions .pf-btn-primary, .sj-head-actions .pf-btn-outline { white-space: nowrap; padding: 10px 10px; font-size: 12.5px; gap: 5px; }
  .sj-stat { padding: 10px; gap: 9px; }
  .sj-stat-icon { width: 34px; height: 34px; }
  .sj-stat-num { font-size: 18px; }
  .sj-stat .sj-chip { display: none; }
  .sj-places-grid { grid-template-columns: minmax(0, 1fr); }
}
