/* Social building blocks (js/components/social.js): X-style post rows, media grid, comic quote card,
 * action bar, user rows with follow pills, and the bottom action sheet. Tokens: css/base/components.css. */

:where(body) {
  --tbs-like: #e0245e;
  --tbs-handle: var(--tb-muted);
}

/* ---------- Post row (feed) ---------- */
.tbs-post {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 12px var(--tb-gutter);
  background: var(--tb-surface);
  color: var(--tb-ink);
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) { .tbs-post:not(.tbs-post--detail):hover { background: #fafafa; } }
.tbs-post:focus-visible { box-shadow: inset 0 0 0 2px var(--tb-line-strong); }
.tbs-post > .tb-avatar { --tb-avatar: 40px; }
.tbs-post__main { flex: 1 1 auto; min-width: 0; }
.tbs-post__head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  height: 20px;
  font-size: 15px;
  line-height: 20px;
}
.tbs-post__context {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 4px;
  color: var(--tb-muted);
  font-size: 13px;
  font-weight: 600;
  line-height: 16px;
}
.tbs-post__context ti-icon { --ti-icon-size: 14px !important; width: 14px; height: 14px; }
.tbs-post__context.is-danger { color: var(--tb-danger, #d93025); }
.tbs-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--tb-ink);
  font-weight: 700;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (hover: hover) { a.tbs-name:hover { text-decoration: underline; } }
.tbs-handle, .tbs-time, .tbs-dot {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--tbs-handle);
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tbs-time { flex: none; }
.tbs-more {
  --tb-icon: 18px;
  width: 34px;
  height: 34px;
  margin: -8px -8px -8px auto;
  color: var(--tb-muted);
}
.tbs-post__text {
  margin-top: 2px;
  color: var(--tb-ink);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: normal;
}
.tbs-post__text p { margin: 0; }
.tbs-post__text p + p { margin-top: .5em; }
.tbs-post__text.is-clamped { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 8; }
.tbs-show-more {
  display: block;
  margin: 2px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tb-primary);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}
.tbs-tag, .tbs-at { color: var(--tb-primary); text-decoration: none; }
@media (hover: hover) { a.tbs-tag:hover { text-decoration: underline; } }
.tbs-emoji { display: inline-block; width: 1.4em; height: 1.4em; margin: 0 1px; object-fit: contain; vertical-align: -0.35em; }

/* ---------- Media grid: 1 = natural ratio, 2–4 = 16:9 mosaic ---------- */
.tbs-media {
  display: grid;
  gap: 2px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--tb-divider);
  border-radius: 16px;
  background: var(--tb-divider);
}
.tbs-media__item {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--tb-bg);
  cursor: zoom-in;
}
.tbs-media__item > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.tbs-media[data-count="1"] { justify-self: start; max-width: 100%; }
.tbs-media[data-count="1"] > .tbs-media__item { aspect-ratio: var(--tbs-ratio, 1.333); max-height: 510px; }
.tbs-media[data-count="1"] > .tbs-media__item > img { object-position: center top; }
.tbs-media:not([data-count="1"]) { grid-template-columns: 1fr 1fr; aspect-ratio: 16 / 9; }
.tbs-media[data-count="3"], .tbs-media[data-count="4"] { grid-template-rows: 1fr 1fr; }
.tbs-media[data-count="3"] > .tbs-media__item:first-child { grid-row: span 2; }

/* ---------- Comic quote card ---------- */
.tbs-quote {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--tb-line);
  border-radius: 12px;
  color: var(--tb-ink);
  text-decoration: none;
}
@media (hover: hover) { .tbs-quote:hover { background: #fafafa; } }
.tbs-quote__cover { flex: none; width: 44px; height: 58px; border-radius: 6px; background: var(--tb-bg); object-fit: cover; }
.tbs-quote__body { display: grid; flex: 1 1 auto; gap: 2px; min-width: 0; }
.tbs-quote__title { overflow: hidden; font-size: 15px; font-weight: 600; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.tbs-quote__meta { overflow: hidden; color: var(--tb-muted); font-size: 13px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.tbs-quote__go { --ti-icon-size: 16px !important; flex: none; width: 16px; height: 16px; color: var(--tb-muted); }

/* ---------- Action bar ---------- */
.tbs-actions {
  display: flex;
  justify-content: space-between;
  max-width: 425px;
  margin: 4px 0 -6px -8px;
}
.tbs-act {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 52px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--tb-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tbs-act::after { content: ""; position: absolute; top: 50%; right: 0; left: 0; height: var(--tb-hit); transform: translateY(-50%); }
.tbs-act__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  transition: background-color .15s ease, color .15s ease;
}
.tbs-act__icon ti-icon { --ti-icon-size: 19px !important; width: 19px; height: 19px; }
.tbs-act__num { min-width: 1ch; margin-left: -2px; padding-right: 8px; font-variant-numeric: tabular-nums; }
.tbs-act--like[aria-pressed="true"] { color: var(--tbs-like); }
.tbs-act--fav[aria-pressed="true"] { color: var(--tb-primary); }
@media (hover: hover) {
  .tbs-act:hover { color: var(--tb-primary); }
  .tbs-act:hover .tbs-act__icon { background: rgb(33 150 243 / 10%); }
  .tbs-act--like:hover { color: var(--tbs-like); }
  .tbs-act--like:hover .tbs-act__icon { background: rgb(224 36 94 / 10%); }
}
.tbs-act.is-popping .tbs-act__icon ti-icon { animation: tbs-pop .32s ease; }
@keyframes tbs-pop { 40% { transform: scale(1.28); } }

/* ---------- Focused post (detail page) ---------- */
.tbs-post--detail { display: block; padding: 12px var(--tb-gutter) 0; cursor: default; }
.tbs-post__head--detail { display: flex; align-items: center; gap: 12px; height: auto; }
.tbs-post__head--detail > .tb-avatar { --tb-avatar: 44px; }
.tbs-post__who { display: grid; flex: 1 1 auto; min-width: 0; line-height: 1.35; }
.tbs-post__who .tbs-handle { font-size: 15px; }
.tbs-post__head--detail .tbs-more { margin: 0 -10px 0 0; }
.tbs-post--detail .tbs-post__body { padding-top: 12px; }
.tbs-post--detail .tbs-post__text { font-size: 17px; line-height: 1.6; }
.tbs-post__stamp {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--tb-divider);
  color: var(--tb-muted);
  font-size: 15px;
}
.tbs-post__stamp strong { color: var(--tb-ink); font-weight: 600; }
.tbs-post--detail .tbs-actions { max-width: none; justify-content: space-around; margin: 0; padding: 4px 0; }

/* ---------- Follow pill and user rows ---------- */
.tbs-follow { flex: none; min-width: 64px; }
.tbs-follow[aria-pressed="true"] { color: var(--tb-ink); }
@media (hover: hover) {
  .tbs-follow[aria-pressed="true"]:hover { border-color: rgb(201 53 63 / 40%); background: rgb(201 53 63 / 6%); color: var(--tb-danger); }
}
.tbs-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--tb-gutter);
  background: var(--tb-surface);
}
.tbs-user > .tb-avatar { --tb-avatar: 40px; }
.tbs-user__body { display: grid; flex: 1 1 auto; gap: 1px; min-width: 0; color: var(--tb-ink); text-decoration: none; }
.tbs-user__name { overflow: hidden; font-size: 15px; font-weight: 700; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.tbs-user__desc { overflow: hidden; color: var(--tb-muted); font-size: 14px; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) { .tbs-user:hover { background: #fafafa; } }

/* ---------- Skeleton / empty ---------- */
.tbs-post--skeleton { cursor: default; }
.tbs-post--skeleton .tbs-post__main { display: grid; gap: 10px; padding-top: 4px; }
.tbs-empty { padding: 56px 24px; }

/* ---------- Action sheet (phone: bottom sheet; wide screens: centred card) ---------- */
.tbs-sheet-layer { position: fixed; inset: 0; z-index: 2100; }
.tbs-sheet-layer:not(.is-open) { display: none; }
.tbs-sheet-layer.is-open > .tb-mask { animation: tbs-fade .2s ease; }
.tbs-sheet-layer.is-open > .tbs-sheet { animation: tbs-rise .26s cubic-bezier(.2, .8, .2, 1); }
.tbs-sheet { padding-bottom: env(safe-area-inset-bottom, 0px); }
.tbs-sheet__title { margin: 0; padding: 4px var(--tb-gutter) 8px; color: var(--tb-muted); font-size: 13px; text-align: center; }
.tbs-sheet__list .tb-row { min-height: 52px; }
.tbs-sheet__cancel {
  display: block;
  width: 100%;
  height: 52px;
  margin: 0;
  padding: 0;
  border: 0;
  border-top: 8px solid var(--tb-bg);
  background: var(--tb-surface);
  color: var(--tb-ink);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  box-sizing: content-box;
}
@keyframes tbs-fade { from { opacity: 0; } }
@keyframes tbs-rise { from { transform: translateY(100%); } }
@media (min-width: 761px) {
  .tbs-sheet-layer > .tbs-sheet {
    top: 50%;
    right: auto;
    bottom: auto;
    left: 50%;
    width: 360px;
    max-height: 80vh;
    padding: 8px 0;
    border-radius: 16px;
    transform: translate(-50%, -50%);
  }
  .tbs-sheet-layer.is-open > .tbs-sheet { animation: tbs-zoom .18s ease; }
  .tbs-sheet > .tb-sheet__handle { display: none; }
  .tbs-sheet__cancel { display: none; }
}
@keyframes tbs-zoom { from { opacity: 0; transform: translate(-50%, -48%) scale(.97); } }

@media (prefers-reduced-motion: reduce) {
  .tbs-sheet-layer.is-open > *, .tbs-act.is-popping .tbs-act__icon ti-icon { animation: none !important; }
}
