* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #14161c;
  --sub: #9aa0ac;
  --soft: #f1f2f5;
  --line: #eef0f3;
  --brand: #5b5bd6;
  --brand-soft: #eeeefb;
  --me: #5b5bd6;
  --me-text: #fff;
  --other: #f1f2f5;
  --good: #1ec98a;
  --warn: #f5a623;
  --shadow: 0 1px 2px rgba(20,22,28,.04), 0 6px 20px rgba(20,22,28,.05);
}
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ---- 상단 바 ---- */
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 16px;
  padding: 11px 20px;
  background: rgba(255,255,255,.8);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo-mark {
  width: 30px; height: 30px; border-radius: 9px; color: #fff;
  display: grid; place-items: center; flex: 0 0 auto;
  background: linear-gradient(135deg,#6a7bff,#5b5bd6);
  box-shadow: 0 4px 12px rgba(91,91,214,.35);
}
.logo-text { font-size: 18px; font-weight: 800; letter-spacing: -.6px; }
.logo-text b { color: var(--brand); font-weight: 800; }

.livestat {
  display: flex; align-items: center; gap: 11px;
  background: var(--soft); padding: 7px 13px; border-radius: 999px;
}
.ls { color: var(--sub); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.ls b { color: var(--ink); font-weight: 700; }
.ls-div { width: 1px; height: 11px; background: var(--line); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--sub); display: inline-block; vertical-align: middle; }
.dot.on { background: var(--good); box-shadow: 0 0 0 0 rgba(30,201,138,.5); animation: pulse 1.9s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(30,201,138,.5);} 70%{box-shadow:0 0 0 6px rgba(30,201,138,0);} 100%{box-shadow:0 0 0 0 rgba(30,201,138,0);} }

.topbtns { margin-left: auto; display: flex; gap: 7px; }
.btn {
  padding: 9px 16px; border-radius: 11px; border: none;
  background: var(--brand); color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 12px rgba(91,91,214,.28);
  transition: opacity .15s, transform .1s, box-shadow .15s;
}
.btn span { display: inline-block; }
.btn.ghost { background: var(--panel); color: var(--sub); box-shadow: inset 0 0 0 1px var(--line); }
.btn:active { transform: scale(.97); opacity: .92; }
#app[data-state="searching"] #nextBtn { opacity: .45; pointer-events: none; box-shadow: none; }

/* ---- 광고 ---- */
.ad {
  background: var(--soft);
  color: #c2c7d0;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: 2px;
  border-radius: 14px;
}
.ad-top { flex: 0 0 auto; height: 64px; margin: 0 20px; }
.ad-bottom { flex: 0 0 auto; height: 52px; margin: 4px 20px 14px; }
.ad-side { flex: 1 1 auto; min-height: 0; }
.ad-side2 { height: 170px; }

/* ---- 3단 레이아웃 ---- */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: 160px minmax(0,1fr) 236px;
  gap: 14px;
  padding: 14px 20px;
}
.col-left, .col-right { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

/* ---- 중앙 채팅 ---- */
.col-chat {
  background: var(--panel); border-radius: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.chat-top {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--soft);
  color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center;
  overflow: hidden; flex: 0 0 auto;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: none; }
#app[data-state="chatting"] .avatar img { display: block; }
/* 찾는 중엔 점멸하는 점만 (이미지 숨김) */
#app[data-state="searching"] .avatar { background: var(--brand-soft); }
.ct-meta #partnerInfo { font-weight: 700; font-size: 14px; line-height: 1.2; }
.ct-status { display: flex; align-items: center; gap: 5px; color: var(--sub); font-size: 11.5px; margin-top: 2px; }
.ct-spacer { flex: 1; }
.ct-tip { font-size: 11px; color: var(--sub); }
#app[data-state="chatting"] #statusDot { background: var(--good); }
#app[data-state="searching"] #statusDot { background: var(--warn); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

#messages {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 18px 16px; display: flex; flex-direction: column; gap: 5px;
}
.msg {
  max-width: min(72%, 440px); padding: 9px 13px; border-radius: 16px;
  font-size: 13.5px; line-height: 1.5; word-break: break-word; white-space: pre-wrap;
  animation: pop .13s ease-out;
}
@keyframes pop { from { transform: translateY(3px); opacity: 0; } to { transform: none; opacity: 1; } }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-text); border-bottom-right-radius: 5px; }
.msg.other { align-self: flex-start; background: var(--other); color: var(--ink); border-bottom-left-radius: 5px; }
.msg.system { align-self: center; background: transparent; color: var(--sub); font-size: 12px; text-align: center; max-width: 92%; padding: 6px 0; }
/* 전송 실패한 내 메시지 */
.msg.failed { opacity: .45; text-decoration: line-through; }
.fail-note { align-self: flex-end; max-width: min(72%,440px); font-size: 11px; color: #e0526b; margin: 1px 2px 4px; }
/* 채팅 중간 광고 카드 */
.chat-ad {
  align-self: stretch; max-width: 560px; margin: 8px auto;
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border-radius: 14px; text-decoration: none;
  background: linear-gradient(135deg,#f3f3fe,#eef0ff);
  box-shadow: inset 0 0 0 1px #e3e3fb; transition: transform .12s, box-shadow .15s;
  animation: pop .15s ease-out;
}
.chat-ad:hover { transform: translateY(-1px); box-shadow: inset 0 0 0 1px #c9c9f6, 0 6px 18px rgba(91,91,214,.14); }
.ca-tag { flex: 0 0 auto; font-size: 9.5px; font-weight: 800; letter-spacing: .5px; color: #fff; background: var(--brand); padding: 3px 7px; border-radius: 6px; }
.ca-body { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.ca-body b { font-size: 13.5px; color: var(--ink); font-weight: 700; }
.ca-body i { font-style: normal; font-size: 12px; color: var(--sub); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-arrow { margin-left: auto; color: var(--brand); font-size: 20px; font-weight: 700; flex: 0 0 auto; }

.searching-line { align-self: center; display: flex; align-items: center; gap: 9px; color: var(--sub); font-size: 12.5px; padding: 20px 0; }
.mini-spin { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.typing { flex: 0 0 auto; padding: 0 18px 6px; font-size: 11.5px; color: var(--sub); }
.hidden { display: none; }
.toast { flex: 0 0 auto; margin: 0 14px 8px; padding: 8px 13px; background: #fff7ec; color: #a86400; border-radius: 10px; font-size: 12px; text-align: center; }

#composer { flex: 0 0 auto; display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--line); }
#msgInput { flex: 1; padding: 12px 15px; border-radius: 12px; border: none; background: var(--soft); font-size: 14px; }
#msgInput:focus { outline: none; box-shadow: inset 0 0 0 1.5px var(--brand); background: #fff; }
#msgInput:disabled { opacity: .55; }
.send { padding: 0 20px; border: none; border-radius: 12px; background: var(--brand); color: #fff; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.send:disabled { background: #cfd2da; cursor: default; }
.send:active:not(:disabled) { opacity: .9; }

/* ---- 우측 정보 ---- */
.panel { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 15px; }
.panel-h { display: flex; align-items: center; gap: 7px; font-size: 11px; font-weight: 700; color: var(--sub); letter-spacing: .5px; margin-bottom: 13px; text-transform: uppercase; }
.live-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: #ffeaec; color: #ff4d5e; font-size: 9.5px; font-weight: 800;
  padding: 3px 7px; border-radius: 999px; letter-spacing: .5px;
}
.live-badge .dot { width: 5px; height: 5px; background: #ff4d5e; animation: blink 1.1s infinite; }

/* 실시간 현황 스탯 카드 */
.stat-cards { display: flex; flex-direction: column; gap: 8px; }
.stat-card {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 13px; background: var(--soft);
  transition: transform .12s;
}
.stat-card:hover { transform: translateY(-1px); }
.sc-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: #fff; flex: 0 0 auto; }
.sc-body { display: flex; flex-direction: column; line-height: 1.1; }
.sc-body b { font-size: 19px; font-weight: 800; color: var(--ink); letter-spacing: -.5px; }
.sc-body b.bump { animation: bump .4s ease; }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.25); color: var(--brand); } 100% { transform: scale(1); } }
.sc-body i { font-style: normal; font-size: 11px; color: var(--sub); margin-top: 1px; }
.c-online .sc-ico { background: linear-gradient(135deg,#23c483,#16c47f); }
.c-wait   .sc-ico { background: linear-gradient(135deg,#f7b733,#f5a623); }
.c-chat   .sc-ico { background: linear-gradient(135deg,#6a7bff,#5b5bd6); }
.c-online { background: #eafaf3; }
.c-wait   { background: #fff6e6; }
.c-chat   { background: #eeeefb; }
.rule-list { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.rule-list li { position: relative; padding-left: 15px; font-size: 12.5px; color: var(--sub); line-height: 1.45; }
.rule-list li::before { content: ""; position: absolute; left: 2px; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--brand); }

/* ---- 반응형 ---- */
@media (max-width: 880px) {
  .col-left { display: none; }
  .layout { grid-template-columns: minmax(0,1fr) 210px; }
}
@media (max-width: 620px) {
  .topbar { gap: 12px; flex-wrap: wrap; padding: 12px 16px; }
  .livestat { order: 3; width: 100%; gap: 12px; }
  .ct-tip { display: none; }
  .ad-top, .ad-bottom { margin: 0 16px; }
  .ad-bottom { margin-bottom: 12px; }
  .layout { grid-template-columns: minmax(0,1fr); gap: 10px; padding: 12px 16px; }
  .col-right { display: none; }
  .col-chat { border-radius: 16px; }
}
