/* jay-ai-bridge — 남용 · 뮤즈 · 피클 3자 소통 보드 */

:root {
  --bg: #080d18;
  --bg-soft: #0d1424;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.075);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e9eefb;
  --text-soft: #b9c5dd;
  --muted: #8794ae;

  --namyong: #4d8dff;
  --namyong-soft: rgba(77, 141, 255, 0.16);
  --muse: #b47bff;
  --muse-soft: rgba(180, 123, 255, 0.15);
  --pickle: #43d18a;
  --pickle-soft: rgba(67, 209, 138, 0.14);
  --danger: #ff6b6b;

  --radius: 18px;
  --radius-sm: 12px;
  --topbar-h: 68px;
  --composer-pad: env(safe-area-inset-bottom, 0px);

  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(77, 141, 255, 0.20), transparent 62%),
    radial-gradient(760px 460px at 92% 2%, rgba(180, 123, 255, 0.16), transparent 60%),
    radial-gradient(700px 520px at 50% 110%, rgba(67, 209, 138, 0.11), transparent 65%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

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

/* ---------- 잠금 게이트 ---------- */

body.locked .app { display: none !important; }
body:not(.locked) .gate { display: none !important; }

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px 18px calc(24px + var(--composer-pad));
  z-index: 60;
  backdrop-filter: blur(6px);
}

.gate-card {
  width: min(400px, 100%);
  padding: 34px 26px 24px;
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(22, 30, 48, 0.92), rgba(12, 18, 32, 0.96));
  border: 1px solid var(--border-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
}

.gate-mark {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 12px;
  filter: drop-shadow(0 8px 20px rgba(77, 141, 255, 0.45));
}

.gate-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.gate-desc {
  margin: 0 0 22px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}

.pin-field {
  position: relative;
  margin-bottom: 14px;
  text-align: left;
}

.pin-field::before {
  content: "🔑";
  position: absolute;
  left: 15px; top: 50%;
  transform: translateY(-50%);
  font-size: 15px;
  opacity: .8;
  pointer-events: none;
}

.pin-field input {
  width: 100%;
  padding: 15px 46px 15px 42px;
  font-family: var(--mono);
  font-size: 17px;
  letter-spacing: 0.18em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}

.pin-field input::placeholder { letter-spacing: 0.05em; color: #5f6c85; }
.pin-field input:focus {
  border-color: rgba(77, 141, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(77, 141, 255, 0.16);
}

.peek {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  display: grid; place-items: center;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}
.peek:hover { background: var(--surface-2); color: var(--text); }

.primary {
  width: 100%;
  padding: 15px 18px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: #061021;
  background: linear-gradient(135deg, #7fb0ff, #4d8dff 55%, #7f6bff);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .12s, filter .18s, opacity .18s;
  box-shadow: 0 12px 28px rgba(77, 141, 255, 0.32);
}
.primary:hover { filter: brightness(1.06); }
.primary:active { transform: translateY(1px) scale(.995); }
.primary[disabled] { opacity: .6; cursor: progress; }

.gate-error {
  margin: 12px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  text-align: left;
  white-space: pre-line;
  color: #ffb4b4;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.28);
  border-radius: 10px;
  padding: 9px 12px;
}

.gate-foot {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: #66738c;
}

/* ---------- 상단 바 ---------- */

.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
  max-width: 980px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(9, 14, 26, 0.92), rgba(9, 14, 26, 0.72));
  backdrop-filter: blur(16px) saturate(140%);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 13px;
  background: linear-gradient(150deg, rgba(77, 141, 255, 0.28), rgba(180, 123, 255, 0.22));
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.brand-text { min-width: 0; }

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.sync {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5b687f;
  flex: 0 0 auto;
  box-shadow: 0 0 0 3px rgba(91, 104, 127, 0.16);
}
.dot.live { background: var(--pickle); box-shadow: 0 0 0 3px rgba(67, 209, 138, 0.18); }
.dot.err { background: var(--danger); box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.18); }
.dot.wait { background: #f0b429; box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.18); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  font-size: 16px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  cursor: pointer;
  transition: background .16s, color .16s, transform .16s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.spin { animation: spin .7s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px 6px 8px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  width: 30px; height: 17px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  transition: background .18s;
  flex: 0 0 auto;
}
.switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #cdd7ea;
  transition: transform .18s, background .18s;
}
.switch input:checked + .switch-track { background: rgba(67, 209, 138, 0.55); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(13px); background: #eafff4; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--namyong); outline-offset: 2px; }
.switch-label { font-size: 11.5px; color: var(--text-soft); white-space: nowrap; }

.lock-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #ffd9d9;
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 11px;
  cursor: pointer;
  transition: background .16s;
}
.lock-btn:hover { background: rgba(255, 107, 107, 0.2); }

.banner {
  margin: 10px 16px 0;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #ffe2b0;
  background: rgba(240, 180, 41, 0.1);
  border: 1px solid rgba(240, 180, 41, 0.3);
  border-radius: 12px;
}

/* ---------- 메시지 영역 ---------- */

.messages {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.09);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 30px 16px;
}
.empty-mark { font-size: 34px; opacity: .8; margin-bottom: 10px; }
.empty-title { margin: 0 0 6px; font-size: 14.5px; font-weight: 600; color: var(--text-soft); }
.empty-desc { margin: 0; font-size: 12.5px; line-height: 1.65; }

.day {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 2px -2px;
  font-size: 11.5px;
  color: var(--muted);
}
.day::before, .day::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.day span {
  padding: 3px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 100%;
  animation: rise .22s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.msg--namyong { flex-direction: row-reverse; }

.avatar {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 17px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.msg--namyong .avatar { background: var(--namyong-soft); border-color: rgba(77, 141, 255, 0.4); }
.msg--muse .avatar { background: var(--muse-soft); border-color: rgba(180, 123, 255, 0.4); }
.msg--pickle .avatar { background: var(--pickle-soft); border-color: rgba(67, 209, 138, 0.4); }

.msg-body {
  min-width: 0;
  max-width: min(74%, 620px);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg--namyong .msg-body { align-items: flex-end; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.msg-name {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.01em;
}
.msg--namyong .msg-name { color: var(--namyong); }
.msg--muse .msg-name { color: var(--muse); }
.msg--pickle .msg-name { color: var(--pickle); }

.msg-role {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
}

.msg-time { font-size: 11px; color: #6d7b95; }

.bubble {
  position: relative;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.62;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: border-color .16s, background .16s;
  cursor: pointer;
}

.msg--namyong .bubble {
  background: linear-gradient(160deg, rgba(77, 141, 255, 0.26), rgba(77, 141, 255, 0.14));
  border-color: rgba(77, 141, 255, 0.34);
  border-bottom-right-radius: 6px;
}
.msg--muse .bubble {
  background: linear-gradient(160deg, rgba(180, 123, 255, 0.18), rgba(180, 123, 255, 0.07));
  border-color: rgba(180, 123, 255, 0.26);
  border-bottom-left-radius: 6px;
}
.msg--pickle .bubble {
  background: linear-gradient(160deg, rgba(67, 209, 138, 0.16), rgba(67, 209, 138, 0.06));
  border-color: rgba(67, 209, 138, 0.24);
  border-bottom-left-radius: 6px;
}

.bubble:hover { border-color: var(--border-strong); }

.bubble .quote {
  margin: 0 0 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-soft);
  background: rgba(0, 0, 0, 0.24);
  border-left: 2px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.bubble .quote b { color: var(--text); font-weight: 600; }

.bubble .masked-note {
  display: inline-block;
  margin-top: 6px;
  font-size: 10.5px;
  color: #ffd39a;
}

.bubble-tools {
  position: absolute;
  top: -10px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
}
.msg--namyong .bubble-tools { left: -6px; }
.msg--muse .bubble-tools, .msg--pickle .bubble-tools { right: -6px; }
.msg:hover .bubble-tools { opacity: 1; pointer-events: auto; }

.tool-btn {
  height: 22px;
  padding: 0 7px;
  font-family: inherit;
  font-size: 10.5px;
  color: var(--text-soft);
  background: #1a2336;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  cursor: pointer;
}
.tool-btn:hover { color: var(--text); background: #222e46; }

.new-pill {
  position: absolute;
  left: 50%;
  bottom: 128px;
  transform: translateX(-50%);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: #061021;
  background: linear-gradient(135deg, #9ec2ff, #4d8dff);
  border: 0;
  border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(77, 141, 255, 0.36);
  z-index: 15;
}

/* ---------- 입력 영역 ---------- */

.composer {
  position: relative;
  padding: 10px 14px calc(12px + var(--composer-pad));
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(9, 14, 26, 0.82), rgba(9, 14, 26, 0.97));
  backdrop-filter: blur(18px) saturate(140%);
}

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--text-soft);
  background: rgba(77, 141, 255, 0.1);
  border: 1px solid rgba(77, 141, 255, 0.26);
  border-radius: 11px;
}
.reply-info { min-width: 0; display: flex; gap: 8px; align-items: baseline; }
.reply-label { font-weight: 700; color: #9ec2ff; white-space: nowrap; }
.reply-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.reply-cancel {
  margin-left: auto;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.reply-cancel:hover { background: var(--surface-2); color: var(--text); }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sender-wrap { flex: 0 0 auto; }

.sender-select {
  height: 42px;
  padding: 0 30px 0 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238794ae' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E")
    no-repeat right 11px center,
    rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  appearance: none;
  cursor: pointer;
}

#input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 148px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  outline: none;
  resize: none;
  transition: border-color .16s, box-shadow .16s;
}
#input::placeholder { color: #64718a; }
#input:focus {
  border-color: rgba(77, 141, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(77, 141, 255, 0.14);
}

.send-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 19px;
  font-weight: 700;
  color: #061021;
  background: linear-gradient(140deg, #8dbaff, #4d8dff);
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  transition: transform .12s, filter .16s, opacity .16s;
  box-shadow: 0 8px 20px rgba(77, 141, 255, 0.32);
}
.send-btn:hover { filter: brightness(1.05); }
.send-btn:active { transform: scale(.95); }
.send-btn[disabled] { opacity: .5; cursor: progress; box-shadow: none; }

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 0 2px;
  font-size: 11px;
  color: #64718a;
}

.link-btn {
  padding: 0;
  font-family: inherit;
  font-size: 11.5px;
  color: #8fb4f5;
  background: none;
  border: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(143, 180, 245, 0.35);
}
.link-btn:hover { color: #b9d2ff; }

/* ---------- API 안내 다이얼로그 ---------- */

.api-dialog {
  width: min(660px, calc(100vw - 28px));
  max-height: min(84vh, 760px);
  padding: 20px 20px 18px;
  color: var(--text);
  background: linear-gradient(180deg, #121a2b, #0b1220);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
  overflow: auto;
}
.api-dialog::backdrop { background: rgba(4, 8, 16, 0.7); backdrop-filter: blur(4px); }

.api-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.api-head h3 { margin: 0; font-size: 16px; }

.api-base { margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.api-base code { color: #b9d2ff; }

.api-block { margin-bottom: 12px; }
.api-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
}

.api-block pre {
  margin: 0;
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.65;
  color: #cfe0ff;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow-x: auto;
  white-space: pre;
}

.api-note {
  margin: 14px 0 0;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--muted);
}
.api-note code { color: #b9d2ff; }

/* ---------- 토스트 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--composer-pad));
  transform: translateX(-50%) translateY(8px);
  padding: 9px 16px;
  font-size: 12.5px;
  color: var(--text);
  background: rgba(26, 35, 54, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 80;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(255, 107, 107, 0.5); color: #ffc9c9; }

/* ---------- 반응형 ---------- */

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .brand-mark { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }
  .brand-text h1 { font-size: 14.5px; }
  .switch-label { display: none; }
  .switch { padding: 6px 8px; }
  .lock-btn { padding: 0 10px; }
  .lock-btn span { display: none; }
  .messages { padding: 14px 12px 6px; gap: 12px; }
  .msg-body { max-width: 84%; }
  .bubble { font-size: 14px; }
  .composer { padding: 8px 10px calc(10px + var(--composer-pad)); }
  .sender-select { padding: 0 26px 0 9px; font-size: 12.5px; height: 40px; }
  .send-btn { width: 42px; height: 42px; }
  .new-pill { bottom: 118px; }
  .gate-card { padding: 28px 20px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .messages { scroll-behavior: auto; }
}
