/* ---------- Tokens ---------- */

:root {
  color-scheme: light;
  --bg: #fff;
  --text: #000;
  --text-secondary: #737373;
  --border: #dbdbdb;
  --divider: #efefef;
  --blue: #0095f6;
  --blue-hover: #1877f2;
  --link: #00376b;
  --button: #efefef;
  --button-hover: #dbdbdb;
  --like: #ff3040;
  --story-ring: linear-gradient(45deg, #f09433, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --topbar-h: 44px;
  --bottom-nav-h: 50px;
  --page-w: 935px;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html.is-locked { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/18px var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { padding: 0; border: 0; background: none; cursor: pointer; }
img, svg { display: block; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.icon { flex: none; width: 24px; height: 24px; }
.icon.verified { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; }
.username { font-weight: 600; }
.tag { color: var(--link); }

/* ---------- Buttons ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--button);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color .15s;
}
.btn:hover { background: var(--button-hover); }
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-hover); }
.btn--primary.is-following { background: var(--button); color: var(--text); }
.btn--primary.is-following:hover { background: var(--button-hover); }

.link-btn { color: var(--blue); font-weight: 600; }
.link-btn:hover { color: var(--link); }
.link-btn.is-following { color: var(--text); }
.link-btn:disabled { opacity: .3; cursor: default; }
.link-btn:disabled:hover { color: var(--blue); }

/* ---------- Avatars ---------- */

.avatar {
  --size: 32px;
  display: grid;
  place-items: center;
  flex: none;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: var(--avatar-bg, var(--border)) center / cover no-repeat;
  color: #fff;
  font-size: calc(var(--size) * .42);
  font-weight: 700;
  line-height: 1;
}

.story-ring {
  display: inline-grid;
  padding: 3px;
  border-radius: 50%;
  background: var(--story-ring);
}
.story-ring > .avatar { border: 3px solid var(--bg); }

/* ---------- Top bar & bottom nav ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  height: var(--topbar-h);
  padding: 0 max(8px, calc((100% - var(--page-w)) / 2));
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}

.topbar__title {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 4px;
  font-size: 16px;
  font-weight: 700;
}

.bottom-nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--divider);
}

/* ---------- Profile header ---------- */

.profile {
  max-width: var(--page-w);
  margin: 0 auto;
  padding: 16px 0 calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
}

.profile-header {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "avatar stats"
    "bio bio"
    "actions actions";
  align-items: center;
  gap: 14px 24px;
  padding: 0 16px;
}

.profile-header__avatar { grid-area: avatar; }
.profile-header__avatar .avatar { --size: 80px; }

.profile-header__top { display: contents; }
.profile-header__title { display: none; }

.profile-header__actions { grid-area: actions; display: flex; gap: 8px; }
.profile-header__actions .btn { flex: 1; }

.profile-header__stats {
  grid-area: stats;
  display: flex;
  justify-content: space-around;
  text-align: center;
}
.stat__value { display: block; font-size: 16px; font-weight: 700; line-height: 20px; }

.profile-header__bio { grid-area: bio; display: grid; gap: 2px; }
.bio__name { font-weight: 600; }
.bio__category { color: var(--text-secondary); }
.bio__text { white-space: pre-line; }

.bio__link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: start;
  color: var(--link);
  font-weight: 600;
}
.bio__link .icon { width: 14px; height: 14px; }

.bio__followed {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 16px;
}
.bio__followed .username { color: var(--text); }

.stacked { display: flex; flex: none; }
.stacked .avatar { border: 2px solid var(--bg); }
.stacked .avatar + .avatar { margin-left: -8px; }

/* ---------- Highlights ---------- */

.highlights {
  display: flex;
  gap: 16px;
  padding: 20px 16px 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.highlights::-webkit-scrollbar { display: none; }

.highlight { display: grid; justify-items: center; gap: 6px; flex: none; width: 64px; }

.highlight__circle {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 50%;
}

.highlight__inner {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fdf0f6;
  font-size: 26px;
}

.highlight__label {
  max-width: 100%;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Tabs & grid ---------- */

.tabs { display: flex; border-top: 1px solid var(--border); }

.tab {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  margin-top: -1px;
  border-top: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.tab.is-active { border-top-color: var(--text); color: var(--text); }
.tab__label { display: none; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; }

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--divider);
}
.tile > img, .tile > .ph { width: 100%; height: 100%; object-fit: cover; }
.tile:focus-visible { outline-offset: -2px; }

.tile__pin {
  position: absolute;
  top: 8px;
  right: 8px;
  color: #fff;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, .45));
}
.tile__pin .icon { width: 20px; height: 20px; }

.tile__overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 24px;
  background: rgba(0, 0, 0, .3);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  opacity: 0;
  transition: opacity .15s;
}
.tile__stat { display: flex; align-items: center; gap: 6px; }
.tile__stat .icon { width: 20px; height: 20px; }
.tile:focus-visible .tile__overlay { opacity: 1; }

@media (hover: hover) {
  .tile:hover .tile__overlay { opacity: 1; }
}

/* ---------- Photo placeholders ---------- */

.ph {
  container-type: size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  text-align: center;
  background: linear-gradient(160deg, #ffc2df, #ff5fa8);
  user-select: none;
}
.ph--daughter { background: linear-gradient(160deg, #fde2f3, #d78cf0); }
.ph--dog { background: linear-gradient(160deg, #ffe0cc, #ff8fb1); }
.ph--duo { background: linear-gradient(160deg, #ffd6e7, #f472b6 55%, #c084fc); }

.ph__emoji { font-size: 34cqmin; line-height: 1; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .15)); }

.ph__label {
  margin-top: 5cqmin;
  padding: .3em .9em;
  border-radius: 999px;
  background: rgba(255, 255, 255, .3);
  font-size: max(11px, 6cqmin);
  font-weight: 700;
}

.ph__hint { margin-top: 2.5cqmin; font-size: max(10px, 4cqmin); opacity: .9; }

@container (max-width: 180px) {
  .ph__hint { display: none; }
}

/* ---------- Post viewer (mobile first: full-screen page) ---------- */

.post-dialog {
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.post-dialog::backdrop { background: rgba(0, 0, 0, .65); }
.post-dialog__close, .post-dialog__nav { display: none; }

.post {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "bar" "author" "media" "actions" "likes" "comments" "date" "form";
  background: var(--bg);
}

.post__bar {
  grid-area: bar;
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.post__author {
  grid-area: author;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 8px 16px;
}
.post__author-info { display: grid; flex: 1; min-width: 0; }
.post__author-line { display: flex; align-items: center; gap: 4px; }
.post__dot { margin: 0 2px; }
.post__location { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.post__media {
  grid-area: media;
  position: relative;
  width: 100%;
  aspect-ratio: var(--ratio, .75);
  max-height: 80vh;
  overflow: hidden;
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.post__media > img, .post__media > .ph { width: 100%; height: 100%; object-fit: contain; }

.heart-burst {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  opacity: 0;
  pointer-events: none;
}
.heart-burst .icon { width: 96px; height: 96px; filter: drop-shadow(0 4px 20px rgba(0, 0, 0, .25)); }

.post__actions { grid-area: actions; display: flex; align-items: center; padding: 4px 6px; }
.post__actions .icon-btn:last-child { margin-left: auto; }
.like-btn.is-liked { color: var(--like); }

.post__likes { grid-area: likes; padding: 0 16px; font-weight: 600; }

.post__comments {
  grid-area: comments;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 12px 16px;
}

.post__date { grid-area: date; padding: 0 16px 12px; color: var(--text-secondary); font-size: 12px; }

.post__form {
  grid-area: form;
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--divider);
}
.post__emoji { color: var(--text-secondary); }
.post__input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: none;
}
.post__input::placeholder { color: var(--text-secondary); }

.comment { display: flex; align-items: flex-start; gap: 12px; }
.comment__body { flex: 1; min-width: 0; }
.comment__text { white-space: pre-line; overflow-wrap: anywhere; }
.comment__text .icon.verified { width: 12px; height: 12px; margin-left: 2px; }

.comment__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 16px;
}
.comment__meta button { font-weight: 600; }

.comment__like { padding-top: 6px; color: var(--text-secondary); }
.comment__like .icon { width: 12px; height: 12px; }
.comment__like.is-liked { color: var(--like); }

/* ---------- Desktop profile ---------- */

@media (min-width: 736px) {
  :root { --topbar-h: 56px; }

  .profile { padding: 30px 20px 48px; }

  .profile-header {
    grid-template-columns: 1fr 2fr;
    grid-template-areas:
      "avatar top"
      "avatar stats"
      "avatar bio";
    align-items: start;
    gap: 20px 30px;
    margin-bottom: 44px;
    padding: 0;
  }
  .profile-header__avatar { align-self: center; justify-self: center; }
  .profile-header__avatar .avatar { --size: 150px; }

  .profile-header__top {
    grid-area: top;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 20px;
  }
  .profile-header__title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 20px;
    font-weight: 400;
    line-height: 25px;
  }
  .profile-header__title .icon.verified { width: 18px; height: 18px; }
  .profile-header__actions .btn { flex: none; }

  .profile-header__stats { justify-content: flex-start; gap: 40px; font-size: 16px; text-align: left; }
  .stat__value { display: inline; font-weight: 600; }

  .highlights { gap: 40px; padding: 0 0 44px 40px; }
  .highlight { width: 87px; }
  .highlight__circle { width: 87px; height: 87px; }
  .highlight__inner { font-size: 34px; }

  .tabs { justify-content: center; gap: 60px; }
  .tab { flex: none; height: 52px; }
  .tab .icon { width: 12px; height: 12px; }
  .tab__label { display: inline; }

  .grid { gap: 4px; }

  .bottom-nav { display: none; }
}

/* ---------- Desktop post viewer (side-by-side modal) ---------- */

@media (min-width: 900px) {
  .post-dialog { background: transparent; overflow: hidden; }
  .post-dialog[open] { display: flex; align-items: center; justify-content: center; }

  .post-dialog__close {
    position: fixed;
    top: 8px;
    right: 8px;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    color: #fff;
  }
  .post-dialog__close .icon { width: 28px; height: 28px; }

  .post-dialog__nav {
    position: fixed;
    top: 50%;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    color: #000;
    transform: translateY(-50%);
  }
  .post-dialog__nav .icon { width: 18px; height: 18px; }
  .post-dialog__nav--prev { left: 24px; }
  .post-dialog__nav--next { right: 24px; }
  .post-dialog__nav[hidden] { display: none; }

  .post {
    --post-h: min(calc(100dvh - 64px), 880px);
    --side-w: clamp(320px, 32vw, 405px);
    grid-template-columns:
      min(calc(var(--post-h) * var(--ratio, .75)), calc(100vw - var(--side-w) - 144px))
      var(--side-w);
    grid-template-rows: auto minmax(0, 1fr) auto auto auto auto;
    grid-template-areas:
      "media author"
      "media comments"
      "media actions"
      "media likes"
      "media date"
      "media form";
    height: var(--post-h);
    overflow: hidden;
    border-radius: 4px;
  }

  .post__bar { display: none; }
  .post__author { padding: 14px 4px 14px 16px; border-bottom: 1px solid var(--divider); }
  .post__media { height: 100%; max-height: none; aspect-ratio: auto; border-right: 1px solid var(--divider); }
  .post__comments { overflow-y: auto; overscroll-behavior: contain; }
  .post__actions { border-top: 1px solid var(--divider); }
  .post__form { position: static; padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .tile__overlay { transition: none; }
}
