:root {
  --bg: #fbf7f2;
  --surface: #ffffff;
  --ink: #2b2420;
  --muted: #7a6e66;
  --line: #ece4db;
  --brand: #e8743b;
  --brand-ink: #ffffff;
  --brand-soft: #fdeadf;
  --accent: #3f8f6b;
  --accent-soft: #e3f3eb;
  --danger: #b4441b;
  --chip-on-bg: #2b2420;
  --chip-on-ink: #ffffff;
  --overlay: rgba(43, 36, 32, .45);
  --tag-bg: rgba(255, 255, 255, .92);
  --shadow: 0 1px 2px rgba(43, 36, 32, .06), 0 6px 20px rgba(43, 36, 32, .06);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1714; --surface: #26201c; --ink: #f2ebe4; --muted: #b0a399; --line: #3a322c;
    --brand: #f08a52; --brand-ink: #1b1714; --brand-soft: #3d281c; --accent: #6cc39b;
    --accent-soft: #1f3a2d; --danger: #f08a6a; --chip-on-bg: #f2ebe4; --chip-on-ink: #1b1714;
    --overlay: rgba(0, 0, 0, .6); --tag-bg: rgba(38, 32, 28, .92);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1714; --surface: #26201c; --ink: #f2ebe4; --muted: #b0a399; --line: #3a322c;
  --brand: #f08a52; --brand-ink: #1b1714; --brand-soft: #3d281c; --accent: #6cc39b;
  --accent-soft: #1f3a2d; --danger: #f08a6a; --chip-on-bg: #f2ebe4; --chip-on-ink: #1b1714;
  --overlay: rgba(0, 0, 0, .6); --tag-bg: rgba(38, 32, 28, .92);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans KR", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); font-size: 14px; }

/* 헤더 */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-mark { font-size: 24px; }
.brand-name { font-weight: 800; font-size: 24px; letter-spacing: .04em; color: var(--brand); }
.tagline { margin: 0; color: var(--muted); font-size: 14px; }

/* 버튼 */
.btn { border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 15px; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--brand-soft); }

/* 위치 바 */
.locbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 20px 0; padding: 16px 20px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.loc-label { font-size: 13px; color: var(--muted); }
.loc-value { font-weight: 700; }
.loc-actions { display: flex; align-items: center; gap: 10px; }
.loc-buttons { display: flex; gap: 8px; }

/* 경기도 정보를 못 불러왔을 때 안내 */
.notice {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  margin: 0 0 16px; padding: 10px 14px; border-radius: 12px;
  background: var(--brand-soft); color: var(--ink); font-size: 14px; word-break: keep-all;
}
.notice .btn { padding: 6px 12px; font-size: 13px; min-height: 36px; }

/* 안내 메시지 (링크 복사 등) */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 60; max-width: min(92vw, 420px); padding: 12px 16px; border-radius: 12px;
  background: var(--chip-on-bg); color: var(--chip-on-ink); font-size: 14px; box-shadow: var(--shadow);
  word-break: keep-all;
}
.badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.badge.live { background: var(--accent-soft); color: var(--accent); }

/* 레이아웃 */
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
/* 그리드 칸이 가로 스크롤 목록 폭만큼 늘어나 휴대폰 화면 전체가 축소되는 것을 막음 */
.layout > * { min-width: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 20px; }

.animals { scroll-margin-top: 76px; }

/* 보호소 목록 */
.shelters { position: sticky; top: 84px; }
.shelter-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 150px); overflow: auto; }
/* 보호소 한 칸 = 선택 버튼 + (따로 떨어진) 전화 링크 */
.shelter-item {
  background: var(--surface); border: 2px solid transparent; border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden;
}
.shelter-item:hover { border-color: var(--line); }
.shelter-item.is-on { border-color: var(--brand); }
.shelter {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 12px 14px 8px; color: var(--ink); min-height: 44px;
}
.shelter-top { display: flex; justify-content: space-between; gap: 8px; }
.shelter-name { font-weight: 700; min-width: 0; }
.shelter-dist { font-weight: 700; color: var(--brand); white-space: nowrap; }
.shelter-addr { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.shelter-count { font-size: 13px; margin-top: 4px; display: block; }
.shelter-item .tel { margin: 0 14px 12px; }

/* 전화번호: 이 링크를 누를 때만 전화 앱으로 이동 */
.tel {
  display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 4px 10px;
  border-radius: 999px; border: 1px solid var(--accent); color: var(--accent);
  font-size: 13px; font-weight: 700; text-decoration: none; font-variant-numeric: tabular-nums;
}
.tel:hover { background: var(--accent-soft); }

:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* 필터 */
.filters { display: flex; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--ink); min-height: 36px; }
.chip.is-on { background: var(--chip-on-bg); color: var(--chip-on-ink); border-color: var(--chip-on-bg); }

/* 동물 카드 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.photo { position: relative; aspect-ratio: 4 / 3; background: var(--brand-soft); }
.photo img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 56px; }
.kind-tag { position: absolute; z-index: 2; left: 10px; top: 10px; background: var(--tag-bg); border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { margin: 0; font-size: 17px; font-weight: 800; }
.facts { display: flex; flex-wrap: wrap; gap: 6px; }
.fact { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; }
.feature { margin: 0; font-size: 14px; color: var(--ink); }
.feature b { color: var(--muted); font-weight: 500; margin-right: 4px; }
.tagline-text { margin: -4px 0 0; font-size: 14px; color: var(--brand); font-weight: 500; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--muted); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.intro { font-size: 13px; }
.intro summary { cursor: pointer; color: var(--accent); font-weight: 700; }
.intro p { white-space: pre-line; margin: 8px 0; color: var(--ink); max-height: 260px; overflow: auto; }
.intro a { color: var(--accent); font-weight: 700; text-decoration: none; }
.card-foot {
  margin-top: auto; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12px; color: var(--muted);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 10px;
}
.card-foot .care { min-width: 0; }
.card-foot .care b { display: block; color: var(--ink); font-weight: 700; }
.shelter-group-title { grid-column: 1 / -1; margin: 12px 0 0; font-size: 15px; color: var(--muted); font-weight: 700; }
.shelter-group-title:first-child { margin-top: 0; }

.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* 로딩 */
.loading { text-align: center; padding: 80px 0; color: var(--muted); }
.spinner { width: 36px; height: 36px; margin: 0 auto 12px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 동의 모달 */
.modal-backdrop { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--surface); border-radius: 20px; padding: 28px; max-width: 460px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-icon { font-size: 40px; }
.modal h1 { font-size: 22px; margin: 8px 0 10px; }
.modal p { margin: 0 0 12px; }
.consent-points { margin: 0 0 20px; padding-left: 18px; color: var(--muted); font-size: 14px; }
.consent-points li { margin-bottom: 4px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.region-pick { margin-top: 18px; }
.region-pick label { font-size: 14px; font-weight: 700; display: block; margin-bottom: 6px; }
.region-row { display: flex; gap: 8px; }
.region-row select { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); font: inherit; background: var(--surface); color: var(--ink); }
.modal-error { color: var(--danger); font-size: 14px; margin-top: 12px !important; }

.foot { color: var(--muted); font-size: 12px; padding: 40px 16px; }
.ver { white-space: nowrap; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 16px; }
  .shelters { position: static; }
  .shelter-list { flex-direction: row; overflow-x: auto; max-height: none; padding: 2px 2px 8px; scroll-snap-type: x proximity; }
  .shelter-list li { flex: 0 0 220px; scroll-snap-align: start; }
  .tagline { display: none; }
}

/* ---------- 휴대폰 (세로) ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; line-height: 1.5; }
  .wrap { padding: 0 14px; }

  .topbar-inner { height: 52px; }
  .brand-mark { font-size: 20px; }
  .brand-name { font-size: 20px; }

  /* 위치 바: 한 줄로 */
  .locbar { margin: 12px 0; padding: 10px 12px; gap: 8px; border-radius: 12px; flex-wrap: nowrap; }
  .locbar > div:first-child { min-width: 0; }
  .loc-label { font-size: 12px; }
  .loc-value { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .loc-actions { flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
  .badge { font-size: 11px; padding: 2px 8px; }
  .loc-buttons { gap: 6px; }
  #relocate, #shareBtn { padding: 6px 12px; font-size: 13px; min-height: 36px; }

  .section-head { margin-bottom: 8px; }
  .section-head h2 { font-size: 17px; }

  /* 보호소: 가로로 넘기는 작은 카드 */
  .shelter-list li { flex-basis: 200px; }
  .shelter { padding: 10px 12px 6px; }
  .shelter-name { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  .shelter-addr { display: none; }
  .shelter-item .tel { margin: 0 12px 10px; }

  /* 동물 목록 머리: 제목 + 종류 필터를 화면 위에 고정 */
  .animals > .section-head {
    position: sticky; top: calc(52px + env(safe-area-inset-top, 0px)); z-index: 5;
    background: var(--bg); padding: 8px 0; margin: 0 0 4px; flex-wrap: nowrap;
  }
  .animals > .section-head h2 { font-size: 15px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .filters { flex-shrink: 0; gap: 4px; }
  .chip { min-height: 40px; padding: 6px 10px; font-size: 13px; }
  .card.has-tagline .feature { display: none; }

  /* 동물 카드: 한 줄에 한 마리, 화면 한 번에 약 2마리 */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { border-radius: 14px; }
  .photo { aspect-ratio: auto; height: min(44vw, 170px); }
  .photo .ph { font-size: 40px; }
  .card-body { padding: 10px 12px 10px; gap: 5px; }
  .card-title { font-size: 16px; }
  .tagline-text { font-size: 13px; margin: -2px 0 0; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
  /* 나이·성별 등은 한 줄, 넘치면 옆으로 밀어서 보기 */
  .facts { gap: 4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .facts::-webkit-scrollbar { display: none; }
  .fact, .pill { font-size: 12px; padding: 1px 7px; white-space: nowrap; flex-shrink: 0; }
  .card-foot { padding-top: 6px; flex-wrap: nowrap; }
  .card-foot .found { display: none; }
  .card-foot .care { overflow: hidden; }
  .card-foot .care b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .card-foot .tel { flex-shrink: 0; }
  .feature { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .intro summary { min-height: 32px; display: flex; align-items: center; }
  .shelter-group-title { font-size: 14px; margin-top: 8px; }

  .modal { padding: 22px 18px; border-radius: 16px; }
  .modal h1 { font-size: 19px; }
  .modal .btn { min-height: 48px; }
  .region-row .btn { min-height: 44px; }
}
