:root {
  --bg: #fff7ec;
  --paper: #ffffff;
  --ink: #3a2e26;
  --muted: #8a7a6d;
  --line: #f0e2cf;
  --accent: #f08a24;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7cc;
  --danger: #d9534f;
  --shadow: 0 6px 18px rgba(120, 72, 20, 0.12);
  --radius: 18px;
  --head: 'Jua', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  line-height: 1.5;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

h1, h2, .logo, .stats b, .num, .card .name, .btn.big { font-family: var(--head); font-weight: 400; }
h1 { font-size: 1.6rem; margin: 0.2em 0; }
h2 { font-size: 1.25rem; margin: 1.2em 0 0.4em; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

main { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }

/* 밀크·초코 스티커는 흰 바탕 사진이라 곱하기로 섞어서 바탕색에 녹인다 */
.sticker { mix-blend-mode: multiply; display: block; }

/* ---------- 위 막대 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: rgba(255, 243, 226, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 6px; text-decoration: none; font-size: 1.3rem; margin-right: auto; }
.logo img { width: 38px; height: 38px; mix-blend-mode: multiply; }
.logo b { color: var(--accent); font-weight: 400; }
.member-bar { display: flex; }
.me-button {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--paper); border-radius: 999px;
  padding: 3px 12px 3px 3px; font: inherit; font-size: 0.9rem; cursor: pointer; color: var(--ink);
}
.me-button.ask { padding: 6px 12px; color: var(--accent); font-weight: 700; }
.sync-button {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--paper); font-size: 1.1rem; cursor: pointer; color: #b9aa9b;
}
.sync-button.on { color: var(--accent); }
.sync-button.err { color: var(--danger); }

/* 가족 동그라미 */
.mark {
  --c: #f08a24;
  display: inline-block; width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--c); background: #fff; overflow: hidden; flex: none; vertical-align: middle;
}
.mark img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.35) translateY(8%); }
.mark img.face { transform: none; }
.runner img.face { object-position: center 30%; }
.mark.small { width: 22px; height: 22px; border-width: 2px; }
.mark.big { width: 64px; height: 64px; border-width: 4px; }

/* ---------- 아래 메뉴 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 500;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; text-decoration: none; font-size: 0.78rem; color: var(--muted); padding: 4px 0; }
.tabbar a span { font-size: 1.35rem; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar .catch-tab span {
  display: grid; place-items: center; width: 56px; height: 56px; margin-top: -26px;
  border-radius: 50%; background: var(--accent); color: #fff; box-shadow: var(--shadow); border: 4px solid #fff;
}

/* ---------- 단추 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 10px 20px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 700;
  text-decoration: none; cursor: pointer; box-shadow: 0 3px 0 #c96d14;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #c96d14; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.ghost { background: var(--paper); color: var(--ink); border: 2px solid var(--line); box-shadow: none; }
.btn.danger { background: var(--danger); box-shadow: 0 3px 0 #a33a37; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 0.9rem; }
.btn.big { font-size: 1.3rem; padding: 14px 28px; min-height: 56px; width: 100%; max-width: 360px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 0.85rem; cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.actions.center { justify-content: center; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chip {
  flex: none; border: 2px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 5px 14px; font: inherit; font-size: 0.9rem; cursor: pointer;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- 도감 ---------- */
.hero { display: flex; align-items: center; gap: 12px; margin: 8px 0 14px; }
.hero-sticker { width: 108px; height: auto; flex: none; transform: rotate(-4deg); }
.hero p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stats div { background: var(--paper); border-radius: var(--radius); padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stats b { display: block; font-size: 1.8rem; color: var(--accent); line-height: 1.1; }
.stats span { font-size: 0.82rem; color: var(--muted); }

.dex { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  --coat: #c9b8a8;
  position: relative; display: flex; flex-direction: column; text-decoration: none;
  background: var(--paper); border-radius: var(--radius); padding: 8px 8px 10px; box-shadow: var(--shadow);
  border: 3px solid color-mix(in srgb, var(--coat) 55%, white);
  transition: transform 0.15s;
}
.card:active { transform: scale(0.97); }
.card .num { position: absolute; top: 12px; left: 14px; z-index: 1; font-size: 0.8rem; background: rgba(255,255,255,0.85); border-radius: 8px; padding: 0 6px; }
.card .photo {
  display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--coat) 30%, white), color-mix(in srgb, var(--coat) 55%, white));
}
.card .photo img, .target img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .name { font-size: 1.15rem; margin-top: 6px; }
.card .meta { display: flex; align-items: center; justify-content: space-between; font-size: 0.8rem; }
.card .marks { position: absolute; top: 10px; right: 10px; display: flex; gap: 2px; }
.coat-tag { display: inline-block; font-size: 0.78rem; padding: 0 8px; border-radius: 999px; background: color-mix(in srgb, var(--coat, #ccc) 35%, white); }
.hearts { color: #ef5b7a; letter-spacing: 1px; }
.hearts .dim { color: #ecd9d0; }
img.missing { visibility: hidden; }

.empty { text-align: center; padding: 24px 8px; }
.empty .sticker { width: 160px; margin: 0 auto 8px; }

/* ---------- 고양이 카드 ---------- */
.cat-page { --coat: #c9b8a8; }
.cat-hero {
  position: relative; border-radius: 24px; overflow: hidden; box-shadow: var(--shadow);
  background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--coat) 25%, white), color-mix(in srgb, var(--coat) 60%, white));
  border: 4px solid #fff; max-width: 420px; margin: 0 auto;
}
.cat-hero .num { position: absolute; top: 10px; left: 12px; background: #fff; border-radius: 10px; padding: 0 8px; }
.cat-photo { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; }
.cat-page h1 { text-align: center; font-size: 2rem; margin-top: 10px; }
.cat-sub, .cat-first { text-align: center; margin: 4px 0; }
.memo { background: var(--paper); border-radius: 14px; padding: 10px 14px; border: 1px dashed var(--line); white-space: pre-wrap; }
.cat-page .actions { justify-content: center; }
.mini-map { height: 220px; border-radius: var(--radius); overflow: hidden; margin: 10px 0; border: 2px solid var(--line); z-index: 0; }
.timeline { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.timeline li { display: flex; gap: 12px; background: var(--paper); border-radius: 14px; padding: 8px; box-shadow: var(--shadow); }
.timeline > li > img { width: 76px; height: 76px; border-radius: 10px; object-fit: cover; flex: none; cursor: zoom-in; background: var(--accent-soft); }
.timeline div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.timeline .note { color: var(--muted); }
.row-actions { display: flex; gap: 12px; }

.edit-form, .catch-form { background: var(--paper); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.field { display: block; margin: 10px 0; font-weight: 700; border: 0; padding: 0; }
.field input:not([type=radio]):not([type=color]), .field textarea, .link-box, #join-text {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-weight: 400;
  border: 2px solid var(--line); border-radius: 12px; background: #fffdf9; color: var(--ink);
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.name-row { display: flex; gap: 6px; align-items: center; }
.name-row input { flex: 1; }
.name-row .btn { margin-top: 4px; }
.coat-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; font-weight: 400; }
.coat-pick input { position: absolute; opacity: 0; }
.coat-pick span {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  border: 2px solid var(--line); cursor: pointer;
}
.coat-pick span::before { content: ''; width: 14px; height: 14px; border-radius: 50%; background: var(--coat); border: 1px solid rgba(0,0,0,0.15); }
.coat-pick input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.coat-pick input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- 잡기 ---------- */
.catch-start, .join-page { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 12px; }
.big-sticker { width: 180px; }
.wobble { animation: wobble 1.2s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.found { display: flex; align-items: center; gap: 10px; border-radius: var(--radius); padding: 8px 12px; }
.found.yes { background: #e6f7e9; }
.found.no { background: #fff0e0; }
.found .sticker { width: 64px; }
.found p { margin: 0; }
.preview { max-width: 320px; margin: 12px auto 0; border-radius: 24px; overflow: hidden; border: 4px solid #fff; box-shadow: var(--shadow); }
.preview img { display: block; width: 100%; }
.preview.cutout { background: repeating-conic-gradient(#fff3e2 0 25%, #fff 0 50%) 0 / 24px 24px; }
.target-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; margin-bottom: 12px; }
.target { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px; border-radius: 14px; border: 3px solid var(--line); background: var(--paper); cursor: pointer; font-size: 0.85rem; text-align: center; }
.target input { position: absolute; opacity: 0; }
.target.on { border-color: var(--accent); background: var(--accent-soft); }
.target img, .new-cat { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.new-cat { display: grid; place-items: center; font-size: 1.8rem; background: var(--accent-soft); }
.target small { display: block; color: var(--muted); }
.who-line { display: flex; align-items: center; gap: 6px; justify-content: center; }
.catch-form .btn.big { display: flex; margin: 8px auto 0; }

/* ---------- 지도 ---------- */
.big-map { height: calc(100vh - 260px); min-height: 320px; border-radius: var(--radius); overflow: hidden; border: 2px solid var(--line); z-index: 0; }
.cat-pin span { display: block; width: 48px; height: 48px; border-radius: 50%; border: 3px solid var(--c); background: #fff; overflow: hidden; box-shadow: var(--shadow); }
.cat-pin img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- 가족 ---------- */
.family-page { text-align: center; }
.race { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 10px; text-align: left; }
.race li { display: grid; grid-template-columns: 28px 36px 1fr; grid-template-rows: auto auto; align-items: center; gap: 4px 8px; background: var(--paper); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.race .rank { font-family: var(--head); font-size: 1.3rem; text-align: center; grid-row: span 2; }
.race .mark { grid-row: span 2; }
.lane { position: relative; height: 46px; border-radius: 999px; background: repeating-linear-gradient(90deg, #fbf1e3 0 18px, #fff8ef 18px 36px); }
.runner { position: absolute; top: 0; left: calc(var(--p) * 0.82); transition: left 0.8s ease-out; }
.runner img { width: 46px; height: 46px; border-radius: 50%; border: 3px solid var(--c); object-fit: cover; background: #fff; }
.fish { position: absolute; right: 8px; top: 8px; font-size: 1.4rem; }
.score { font-size: 0.95rem; }
.score small { color: var(--muted); margin-left: 8px; }

/* ---------- 창 ---------- */
dialog.sheet {
  width: min(520px, calc(100vw - 24px)); max-height: 86vh; border: 0; border-radius: 24px; padding: 18px;
  background: var(--paper); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
dialog::backdrop { background: rgba(58, 46, 38, 0.45); }
dialog h2 { margin-top: 0; text-align: center; }
.dialog-sticker { width: 120px; margin: 0 auto; }
.who-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.who { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 3px solid transparent; background: none; border-radius: 16px; padding: 8px 2px; font: inherit; cursor: pointer; color: var(--ink); }
.who.on { border-color: var(--accent); background: var(--accent-soft); }
.member-edit { border: 2px solid var(--line); border-radius: 16px; margin: 10px 0; }
.member-edit legend { display: flex; align-items: center; gap: 6px; font-weight: 700; padding: 0 6px; }
.avatar-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 4px; }
.avatar-pick button { border: 3px solid transparent; border-radius: 12px; padding: 0; background: #fff; cursor: pointer; aspect-ratio: 1; overflow: hidden; }
.avatar-pick button.on { border-color: var(--accent); }
.avatar-pick img { width: 100%; height: 100%; object-fit: cover; }
.face-row input[type=file] { display: none !important; }
.face-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; font-weight: 400; }
.device-box { background: #fffaf2; border-radius: 12px; padding: 8px 10px; margin-top: 6px; }
.sync-message { color: var(--danger); font-weight: 700; text-align: center; }
.paste-link { margin-top: 10px; }
.paste-link summary { cursor: pointer; color: var(--accent); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 2000;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; max-width: calc(100vw - 32px);
  transition: opacity 0.2s, transform 0.2s; font-size: 0.92rem; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.celebrate { position: fixed; inset: 0; z-index: 1500; display: grid; place-items: center; background: rgba(58, 46, 38, 0.55); padding: 16px; }
.celebrate[hidden] { display: none; }
.celebrate-card { background: #fff; border-radius: 28px; padding: 20px 24px; text-align: center; max-width: 340px; animation: pop 0.35s ease-out; }
.celebrate-card .sticker { width: 180px; margin: 0 auto; mix-blend-mode: normal; }
.celebrate-card p { color: var(--muted); margin: 0; }
.full-photo { max-width: 100%; max-height: 86vh; border-radius: 16px; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .wobble, .celebrate-card { animation: none; }
  .runner { transition: none; }
}

@media (max-width: 380px) {
  .hero-sticker { width: 84px; }
  h1 { font-size: 1.35rem; }
  .dex { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

/* ---------- 소식 · 댓글 · 한 사람 수집첩 ---------- */
.tabbar a { position: relative; }
.badge {
  position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: #ef4444; color: #fff; font-size: 0.7rem; line-height: 18px; text-align: center; font-weight: 700;
}
.badge[hidden] { display: none; }
.center-text { text-align: center; }
.news { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.news li a { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 16px; background: var(--paper); box-shadow: var(--shadow); text-decoration: none; }
.news li.fresh a { background: #fff4e3; outline: 2px solid var(--accent-soft); }
.news-text { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 0.93rem; }
.quote { background: #fbf6ef; border-radius: 10px; padding: 4px 10px; color: var(--ink); overflow-wrap: anywhere; }
.news-photo { width: 58px; height: 58px; border-radius: 12px; object-fit: cover; flex: none; background: var(--accent-soft); }
.comments { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.comments li { display: flex; gap: 10px; align-items: flex-start; background: var(--paper); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.comments li.none { display: block; box-shadow: none; background: none; text-align: center; }
.comments li div { flex: 1; min-width: 0; }
.comments p { margin: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; background: var(--paper); border-radius: 16px; padding: 10px; box-shadow: var(--shadow); }
.comment-form textarea { flex: 1; min-width: 0; font: inherit; border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px; resize: vertical; background: #fffdf9; color: var(--ink); }
.comment-form textarea:focus { outline: none; border-color: var(--accent); }
.race a.score { text-decoration: none; }
.race .go { color: var(--accent); font-size: 0.82rem; margin-left: 6px; white-space: nowrap; }
.member-page .back { display: inline-block; text-decoration: none; color: var(--muted); margin-bottom: 4px; }
.member-head { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 12px; }
.mark.huge { width: 110px; height: 110px; border-width: 5px; }
