/* AI 질문 사이드바 (assets/js/ask.js). 색은 Chirpy 테마 변수를 따라 라이트·다크 모두 맞춘다. */
:root {
  --ask-bg: var(--main-bg, #fff);
  --ask-fg: var(--text-color, #1f2328);
  --ask-muted: var(--text-muted-color, #57606a);
  --ask-accent: var(--link-color, #0b5cad);
  --ask-border: var(--main-border-color, #d0d7de);
  --ask-surface: color-mix(in srgb, var(--ask-fg) 5%, var(--ask-bg));
  /* 블랙 + 실버 스틸. 은색 아이콘/검정 버튼 8.2~15:1 (측정) */
  --ask-grad: linear-gradient(150deg, #34383d 0%, #1a1c1f 45%, #050506 100%);
  --ask-rim: #8f969e;                    /* 은색 테두리: 다크 배경에서도 버튼이 보이게(5.6:1) */
  --ask-green: #3a3f45;                  /* (이름 유지) 포커스·커서 등 강조: 차콜 9.7:1 */
  --ask-user: #24272b;   /* 내 말풍선(차콜): 흰 글자 대비 15.0:1(측정), AAA */
  --ask-shadow: 0 12px 32px rgba(0, 0, 0, .16), 0 2px 6px rgba(0, 0, 0, .06);
  --ask-w: 400px;
  --ask-gap: 12px;
}
/* 다크 모드: Chirpy 7은 :root[data-bs-theme=dark]로 표시(2026-11-09 수정: 예전엔 data-mode로 잘못 씀).
   스크립트가 속성을 붙이기 전·미리보기 페이지를 위해 시스템 설정도 함께 본다. */
@media (prefers-color-scheme: dark) { :root:not([data-bs-theme="light"]) { --ask-green: #c3c8ce; --ask-user: #2c3036; } }
:root[data-bs-theme="dark"] { --ask-green: #c3c8ce; --ask-user: #2c3036; }

/* ── 접힌 상태: 오른쪽 아래 AI 버튼 (파랑·보라 그라데이션, 둥근 모서리, 흰 아이콘, 통통 튀는 모션) ── */
.ask-launcher {
  position: fixed; z-index: 1140;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 56px; height: 56px; padding: 0; border: 0; border-radius: 18px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ask-grad); color: #e9ecef;
  border: 1px solid var(--ask-rim);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), inset 0 -2px 4px rgba(0, 0, 0, .5),
              0 8px 20px rgba(0, 0, 0, .35), 0 2px 5px rgba(0, 0, 0, .2);
  animation: ask-bounce 3.2s ease-in-out infinite;
  transition: transform .15s ease, box-shadow .15s ease;
}
.ask-launcher svg { width: 30px; height: 30px; }
.ask-launcher:hover { animation-play-state: paused; transform: translateY(-2px) scale(1.06); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 12px 26px rgba(0, 0, 0, .4); }
.ask-launcher:active { transform: scale(.96); }
html.ask-open .ask-launcher { display: none; }
@keyframes ask-bounce {
  0%, 62%, 100% { transform: translateY(0); }
  70% { transform: translateY(-12px); }
  78% { transform: translateY(0); }
  84% { transform: translateY(-5px); }
  90% { transform: translateY(0); }
}

/* ── 사이드바 (데스크톱: 오른쪽에 붙는 둥근 패널) ── */
.ask-panel {
  position: fixed; z-index: 1150;
  top: var(--ask-gap); right: var(--ask-gap); bottom: var(--ask-gap);
  width: min(var(--ask-w), calc(100vw - 2 * var(--ask-gap)));
  display: flex; flex-direction: column;
  background: var(--ask-bg);
  color: var(--ask-fg);
  border: 1px solid var(--ask-border); border-radius: 18px; box-shadow: var(--ask-shadow);
  font-size: .93rem; line-height: 1.65;
  transform: translateX(calc(100% + 2 * var(--ask-gap))); visibility: hidden;
  transition: transform .24s ease, visibility 0s linear .24s;
}
html.ask-open .ask-panel { transform: none; visibility: visible; transition: transform .24s ease; }

/* 넓은 화면에서는 본문을 밀어 사이드바가 글을 가리지 않게 */
@media (min-width: 1280px) {
  body { transition: margin-right .24s ease; }
  html.ask-open body { margin-right: calc(var(--ask-w) + 2 * var(--ask-gap)); }
}

.ask-head { display: flex; align-items: center; gap: .25rem; padding: .55rem .6rem .55rem 1rem; }
.ask-head .ask-titles { flex: 1; min-width: 0; }
.ask-head h2 { font-size: .95rem; margin: 0; font-weight: 600; line-height: 1.35; }
.ask-head p { margin: 0; font-size: .74rem; color: var(--ask-muted); }
.ask-iconbtn {
  flex: none; width: 2.2rem; height: 2.2rem; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 1.05rem; line-height: 1;
  border: 0; background: transparent; color: var(--ask-muted);
}
.ask-iconbtn:hover { background: var(--ask-surface); color: var(--ask-fg); }
.ask-iconbtn svg { width: 18px; height: 18px; fill: currentColor; }

/* 대화 */
.ask-log { flex: 1; min-height: 0; overflow-y: auto; padding: .5rem 1.1rem 1rem; display: flex; flex-direction: column; gap: .9rem; overscroll-behavior: contain; }
.ask-welcome { margin: auto 0; text-align: center; padding: 1rem 0; }
.ask-welcome svg { width: 52px; height: 52px; }
.ask-welcome h3 { font-size: 1.45rem; font-weight: 500; margin: .6rem 0 .3rem; }
.ask-welcome p { margin: 0; font-size: .85rem; color: var(--ask-muted); }

.ask-msg { max-width: 92%; word-break: keep-all; overflow-wrap: anywhere; }
.ask-msg.user {
  align-self: flex-end; background: var(--ask-user); color: #fff;
  padding: .55rem .9rem; border-radius: 18px 18px 4px 18px; white-space: pre-wrap;
}
.ask-msg.bot { align-self: flex-start; }
.ask-bubble {
  background: var(--ask-bg); border: 1px solid var(--ask-border);
  padding: .7rem .95rem; border-radius: 18px 18px 18px 4px; white-space: pre-wrap;
}
.ask-msg.bot.is-error .ask-bubble, .ask-msg.bot.is-none .ask-bubble { color: var(--ask-muted); }
.ask-msg.bot.is-streaming .ask-text::after { content: "▍"; margin-left: 1px; animation: ask-blink 1s steps(1) infinite; color: var(--ask-green); }
.ask-thinking { display: inline-flex; gap: 4px; vertical-align: middle; margin-right: .4rem; }
.ask-thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--ask-green); animation: ask-dot 1.2s infinite ease-in-out; }
.ask-thinking i:nth-child(2) { animation-delay: .15s; }
.ask-thinking i:nth-child(3) { animation-delay: .3s; }
.ask-meta { font-size: .75rem; color: var(--ask-muted); margin: .3rem .3rem 0; font-variant-numeric: tabular-nums; }
.ask-sources { list-style: none; margin: .45rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.ask-sources a {
  display: block; font-size: .82rem; padding: .45rem .7rem; border-radius: 12px; background: var(--ask-bg);
  border: 1px solid var(--ask-border); color: var(--ask-accent); text-decoration: none;
}
.ask-sources a:hover { border-color: var(--ask-accent); text-decoration: underline; text-underline-offset: 3px; }
.ask-feedback { margin-top: .4rem; }
.ask-fb-row { display: flex; align-items: center; gap: .45rem; }
/* 평가 버튼: 테두리 없이 살짝 떠 있는 입체 버튼. 고르면 색이 가운데에서 차오르고 반짝인다(👍 오렌지, 👎 파랑→보라: 아래 DAY / NIGHT). */
.ask-fb-row button {
  position: relative; isolation: isolate; font: inherit; font-size: .95rem; line-height: 1; cursor: pointer;
  width: 2.5rem; height: 2.1rem; padding: 0; border: 0; border-radius: 999px; color: var(--ask-fg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--ask-fg) 3%, var(--ask-bg)), color-mix(in srgb, var(--ask-fg) 11%, var(--ask-bg)));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55), inset 0 -2px 0 rgba(0, 0, 0, .07), 0 1px 2px rgba(0, 0, 0, .16), 0 3px 8px rgba(0, 0, 0, .08);
  transition: transform .12s ease, box-shadow .15s ease;
  --fx-c1: #ff5a36; --fx-c2: #ffc93c;
}
.ask-fb-row button:hover { transform: translateY(-1px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), inset 0 -2px 0 rgba(0, 0, 0, .07), 0 2px 4px rgba(0, 0, 0, .18), 0 6px 14px rgba(0, 0, 0, .1); }
.ask-fb-row button:active { transform: translateY(1px); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .18); }
/* 채워지는 색(가운데에서 퍼짐)과 반짝이(빛줄기 + 작은 별점) */
.ask-fb-row button::before, .ask-fb-row button::after { content: ""; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none; }
.ask-fb-row button::before {
  background: linear-gradient(135deg, #ff3d4f 0%, #ff7a1a 45%, #ffb300 75%, #ffe24a 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6), inset 0 -3px 5px rgba(196, 52, 0, .35);
  transform: scale(0); opacity: 0; transition: transform .38s cubic-bezier(.2, 1.4, .4, 1), opacity .18s ease;
}
.ask-fb-row button::after {
  background:
    radial-gradient(circle at 22% 30%, rgba(255, 255, 255, .95) 0 1.1px, transparent 1.8px),
    radial-gradient(circle at 78% 26%, rgba(255, 255, 255, .9) 0 .9px, transparent 1.6px),
    radial-gradient(circle at 66% 76%, rgba(255, 255, 255, .85) 0 1px, transparent 1.7px),
    linear-gradient(115deg, transparent 38%, rgba(255, 255, 255, .7) 50%, transparent 62%) 180% 0 / 260% 100% no-repeat;
  opacity: 0;
}
.ask-fb-row button[aria-pressed="true"] { box-shadow: 0 2px 5px rgba(255, 98, 0, .38), 0 6px 16px rgba(255, 140, 0, .3); }
.ask-fb-row button[aria-pressed="true"]::before { transform: scale(1); opacity: 1; }
.ask-fb-row button[aria-pressed="true"]::after { opacity: 1; animation: ask-fb-shine 3.2s ease-in-out .25s infinite, ask-fb-twinkle 1.6s ease-in-out infinite; }
/* DAY / NIGHT: 👍는 트로피칼 오렌지(낮), 👎는 파랑→보라(밤하늘). 반짝이는 같은 방식 */
.ask-fb-row button.is-down { --fx-c1: #5b8cff; --fx-c2: #c77dff; }
.ask-fb-row button.is-down::before {
  background: linear-gradient(135deg, #2563ff 0%, #4f5bf5 40%, #7c4dff 72%, #c77dff 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), inset 0 -3px 5px rgba(38, 18, 120, .45);
}
.ask-fb-row button.is-down[aria-pressed="true"] { box-shadow: 0 2px 5px rgba(72, 88, 255, .42), 0 6px 16px rgba(124, 77, 255, .32); }
@keyframes ask-fb-shine { 0% { background-position: 0 0, 0 0, 0 0, 180% 0; } 28%, 100% { background-position: 0 0, 0 0, 0 0, -80% 0; } }
@keyframes ask-fb-twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
/* 다크: 안 고른 버튼의 윗면 하이라이트를 약하게(밝은 테두리처럼 보이지 않게) */
:root[data-bs-theme="dark"] .ask-fb-row button:not([aria-pressed="true"]) {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1), inset 0 -2px 0 rgba(0, 0, 0, .3), 0 1px 2px rgba(0, 0, 0, .5), 0 3px 8px rgba(0, 0, 0, .35); }
.ask-fb-hint { font-size: .75rem; color: var(--ask-muted); }
.ask-fb-hint:empty { display: none; }
/* 의견 칸(선택): 오른쪽 위 X로 닫는다 */
.ask-fb-form { position: relative; width: 19rem; max-width: 100%; margin-top: .45rem; padding: .5rem .6rem .4rem; border: 1px solid var(--ask-border);
  border-radius: 14px; background: var(--ask-bg); }
.ask-fb-form:focus-within { border-color: #ff8a1f; box-shadow: 0 0 0 3px rgba(255, 138, 31, .18); }   /* 검정 테두리 대신 버튼과 같은 오렌지 */
.ask-fb-form textarea { display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--ask-fg);
  font: inherit; font-size: 16px; line-height: 1.5; padding: 0 1.9rem 0 0; min-height: 3em; max-height: 9em; overflow-y: auto; }
.ask-fb-close { position: absolute; top: .3rem; right: .3rem; width: 1.7rem; height: 1.7rem; border-radius: 999px; border: 0;
  background: transparent; color: var(--ask-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.ask-fb-close:hover { background: var(--ask-surface); color: var(--ask-fg); }
.ask-fb-close svg { width: 13px; height: 13px; fill: currentColor; }
.ask-fb-bar { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; margin-top: .2rem; }
.ask-fb-note { margin-right: auto; font-size: .75rem; color: #b3261e; }
.ask-fb-send { font: inherit; font-size: .8rem; padding: .2rem .8rem; border-radius: 999px; cursor: pointer;
  background: var(--ask-grad); color: #e9ecef; border: 1px solid var(--ask-rim); }
.ask-fb-send:disabled { opacity: .4; cursor: not-allowed; }
.ask-fb-done { margin: .4rem .3rem 0; font-size: .78rem; color: var(--ask-muted); }

/* 하단: 예시 질문(오른쪽 정렬 칩) + 안내 + 입력 */
.ask-foot { padding: .4rem .9rem calc(.9rem + env(safe-area-inset-bottom, 0px)); }
.ask-examples { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; margin: 0 0 .7rem; }
.ask-examples[hidden] { display: none; }
.ask-example {
  font: inherit; font-size: .86rem; text-align: left; cursor: pointer; max-width: 100%;
  padding: .55rem .95rem; border-radius: 999px;
  border: 1px solid var(--ask-border); background: var(--ask-bg); color: var(--ask-fg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.ask-example:hover { border-color: var(--ask-green); }
.ask-card { background: var(--ask-bg); border: 1px solid var(--ask-border); border-radius: 18px; box-shadow: 0 2px 10px rgba(0, 0, 0, .06); padding: .55rem .55rem .45rem .9rem; }
.ask-card:focus-within { border-color: var(--ask-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ask-green) 25%, transparent); }
.ask-notice { font-size: .73rem; color: var(--ask-muted); margin: 0 0 .25rem; }
.ask-notice a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.ask-box { display: flex; align-items: flex-end; gap: .4rem; }
.ask-box textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent; color: var(--ask-fg);
  font: inherit; font-size: 16px; line-height: 1.5; padding: .3rem 0; max-height: 8.5em;
}
.ask-send {
  flex: none; width: 2.3rem; height: 2.3rem; border-radius: 12px; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ask-grad); color: #e9ecef; border: 1px solid var(--ask-rim);
}
.ask-send svg { width: 18px; height: 18px; fill: currentColor; }
.ask-send:disabled { opacity: .4; cursor: not-allowed; }
.ask-row2 { display: flex; justify-content: flex-end; align-items: center; gap: .5rem; }
.ask-count { font-size: .7rem; color: var(--ask-muted); font-variant-numeric: tabular-nums; }
.ask-count.over { color: #b3261e; font-weight: 700; }
.ask-human:empty { display: none; }
.ask-human { margin-top: .4rem; }

.ask-panel button:focus-visible, .ask-panel a:focus-visible, .ask-launcher:focus-visible {
  outline: 3px solid var(--ask-green); outline-offset: 2px;
}
.ask-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@keyframes ask-blink { 50% { opacity: 0; } }
@keyframes ask-dot { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

/* ── 휴대폰: AI 버튼을 누르면 화면 전체가 대화창 ── */
@media (max-width: 767.98px) {
  .ask-launcher { right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .ask-panel {
    inset: 0; width: 100%; height: 100vh; height: 100dvh;
    border: 0; border-radius: 0; box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px);
    padding-left: env(safe-area-inset-left, 0px); padding-right: env(safe-area-inset-right, 0px);
    transform: translateY(100%);
  }
  .ask-head { padding: .5rem .5rem .5rem 1rem; border-bottom: 1px solid var(--ask-border); }
  html.ask-open.ask-mobile, html.ask-open.ask-mobile body { overflow: hidden; }
  .ask-msg { max-width: 94%; }
  .ask-welcome h3 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  .ask-launcher { animation: none; }
  .ask-panel, html.ask-open .ask-panel, body { transition: none !important; }
  .ask-msg.bot.is-streaming .ask-text::after, .ask-thinking i { animation: none; }
  .ask-fb-row button, .ask-fb-row button::before { transition: none; }
  .ask-fb-row button[aria-pressed="true"]::after { animation: none; }
}
@media (prefers-contrast: more) {
  .ask-panel, .ask-card, .ask-example, .ask-bubble, .ask-sources a, .ask-fb-form { border-width: 2px; border-color: currentColor; }
}
@media (forced-colors: active) {
  .ask-launcher, .ask-send, .ask-msg.user { forced-color-adjust: none; background: ButtonText; color: ButtonFace; }
  .ask-launcher svg * { stroke: ButtonFace; }
  .ask-launcher svg .ask-fill { fill: ButtonFace; }
  .ask-send svg { fill: ButtonFace; }
  .ask-panel { border: 2px solid CanvasText; }
  .ask-fb-row button { border: 1px solid ButtonText; }
  .ask-fb-row button[aria-pressed="true"] { forced-color-adjust: none; background: Highlight; }
}

/* 첫 화면 가운데 봇: 검정 둥근 배지 안에 은색 봇 */
.ask-welcome .ask-badge {
  display: inline-flex; align-items: center; justify-content: center; width: 72px; height: 72px; border-radius: 22px;
  background: var(--ask-grad); border: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 6px 16px rgba(0, 0, 0, .25);
}
/* 환영 문구: 메탈릭(은색) 그라데이션 글자. 라이트는 어두운 강철, 다크는 밝은 은색 */
.ask-welcome h3 {
  background: linear-gradient(100deg, #24272c 0%, #6d757f 38%, #2c3036 62%, #59606a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 600;
}
:root[data-bs-theme="dark"] .ask-welcome h3 {
  background-image: linear-gradient(100deg, #9aa1aa 0%, #f4f6f8 38%, #a7aeb7 62%, #e3e7eb 100%);
}
@media (forced-colors: active) { .ask-welcome h3 { color: CanvasText; background: none; } }
.ask-welcome .ask-badge svg { width: 40px; height: 40px; }

/* 다크: 패널은 바탕(#121212)보다 한 단계 밝은 면(그림자 대신 밝기로 층 구분) */
:root[data-bs-theme="dark"] .ask-panel { --ask-bg: #1c1c1e; --ask-border: #2c2c30; }

/* 답 서식(문단·목록·굵게·코드). 입력창은 코드 블록이면 고정폭 느낌 대신 높이만 늘린다 */
.ask-msg.bot .ask-bubble { white-space: normal; }
.ask-text p { margin: 0 0 .55em; white-space: pre-wrap; }
.ask-text > :last-child { margin-bottom: 0; }
.ask-text ul, .ask-text ol { margin: 0 0 .55em; padding-left: 1.25em; }
.ask-text li { margin: .15em 0; }
.ask-text strong { font-weight: 700; }
.ask-text code { font-family: var(--bs-font-monospace, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: .86em;
  padding: .05em .35em; border-radius: 5px; background: var(--ask-surface); }
.ask-text pre { margin: 0 0 .55em; padding: .6em .75em; border-radius: 10px; background: var(--ask-surface);
  overflow-x: auto; white-space: pre; }
.ask-text pre code { padding: 0; background: none; font-size: .82em; }
.ask-copy { border: 0; background: none; padding: 0; font: inherit; color: var(--ask-muted); cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; }
.ask-copy:hover { color: var(--ask-fg); }
#ask-input { tab-size: 2; }
.ask-msg.user p { margin: 0 0 .4em; white-space: pre-wrap; }
.ask-msg.user > :last-child { margin-bottom: 0; }
.ask-msg.user ul, .ask-msg.user ol { margin: 0 0 .4em; padding-left: 1.2em; }
.ask-msg.user code { font-size: .86em; padding: .05em .3em; border-radius: 5px; background: rgba(255, 255, 255, .14); }
.ask-msg.user pre { margin: 0 0 .4em; padding: .5em .65em; border-radius: 8px; background: rgba(255, 255, 255, .1); overflow-x: auto; white-space: pre; }
.ask-msg.user { white-space: normal; }
