:root {
  --bg: #171717;
  --card: #1e1e1e;
  --line: #2e2e2e;
  --hover: #282828;
  --active: #2f2f2f;
  --text: #f3f5f7;
  --muted: #8a8a8a;
  --brand-1: #18e0ff;
  --brand-2: #1a3cff;
  --like: #ff3040;
  --tabbar-h: 56px; /* 모바일 하단 탭바 높이 (안전 영역 제외) */
}

* { box-sizing: border-box; }

/* 모바일 확대 막기: 핀치 줌 · 더블탭 확대 · 가로로 돌렸을 때 글자 자동 확대 (아이폰은 nozoom.js 도 같이) */
html { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* 아이폰은 16px 보다 작은 입력칸을 누르면 화면을 확대한다 → 모든 화면 크기에서 16px */
input, textarea, select { font-size: 16px !important; }

html, body {
  margin: 0;
  /* 넘침은 아래에서 근본적으로 막고, 혹시 남는 가로 넘침만 잘라낸다 (clip은 sticky를 깨지 않음) */
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
svg.fill, svg .fill { fill: currentColor; }

/* ---------- 레이아웃 ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 640px) 1fr;
  gap: 48px;
  min-height: 100vh;
}

/* ---------- 사이드바 ---------- */
.sidebar {
  position: sticky; top: 0;
  height: 100vh;
  padding: 28px 16px;
  overflow-y: auto;
}

.brand {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 36px;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo img { width: 44px; height: 44px; }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px; color: var(--text);
}
.icon-btn:hover { background: var(--hover); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 12px; border-radius: 10px;
  font-size: 17px;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); font-weight: 600; }
.nav-gap { height: 24px; }

.badge-wrap { position: relative; display: grid; }
.badge-wrap .dot {
  position: absolute; top: 1px; right: -1px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--like);
}


/* ---------- 메인 ---------- */
.main { min-width: 0; padding: 20px 0 80px; }
.main-head {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 56px; padding: 0 16px 0 32px;
}
.main-head h1 { margin: 0; font-size: 20px; font-weight: 700; }
.main-head .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.feed-tabs { display: flex; gap: 4px; }
.feed-tab {
  padding: 8px 16px; border-radius: 999px;
  font-size: 16px; font-weight: 600; color: var(--muted);
}
.feed-tab:hover { color: var(--text); }
.feed-tab.active { background: var(--active); color: var(--text); }
.feed-tabs[hidden], .tag-head[hidden] { display: none; }

.tag-head { display: flex; align-items: center; gap: 8px; margin-left: -12px; }
.tag-head h1 { margin: 0; font-size: 20px; }

.hashtag { color: #6f8bff; white-space: nowrap; }
.hashtag:hover { text-decoration: underline; }

.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag-suggest-label { width: 100%; margin: 0 0 2px; font-size: 13px; font-weight: 600; color: #c8c8c8; }
.tag-suggest-label .muted { font-size: 12px; font-weight: 400; }
.tag-chip {
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 13px; color: #c8c8c8;
}
.tag-chip:hover { background: var(--hover); color: var(--text); }
.tag-chip[aria-pressed="true"] { background: #fff; border-color: #fff; color: var(--bg); font-weight: 600; }

.ai-badge {
  padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); font-size: 12px;
}
.post-source {
  display: inline-block; max-width: 100%; margin: 2px 0 6px;
  overflow-wrap: anywhere;
  color: var(--muted); font-size: 13px;
}
.post-source:hover { color: var(--text); text-decoration: underline; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  margin-top: 12px;
}

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
  background: #2b2b2b;
}
.avatar.me { background: #171717; padding: 4px; }
.avatar-link { display: block; width: 40px; height: 40px; }
a.username:hover { text-decoration: underline; }

/* ---------- 프로필 화면 ---------- */
.profile-card[hidden], .icon-btn[hidden], .main-head[hidden] { display: none; }
.profile-card { padding: 20px 24px 0; }
.pc-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.pc-info { min-width: 0; }
.pc-name { margin: 0; font-size: 24px; font-weight: 800; overflow-wrap: anywhere; }
.pc-note { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.pc-avatar { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #2b2b2b; }
.pc-avatar.me { background: #171717; padding: 8px; border: 1px solid var(--line); }
.pc-sectors { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.pc-stats { display: flex; gap: 20px; margin-top: 16px; color: var(--muted); font-size: 14px; }
.pc-stats b { color: var(--text); font-size: 16px; }
.pc-stats a:hover b { text-decoration: underline; }
.pc-actions { display: flex; gap: 8px; margin-top: 16px; }
.pc-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 10px; border-radius: 12px; border: 1px solid var(--line);
  font-size: 14px; font-weight: 600; white-space: nowrap;
}
.pc-btn:hover { background: var(--hover); }
.pc-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.pc-follow { border-color: #f8f6f9; padding: 9px 10px; border-radius: 12px; font-size: 14px; }
.pc-follow.done { border-color: var(--line); }
.pc-tabs { display: flex; margin: 20px -24px 0; border-bottom: 1px solid var(--line); }
.pc-tab {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 4px; color: var(--muted); font-size: 14px; font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pc-tab svg { width: 18px; height: 18px; }
.pc-tab:hover { color: var(--text); }
.pc-tab.active { color: var(--text); border-bottom-color: #f8f6f9; }

/* ---------- 검색 ---------- */
.search-box[hidden] { display: none; }
.search-box {
  display: flex; align-items: center; gap: 10px;
  margin: 8px 0 0; padding: 12px 16px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
}
.search-box:focus-within { border-color: #f8f6f9; }
.search-box svg { width: 20px; height: 20px; flex-shrink: 0; }
.search-box input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none;
  color: var(--text); font: inherit; font-size: 16px;
}
.user-row, .noti-row {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
.noti-row:hover { background: var(--hover); }
.user-link { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.user-link:hover .username { text-decoration: underline; }
.user-row .follow-btn { flex-shrink: 0; }
.request-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-accept, .btn-decline { padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.btn-accept { background: #fff; color: var(--bg); }
.btn-decline { border: 1px solid var(--line); color: var(--muted); }
.section-head {
  padding: 16px 24px 8px; font-size: 14px; font-weight: 700; color: #c8c8c8;
  border-bottom: 1px solid var(--line);
}
.noti-row .user-info { line-height: 1.45; }
.noti-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-follow { margin-left: auto; }
.head-follow[hidden] { display: none; }
.tag-head { flex: 1; }
.user-info { min-width: 0; }
.user-info .username { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-sub { margin-top: 2px; color: var(--muted); font-size: 13px; }
.tag-head .sub[hidden] { display: none; }

.btn-outline {
  padding: 9px 20px; border-radius: 999px; font-weight: 600;
  background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
  color: #fff;
}
.btn-outline:hover:not(:disabled) { filter: brightness(1.1); }
.btn-outline:disabled { background: var(--active); color: var(--muted); cursor: default; }

/* ---------- 게시물 ---------- */
.post {
  display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--line);
}
.post-body { min-width: 0; }
.post:last-child { border-bottom: 0; }

.follow-btn {
  padding: 3px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  border: 1px solid #f8f6f9; color: #f8f6f9;
}
.follow-btn:hover { background: rgba(248,246,249,.12); }
.follow-btn.done { border-color: var(--line); color: var(--muted); }

.post-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.username { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.ai-badge, .follow-btn { flex-shrink: 0; white-space: nowrap; }
.post-head .more { margin-left: auto; width: 32px; height: 28px; color: var(--muted); }

.post-text {
  margin: 2px 0 10px; line-height: 1.5;
  white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere;
}

.media {
  display: flex; gap: 8px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  margin-bottom: 6px;
  scrollbar-width: none;
}
.media::-webkit-scrollbar { display: none; }
.media img {
  display: block; flex-shrink: 0;
  width: 75%; height: 300px;
  object-fit: cover; border-radius: 12px;
  border: 1px solid var(--line);
  scroll-snap-align: start;
  background: #222;
}
.media.single { overflow: visible; }
/* 영상: 화면에 보이면 음소거로 자동 재생, 오른쪽 아래 버튼으로 소리 켜기 */
.video-wrap {
  position: relative; flex-shrink: 0; width: 75%;
  border-radius: 12px; overflow: hidden; background: #000;
  border: 1px solid var(--line); scroll-snap-align: start;
}
.media.single .video-wrap { width: 100%; }
.video-wrap video { display: block; width: 100%; height: 300px; object-fit: cover; }
.media.single .video-wrap video { height: auto; max-height: 560px; object-fit: contain; }
.video-mute {
  position: absolute; right: 10px; bottom: 10px;
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(0,0,0,.6); color: #fff;
}
.video-mute svg { width: 18px; height: 18px; }
.preview video { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; background: #000; }
.preview-badge {
  position: absolute; left: 4px; bottom: 4px; padding: 1px 6px; border-radius: 6px;
  background: rgba(0,0,0,.7); color: #fff; font-size: 11px;
}
.media.single img { width: 100%; height: auto; max-height: 500px; }

.actions { display: flex; flex-wrap: wrap; gap: 4px; margin-left: -12px; }
.action {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  font-size: 13px; color: #c8c8c8;
}
.action svg { width: 20px; height: 20px; }
.action:hover { background: var(--hover); }
.action.liked { color: var(--like); }
.action.liked svg { fill: var(--like); }

/* ---------- 글쓰기 버튼 (FAB) ---------- */

.fab {
  position: fixed; right: 32px; bottom: 32px;
  display: flex; align-items: center; gap: 8px;
  padding: 16px 24px 16px 20px; border-radius: 14px;
  background: #fff;
  color: #171717; font-size: 16px; font-weight: 700;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  transition: transform .15s;
}
.fab:hover { transform: scale(1.05); }
.fab svg { width: 24px; height: 24px; stroke-width: 2.4; }

/* ---------- 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(0,0,0,.7);
}
.modal[hidden] { display: none; }
/* 창이 화면보다 길어지면 창 안에서 스크롤 (위아래가 잘리지 않게) */
.modal-box {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; overflow: hidden;
}
body.modal-open { overflow: hidden; }
.modal-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.text-btn { justify-self: start; }
.modal-body { display: flex; gap: 12px; padding: 20px; flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.modal-body > div { flex: 1; }
.modal-body textarea {
  width: 100%; min-height: 72px; margin-top: 4px; resize: none; overflow: hidden;
  background: none; border: 0; outline: none; color: var(--text); font: inherit;
}
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
  padding: 12px 20px 20px;
}
.muted { color: var(--muted); font-size: 14px; }

.photo-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; margin-left: -12px; border-radius: 999px;
  cursor: pointer; font-size: 14px;
}
.photo-btn:hover { background: var(--hover); }
.photo-btn svg { width: 20px; height: 20px; }

.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews:not(:empty) { margin-top: 10px; }
.preview { position: relative; }
.preview img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.preview button {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0,0,0,.7); color: #fff; font-size: 16px; line-height: 1;
}
.modal-error { margin: 10px 0 0; color: var(--like); font-size: 14px; }

/* ---------- 글 상세: 댓글 ---------- */
.thread[hidden] { display: none; }
.thread { border-top: 1px solid var(--line); }
.reply-box {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 16px 24px; padding: 10px 10px 10px 12px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--bg);
}
.reply-box .avatar { width: 32px; height: 32px; }
.reply-box textarea {
  flex: 1; min-width: 0; resize: none; max-height: 200px;
  padding: 6px 0; background: none; border: 0; outline: none;
  color: var(--text); font: inherit; line-height: 1.45;
}
.reply-box textarea::placeholder { color: var(--muted); }
.reply-submit {
  flex-shrink: 0; padding: 6px 14px; border-radius: 999px;
  background: #fff; color: var(--bg); font-weight: 700; font-size: 14px;
}
.reply-submit:disabled { background: var(--active); color: var(--muted); cursor: default; }
.reply-error { margin: -6px 24px 12px; }
.comments-head {
  padding: 4px 24px 12px; color: var(--muted); font-size: 14px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.comment {
  display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
}
.comment .avatar { width: 36px; height: 36px; }
.comment .post-text { margin-bottom: 0; }
.comment-delete { margin-left: auto; color: var(--muted); font-size: 13px; }
.comment-delete:hover { color: var(--like); }
.post:not(:only-child) { cursor: pointer; }

/* ---------- 메시지 ---------- */
.conv-row .user-sub.unread { color: var(--text); font-weight: 600; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; font-size: 12px; }
.unread-count {
  min-width: 20px; padding: 1px 6px; border-radius: 999px;
  background: var(--like); color: #fff; font-weight: 700; text-align: center;
}
.conv-start { flex-shrink: 0; font-size: 13px; }
.noti-row .user-info { flex: 1; min-width: 0; }

.chat[hidden], #feed[hidden], .fab[hidden] { display: none; }
/* 입력칸이 화면 아래에 붙어 있도록 (overflow: hidden 이면 sticky 가 동작하지 않는다) */
.card:has(.chat:not([hidden])) { overflow: visible; }
.chat-messages { display: flex; flex-direction: column; gap: 6px; padding: 16px 20px; min-height: 50vh; }
.bubble-row { display: flex; align-items: flex-end; gap: 6px; max-width: 80%; }
.bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble {
  padding: 9px 14px; border-radius: 18px; line-height: 1.45;
  background: var(--active); white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere;
}
.bubble-row.mine .bubble { background: #fff; color: var(--bg); }
.bubble-row.mine .bubble .hashtag { color: #1a3cff; }
.bubble-time { flex-shrink: 0; color: var(--muted); font-size: 11px; }
.chat-error { margin: 0 20px 8px; }
.chat-form {
  position: sticky; bottom: 0;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px; background: var(--card); border-top: 1px solid var(--line);
}
.chat-form[hidden] { display: none; }
.chat-form textarea {
  flex: 1; min-width: 0; max-height: 160px; resize: none;
  padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; line-height: 1.4; outline: none;
}
.chat-form textarea:focus { border-color: #f8f6f9; }
.chat-form .reply-submit { padding: 9px 16px; }

/* ---------- 내 글 메뉴 (··· → 수정 · 삭제) ---------- */
.post-menu {
  position: absolute; z-index: 20; min-width: 140px; padding: 6px;
  background: var(--active); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.post-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 10px; font-size: 15px; font-weight: 600; text-align: left;
}
.post-menu button:hover { background: var(--hover); }
.post-menu button svg { width: 18px; height: 18px; }
.post-menu .danger { color: var(--like); }

.feed-status { margin: 0; padding: 40px 24px; text-align: center; color: var(--muted); line-height: 1.6; }
.feed-status a { color: var(--text); text-decoration: underline; }
.load-more {
  display: block; width: 100%; padding: 16px;
  color: var(--muted); border-top: 1px solid var(--line);
}
.load-more:hover { background: var(--hover); color: var(--text); }

/* ---------- 반응형 ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 84px minmax(0, 640px) 1fr; gap: 24px; }
  .brand { justify-content: center; padding-bottom: 28px; }
  .brand .icon-btn, .nav-item span:not(.badge-wrap) { display: none; }
  .nav-item { justify-content: center; }
}

@media (max-width: 640px) {
  /* 글쓰기 창: 전체 화면 시트. 키보드가 올라오면 보이는 높이(--vvh)에 맞춰 올리기 버튼이 키보드 위에 */
  .modal { top: var(--vvt, 0px); bottom: auto; height: var(--vvh, 100dvh); place-items: stretch; background: var(--card); }
  .modal-box { width: 100%; max-height: none; height: 100%; border: 0; border-radius: 0; }
  .modal-head { padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  .preview img, .preview video { width: 76px; height: 76px; }
  .video-wrap video { height: 240px; }

  /* 입력 중에는 하단 탭바 · 글쓰기 버튼을 숨겨 입력칸을 가리지 않게 */
  body.typing .sidebar, body.typing .fab { display: none; }
  body.typing .chat-form { bottom: 0; }

  .layout { display: block; }
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 5;
    height: auto; min-height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
    background: rgba(23,23,23,.94); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .brand, .nav-gap { display: none; }
  .nav { flex-direction: row; justify-content: space-around; }
  .nav-item { padding: 10px; }
  /* 탭바 + 글쓰기 버튼에 마지막 글이 가리지 않게 */
  .main { padding: 0 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 80px); }
  .main-head { padding: 0 16px; }
  .card { border-radius: 0; border-left: 0; border-right: 0; }
  .post, .comment, .user-row, .noti-row, .section-head { padding-left: 16px; padding-right: 16px; }
  .profile-card { padding: 12px 16px 0; }
  .pc-tabs { margin: 16px -16px 0; }
  .pc-tab span { font-size: 12px; }
  .pc-avatar { width: 72px; height: 72px; }
  .pc-actions { flex-wrap: wrap; }
  .pc-btn { padding: 9px 6px; font-size: 13px; }
  .chat-messages { padding: 12px 12px; }
  /* 하단 탭바 위에 입력칸 */
  .chat-form { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
  .search-box { margin: 8px 16px 0; }
  .reply-box { margin: 12px 16px; }
  .reply-error { margin: -4px 16px 12px; }
  .comments-head { padding-left: 16px; padding-right: 16px; }
  .media img { height: 240px; }
  .media.single img { height: auto; max-height: 500px; }
  .fab {
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); right: 16px;
    padding: 12px 18px 12px 14px; font-size: 15px;
  }
  .action span { font-size: 12px; }
}
