/* 비밀쪽지 화면 스타일. 외부 리소스 없음. */

:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #16181d;
  --text-2: #5b6170;
  --border: #d9dce3;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --accent-soft: #e5ecff;
  --mine: #2f5bea;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --theirs-text: #16181d;
  --ok: #1f9d55;
  --wait: #c98a00;
  --bad: #d23b3b;
  --warn-bg: #fff3d6;
  --warn-text: #6b4a00;
  --warn-border: #f0c75e;
  --danger-bg: #fde7e7;
  --danger-text: #8a1c1c;
  --danger-border: #f1a5a5;
  --focus: #2f5bea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 18px;
  --vvh: 100dvh;
  --vv-top: 0px;
  --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 {
    --bg: #14161a;
    --surface: #1d2026;
    --surface-2: #272b33;
    --text: #eceef2;
    --text-2: #a2a8b5;
    --border: #343944;
    --accent: #6d8dff;
    --accent-text: #0d1020;
    --accent-soft: #232c4a;
    --mine: #3b63f0;
    --mine-text: #ffffff;
    --theirs: #262a32;
    --theirs-text: #eceef2;
    --ok: #3fc27a;
    --wait: #e2a92a;
    --bad: #ff6b6b;
    --warn-bg: #3a2f12;
    --warn-text: #ffd98a;
    --warn-border: #7a5c14;
    --danger-bg: #3b1c1c;
    --danger-text: #ffb4b4;
    --danger-border: #7a2c2c;
    --focus: #8aa4ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 10px;
}

p { margin: 0; }

/* 앱 틀: 키보드가 올라오면 app.js 가 --vvh/--vv-top 을 보이는 영역에 맞춘다 */
.app {
  position: fixed;
  left: 0; right: 0;
  top: var(--vv-top);
  height: var(--vvh);
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- 버튼 ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { flex: none; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:not(:disabled):hover { filter: brightness(1.06); }
.btn-primary:not(:disabled):active { filter: brightness(.94); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:not(:disabled):hover { background: var(--surface-2); }

.btn-danger { background: var(--bad); color: #fff; }

.btn-ghost { color: var(--text); }
.btn-ghost:not(:disabled):hover { background: var(--surface-2); }

.btn-icon { padding: 0; width: 44px; border-radius: 50%; }
.btn-leave { padding: 0 10px 0 4px; gap: 2px; flex: none; }

.btn-chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 14px;
  background: var(--surface-2);
  position: relative;
}
/* 작은 칩도 터치 영역은 44px */
.btn-chip::after {
  content: "";
  position: absolute;
  inset: -4px 0;
}

.btn-wide { width: 100%; min-height: 52px; font-size: 17px; }

/* ---------- 첫 화면 ---------- */
.home {
  flex: 1;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
}
.home-inner {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  text-align: center;
}
.home-mark {
  align-self: center;
  width: 72px; height: 72px;
  display: grid; place-items: center;
  border-radius: 22px;
  background: var(--accent-soft);
  color: var(--accent);
}
.home-title { margin: 0; font-size: 28px; line-height: 1.25; letter-spacing: -.02em; }
.home-lead { color: var(--text-2); font-size: 17px; }
.home-points {
  margin: 4px 0 0;
  padding: 16px 16px 16px 34px;
  text-align: left;
  color: var(--text-2);
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: grid;
  gap: 6px;
}

.notice {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 15px;
  text-align: left;
}
.notice-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); }

/* ---------- 방 화면 ---------- */
.room {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.room-head {
  flex: none;
  padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.head-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
}
.head-status {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}
.status-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--text-2);
}
.dot[data-tone="ok"] { background: var(--ok); }
.dot[data-tone="wait"] { background: var(--wait); animation: pulse 1.4s ease-in-out infinite; }
.dot[data-tone="off"] { background: var(--text-2); }
.dot[data-tone="bad"] { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

.banner {
  flex: none;
  margin: 10px calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 15px;
}
.banner[data-tone="warn"] { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.banner[data-tone="bad"] { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.banner-actions { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.banner-note { flex: 1 1 200px; font-size: 13px; opacity: .9; }

.invite {
  flex: none;
  margin: 10px calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.invite-title { font-weight: 700; font-size: 16px; }
.invite-link {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-overflow: ellipsis;
}
.invite-actions { display: flex; gap: 8px; }
.invite-actions .btn { flex: 1; }
.invite-note { font-size: 13px; color: var(--text-2); }
.copy-feedback { font-size: 14px; color: var(--ok); font-weight: 600; min-height: 0; }
.copy-feedback:empty { display: none; }

/* 대화 목록 */
.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px calc(12px + var(--safe-r)) 12px calc(12px + var(--safe-l));
}
.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: var(--shadow);
}
.mine .bubble { background: var(--mine); color: var(--mine-text); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--theirs); color: var(--theirs-text); border-bottom-left-radius: 6px; }

.bubble.photo {
  padding: 0;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: 14px;
}
.photo-btn {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  border-radius: 14px;
}
.photo-btn img {
  display: block;
  max-width: min(260px, 64vw);
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 14px;
}
.photo-wait {
  width: 200px;
  height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-2);
  font-size: 14px;
  padding: 12px;
}
.photo-wait.failed { width: auto; height: auto; padding: 10px 14px; }
.progress {
  width: 140px;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s linear;
}
.progress.indeterminate > span { width: 40%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

.meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 2px 6px 0;
  font-size: 12px;
  color: var(--text-2);
}
.meta svg { flex: none; }
.meta[data-status="delivered"] { color: var(--ok); }
.meta[data-status="failed"] { color: var(--bad); }

.sys {
  align-self: center;
  max-width: 92%;
  margin: 6px 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
}
.sys.info { border-radius: 12px; }
.sys.warn {
  align-self: stretch;
  max-width: none;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.sys.warn svg { flex: none; margin-top: 2px; }

.jump-new {
  position: absolute;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: var(--shadow);
  z-index: 2;
}

/* 입력창 */
.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) calc(8px + var(--safe-l));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* iOS 확대 방지 */
  line-height: 22px;
  resize: none;
  overflow-y: auto;
}
.input:disabled { opacity: .6; }
.input:focus-visible { outline-offset: 0; border-radius: 22px; }
.input::placeholder { color: var(--text-2); }

.btn-send { background: var(--accent); color: var(--accent-text); }
.btn-send:disabled { background: var(--surface-2); color: var(--text-2); opacity: 1; }

/* 드래그 앤 드롭 */
.drop-overlay {
  position: absolute;
  inset: 8px;
  z-index: 5;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  pointer-events: none;
}

/* 크게 보기 */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .92);
  padding: calc(56px + var(--safe-t)) calc(8px + var(--safe-r)) calc(16px + var(--safe-b)) calc(8px + var(--safe-l));
}
.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}
.viewer-close {
  position: absolute;
  top: calc(8px + var(--safe-t));
  right: calc(8px + var(--safe-r));
  color: #fff;
  background: rgba(255, 255, 255, .14);
}
.viewer-close:focus-visible { outline-color: #fff; }

/* 확인 창 */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, .45);
}
.confirm {
  width: 100%;
  max-width: 340px;
  padding: 20px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.confirm-text { font-size: 16px; white-space: pre-line; }
.confirm-actions { margin-top: 18px; display: flex; gap: 8px; }
.confirm-actions .btn { flex: 1; }

.noscript { padding: 24px; text-align: center; }

/* 데스크톱 */
@media (min-width: 761px) {
  .app {
    top: calc(var(--vv-top) + 16px);
    height: calc(var(--vvh) - 32px);
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    background: var(--bg);
    box-shadow: 0 8px 30px rgba(16, 24, 40, .08);
  }
  .msg { max-width: 70%; }
}
@media (min-width: 761px) and (prefers-color-scheme: dark) {
  html, body { background: #0e1013; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
