:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --ink: #2b2a28;
  --sub: #8a857c;
  --accent: #ff7a3d;
  --accent-soft: #ffe8db;
  --line: #eceae4;
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

.hidden { display: none !important; }

/* 헤더 */
.header {
  background: linear-gradient(135deg, #ff7a3d, #ff9d5c);
  color: #fff;
  padding: 18px 16px 16px;
}
.header-inner { max-width: 680px; margin: 0 auto; }
.header h1 { font-size: 22px; letter-spacing: -0.5px; }
.header p { font-size: 13px; opacity: 0.92; margin-top: 2px; }

.container { max-width: 680px; margin: 0 auto; padding: 0 12px 90px; }

/* 지도 */
.map-wrap { position: relative; margin-top: 12px; border-radius: var(--radius); overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.07); }
#map { width: 100%; height: 300px; }
.map-pick-banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px;
  padding: 8px 12px; border-radius: 99px; z-index: 10; white-space: nowrap;
}
.map-pick-banner button {
  margin-left: 8px; background: #555; color: #fff; border: none;
  border-radius: 99px; padding: 2px 10px; cursor: pointer; font-size: 12px;
}
.home-label {
  background: #fff; border: 1.5px solid var(--accent); color: var(--ink);
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15); transform: translateY(6px);
}
.map-error {
  height: 100%; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px; text-align: center;
  background: #f1efe9; color: var(--sub); font-size: 15px; padding: 20px;
}
.map-error small { font-size: 12px; }
.post-marker {
  font-size: 22px; cursor: pointer; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
  transition: transform 0.15s;
}
.post-marker:hover { transform: scale(1.3); }

/* 지도 크기 조절 앵커 */
.map-resizer {
  display: flex; align-items: center; justify-content: center;
  height: 20px; cursor: ns-resize; touch-action: none; user-select: none;
  background: var(--card); border-top: 1px solid var(--line);
}
.map-resizer span {
  width: 44px; height: 5px; border-radius: 99px; background: var(--line);
  transition: background 0.15s;
}
.map-resizer:hover span, .map-resizer.dragging span { background: var(--accent); }
.map-wrap { border-radius: var(--radius); } /* 지도 0 높이(접힘)여도 앵커 바가 모양 유지 */

/* 카테고리 칩 */
.chips { display: flex; gap: 8px; margin: 14px 2px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: var(--card); border: 1px solid var(--line);
  border-radius: 99px; padding: 7px 14px; font-size: 14px; cursor: pointer; color: var(--sub);
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }

/* 피드 */
.feed { display: flex; flex-direction: column; gap: 12px; }
.empty { text-align: center; color: var(--sub); padding: 48px 0; }

.post {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  transition: box-shadow 0.3s;
}
.post.flash { box-shadow: 0 0 0 3px var(--accent); }

.post-head { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; flex: 0 0 auto;
}
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.post-meta { flex: 1; min-width: 0; }
.post-meta strong { font-size: 15px; }
.post-meta .time, .time { display: block; font-size: 12px; color: var(--sub); }
.post-del { background: none; border: none; cursor: pointer; font-size: 14px; opacity: 0.35; }
.post-del:hover { opacity: 1; }

.post-content { margin: 10px 2px; white-space: pre-wrap; word-break: break-word; font-size: 15px; }

/* 글 수정 인라인 에디터 */
.edit-box textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; font-family: inherit; font-size: 15px;
  margin: 10px 0 6px; resize: vertical;
}
.edit-box .photo-add { margin: 10px 0 4px; }
.edit-box .photo-previews { margin-top: 8px; }
.edit-actions { display: flex; gap: 6px; margin: 10px 0; }
.edit-actions button { border: none; border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.edit-actions .save { background: var(--accent); color: #fff; }
.edit-actions .cancel { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }

/* 사진 그리드 (인스타처럼 글보다 먼저) */
.post-photos { display: grid; gap: 4px; border-radius: 12px; overflow: hidden; margin: 12px 0 2px; }
.post-photos img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; aspect-ratio: 4/3; }
.grid-1 { grid-template-columns: 1fr; }
.grid-1 img { aspect-ratio: 16/10; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr; }

.place-chip {
  background: var(--accent-soft); color: #c4511a; border: none; cursor: pointer;
  font-size: 13px; padding: 5px 10px; border-radius: 99px; margin-bottom: 8px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.post-actions { display: flex; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.post-actions button {
  background: none; border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; color: var(--ink);
}
.post-actions button:hover { background: var(--bg); }
.post-actions .kakao-share { background: #FEE500; border-color: #FEE500; color: #191919; font-weight: 600; }
.post-actions .kakao-share:hover { background: #f5dc00; }

/* 토스트 */
.toast {
  position: fixed; bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 14px;
  padding: 10px 18px; border-radius: 99px; z-index: 300;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25); white-space: nowrap;
}

/* 댓글 스레드 */
.replies { margin-top: 12px; border-left: 2px solid var(--line); padding-left: 12px; display: flex; flex-direction: column; gap: 10px; }
.reply { display: flex; gap: 8px; align-items: flex-start; }
.reply-body { flex: 1; min-width: 0; }
.reply-body strong { font-size: 13px; }
.reply-body .time { display: inline; margin-left: 4px; }
.reply-body p { font-size: 14px; word-break: break-word; }
.reply-form { display: flex; flex-wrap: wrap; gap: 6px; }
.reply-form input[name="author"] { width: 90px; }
.reply-form input[name="password"] { width: 90px; }
.reply-form input[name="content"] { flex: 1; min-width: 140px; }
.reply-form input {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px;
}
.reply-form button {
  background: var(--ink); color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 13px; cursor: pointer;
}

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: 24px; width: 56px; height: 56px;
  border-radius: 50%; background: var(--accent); color: #fff; border: none;
  font-size: 22px; cursor: pointer; box-shadow: 0 4px 14px rgba(255, 122, 61, 0.45);
  z-index: 50;
}
.fab:hover { transform: scale(1.06); }

/* 모달 */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-box {
  background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 20px;
}
@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 20px; }
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-head h2 { font-size: 18px; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--sub); }

.cat-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.cat-row input { display: none; }
.cat-row span {
  display: inline-block; border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.cat-row input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: #c4511a; font-weight: 600; }

#compose-form textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 15px; font-family: inherit; resize: vertical;
}

.photo-row { margin: 12px 0; }
.photo-add {
  display: inline-block; border: 1px dashed var(--accent); color: #c4511a;
  border-radius: 10px; padding: 8px 14px; font-size: 14px; cursor: pointer;
}
.photo-previews { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.preview { position: relative; }
.preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; }
.preview button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; border: none; background: var(--ink); color: #fff;
  font-size: 10px; cursor: pointer;
}

.place-row { display: flex; gap: 8px; }
.place-row input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 14px; }
.place-row button {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 0 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.place-results { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; margin-top: 6px; overflow: hidden; }
.place-results button {
  background: #fff; border: none; border-bottom: 1px solid var(--line);
  text-align: left; padding: 10px 12px; font-size: 14px; cursor: pointer;
}
.place-results button:last-child { border-bottom: none; }
.place-results button:hover { background: var(--bg); }
.place-results small { color: var(--sub); display: block; font-size: 12px; }
.place-selected {
  margin-top: 8px; background: var(--accent-soft); color: #c4511a;
  border-radius: 10px; padding: 8px 12px; font-size: 13px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.place-selected button { background: none; border: none; cursor: pointer; color: #c4511a; }

.auth-row { display: flex; gap: 8px; margin: 12px 0; }
.auth-row input { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font-size: 14px; min-width: 0; }

.submit-btn {
  width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.submit-btn:disabled { opacity: 0.6; }

/* 라이트박스 (슬라이드) */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.88); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  touch-action: pan-y;
}
.lightbox img {
  max-width: 94vw; max-height: 88vh; border-radius: 8px;
  user-select: none; -webkit-user-drag: none;
}
.lb-close {
  position: absolute; top: calc(14px + env(safe-area-inset-top, 0px)); right: 14px;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.18); color: #fff; font-size: 18px;
  cursor: pointer; z-index: 2;
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.18); color: #fff; font-size: 28px;
  cursor: pointer; z-index: 2; line-height: 1; padding-bottom: 4px;
}
.lb-nav:hover, .lb-close:hover { background: rgba(255,255,255,0.32); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
.lb-counter {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  color: #fff; font-size: 13px; background: rgba(0,0,0,0.55);
  padding: 4px 12px; border-radius: 99px;
}

/* ---------- 반응형 ---------- */

/* 모바일: iOS 입력 포커스 확대 방지 + 안전영역 */
@media (max-width: 899px) {
  input, textarea { font-size: 16px !important; }
  .fab { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .container { padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)); }
}

/* 데스크톱(900px~): 전체 너비 2패널 — 좌 피드 · 우 지도(전체 높이) */
@media (min-width: 900px) {
  html, body { height: 100%; }
  body { overflow: hidden; display: flex; flex-direction: column; }
  .header { flex: 0 0 auto; }
  .container {
    max-width: none; width: 100%; flex: 1; min-height: 0;
    display: grid;
    grid-template-columns: minmax(400px, 46%) 1fr; /* 피드가 화면 너비에 비례해 커진다 */
    grid-template-rows: auto 1fr;
    grid-template-areas: "chips map" "feed map";
    column-gap: 16px;
    padding: 0 20px 16px;
  }
  .map-wrap { grid-area: map; margin-top: 14px; min-height: 0; }
  #map { height: 100% !important; } /* 모바일에서 저장한 인라인 높이 무시 */
  .map-resizer { display: none; }   /* 지도가 전체 높이라 앵커 불필요 */
  .map-wrap { display: flex; flex-direction: column; }
  #map { flex: 1; }
  .chips { grid-area: chips; }
  .feed { grid-area: feed; overflow-y: auto; min-height: 0; padding: 2px 6px 20px 2px; }
  .empty { grid-area: feed; align-self: start; width: 100%; }
}

/* 광폭(1280px~): 피드 칸이 넓어지면 카드가 자동으로 2~3열로 채워진다 */
@media (min-width: 1280px) {
  .feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 12px; align-content: start;
  }
  .post { height: fit-content; }
}
