* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #221c2b; --panel: #2c2438; --panel2: #362c46; --line: #4a3d60;
  --text: #f2ecdf; --dim: #a99cc0; --accent: #f2a33c; --accent2: #7ec8e3;
  --ok: #7fd08a; --bad: #e2483d;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
html, body { height: 100%; overflow: hidden; }
body { font-family: "Apple SD Gothic Neo", Pretendard, sans-serif; background: var(--bg); color: var(--text);
  -webkit-tap-highlight-color: transparent; }

#map { position: fixed; inset: 0; background: #1a1622; z-index: 0; }
.hidden { display: none !important; }

button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-size: 14px; font-family: inherit; }
button.primary { background: var(--accent); color: #221c2b; font-weight: 700; border: none; }
button.primary:disabled { opacity: .4; }
button.linky { background: none; border: none; color: var(--dim); font-size: 12px; text-decoration: underline; margin-top: 14px; }
input, textarea { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px; font-size: 15px; font-family: inherit; margin-bottom: 10px; }
h1 { font-size: 22px; margin-bottom: 6px; }
.tag { font-size: 12px; color: var(--dim); line-height: 1.7; margin-bottom: 12px; }
.hint { font-size: 12px; color: var(--accent); margin-bottom: 10px; line-height: 1.6; }
.err { color: var(--bad); font-size: 12px; margin-top: 8px; min-height: 15px; }
.big { font-size: 16px; line-height: 1.6; margin-bottom: 10px; }
.row { display: flex; gap: 8px; }
.row button { flex: 1; }

/* 오버레이 (온보딩/페어링) — 지도 조작 가능하게 카드만 이벤트 받음 */
.overlay { position: fixed; inset: 0; z-index: 800; display: flex; align-items: flex-end;
  justify-content: center; pointer-events: none; padding: 12px; padding-bottom: calc(12px + var(--sab)); }
.overlay .card { pointer-events: auto; background: rgba(44,36,56,.96); border: 2px solid var(--line);
  border-radius: 18px; padding: 20px; width: min(420px, 100%); box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  max-height: 72vh; overflow-y: auto; }
.overlay .card .primary { width: 100%; margin-top: 4px; }
#scrPair { align-items: center; background: rgba(20,16,28,.7); }
.authtabs { display: flex; gap: 6px; margin-bottom: 12px; }
.atab { flex: 1; padding: 8px; }
.atab.active { background: var(--accent); color: #221c2b; font-weight: 700; border-color: var(--accent); }
.searchrow { display: flex; gap: 6px; }
.searchrow button { white-space: nowrap; margin-bottom: 10px; }
#crosshair { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -100%); font-size: 34px;
  z-index: 850; pointer-events: none; text-shadow: 0 2px 6px rgba(0,0,0,.6); }

/* 메인 레이아웃 */
#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 700; height: calc(52px + var(--sat));
  padding: calc(6px + var(--sat)) 12px 6px; display: flex; align-items: center; gap: 8px;
  background: rgba(34,28,43,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
#pairTitle { font-weight: 700; font-size: 15px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#queueBadge { background: var(--bad); color: #fff; border-radius: 10px; padding: 2px 8px; font-size: 11px; }
#gearBtn { padding: 6px 10px; }

#tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 700; display: flex;
  background: rgba(34,28,43,.96); border-top: 1px solid var(--line);
  padding-bottom: var(--sab); backdrop-filter: blur(6px); }
.tb { flex: 1; background: none; border: none; border-radius: 0; color: var(--dim); font-size: 19px;
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tb span { font-size: 10px; }
.tb.active { color: var(--accent); }

.view { position: fixed; z-index: 500; top: calc(52px + var(--sat)); bottom: calc(53px + var(--sab));
  left: 0; right: 0; }
#viewChat, #viewCats { background: var(--bg); overflow: hidden; }
#viewMap { pointer-events: none; } /* 지도 탭: 아래 #map이 직접 받음 */
#viewCats { overflow-y: auto; padding: 12px; }

/* 채팅 */
#viewChat { display: flex; flex-direction: column; }
#thread { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 10px 13px; border-radius: 16px; font-size: 14px; line-height: 1.55; white-space: pre-wrap;
  word-break: break-word; }
.mine .bubble { background: var(--accent); color: #221c2b; border-bottom-right-radius: 4px; }
.theirs .bubble { background: var(--panel2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .meta { font-size: 10.5px; color: var(--dim); margin-top: 3px; padding: 0 4px; line-height: 1.5; }
.meta .st-running { color: var(--accent); } .meta .st-queued, .meta .st-pending { color: var(--accent2); }
.meta .st-failed { color: var(--bad); } .meta .st-delivered { color: var(--ok); }
.meta button { font-size: 10.5px; padding: 2px 8px; margin-left: 4px; border-radius: 6px; }
.daysep { align-self: center; font-size: 11px; color: var(--dim); background: var(--panel);
  border-radius: 10px; padding: 3px 10px; }
.emptythread { align-self: center; text-align: center; color: var(--dim); font-size: 13px;
  line-height: 1.8; margin-top: 40px; }

#composer { display: flex; gap: 8px; padding: 8px 10px; background: var(--panel); border-top: 1px solid var(--line); }
#composer textarea { flex: 1; margin: 0; resize: none; max-height: 90px; }
#composer button { font-size: 20px; padding: 0 16px; background: var(--accent); border: none; border-radius: 12px; }

/* 냥이 카드 */
.catcard { display: flex; gap: 10px; align-items: center; background: var(--panel2); border-radius: 14px;
  padding: 10px 12px; margin-bottom: 10px; border: 1px solid var(--line); }
.catcard img { width: 76px; image-rendering: pixelated; }
.catcard .info { flex: 1; min-width: 0; }
.catcard .cname { font-weight: 700; font-size: 15px; }
.catcard .cname small { color: var(--dim); font-weight: 400; margin-left: 4px; }
.catcard .cdesc { font-size: 11px; color: var(--dim); margin-top: 2px; }
.catcard .cstat { font-size: 12px; margin-top: 4px; }
.catcard .records { font-size: 11px; color: var(--dim); margin-top: 3px; }
.catcard.busy { border-color: var(--accent); }
.progressbar { height: 5px; background: var(--line); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.progressbar > div { height: 100%; background: var(--accent); transition: width 1s linear; }

/* 지도 마커 */
.leaflet-marker-icon.smooth { transition: transform 1s linear; }
.catmarker { position: relative; width: 144px; }
.catmarker img { width: 144px; image-rendering: pixelated; position: absolute; left: 0; top: 0;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.45)); }
.catmarker img.f2 { opacity: 0; }
.catmarker.run img.f1 { animation: fA .35s steps(1) infinite; }
.catmarker.run img.f2 { animation: fB .35s steps(1) infinite; }
@keyframes fA { 0%,49% { opacity: 1; } 50%,100% { opacity: 0; } }
@keyframes fB { 0%,49% { opacity: 0; } 50%,100% { opacity: 1; } }
.catmarker .bubble2 { position: absolute; top: -34px; left: 48px; background: #fffdf5; color: #221c2b;
  border-radius: 12px; padding: 3px 8px; font-size: 18px; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.catmarker .bubble2::after { content: ""; position: absolute; bottom: -6px; left: 14px;
  border: 6px solid transparent; border-top-color: #fffdf5; border-bottom: 0; }
.homeicon { font-size: 26px; text-shadow: 0 2px 4px rgba(0,0,0,.6); }
.homeicon .hname { font-size: 11px; background: rgba(34,28,43,.85); color: var(--text);
  border-radius: 8px; padding: 1px 6px; display: block; text-align: center; margin-top: -4px; text-shadow: none; }

/* 모달/토스트 */
#modal { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal-card { background: var(--panel); border: 2px solid var(--line); border-radius: 16px; padding: 20px;
  width: min(460px, 100%); max-height: 82vh; overflow-y: auto; position: relative; }
.modal-card h2 { font-size: 15px; color: var(--accent); margin-bottom: 10px; }
#modalClose { position: absolute; top: 10px; right: 10px; padding: 4px 10px; }
.letter { background: #fffdf5; color: #33291f; border-radius: 10px; padding: 16px; margin: 10px 0;
  font-size: 14px; line-height: 1.7; white-space: pre-wrap; box-shadow: inset 0 0 0 1px #d8cfc0; }
.timeline { list-style: none; padding: 0; font-size: 12px; }
.timeline li { padding: 5px 0 5px 24px; position: relative; border-left: 2px solid var(--line); margin-left: 8px; }
.timeline li::before { content: attr(data-emoji); position: absolute; left: -11px; top: 3px; background: var(--panel); }
.timeline .ttime { color: var(--dim); margin-right: 6px; }
.setrow { margin-bottom: 14px; }
.setrow label { font-size: 12px; color: var(--dim); display: block; margin-bottom: 6px; }
select { width: 100%; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-size: 14px; font-family: inherit; }

#toasts { position: fixed; left: 12px; right: 12px; top: calc(60px + var(--sat)); z-index: 3000;
  display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--panel2); border: 1px solid var(--accent); border-radius: 12px; padding: 12px 16px;
  font-size: 13px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: slidein .3s; cursor: pointer; }
.toast.bad { border-color: var(--bad); }
@keyframes slidein { from { transform: translateY(-16px); opacity: 0; } }
