* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --rail: #4a5158;
  --chat-bg: #b2c7d9;
  --kakao: #fee500;
  --ink: #191919;
  --gray: #8c9299;
}

html, body { height: 100%; }
body {
  font: 13px/1.45 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  color: var(--ink);
  background: var(--rail);
  display: flex; flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ESC 한 번이면 게임 흔적이 전부 사라진다 */
body.calm .gamey,
body.calm .cc,
body.calm .hn,
body.calm .dotsep { display: none !important; }

/* 카톡은 레일이 창 맨 위까지 올라오고, 타이틀바는 오른쪽 본문 위에만 있다.
   전체 폭으로 깔면 회색 레일이 잘려 보인다. 창 모드 제약이 아니라 배치 문제였다. */
#right { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#titlebar {
  height: 29px; flex: none;
  -webkit-app-region: drag;
  background: #ffffff;
}

#app { flex: 1; display: flex; min-height: 0; }

/* 대화 창에는 좌측 레일이 없다. 목록 창에는 대화방이 없다. */
/* 카톡 단톡방의 대화상대 서랍. 인원수를 누르면 오른쪽에서 밀려 나온다. */
#members {
  position: absolute; top: 0; right: 0; bottom: 0; width: 244px; z-index: 30;
  background: #fff; border-left: 1px solid #e2e3e6; display: flex; flex-direction: column;
  box-shadow: -6px 0 18px #0000000f;
  transform: translateX(100%); transition: transform .16s ease-out;
}
#members:not([hidden]) { transform: none; }
#members[hidden] { display: flex; pointer-events: none; }
.mb-head {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 13px 10px 13px 16px; border-bottom: 1px solid #f0f0f2;
  font-size: 14px; font-weight: 600; color: #191919;
}
.mb-head .cnt { color: #a7aeb5; font-weight: 500; }
.mb-head .grow { flex: 1; }
#mb-list { padding: 4px 0 10px; }
#mb-list .chatrow { padding: 8px 16px; cursor: default; }
#mb-list .chatrow:hover { background: #f6f7f9; }
#mb-list .out { opacity: .4; }
.rhead b, .rhead .cnt { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { #members { transition: none; } }

body.roomwin #rail { display: none; }
/* 따로 띄운 대화 창에는 돌아갈 데가 없다. 창을 닫으면 그만이다. */
body.roomwin #back { display: none; }
body.roomwin .rhead { padding-left: 16px; }        /* 뒤로가기가 하던 여백을 대신 준다 */
body.roomwin #titlebar { background: #a7bccf; border-bottom: 0; }   /* 대화창과 한 면으로 이어진다 */

/* ---------- 좌측 레일 ---------- */
#rail {
  width: 56px; flex: none; background: #ececed; border-right: 1px solid #e0e0e2;
  -webkit-app-region: drag;                        /* 빈 자리를 잡고 창을 끌 수 있다 */
  display: flex; flex-direction: column; align-items: center; padding: 10px 0 14px; gap: 12px;
}
.rail-spacer { flex: 1; }
.rail-btn {
  width: 44px; height: 44px; border: 0; background: none; cursor: pointer; -webkit-app-region: no-drag;
  border-radius: 8px; position: relative; display: grid; place-items: center;
}
.rail-btn svg { width: 25px; height: 25px; fill: #9a9da2; transition: fill .12s; }
.rail-btn:hover svg { fill: #55585d; }
.rail-btn.on svg { fill: #191919; }

/* ---------- 뷰 ---------- */
main { flex: 1; min-width: 0; min-height: 0; background: #fff; position: relative; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.on { display: flex; }

.vhead { flex: none; padding: 11px 14px 7px; display: flex; align-items: center; gap: 4px; }
.vhead b { font-size: 19px; font-weight: 700; }
.vhead .grow { flex: 1; }
.caret { width: 9px; height: 7px; fill: #2b2b2b; flex: none; margin: 3px 0 0 1px; }
.hicon { border: 0; background: none; cursor: pointer; padding: 4px; border-radius: 6px; display: grid; place-items: center; }
.hicon svg {                                        /* 카톡 헤더 아이콘은 선. 채워 그리면 훨씬 무거워 보인다 */
  width: 21px; height: 21px;
  fill: none; stroke: #55585d; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.hicon:hover { background: #eeeef0; }

/* 카톡 채팅탭의 필터 칩 */
.chips { flex: none; display: flex; gap: 6px; padding: 2px 14px 10px; }
.fchip {
  border: 1px solid #e3e3e5; background: #fff; color: #4c5359;
  border-radius: 14px; padding: 4px 11px; font: inherit; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; flex: none;
}
.fchip.on { background: #2b2b2b; border-color: #2b2b2b; color: #fff; }
.fchip.plus { padding: 4px 10px; color: #8a8d92; }

/* 그룹 아바타 — 카톡 단톡방 프로필. 둥근 사각 타일 넷을 띄워 붙인 모양이다. */
.avatar.grid {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  gap: 2px; background: none; border-radius: 0; padding: 0; place-items: stretch;
}
.avatar.grid > * { min-width: 0; min-height: 0; border-radius: 30%; overflow: hidden; }
.avatar.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* 사진을 안 건 사람 — 카톡 기본 프로필 이미지를 그대로 쓴다 */
.avatar.blank, .avatar.grid i { background: url(av/default.svg) center / cover; display: block; }

.avatar.logo { font-size: 13px; font-weight: 800; letter-spacing: -.6px; }
.avatar.logo.lg-b { background: #4a90d9; }
.avatar.logo.lg-c { background: #c48f5a; }

/* 창 하단 광고 — 카톡 PC와 같은 자리 */
/* 광고 — 카톡과 같은 자리, 같은 모양. 레일 아래까지 전체 폭으로 깔린다. */
#adbar {
  flex: none; height: 76px; display: flex; align-items: center; gap: 12px;
  padding: 0 15px; background: #fff; border-top: 1px solid #ececee; cursor: pointer;
}
#adbar:hover { background: #fafafb; }
.ad-img { width: 56px; height: 56px; flex: none; border-radius: 6px; object-fit: cover; display: block; }
.ad-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ad-copy b {
  font-size: 14px; font-weight: 600; color: #191919; line-height: 1.32;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ad-copy span { font-size: 11.5px; color: #7c8288; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#adbar.has-note .ad-copy span {
  white-space: normal; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}


.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #0002; border-radius: 4px; }

.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 12px;
  display: grid; place-items: center; background: #dfe3e8;
  color: #fff; font-size: 14px; font-weight: 600; letter-spacing: -.3px;
}
.avatar.big { width: 44px; height: 44px; border-radius: 15px; font-size: 17px; }
/* 아바타 색. CSP(style-src 'self')가 인라인 스타일을 막아서 클래스로 둔다. */
.av0 { background: #c2a13f } .av1 { background: #7f9cb5 } .av2 { background: #8fae87 }
.av3 { background: #c19aa2 } .av4 { background: #a79ac0 } .av5 { background: #9aa8b8 }
.av6 { background: #c4ab8e } .av7 { background: #86a89b } .av8 { background: #b39ab0 }
.av9 { background: #a9a2b8 } .av10 { background: #b0a58c } .av11 { background: #93a4ae }
.avatar.hole { background: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }

/* 목록 행 */
.chatrow { display: flex; gap: 11px; align-items: center; padding: 9px 16px; cursor: pointer; user-select: none; }
.chatrow:hover { background: #f4f5f7; }
.chatrow.sel, .chatrow.sel:hover { background: #e4e9ef; }

/* 우클릭 메뉴 */
.ctx {
  position: fixed; z-index: 90; min-width: 178px; padding: 5px 0;
  background: #fff; border: 1px solid #d8dade; border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.14); font-size: 13px; color: #2b2b2b;
}
.ctx button {
  display: block; width: 100%; padding: 7px 16px; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.ctx button:hover { background: #f0f2f5; }
.ctx hr { margin: 5px 0; border: 0; border-top: 1px solid #eceef1; }
.chatrow-mid { flex: 1; min-width: 0; }
.chatrow-top { display: flex; align-items: baseline; gap: 5px; }
.chatrow-top b { font-size: 14px; }
.cnt { color: var(--gray); font-size: 12px; }
.preview {
  color: var(--gray); font-size: 12px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chatrow-right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.badge {
  font-style: normal; min-width: 17px; height: 17px; padding: 0 5px; box-sizing: border-box;
  border-radius: 9px; background: #ff3b30; color: #fff;
  font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}
.rail-btn .badge {                                 /* 아이콘을 다 덮지 않게 작게, 흰 테두리로 띄운다 */
  position: absolute; top: 2px; right: 2px;
  min-width: 15px; height: 15px; line-height: 15px; font-size: 10px; padding: 0 4px;
  box-shadow: 0 0 0 2px #ececed;
}
.fchip .badge { min-width: 15px; height: 15px; line-height: 15px; font-size: 10px; padding: 0 4px; }
.fchip .ci { width: 13px; height: 13px; fill: #3b82f6; flex: none; }
.chatrow-right time { color: #b3b8bd; font-size: 11px; }
.num { color: #9aa0a6; font-size: 11px; font-variant-numeric: tabular-nums; }
.note { font-size: 10.5px; color: #a7aeb5; }
.chatrow.dim { opacity: .45; }

/* ---------- 대화방 ---------- */
/* 다음 일정 알림 줄. 방이 아니라 안내라 눌러도 열 것이 없다. */
#net-rooms .chatrow.soon { cursor: default; }

#view-room { background: var(--chat-bg); }

.rhead {
  flex: none; height: 44px; display: flex; align-items: center; gap: 6px;
  padding: 0 12px 0 4px; background: #a7bccf; color: #1c2a36;
}
.rhead b { font-size: 14px; }
.rhead .grow { flex: 1; }
#back { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: #1c2a36; width: 30px; }

/* 입력창 바로 위. 시선이 아래에 머물도록 카드·족보·칩을 한자리에 모았다. */
#notice {
  min-height: 30px; background: #f5f6f8; border-radius: 10px;
  padding: 6px 10px; margin-bottom: 8px;
  display: flex; align-items: center; flex-wrap: wrap; row-gap: 4px;
  font-size: 11px; color: #6a727a; transition: background .25s;
}
.dotsep { font-style: normal; color: #c3cbd2; margin: 0 7px; }
#notice .num { margin-left: auto; padding-left: 8px; }
.hint { color: #2f3439; font-weight: 700; font-size: 13.5px; letter-spacing: .2px; }

/* 카드 = 두 글자 코드. 흘끗 보면 그냥 약어. */
.cc {
  font: 600 11.5px/1 ui-monospace, 'Consolas', monospace;
  letter-spacing: .2px; color: #3b4349;
  background: #0000000a; border-radius: 3px; padding: 2px 3px;
}
.bubble .cc { font-size: 12.5px; background: #00000010; }
.cc.mine { background: #fee50066; color: #2f3439; }        /* 내 패만 살짝 구분 */
.hn { color: #8c9299; font-size: 11px; }

/* ---------- 말풍선 ---------- */
#chat { padding: 8px 12px 6px; display: flex; flex-direction: column; }

.pill { align-self: center; margin: 8px 0; }
.pill span { background: #00000021; color: #fff; font-size: 11px; padding: 3px 11px; border-radius: 11px; }

.sep { display: flex; align-items: center; gap: 8px; margin: 12px 2px 8px; }
.sep::before, .sep::after { content: ''; flex: 1; height: 1px; background: #00000014; }
.sep span { font-size: 10px; color: #5d6a76; }

.msg { display: flex; gap: 7px; align-items: flex-end; max-width: 100%; margin-top: 6px; }
.msg.same { margin-top: 2px; }
.msg .avatar { align-self: flex-start; }
.msg-body { max-width: 72%; }
.msg-name { font-size: 11px; color: #3d4a56; margin: 0 0 3px 2px; }
.bubble {
  background: #fff; border-radius: 4px 14px 14px 14px;
  padding: 7px 10px; font-size: 13px; word-break: break-word;
  box-shadow: 0 1px 1px #0000000f;
}
.msg.same .bubble { border-radius: 14px; }
.meta { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; padding-bottom: 2px; }
.msg time { font-size: 10px; color: #55606b; }
.bbm {
  font-style: normal; font-size: 10px; font-weight: 600;
  color: #63707c; font-variant-numeric: tabular-nums; letter-spacing: .2px;
}

.msg.me { flex-direction: row-reverse; }
.msg.me .bubble { background: var(--kakao); border-radius: 14px 4px 14px 14px; }
.msg.me.same .bubble { border-radius: 14px; }

/* 카톡 이모티콘처럼 말풍선 없이 큰 이모지 하나 */
.sticker .msg-body { max-width: none; }
.emoticon { font-size: 54px; line-height: 1.05; animation: pop .38s cubic-bezier(.2, 1.55, .4, 1); }
@keyframes pop { from { transform: scale(.35); opacity: 0 } to { transform: scale(1); opacity: 1 } }

.typing .bubble { display: flex; gap: 4px; padding: 11px 12px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: #b8bfc6; animation: blink 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3 } 30% { opacity: 1 } }

/* ---------- 입력 ---------- */
#bar { flex: none; background: #fff; border-top: 1px solid #0001; padding: 8px; transition: background .25s; }

/* 내 차례 — 답장할 차례처럼 보이는 노란 톤. 주변시로도 바로 걸린다. */
body.myturn #bar { background: #fffdf0; }
body.myturn #notice { background: #fdf4cf; }
body.myturn #say { background: #fff; box-shadow: inset 0 0 0 1px #ecd96b; }
body.myturn #q-call { background: var(--kakao); border-color: #f0d400; color: var(--ink); font-weight: 700; }
body.myturn .tick { background: #f2cf00; }

#quick { display: flex; gap: 6px; padding: 0 2px 10px; position: relative; }
.qr {
  border: 1px solid #dbdfe3; background: #fff; color: #4c5359;
  border-radius: 14px; padding: 5px 13px; font: inherit; font-size: 12px; cursor: pointer;
}
.qr:hover { background: #f6f7f8; border-color: #c6cbd0; }
.qr.on { background: #e9ecef; border-color: #cfd4d9; color: #2f3439; font-weight: 600; }

/* 남은 시간. 흘끗 보면 그냥 로딩바로 보이는 회색 실선. */
.tick {
  position: absolute; left: 2px; right: 2px; bottom: 2px; height: 2px;
  background: #e2e6ea; border-radius: 1px; transform-origin: left; transform: scaleX(0);
}
.tick.run { animation: tick 5s linear forwards; }
@keyframes tick { from { transform: scaleX(1) } to { transform: scaleX(0) } }

.input-row { display: flex; gap: 6px; }
#say {
  flex: 1; border: 0; background: #f1f2f4; border-radius: 16px;
  padding: 8px 12px; font: inherit; outline: none; user-select: text;
}
#send { border: 0; background: #f1f2f4; color: var(--gray); border-radius: 16px; padding: 0 14px; cursor: pointer; font: inherit; }
#send:hover { background: var(--kakao); color: var(--ink); }

/* ---------- 새로운 채팅 (친구 초대) ---------- */
#invite, #picker {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: #0006;
}
#invite .sheet, #picker .sheet {
  width: 268px; background: #fff; border-radius: 12px; padding: 18px 18px 14px;
  display: flex; flex-direction: column; gap: 11px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
#invite b, #picker b { font-size: 15px; }
#invite label, #picker label { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: #8b9096; }
#invite label.row, #picker label.row { flex-direction: row; align-items: center; justify-content: space-between; }
#invite input, #invite select, #picker select {
  border: 1px solid #e0e2e5; border-radius: 7px; padding: 7px 9px;
  font: inherit; font-size: 13px; color: #191919; background: #fff; outline: none;
}
#invite input:focus { border-color: #b7c4d2; }
#invite select, #picker select { padding: 5px 6px; max-width: 148px; }
.sheet-btns { display: flex; gap: 7px; margin-top: 3px; }
.sheet-btns button {
  flex: 1; border: 1px solid #e0e2e5; background: #fff; color: #4c5359;
  border-radius: 8px; padding: 8px; font: inherit; font-size: 13px; cursor: pointer;
}
.sheet-btns button.primary { background: #191919; border-color: #191919; color: #fff; }
.sheet-note { margin: 0; font-size: 11px; color: #b0b5ba; min-height: 14px; user-select: text; word-break: break-all; line-height: 1.5; white-space: pre-line; }

/* 친구 고르기 — 카톡 '새로운 채팅'의 사람 목록 */
.pk-list { max-height: 232px; overflow-y: auto; margin: 0 -4px; }
.pk-row { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 8px; cursor: pointer; }
.pk-row:hover { background: #f4f5f7; }
.pk-row .avatar { width: 30px; height: 30px; border-radius: 10px; }
.pk-row b { font-size: 13px; font-weight: 500; color: #191919; flex: 1; }
.pk-row .off { font-size: 11px; color: #b0b5ba; }
.pk-row .box {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 1.5px solid #d3d6da; display: grid; place-items: center;
}
.pk-row.on .box { background: #ffd83d; border-color: #ffd83d; }
.pk-row.on .box::after { content: ''; width: 8px; height: 4px; border: 2px solid #3c2f00; border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.pk-empty { padding: 18px 6px; font-size: 12px; color: #b0b5ba; text-align: center; }

/* 배포된 앱의 첫 실행 — 물어볼 건 이름 하나뿐이다.
   위치로 잡으면 칸을 하나 끼워 넣는 순간 엉뚱한 게 숨는다. 아이디로 잡는다. */
#invite.name-only #iv-urlrow,
#invite.name-only #iv-tierrow,
#invite.name-only #iv-off { display: none; }

/* 연결이 끊긴 동안 — 요란하게 알리지 않고 아이콘만 흐려둔다 */
body.offline .rail-btn.on svg { fill: #b9bcc0; }

/* 대회 개최 — 운영자에게만 보인다 */
#pk-open { display: flex; flex-direction: column; gap: 9px; }
#invite label.check, #picker label.check { flex-direction: row; align-items: center; justify-content: space-between; }
#picker label.check input { width: 16px; height: 16px; accent-color: #191919; }

/* 참가 신청을 받는 중인 모임 — 카톡 상단 고정 줄과 같은 결. 튀지 않으면서 먼저 보인다. */
.chatrow.pinned { background: #fffdf2; }
.chatrow.pinned:hover { background: #fffaea; }
.chatrow.pinned .preview { color: #a08a3c; }

#invite label.check input { width: 16px; height: 16px; accent-color: #191919; }
