/* AIDB 記事読み上げ（TCD PANDORA に馴染むニュートラルな最小スタイル） */

.aidb-ra {
	margin: 1.5em 0;
	padding: 12px 14px;
	border: 1px solid #e2e2e2;
	border-radius: 6px;
	background: #fafafa;
	box-sizing: border-box;
}

.aidb-ra[hidden] {
	display: none;
}

.aidb-ra__head {
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-bottom: 10px;
}

.aidb-ra__head-label {
	font-size: 0.9em;
	font-weight: 700;
}

.aidb-ra__head-label::before {
	content: "\1F509"; /* 🔉 */
	margin-right: 6px;
}

.aidb-ra__head-sub {
	font-size: 0.75em;
	color: #767676;
}

.aidb-ra__bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 12px;
}

/* --- 再生/一時停止トグル ------------------------------------------------ */

.aidb-ra__toggle {
	display: inline-flex;
	align-items: center;
	justify-content: flex-start;
	gap: 9px;
	min-width: 13.5em; /* ラベル変化（再生/一時停止/準備中）で幅が動かないよう固定 */
	padding: 9px 18px;
	border: 1px solid #333;
	border-radius: 999px;
	background: #333;
	color: #fff;
	font-size: 0.95em;
	font-weight: 700;
	line-height: 1.2;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.12s ease;
}

.aidb-ra__toggle:hover {
	background: #1f1f1f;
}

.aidb-ra__toggle:active {
	background: #000;
}

.aidb-ra.is-playing .aidb-ra__toggle {
	background: #1f1f1f;
}

/* --- アイコン（固定寸法の箱に triangle / pause bars / spinner を描画）--- */

.aidb-ra__icon {
	position: relative;
	flex: 0 0 auto;
	width: 14px;
	height: 14px;
	color: #fff;
	box-sizing: border-box;
}

/* idle: 再生（三角） */
.aidb-ra__icon::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 0;
	height: 0;
	transform: translate(-35%, -50%);
	border-style: solid;
	border-width: 6px 0 6px 10px;
	border-color: transparent transparent transparent currentColor;
}

.aidb-ra__icon::after {
	content: "";
	position: absolute;
}

/* playing: 一時停止（縦2本） */
.aidb-ra.is-playing .aidb-ra__icon::before {
	width: 3px;
	height: 12px;
	border: 0;
	border-radius: 1px;
	background: currentColor;
	transform: translate(-50%, -50%) translateX(-3px);
}

.aidb-ra.is-playing .aidb-ra__icon::after {
	content: "";
	top: 50%;
	left: 50%;
	width: 3px;
	height: 12px;
	border-radius: 1px;
	background: currentColor;
	transform: translate(-50%, -50%) translateX(3px);
}

/* loading: スピナー（onstart 待ち = 『準備中…』） */
.aidb-ra.is-loading .aidb-ra__icon::before,
.aidb-ra.is-loading .aidb-ra__icon::after {
	display: none;
}

.aidb-ra.is-loading .aidb-ra__icon {
	border: 2px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	animation: aidb-ra-spin 0.7s linear infinite;
}

@keyframes aidb-ra-spin {
	to {
		transform: rotate(360deg);
	}
}

/* --- 停止ボタン（レイアウトを予約して reflow を防ぐ）------------------- */

.aidb-ra__stop {
	padding: 7px 14px;
	border: 1px solid #767676;
	border-radius: 999px;
	background: #fff;
	color: #555;
	font-size: 0.85em;
	line-height: 1.2;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	-webkit-tap-highlight-color: transparent;
	transition: opacity 0.15s ease, background-color 0.12s ease, border-color 0.12s ease;
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
}

.aidb-ra.is-active .aidb-ra__stop {
	visibility: visible;
	opacity: 1;
	pointer-events: auto;
}

.aidb-ra__stop:hover {
	border-color: #333;
	background: #f2f2f2;
}

.aidb-ra__stop:active {
	background: #f0f0f0;
}

/* --- 速度ピル ---------------------------------------------------------- */

.aidb-ra__speeds {
	margin-left: auto;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-size: 0.8em;
	color: #666;
}

.aidb-ra__speed {
	padding: 3px 9px;
	border: 1px solid #767676;
	border-radius: 12px;
	background: #fff;
	color: #555;
	font-size: 1em;
	line-height: 1.4;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.aidb-ra__speed:hover {
	border-color: #333;
	background: #f2f2f2;
}

.aidb-ra__speed:active {
	background: #f0f0f0;
}

.aidb-ra__speed.is-active {
	border-color: #333;
	background: #333;
	color: #fff;
}

/* --- 進捗 -------------------------------------------------------------- */

.aidb-ra__progress-wrap {
	display: none;
	align-items: center;
	gap: 10px;
	margin-top: 10px;
}

.aidb-ra.is-active .aidb-ra__progress-wrap,
.aidb-ra.is-finished .aidb-ra__progress-wrap {
	display: flex;
}

.aidb-ra__progress {
	display: block;
	flex: 1 1 auto;
	height: 5px;
	border-radius: 3px;
	background: #e2e2e2;
	overflow: hidden;
}

.aidb-ra__progress-fill {
	display: block;
	width: 0;
	height: 100%;
	background: #333;
	transition: width 0.25s ease;
}

.aidb-ra.is-finished .aidb-ra__progress-fill {
	background: #2e7d32; /* 完了は控えめな緑で idle と区別 */
}

.aidb-ra__progress-text {
	flex: 0 0 auto;
	min-width: 3em;
	text-align: right;
	font-size: 0.78em;
	color: #666;
	font-variant-numeric: tabular-nums;
}

/* --- 注記 / エラー ----------------------------------------------------- */

.aidb-ra__note {
	margin: 8px 0 0;
	font-size: 0.78em;
	line-height: 1.5;
	color: #595959; /* #fafafa 上で 4.5:1 以上を確保（WCAG AA） */
}

.aidb-ra__status {
	display: none;
	margin: 8px 0 0;
	font-size: 0.82em;
	line-height: 1.5;
	color: #b32d2e;
}

.aidb-ra.is-error .aidb-ra__status {
	display: block;
}

/* --- スクリーンリーダー専用（aria-live 領域）-------------------------- */

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

/* --- フォーカス可視化（WCAG 2.4.7）------------------------------------ */

.aidb-ra__toggle:focus-visible,
.aidb-ra__stop:focus-visible,
.aidb-ra__speed:focus-visible {
	outline: 2px solid #1a73e8;
	outline-offset: 2px;
}

/* --- タッチ端末: ターゲット 44px 以上（主用途がモバイル）-------------- */

@media (pointer: coarse) {
	.aidb-ra__toggle {
		padding: 12px 20px;
	}

	.aidb-ra__stop {
		min-height: 44px;
		padding: 10px 16px;
	}

	.aidb-ra__speed {
		min-height: 44px;
		padding: 0 14px;
		display: inline-flex;
		align-items: center;
	}
}

/* --- 狭幅: トグルをフル幅、速度行を左寄せフル幅に --------------------- */

@media (max-width: 480px) {
	.aidb-ra__bar {
		gap: 10px;
	}

	.aidb-ra__toggle {
		flex: 1 1 auto;
		min-width: 0;
		justify-content: center;
	}

	.aidb-ra__speeds {
		margin-left: 0;
		width: 100%;
		flex-wrap: wrap;
		gap: 6px;
	}
}

/* --- モーション過敏配慮 ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.aidb-ra__progress-fill,
	.aidb-ra__toggle,
	.aidb-ra__stop,
	.aidb-ra__speed {
		transition: none;
	}

	.aidb-ra.is-loading .aidb-ra__icon {
		animation: none;
	}
}
