/* YKDH Live2D AI 助手 —— 右下角小人 + 对话面板 */

.ykdh-l2d,
.ykdh-l2d * { box-sizing: border-box; }

.ykdh-l2d {
	position: fixed;
	right: 0;
	bottom: 0;
	z-index: 9998;
	font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
	-webkit-tap-highlight-color: transparent;
}

/* ---------- 小人舞台 ---------- */
.ykdh-l2d-stage {
	position: fixed;
	right: 8px;
	bottom: 0;
	width: 300px;
	height: 420px;
	pointer-events: none;
	transition: opacity .25s, transform .25s;
}
.ykdh-l2d-stage canvas {
	width: 300px;
	height: 420px;
	display: block;
	pointer-events: auto;
	cursor: grab;
	touch-action: none;          /* 触屏拖动时别让页面跟着滚 */
	filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .28));
}
.ykdh-l2d-stage.is-dragging { transition: none; }
.ykdh-l2d-stage.is-dragging canvas { cursor: grabbing; }
.ykdh-l2d-stage.is-hidden {
	opacity: 0;
	transform: translateY(20px);
	pointer-events: none;
}

/* 跳舞：模型本身没有点击动作时，也能上下轻跳、左右摆一摆 */
/* 【v958】跳舞/唱歌改用模型自带动作（.mtn），CSS 抖动动画已移除 */

.ykdh-l2d-bubble {
	position: absolute;
	right: 210px;
	bottom: 250px;
	max-width: 230px;
	padding: 10px 13px;
	background: #fff;
	color: #2b2b2b;
	border-radius: 12px;
	box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
	font-size: 13px;
	line-height: 1.6;
	pointer-events: none;
	animation: ykdh-l2d-pop .18s ease-out;
	white-space: pre-wrap;
	word-break: break-word;
}
/* 【v955】被浏览器拦下语音时，气泡变成可点提示 */
.ykdh-l2d-bubble.is-clickable {
	pointer-events: auto;
	cursor: pointer;
	border: 1px solid rgba(79, 140, 255, .45);
	box-shadow: 0 6px 20px rgba(47, 111, 228, .28);
	animation: ykdh-l2d-pop .18s ease-out, ykdh-l2d-voice-pulse 1.8s ease-in-out infinite;
}

.ykdh-l2d-bubble::after {
	content: "";
	position: absolute;
	right: -6px;
	bottom: 18px;
	width: 12px;
	height: 12px;
	background: #fff;
	transform: rotate(45deg);
	border-radius: 2px;
}
@keyframes ykdh-l2d-pop {
	from { opacity: 0; transform: translateY(6px) scale(.96); }
	to   { opacity: 1; transform: none; }
}

/* ---------- 悬浮按钮 ---------- */
.ykdh-l2d-fab {
	position: fixed;
	right: 18px;
	bottom: 18px;
	width: 52px;
	height: 52px;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(135deg, #4f8cff, #2f6fe4);
	color: #fff;
	font-size: 22px;
	line-height: 52px;
	text-align: center;
	cursor: pointer;
	box-shadow: 0 8px 22px rgba(47, 111, 228, .45);
	transition: transform .18s, box-shadow .18s;
	display: none;
}
.ykdh-l2d-fab:hover { transform: translateY(-2px) scale(1.04); }
.ykdh-l2d-fab.is-on { display: block; }

/* ---------- 对话面板 ---------- */
/* 位置由 JS 算：贴在人物头部/嘴巴上方，人物拖到哪它跟到哪 */
.ykdh-l2d-panel {
	position: fixed;
	left: 16px;
	bottom: 16px;
	width: 350px;
	max-width: calc(100vw - 24px);
	background: #fff;
	border-radius: 14px;
	box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
	display: flex;
	flex-direction: column;
	overflow: visible;
	animation: ykdh-l2d-pop .18s ease-out;
}
/* 小尾巴，指向人物 */
.ykdh-l2d-panel::after {
	content: "";
	position: absolute;
	bottom: -6px;
	left: var(--ykdh-l2d-tail, 50%);
	margin-left: -6px;
	width: 12px;
	height: 12px;
	background: #fff;
	transform: rotate(45deg);
	border-radius: 2px;
	z-index: 0;
}
.ykdh-l2d-panel.ykdh-l2d-panel--below::after {
	bottom: auto;
	top: -6px;
}
/* 【v962】面板在人物左侧时，小尾巴改到右边、竖着指过去 */
.ykdh-l2d-panel.ykdh-l2d-panel--side::after {
	bottom: auto;
	top: var(--ykdh-l2d-tail-v, 50%);
	left: auto;
	right: -6px;
	margin-left: 0;
}
.ykdh-l2d-head {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 10px 12px;
	background: linear-gradient(135deg, #4f8cff, #2f6fe4);
	color: #fff;
	font-size: 13px;
	font-weight: 600;
	border-radius: 14px 14px 0 0;
}
.ykdh-l2d-name { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ykdh-l2d-sel {
	max-width: 150px;
	background: rgba(255, 255, 255, .18);
	color: #fff;
	border: 1px solid rgba(255, 255, 255, .35);
	border-radius: 6px;
	font-size: 11px;
	padding: 2px 4px;
	outline: none;
}
.ykdh-l2d-sel option { color: #222; background: #fff; }
.ykdh-l2d-x {
	background: rgba(255, 255, 255, .18);
	border: 0;
	color: #fff;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	font-size: 16px;
	line-height: 22px;
	cursor: pointer;
	flex: 0 0 auto;
}
.ykdh-l2d-x:hover { background: rgba(255, 255, 255, .32); }

/* 语音播报开关（只在后台开启语音时才渲染） */
.ykdh-l2d-voice {
	background: rgba(255, 255, 255, .18);
	border: 0;
	color: #fff;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	padding: 0;
	cursor: pointer;
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	transition: background .18s, opacity .18s;
}
.ykdh-l2d-voice svg { width: 15px; height: 15px; display: block; }
.ykdh-l2d-voice:hover { background: rgba(255, 255, 255, .32); }
.ykdh-l2d-voice .ykdh-l2d-slash { display: none; }
.ykdh-l2d-voice.is-off { opacity: .55; }
.ykdh-l2d-voice.is-off .ykdh-l2d-wave { display: none; }
.ykdh-l2d-voice.is-off .ykdh-l2d-slash { display: block; }
.ykdh-l2d-voice.is-on { animation: ykdh-l2d-voice-pulse 1.6s ease-in-out infinite; }
@keyframes ykdh-l2d-voice-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .5); }
	50% { box-shadow: 0 0 0 5px rgba(255, 255, 255, 0); }
}

.ykdh-l2d-log {
	flex: 1 1 auto;
	height: 300px;
	max-height: 46vh;
	overflow-y: auto;
	padding: 12px;
	background: #f6f8fc;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.ykdh-l2d-msg {
	max-width: 84%;
	padding: 8px 11px;
	border-radius: 10px;
	font-size: 13px;
	line-height: 1.6;
	white-space: pre-wrap;
	word-break: break-word;
}
.ykdh-l2d-msg.me {
	align-self: flex-end;
	background: #2f6fe4;
	color: #fff;
	border-bottom-right-radius: 3px;
}
.ykdh-l2d-msg.ai {
	align-self: flex-start;
	background: #fff;
	color: #222;
	box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
	border-bottom-left-radius: 3px;
}
.ykdh-l2d-msg.err { background: #ffe9e9; color: #b3261e; }
.ykdh-l2d-msg.typing { color: #7a869a; font-style: italic; }
.ykdh-l2d-msg img { max-width: 160px; border-radius: 8px; display: block; margin-top: 6px; }

.ykdh-l2d-imgprev {
	position: relative;
	padding: 8px 12px 0;
	background: #f6f8fc;
}
.ykdh-l2d-imgprev img { max-height: 70px; border-radius: 8px; display: block; }
.ykdh-l2d-imgprev button {
	position: absolute;
	left: 74px;
	top: 4px;
	width: 20px;
	height: 20px;
	border: 0;
	border-radius: 50%;
	background: rgba(0, 0, 0, .55);
	color: #fff;
	cursor: pointer;
	line-height: 18px;
	font-size: 13px;
}

.ykdh-l2d-input {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 10px 12px;
	border-top: 1px solid #e6eaf2;
	background: #fff;
	border-radius: 0 0 14px 14px;
}
.ykdh-l2d-pic {
	font-size: 18px;
	cursor: pointer;
	line-height: 1;
	opacity: .75;
	flex: 0 0 auto;
}
.ykdh-l2d-pic:hover { opacity: 1; }
.ykdh-l2d-input input[type="text"] {
	flex: 1 1 auto;
	min-width: 0;
	border: 1px solid #dfe5f0;
	border-radius: 8px;
	padding: 7px 10px;
	font-size: 13px;
	outline: none;
	background: #fbfcfe;
}
.ykdh-l2d-input input[type="text"]:focus { border-color: #2f6fe4; background: #fff; }
.ykdh-l2d-send {
	flex: 0 0 auto;
	border: 0;
	border-radius: 8px;
	background: #2f6fe4;
	color: #fff;
	padding: 7px 14px;
	font-size: 13px;
	cursor: pointer;
}
.ykdh-l2d-send:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 人物切换条 ---------- */
.ykdh-l2d-charbar {
	position: fixed;
	right: 16px;
	bottom: 8px;
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	justify-content: flex-end;
	max-width: 300px;
}
.ykdh-l2d-charbar button {
	border: 1px solid #dfe5f0;
	background: rgba(255, 255, 255, .94);
	color: #445;
	border-radius: 14px;
	padding: 3px 10px;
	font-size: 12px;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
}
.ykdh-l2d-charbar button.on {
	background: #2f6fe4;
	color: #fff;
	border-color: #2f6fe4;
}

/* ---------- 移动端 ---------- */
@media (max-width: 768px) {
	.ykdh-l2d-stage { width: 200px; height: 280px; right: -10px; }
	.ykdh-l2d-stage canvas { width: 200px; height: 280px; }
	.ykdh-l2d-bubble { right: 130px; bottom: 190px; max-width: 180px; font-size: 12px; }
	.ykdh-l2d-panel { right: 8px; bottom: 8px; width: calc(100vw - 16px); }
	.ykdh-l2d-log { height: 240px; }
	.ykdh-l2d-charbar { right: 8px; bottom: 74px; max-width: 200px; }
}

/* 夜间模式跟随（主题深色时用深色面板） */
body.io-black-mode .ykdh-l2d-panel { background: #23262b; }
body.io-black-mode .ykdh-l2d-log { background: #1b1e22; }
body.io-black-mode .ykdh-l2d-msg.ai { background: #2b2f36; color: #e8eaf0; }
body.io-black-mode .ykdh-l2d-input { background: #23262b; border-top-color: #333842; }
body.io-black-mode .ykdh-l2d-input input[type="text"] { background: #1b1e22; border-color: #333842; color: #e8eaf0; }
body.io-black-mode .ykdh-l2d-bubble { background: #2b2f36; color: #e8eaf0; }
body.io-black-mode .ykdh-l2d-bubble::after { background: #2b2f36; }
