:root {
  --bg: #eef1f6; --card: #fff; --fg: #1a1d21; --sub: #6b7280;
  --line: #e5e7eb; --primary: #4f6ef2; --primary2: #7a5cf0; --mine: #4f6ef2; --peer: #e9ebef;
  --danger: #e24b4b;
  --grad: linear-gradient(135deg, #4f6ef2, #7a5cf0);
  /* 노치·홈바 안전 영역 */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
/* 다크 팔레트: 시스템이 다크일 때(사용자가 라이트로 고정하지 않았으면) + 수동 다크 선택 시 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --card: #1c1f25; --fg: #eceef1; --sub: #9aa1ab;
    --line: #2c3036; --peer: #2a2e34;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --card: #1c1f25; --fg: #eceef1; --sub: #9aa1ab;
  --line: #2c3036; --peer: #2a2e34;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Pretendard", "Pretendard Variable", -apple-system, "Apple SD Gothic Neo",
               "Malgun Gothic", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;              /* 당겨서 새로고침 방지 */
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}

/* 동의 화면 히어로(로고+태그라인) */
.hero { text-align: center; margin-bottom: 18px; }
.hero-logo { font-size: 32px; font-weight: 800; letter-spacing: -.5px; }
.hero-logo .brand-num {
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-tag { color: var(--sub); font-size: 14px; margin-top: 4px; }
.hero-live { margin-top: 10px; font-size: 13px; color: var(--sub); }
.hero-live b { color: #2e9e5b; }

/* 연령·성별 선택 칩 */
.profile { margin: 6px 0 10px; }
.pf-label { font-size: 13px; color: var(--sub); margin: 10px 0 6px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.center-chips { justify-content: center; }
.chip {
  background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 14px; font-size: 14px; min-height: 40px;
}
.chip.on { background: var(--grad); color: #fff; border-color: transparent; font-weight: 700; }
.chip:active { filter: brightness(.96); }
.pprofile { color: var(--sub); font-size: 13px; }

/* 채팅 안전 안내 배너 */
.safety-bar {
  flex: none; background: #fff4e5; color: #8a5a12; font-size: 12.5px;
  padding: 8px 14px; text-align: center; line-height: 1.4;
  padding-left: calc(14px + var(--safe-l)); padding-right: calc(14px + var(--safe-r));
}
:root:not([data-theme="light"]) .safety-bar,
:root[data-theme="dark"] .safety-bar { background: #3a2f1c; color: #e3b667; }


/* 화면 전환 */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; min-height: 100dvh; }
#screen-consent.active, #screen-ready.active, #screen-waiting.active {
  align-items: center; justify-content: center;
  padding: calc(52px + var(--safe-t)) calc(16px + var(--safe-r))
           calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 24px; width: 100%; max-width: 440px; box-shadow: 0 12px 40px rgba(20,30,60,.10);
}
.card.center { text-align: center; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
p { color: var(--sub); line-height: 1.5; margin: 8px 0; }
.fine { font-size: 12px; color: var(--sub); }

/* 동의 고지 */
.notice { background: var(--bg); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; }
.notice ul { margin: 0; padding-left: 18px; }
.notice li { color: var(--fg); font-size: 14px; line-height: 1.6; margin-bottom: 7px; }
.agree { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; margin-bottom: 16px; cursor: pointer; }
.agree input { margin-top: 2px; width: 22px; height: 22px; flex: none; }

/* 버튼 — 터치 영역 최소 48px */
button { font: inherit; border: none; border-radius: 12px; padding: 14px 16px;
         cursor: pointer; min-height: 48px; touch-action: manipulation; }
.primary { background: var(--grad); color: #fff; width: 100%; font-weight: 700; font-size: 16px;
           box-shadow: 0 4px 14px rgba(79,110,242,.3); transition: transform .06s, filter .1s; }
.primary:active { transform: translateY(1px); filter: brightness(.96); }
.primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.secondary { background: var(--peer); color: var(--fg); }
.secondary:active { filter: brightness(.94); }
.row { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.loc { font-size: 14px; color: var(--sub); }

/* 대기 스피너 */
.spinner {
  width: 48px; height: 48px; margin: 8px auto 18px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--primary);
  animation: spin .9s cubic-bezier(.5,.1,.5,.9) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 채팅 — 모바일 키보드/안전영역 대응 */
#screen-chat.active { background: var(--bg); height: 100dvh; overflow: hidden; }
.chat-head {
  display: flex; flex-direction: column; gap: 8px;
  padding: 8px 12px; padding-top: calc(8px + var(--safe-t));
  padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r));
  background: var(--card); border-bottom: 1px solid var(--line); flex: none;
}
.head-row { display: flex; align-items: center; gap: 8px; }
.head-row .brand { flex: 1; text-align: center; }
.head-actions { display: flex; gap: 6px; flex: none; }
.names {
  flex: 1; min-width: 0; font-size: 14px; color: var(--sub); line-height: 1.35;
  word-break: break-all;                 /* 작은 화면에서도 상대명이 잘리지 않고 줄바꿈 */
}
.names b { color: var(--fg); }
.leave { background: var(--primary); color: #fff; padding: 9px 12px; font-weight: 600;
         font-size: 14px; flex: none; min-height: 40px; }
.report { background: transparent; color: var(--danger); padding: 10px 10px; font-size: 18px; }
.loctoggle { background: var(--peer); color: var(--sub); padding: 9px 10px; font-size: 13px;
             min-height: 40px; flex: none; }
.loctoggle.on { background: #2e7d4620; color: #2e9e5b; }
.report { min-height: 40px; }

/* 사이트명 로고 */
.brand { font-size: 18px; font-weight: 800; letter-spacing: -.3px; color: var(--fg); }
.brand-num {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.topbrand {
  position: fixed; z-index: 55; top: calc(12px + var(--safe-t)); left: 0; right: 0;
  text-align: center; font-size: 20px; font-weight: 800; letter-spacing: -.3px;
  color: var(--fg); pointer-events: none;
}
#screen-chat.active ~ .topbrand { display: none; }

.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  padding-left: calc(14px + var(--safe-l)); padding-right: calc(14px + var(--safe-r));
}
.msg { max-width: 80%; padding: 10px 13px; border-radius: 16px; line-height: 1.4;
       word-break: break-word; font-size: 16px; }
.msg.mine { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 4px; }
.msg.peer { align-self: flex-start; background: var(--peer); color: var(--fg); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--sub); font-size: 13px; text-align: center; }
.msg img { width: 160px; max-width: 60vw; height: 160px; max-height: 40vh;
           object-fit: cover; border-radius: 10px; display: block; cursor: pointer; }

.chat-input {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-b));
  padding-left: calc(12px + var(--safe-l)); padding-right: calc(12px + var(--safe-r));
  background: var(--card); border-top: 1px solid var(--line); flex: none;
}
.chat-input .primary { width: auto; padding: 12px 18px; }
#msg-input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 22px;
  padding: 12px 16px; background: var(--bg); color: var(--fg);
  font-size: 16px;                         /* iOS 자동 확대 방지 */
}
.photo-btn {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 12px;
  background: var(--peer); cursor: pointer; font-size: 22px; flex: none;
  touch-action: manipulation;
}
.photo-btn:active { filter: brightness(.94); }

/* 신고 사유 모달 (하단 시트) */
.modal { display: none; position: fixed; inset: 0; z-index: 50;
         background: rgba(0,0,0,.45); align-items: flex-end; justify-content: center; }
.modal.open { display: flex; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--card); width: 100%; max-width: 440px;
  border-radius: 18px 18px 0 0; padding: 20px;
  padding-bottom: calc(20px + var(--safe-b));
  animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h2 { margin: 0 0 4px; }
.reasons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.reason { background: var(--bg); color: var(--fg); border: 1px solid var(--line);
          font-size: 14px; padding: 14px 10px; }
.reason:active { background: var(--peer); }
.wide { width: 100%; }
@media (max-width: 360px) { .reasons { grid-template-columns: 1fr; } }

/* 사진 전체화면 뷰어 */
.viewer { display: none; position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.92);
          flex-direction: column; }
.viewer.open { display: flex; }
.viewer-bar { display: flex; justify-content: flex-end; gap: 8px;
              padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 10px 12px; }
.viewer-btn { background: rgba(255,255,255,.15); color: #fff; font-size: 15px;
              padding: 10px 14px; border-radius: 10px; }
.viewer-btn:active { background: rgba(255,255,255,.3); }
#viewer-img { flex: 1; min-height: 0; width: 100%; object-fit: contain;
              padding: 0 10px calc(10px + var(--safe-b)); }

/* 테마 전환 버튼 */
.theme-toggle {
  position: fixed; z-index: 60;
  top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r));
  width: 42px; height: 42px; min-height: 42px; padding: 0;
  border-radius: 50%; background: var(--card); border: 1px solid var(--line);
  font-size: 18px; line-height: 1; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.theme-toggle:active { filter: brightness(.94); }
/* 채팅 화면에서는 헤더와 겹치지 않게 숨김 */
#screen-chat.active ~ .theme-toggle { display: none; }
