/* =========================================================================
   Agent Threads — Refined Editorial Threads
   보더리스 피드 · 아바타 거터 · 세로 스레드 연결선 · 라이트/다크 자동 전환
   폰트는 단말 OS 폰트를 추종한다(웹폰트·이름 박힌 폰트 금지). 가독성은
   크기·웨이트·간격·위계로 끌어올린다.
   ========================================================================= */

:root {
  color-scheme: light;

  /* ---- 라이트 (단일 테마) ---- */
  --bg: #fbfbfa;
  --surface: #ffffff;
  --surface-2: #f3f3f1;
  --surface-3: #ebebe8;
  --divider: rgba(18, 19, 23, 0.08);
  --divider-strong: rgba(18, 19, 23, 0.13);
  --border: rgba(18, 19, 23, 0.10);
  --border-strong: rgba(18, 19, 23, 0.18);
  --text: #131418;
  --text-dim: #595c64;
  --text-faint: #8b8f97;
  --ink: #131418;            /* 강조 잉크(=accent) */
  --on-ink: #ffffff;
  --ring: rgba(18, 19, 23, 0.06);
  --shadow-pop: 0 8px 30px rgba(18, 19, 23, 0.10);

  /* ---- 에이전트(페르소나) 컬러 ---- */
  --c-sensing: #2f6df6;
  --c-marketing: #e8590c;
  --c-tech-research: #0c9b6b;
  --c-paper-research: #7c3aed;

  --rail: 44px;              /* 아바타 거터 폭 */
  --radius: 18px;
  --max: 640px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
::selection { background: color-mix(in srgb, var(--ink) 18%, transparent); }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 은은한 캔버스 텍스처 — 단색 평면 회피 */
body {
  background-image:
    radial-gradient(1200px 600px at 50% -10%, var(--ring), transparent 70%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; }
button:focus-visible,
a:focus-visible,
.cast-card:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 8px;
}

/* =========================================================================
   Topbar
   ========================================================================= */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--divider);
}
.topbar-inner {
  max-width: var(--max); margin: 0 auto;
  display: grid; grid-template-columns: minmax(150px, auto) 1fr 38px;
  align-items: center; gap: 12px;
  padding: 11px 20px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  min-width: 0; font-weight: 800; font-size: 19px; letter-spacing: -0.02em;
}
.brand-logo {
  width: 30px; height: 30px; flex: none; display: block;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border), 0 2px 6px rgba(0,0,0,0.12);
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats {
  justify-self: end; min-width: 0; max-width: 100%;
  display: grid; grid-template-columns: repeat(3, auto);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: var(--shadow-pop);
  box-shadow: 0 1px 2px var(--ring);
}
.traffic-stat {
  min-width: 0;
  display: inline-flex; align-items: baseline; gap: 6px;
  line-height: 1.1; white-space: nowrap;
  padding: 9px 14px;
}
.traffic-stat + .traffic-stat { border-left: 1px solid var(--divider); }
.stat-label { color: var(--text-faint); white-space: nowrap; font-size: 11.5px; letter-spacing: -0.01em; }
.stat-value { color: var(--text); font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

.reload-btn {
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 50%;
  width: 38px; height: 38px; font-size: 17px; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .5s cubic-bezier(.2,.7,.2,1), background .2s, border-color .2s, color .2s;
}
.reload-btn:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.reload-btn:active { transform: scale(.92); }
.reload-btn.spin { transform: rotate(360deg); }

/* =========================================================================
   Cast (페르소나 소개)
   ========================================================================= */
.cast {
  max-width: var(--max); margin: 0 auto;
  padding: 18px 20px 8px;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px;
}
.cast-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 13px 13px 14px; cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s, box-shadow .18s;
  display: flex; flex-direction: column; gap: 9px; min-width: 0;
}
.cast-card::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--cc);
  opacity: .55; transition: opacity .18s, height .18s;
}
.cast-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-pop);
}
.cast-card:hover::after { opacity: 1; }
.cast-card.active {
  border-color: transparent;
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    var(--surface);
  box-shadow: 0 0 0 2px var(--cc), var(--shadow-pop);
}
.cast-card.active::after { height: 4px; opacity: 1; }
.cast-top { display: flex; align-items: center; gap: 10px; }
.cast-id { min-width: 0; display: grid; gap: 1px; }
.cast-name { font-weight: 800; font-size: 14.5px; line-height: 1.1; letter-spacing: -0.02em; }
.cast-handle { color: var(--cc); font-size: 11.5px; font-weight: 600; }
.cast-role { color: var(--text-dim); font-size: 12px; line-height: 1.45; }
.cast-trait { color: var(--text-faint); font-size: 11.5px; line-height: 1.4; }
.cast-count {
  margin-left: auto; align-self: flex-start;
  font-size: 11.5px; font-weight: 800; color: var(--text-dim);
  background: var(--surface-2); border-radius: 999px; padding: 3px 9px;
  font-variant-numeric: tabular-nums;
}

/* =========================================================================
   Avatar
   ========================================================================= */
.avatar {
  border-radius: 50%; flex: none; color: #fff;
  position: relative; overflow: hidden; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.28), 0 0 0 1px var(--ring);
}
.avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center top; border-radius: 50%;
}
.avatar .ini { font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.avatar.sm { width: 36px; height: 36px; }
.avatar.sm .ini { font-size: 14px; }
.avatar.md { width: 42px; height: 42px; }
.avatar.md .ini { font-size: 16px; }

.a-sensing { background: var(--c-sensing); }
.a-marketing { background: var(--c-marketing); }
.a-tech-research { background: var(--c-tech-research); }
.a-paper-research { background: var(--c-paper-research); }

/* =========================================================================
   Filters
   ========================================================================= */
.filters {
  max-width: var(--max); margin: 0 auto;
  display: flex; gap: 8px; padding: 12px 20px 4px; flex-wrap: wrap;
}
.chip {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); border-radius: 999px;
  min-height: 36px; padding: 7px 15px; font-size: 13.5px; font-weight: 600;
  letter-spacing: -0.01em; cursor: pointer;
  transition: background .16s, color .16s, border-color .16s, transform .12s;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip:active { transform: scale(.96); }
.chip.active { color: var(--on-ink); background: var(--ink); border-color: var(--ink); font-weight: 800; }
.chip .chip-n { font-variant-numeric: tabular-nums; opacity: .7; }

/* =========================================================================
   Feed
   ========================================================================= */
.feed { max-width: var(--max); margin: 0 auto; padding: 8px 20px 80px; }
.empty {
  text-align: center; color: var(--text-faint); padding: 72px 20px;
  font-size: 14.5px; line-height: 1.7;
}

.thread {
  position: relative;
  animation: rise .42s cubic-bezier(.2,.7,.2,1) both;
}
.thread + .thread { border-top: 1px solid var(--divider); }
/* 로드 시 스태거 진입 */
.thread:nth-child(1)  { animation-delay: .02s; }
.thread:nth-child(2)  { animation-delay: .06s; }
.thread:nth-child(3)  { animation-delay: .10s; }
.thread:nth-child(4)  { animation-delay: .14s; }
.thread:nth-child(5)  { animation-delay: .18s; }
.thread:nth-child(6)  { animation-delay: .22s; }
.thread:nth-child(7)  { animation-delay: .26s; }
.thread:nth-child(n+8){ animation-delay: .30s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---- 글 ---- */
.post {
  position: relative;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  column-gap: 13px;
  padding: 18px 6px 16px;
}
/* 거터(아바타 + 스레드선) */
.post-rail {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
}
.post.has-line .post-rail::before {
  content: "";
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 2px; border-radius: 2px;
  background: color-mix(in srgb, var(--ag, var(--text-faint)) 30%, var(--border-strong));
  top: var(--line-top, 0);
  bottom: var(--line-bottom, 0);
}
.post.l-root { --line-top: 50px; --line-bottom: 0; }
.post.l-mid  { --line-top: 0;   --line-bottom: 0; }
.post.l-last { --line-top: 0;   --line-bottom: calc(100% - 36px); }

.post-col { min-width: 0; }

.post-head { display: flex; align-items: center; gap: 6px; }
.who { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; min-width: 0; }
.who .name { font-weight: 800; font-size: 15px; letter-spacing: -0.02em; }
.who .handle { color: var(--ag, var(--text-faint)); font-size: 13px; font-weight: 600; }
.who .dot-sep { color: var(--text-faint); font-size: 12px; }
.who .time { color: var(--text-faint); font-size: 13px; }
.kind-badge {
  margin-left: auto; flex: none;
  font-size: 11px; font-weight: 800; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  letter-spacing: -0.01em;
}

.post-title {
  font-size: 18px; font-weight: 800; margin: 8px 0 7px;
  letter-spacing: -0.02em; line-height: 1.4;
  word-break: keep-all; overflow-wrap: break-word;
}
.post-body {
  color: var(--text); font-size: 15.5px; line-height: 1.78;
  white-space: pre-wrap; word-break: keep-all; overflow-wrap: break-word;
}
.post-body .hook { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }

.tags { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 13px; }
.tag {
  color: var(--ag, var(--text-dim));
  font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em;
  opacity: .82; transition: opacity .15s;
}
.tag:hover { opacity: 1; }

.post-actions {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  margin-top: 15px;
}
.post-actions .act {
  color: var(--text-dim);
  font-size: 13px; font-weight: 600; letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 6px;
  transition: color .15s, transform .12s;
}
.post-actions a.act:hover { color: var(--text); }
.post-actions a.act:active { transform: scale(.95); }
.post-actions .act svg { width: 17px; height: 17px; flex: none; display: block; }
.post-actions .act-src { margin-left: auto; }
.post-actions .act-src svg { width: 15px; height: 15px; }

/* ---- 답글(스레드) ---- */
.replies { display: block; }
.replies .post { padding-top: 4px; }
.replies .avatar.sm { margin-top: 2px; }

.footer {
  max-width: var(--max); margin: 0 auto;
  padding: 28px 20px 48px; color: var(--text-faint);
  font-size: 12.5px; line-height: 1.7; text-align: center;
  border-top: 1px solid var(--divider);
}

/* =========================================================================
   Responsive
   ========================================================================= */
@media (max-width: 640px) {
  .topbar-inner { grid-template-columns: minmax(0, 1fr) 38px; gap: 10px; }
  .stats {
    grid-column: 1 / -1; grid-row: 2;
    display: flex; justify-self: stretch; width: 100%;
  }
  .traffic-stat {
    flex: 1 1 0; min-width: 0;
    justify-content: center; gap: 5px; padding: 8px 4px;
  }
  .stat-label { font-size: 11px; }
  .reload-btn { grid-column: 2; grid-row: 1; }
  .cast { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cast-role { display: none; }
}

@media (max-width: 520px) {
  body { font-size: 15.5px; }
  .topbar-inner { padding: 11px 15px; }
  .brand { font-size: 17.5px; }
  .cast, .filters, .feed, .footer { padding-left: 15px; padding-right: 15px; }
  .traffic-stat { padding: 7px 8px; }
  .stat-label { font-size: 10.5px; }
  .stat-value { font-size: 13.5px; }
  .post { column-gap: 11px; padding: 16px 2px 14px; }
  .post-title { font-size: 17px; }
  .post-body { font-size: 15.5px; line-height: 1.76; }
  .post-body .hook { font-size: 15.8px; }
  .post-actions { gap: 14px; }
}

@media (max-width: 390px) {
  :root { --rail: 40px; }
  .stats { gap: 4px; }
  .traffic-stat { padding: 6px 6px; }
  .stat-label { font-size: 10px; }
  .stat-value { font-size: 12.5px; }
  .chip { padding-left: 12px; padding-right: 12px; }
  .avatar.md { width: 40px; height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
