/* widget_randomquote - 랜덤 대사 출력기 (아이메시지 스타일, 라이트/다크) */
#rq-root { display: contents; }

#rq-widget {
  position: fixed;
  left: 0;
  top: 0; /* 실제 위치는 JS가 left/top(px)으로 지정 */
  z-index: 99997;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  -webkit-font-smoothing: antialiased;
  visibility: hidden; /* 위치 계산이 끝나면 JS가 rq-ready를 붙여 보이게 한다 */

  /* 라이트 모드 색 */
  --rq-bg: #fff;
  --rq-head-bg: rgba(246, 246, 248, .96);
  --rq-line: rgba(0, 0, 0, .12);
  --rq-ring: rgba(0, 0, 0, .06);
  --rq-in-bg: #e9e9eb;
  --rq-in-fg: #000;
  --rq-name: #000;
  --rq-muted: #8e8e93;
  --rq-dim: #9d9da3;
  --rq-pill-line: #c7c7cc;
  --rq-pill-hover: #f6f6f8;
  --rq-track: #d9d9de;
}
/* 다크 모드 색 */
#rq-widget.rq-dark {
  --rq-bg: #000;
  --rq-head-bg: rgba(28, 28, 30, .96);
  --rq-line: rgba(255, 255, 255, .15);
  --rq-ring: rgba(255, 255, 255, .12);
  --rq-in-bg: #26262a;
  --rq-in-fg: #fff;
  --rq-name: #fff;
  --rq-muted: #8e8e93;
  --rq-dim: #7c7c82;
  --rq-pill-line: #3a3a3c;
  --rq-pill-hover: #1c1c1e;
  --rq-track: #3a3a3c;
}
#rq-widget.rq-ready { visibility: visible; }
#rq-widget * { box-sizing: border-box; }

/* ===== 토글(접힌 상태) ===== */
#rq-toggle {
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rq-accent, #007AFF);
  color: #fff;
  font-size: 20px;
  cursor: grab;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s ease;
}
#rq-toggle:hover { transform: scale(1.06); }
#rq-widget.rq-dragging #rq-toggle,
#rq-widget.rq-dragging #rq-head { cursor: grabbing; }
#rq-widget.rq-open #rq-toggle { display: none; }

/* ===== 패널(펼친 상태) ===== */
#rq-panel {
  display: none;
  flex-direction: column;
  width: min(320px, calc(100vw - 16px));
  height: min(460px, calc(100vh - 16px));
  background: var(--rq-bg);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .28), 0 0 0 1px var(--rq-ring);
  transition: background-color .2s ease;
}
#rq-widget.rq-open #rq-panel { display: flex; animation: rq-pop .22s ease-out; }
@keyframes rq-pop { from { opacity: 0; transform: translateY(8px) scale(.96); } to { opacity: 1; transform: none; } }

/* 상단 바: 왼쪽 접기 · 가운데 연락처 · 오른쪽 라이트/다크 토글. 이 영역을 잡고 끌면 위젯이 움직인다 */
#rq-head {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  padding: 8px 8px 7px;
  background: var(--rq-head-bg);
  border-bottom: 1px solid var(--rq-line);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color .2s ease;
}
#rq-close {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--rq-accent, #007AFF);
  font-size: 18px;
  cursor: pointer;
}
#rq-contact { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
#rq-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(#a9adb8, #7f8491);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
#rq-contact-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--rq-name);
  font-size: 11px;
  line-height: 1.1;
}
#rq-contact-name i { margin-left: 3px; color: var(--rq-dim); font-size: 8px; }

/* 라이트/다크 스위치 */
#rq-theme {
  position: relative;
  justify-self: end;
  width: 44px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: var(--rq-track);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease;
}
#rq-widget.rq-dark #rq-theme { background: var(--rq-accent, #007AFF); }
.rq-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  font-size: 12px;
  transition: transform .2s ease;
}
#rq-widget.rq-dark .rq-knob { transform: translateX(18px); }
.rq-i-sun { color: #f5a623; }
.rq-i-moon { display: none; color: #5b5bd6; }
#rq-widget.rq-dark .rq-i-sun { display: none; }
#rq-widget.rq-dark .rq-i-moon { display: inline; }

/* 대화 영역: 빈 곳을 누르면 다음 랜덤 대사가 나온다 */
#rq-chat {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--rq-bg);
  font-size: var(--rq-fs, 15px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .2s ease;
}
#rq-chat > :first-child { margin-top: auto; } /* 대화가 아래쪽부터 쌓이게(아이메시지처럼) */
.rq-row { display: flex; flex-direction: column; max-width: 100%; flex: 0 0 auto; }
.rq-row.rq-in { align-items: flex-start; }
.rq-row.rq-out { align-items: flex-end; }
.rq-speaker { margin: 0 0 2px 12px; color: var(--rq-muted); font-size: .75em; }
.rq-out .rq-speaker { margin: 0 12px 2px 0; }
.rq-status { margin: 2px 2px 0 0; color: var(--rq-muted); font-size: .73em; font-weight: 600; }

.rq-msg {
  position: relative;
  max-width: 80%;
  padding: 7px 13px;
  border-radius: 18px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: default;
  animation: rq-in .18s ease-out;
}
@keyframes rq-in { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
.rq-in .rq-msg { background: var(--rq-in-bg); color: var(--rq-in-fg); }
.rq-out .rq-msg { background: var(--rq-accent, #007AFF); color: #fff; }

/* 말풍선 꼬리 */
.rq-msg::before, .rq-msg::after { content: ''; position: absolute; bottom: 0; height: 18px; }
.rq-in .rq-msg::before { left: -7px; width: 20px; background: var(--rq-in-bg); border-bottom-right-radius: 16px 14px; }
.rq-in .rq-msg::after { left: -26px; width: 26px; background: var(--rq-bg); border-bottom-right-radius: 10px; }
.rq-out .rq-msg::before { right: -7px; width: 20px; background: var(--rq-accent, #007AFF); border-bottom-left-radius: 16px 14px; }
.rq-out .rq-msg::after { right: -26px; width: 26px; background: var(--rq-bg); border-bottom-left-radius: 10px; }

/* 입력 중 점 3개 */
.rq-dots { display: inline-flex; align-items: center; gap: 4px; height: 1.4em; padding: 0 2px; }
.rq-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--rq-dim); animation: rq-bounce 1.2s infinite ease-in-out; }
.rq-dots i:nth-child(2) { animation-delay: .18s; }
.rq-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes rq-bounce { 0%, 60%, 100% { opacity: .35; transform: scale(.8); } 30% { opacity: 1; transform: scale(1.1); } }

/* 파란 말풍선 안의 입력 중 점 / 커서 */
.rq-out .rq-dots i { background: rgba(255, 255, 255, .8); }
.rq-out .rq-caret { background: rgba(255, 255, 255, .85); }

/* 타이핑 커서 */
.rq-caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 1px; vertical-align: text-bottom; background: var(--rq-muted); animation: rq-blink 1s steps(1) infinite; }
@keyframes rq-blink { 50% { opacity: 0; } }

/* 하단 입력창 모양의 랜덤 버튼 */
#rq-foot { flex: 0 0 auto; padding: 8px 10px 10px; background: var(--rq-bg); transition: background-color .2s ease; }
#rq-send {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 4px 14px;
  border: 1px solid var(--rq-pill-line);
  border-radius: 20px;
  background: var(--rq-bg);
  color: var(--rq-dim);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .2s ease;
}
#rq-send:hover { background: var(--rq-pill-hover); }
#rq-send:active .rq-arrow { transform: scale(.88); }
.rq-arrow {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rq-accent, #007AFF);
  color: #fff;
  font-size: 13px;
  transition: transform .12s ease;
}

#rq-toggle:focus-visible, #rq-close:focus-visible, #rq-send:focus-visible, #rq-theme:focus-visible { outline: 2px solid var(--rq-accent, #007AFF); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  #rq-widget * { animation: none !important; transition: none !important; }
}
