/**
 * BAIMIRA Core — 学習プレイヤー CSS。
 *
 * レスポンシブ方針（モバイルファースト）：
 * - ベーススタイルはモバイル（375px＝iPhone 想定）向けに書く。
 *   固定幅レイアウトは禁止。全要素は流動幅（% / fr / flex）で構成し、
 *   横スクロール・はみ出し・文字の潰れが起きないようにする。
 * - ブレークポイントで段階的に拡張する：
 *   600px 以上 … コントロールを1行寄りに整え、字幕を大きく。
 *   900px 以上 … ステージ＋セリフ一覧の2カラム構成、最大幅 1080px。
 * - タップターゲットは全ボタン・選択肢で 44px 以上を確保する。
 * - 字幕・本文の文字サイズは rem 単位（ブラウザ設定に追従）。
 * - コントラスト比 4.5:1 以上（字幕は暗背景＋白文字）。
 *
 * 色は BAIMIRA Design（Midnight Cinema）の CSS 変数に追随する。
 * サイトはダークテーマ（背景 #0B1120 系）が前提のため、文字色は
 * 必ず明色を使うこと。変数が無い環境向けにフォールバック値も
 * 同じダークテーマ配色で併記する。
 * （v0.9.7 以前は明テーマ前提の #1a1a1a や白背景ボタンを直書き
 *  しており、クイズの質問文・選択肢などがダーク背景上で読めなく
 *  なっていた。診断 CSS の v0.9.4 修正と同じ流儀で統一した。）
 */

.bm-player,
.bm-player * {
	box-sizing: border-box;
}

.bm-player {
	width: 100%;
	max-width: 100%;
	margin: 0 auto;
	font-size: 1rem;
	line-height: 1.6;
	color: var(--bm-text, #edf2fa);
}

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

/* ---------------------------------------------------------------------
 * ステージ（動画＋字幕レイヤー）
 * ------------------------------------------------------------------- */

.bm-player__stage {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
	background: #000;
	border-radius: 8px;
	overflow: hidden;
}

.bm-player__video {
	display: block;
	width: 100%;
	height: 100%;
	max-width: 100%;
	/* ダブルタップの判定を速くし、ブラウザのダブルタップズームを抑止する。 */
	touch-action: manipulation;
}

.bm-player__fs-icon {
	display: block;
}

.bm-player__captions {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	min-height: 3.4em; /* 字幕領域は固定高さを確保しレイアウトを揺らさない（CLS対策） */
	padding: 0.4em 0.6em;
	text-align: center;
	pointer-events: none;
}

.bm-player__caption-en,
.bm-player__caption-ja {
	margin: 0;
	padding: 0.1em 0.4em;
	display: inline-block;
	max-width: 100%;
	background: rgba(0, 0, 0, 0.78);
	color: #fff; /* 暗背景＋白文字で 4.5:1 以上 */
	font-size: 0.95rem;
	line-height: 1.45;
	overflow-wrap: break-word;
}

.bm-player__caption-ja {
	font-size: 0.85rem;
}

.bm-player__resume {
	position: absolute;
	top: 0.6rem;
	left: 50%;
	transform: translateX(-50%);
	min-height: 44px;
	padding: 0.6em 1.2em;
	border: 2px solid #fff;
	border-radius: 999px;
	background: rgba(0, 0, 0, 0.82);
	color: #fff;
	font-size: 0.95rem;
	cursor: pointer;
	white-space: nowrap;
	max-width: calc(100% - 1.2rem);
	overflow: hidden;
	text-overflow: ellipsis;
}

.bm-player__paywall {
	position: absolute;
	inset: auto 0 0 0;
	padding: 0.8rem;
	background: rgba(0, 0, 0, 0.85);
	color: #fff;
	text-align: center;
}

.bm-player__paywall-text {
	margin: 0 0 0.4em;
	font-size: 0.95rem;
	overflow-wrap: break-word;
}

.bm-player__paywall-link {
	display: inline-block;
	min-height: 44px;
	line-height: 44px;
	padding: 0 1.2em;
	border-radius: 6px;
	background: var(--bm-accent-deep, #0b6b80);
	color: #fff;
	font-weight: 700;
	text-decoration: none;
}

.bm-player__voice {
	margin: 0.5rem 0 0;
	font-size: 0.85rem;
	color: var(--bm-text-2, #a9b7cc);
}

.bm-player__status {
	min-height: 1.4em;
	font-size: 0.85rem;
	color: var(--bm-text-2, #a9b7cc);
}

/* ---------------------------------------------------------------------
 * コントロール（スマホでは親指範囲＝下部に集約し、折り返し前提）
 * ------------------------------------------------------------------- */

.bm-player__controls {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin-top: 0.6rem;
}

.bm-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 44px;
	min-height: 44px;
	padding: 0.5em 0.8em;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	background: var(--bm-bg-2, #111a2e);
	color: var(--bm-text, #edf2fa);
	font-size: 1rem;
	line-height: 1.2;
	cursor: pointer;
	touch-action: manipulation;
}

.bm-btn--wide {
	flex: 1 1 auto;
}

.bm-btn--small {
	min-width: 44px;
	min-height: 44px;
	padding: 0.4em 0.7em;
	font-size: 0.9rem;
}

.bm-btn--primary {
	background: var(--bm-accent-deep, #0b6b80);
	border-color: var(--bm-accent-deep, #0b6b80);
	color: #fff;
	font-weight: 700;
	width: 100%;
}

.bm-btn[aria-pressed="true"] {
	background: var(--bm-bg-3, #182238);
	border-color: var(--bm-accent, #33c4dc);
	color: var(--bm-text, #edf2fa);
}

/* 再生ボタンの読み込み中表示（v0.9.5）： 再生記述子の取得（初期化）が
   終わるまでボタンを無効化し、スピナーで読み込み中を示す。 */
.bm-btn.is-loading {
	opacity: 0.65;
	cursor: progress;
}

.bm-btn.is-loading::after {
	content: '';
	width: 0.85em;
	height: 0.85em;
	margin-left: 0.45em;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: bm-play-spin 0.8s linear infinite;
}

@keyframes bm-play-spin {
	to { transform: rotate(360deg); }
}

.bm-player__time {
	font-variant-numeric: tabular-nums;
	font-size: 0.95rem;
	white-space: nowrap;
}

/* 1行目の操作クラスタ（再生・前のセリフ・次のセリフ・全画面）は
   アイコンのみのボタンのため、横余白を詰めてスマホ幅でも時刻表示の
   右に全画面ボタンまでが1行に収まるようにする（v0.9.6）。
   Design 側 .bm-btn の広い横余白（CTA 用）より詳細度で勝たせる。
   --wide のボタン（字幕・区間リピート・シャドーイング）は対象外。 */
.bm-player__controls > .bm-btn:not(.bm-btn--wide) {
	padding-left: 0.6em;
	padding-right: 0.6em;
	flex: 0 0 auto;
}

.bm-player__speed select {
	min-height: 44px;
	padding: 0 0.6em;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	background: var(--bm-bg-2, #111a2e);
	color: var(--bm-text, #edf2fa);
	font-size: 1rem; /* 16px 以上で iOS の自動ズームを防ぐ */
}

.bm-player__ab {
	margin-top: 0.5rem;
	font-size: 0.9rem;
}

/* フォーカス位置は常に見えるアウトラインを表示（WCAG）。 */
.bm-player button:focus-visible,
.bm-player select:focus-visible,
.bm-player input:focus-visible,
.bm-player a:focus-visible {
	outline: 3px solid var(--bm-accent, #33c4dc);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------------
 * セリフ一覧
 * ------------------------------------------------------------------- */

.bm-player__heading {
	margin: 1.2rem 0 0.6rem;
	font-size: 1.1rem;
}

.bm-player__lines {
	list-style: none;
	margin: 0;
	padding: 0;
}

.bm-player__line {
	display: flex;
	align-items: stretch;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
}

.bm-player__line-main {
	flex: 1 1 auto;
	min-width: 0; /* flex 子要素のはみ出し防止 */
	min-height: 44px;
	padding: 0.6em 0.8em;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	background: var(--bm-bg-2, #111a2e);
	color: var(--bm-text, #edf2fa);
	text-align: left;
	cursor: pointer;
	touch-action: manipulation;
}

.bm-player__line-en,
.bm-player__line-ja {
	display: block;
	overflow-wrap: break-word;
}

.bm-player__line-en {
	font-size: 1rem;
}

.bm-player__line-ja {
	font-size: 0.88rem;
	color: var(--bm-text-2, #a9b7cc);
}

.bm-player__line.is-current .bm-player__line-main {
	border-color: var(--bm-accent, #33c4dc);
	background: var(--bm-bg-3, #182238);
}

.bm-player__line-save {
	flex: 0 0 auto;
	align-self: center;
}

/* ---------------------------------------------------------------------
 * クイズ
 * ------------------------------------------------------------------- */

.bm-quiz__question {
	margin: 0 0 1rem;
	padding: 0.8rem;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	min-width: 0;
}

/* 質問文（legend）と選択肢ラベルはダーク背景上で確実に読めるよう、
   継承任せにせず明色を明示する（v0.9.7）。 */
.bm-quiz__question legend {
	padding: 0 0.3em;
	font-weight: 700;
	color: var(--bm-text, #edf2fa);
	overflow-wrap: break-word;
}

.bm-quiz__choice {
	display: flex;
	align-items: center;
	min-height: 44px;
	padding: 0.4em 0.6em;
	margin-top: 0.4rem;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	background: var(--bm-bg-2, #111a2e);
	color: var(--bm-text, #edf2fa);
	cursor: pointer;
	overflow-wrap: break-word;
}

.bm-quiz__choice:has(input:checked) {
	border-color: var(--bm-accent, #33c4dc);
	background: var(--bm-bg-3, #182238);
}

.bm-quiz__choice input {
	width: 1.3rem;
	height: 1.3rem;
	margin-right: 0.6em;
	flex: 0 0 auto;
}

.bm-quiz__dictation-input {
	width: 100%;
	min-height: 44px;
	padding: 0.5em 0.7em;
	margin: 0.5rem 0;
	border: 1px solid var(--bm-line-strong, rgba(148, 178, 255, 0.28));
	border-radius: 8px;
	background: var(--bm-bg-2, #111a2e);
	color: var(--bm-text, #edf2fa);
	font-size: 1rem; /* 16px 以上で iOS の自動ズームを防ぐ */
}

/* 正解・不正解の意味色はダーク背景上でも判別できる明色にする
   （従来の #14532d / #991b1b は背景 #0B1120 上でコントラスト不足）。 */
.bm-quiz__result.is-correct {
	font-weight: 700;
	color: #4ade80;
}

.bm-quiz__result.is-wrong {
	font-weight: 700;
	color: #f87171;
}

/* 差分表示： 色だけに依存せず、太字＋下線でも区別する。 */
.bm-diff-ok {
	color: #4ade80;
}

.bm-diff-ng {
	color: #f87171;
	font-weight: 700;
	text-decoration: underline;
}

/* ---------------------------------------------------------------------
 * SRS 復習
 * ------------------------------------------------------------------- */

.bm-srs__phrase {
	font-size: 1.15rem;
	font-weight: 700;
	overflow-wrap: break-word;
}

.bm-srs__grades {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-top: 0.6rem;
}

.bm-srs__grades .bm-btn {
	flex: 1 1 30%;
}

/* ---------------------------------------------------------------------
 * 600px 以上： 小タブレット〜。コントロールを整え字幕を大きく
 * ------------------------------------------------------------------- */

@media (min-width: 600px) {
	.bm-player__caption-en {
		font-size: 1.1rem;
	}

	.bm-player__caption-ja {
		font-size: 0.95rem;
	}

	.bm-btn--primary {
		width: auto;
		min-width: 12rem;
	}

	.bm-player__line-en {
		font-size: 1.05rem;
	}
}

/* ---------------------------------------------------------------------
 * 900px 以上： デスクトップ。ステージ＋セリフ一覧の2カラム
 * ------------------------------------------------------------------- */

@media (min-width: 900px) {
	.bm-player {
		max-width: 1080px;
		display: grid;
		grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
		grid-template-areas:
			"stage transcript"
			"voice transcript"
			"status transcript"
			"controls transcript"
			"ab transcript"
			"quiz quiz"
			"srs srs";
		column-gap: 1.5rem;
	}

	.bm-player__stage { grid-area: stage; }
	.bm-player__voice { grid-area: voice; }
	.bm-player__status { grid-area: status; }
	.bm-player__controls { grid-area: controls; }
	.bm-player__ab { grid-area: ab; }
	.bm-player__transcript { grid-area: transcript; }
	.bm-player__quiz { grid-area: quiz; }
	.bm-player__srs { grid-area: srs; }

	.bm-player__transcript .bm-player__heading {
		margin-top: 0;
	}

	.bm-player__lines {
		max-height: 32rem;
		overflow-y: auto;
	}

	.bm-player__caption-en {
		font-size: 1.25rem;
	}
}

/* ---------------------------------------------------------------------
 * 全画面表示（v0.9.1）： コンテナ（.bm-player）ごと全画面にする。
 * ステージを残り領域いっぱいに広げ、コントロールは下部に残す。
 * セリフ一覧・クイズ・復習は全画面では隠す（学習操作はコントロール
 * と字幕オーバーレイに集約）。背景は黒、字幕は一段大きくする。
 * :-webkit-full-screen は未知の疑似クラスを含むセレクタリストが
 * 丸ごと無効化されるブラウザがあるため、:fullscreen と分けて書く。
 * .is-fullscreen は JS（fullscreenchange 同期）が付ける保険クラス。
 * ------------------------------------------------------------------- */

.bm-player:fullscreen,
.bm-player.is-fullscreen {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	max-width: none;
	background: #000;
	color: #fff;
}

.bm-player:-webkit-full-screen {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	max-width: none;
	background: #000;
	color: #fff;
}

.bm-player:fullscreen .bm-player__stage,
.bm-player.is-fullscreen .bm-player__stage {
	flex: 1 1 auto;
	min-height: 0;
	aspect-ratio: auto;
	border-radius: 0;
}

.bm-player:-webkit-full-screen .bm-player__stage {
	flex: 1 1 auto;
	min-height: 0;
	aspect-ratio: auto;
	border-radius: 0;
}

.bm-player:fullscreen .bm-player__video,
.bm-player.is-fullscreen .bm-player__video {
	object-fit: contain;
}

.bm-player:-webkit-full-screen .bm-player__video {
	object-fit: contain;
}

.bm-player:fullscreen .bm-player__controls,
.bm-player.is-fullscreen .bm-player__controls {
	flex: 0 0 auto;
	margin-top: 0;
	padding: 0.6rem;
	background: #000;
}

.bm-player:-webkit-full-screen .bm-player__controls {
	flex: 0 0 auto;
	margin-top: 0;
	padding: 0.6rem;
	background: #000;
}

.bm-player:fullscreen .bm-player__transcript,
.bm-player:fullscreen .bm-player__quiz,
.bm-player:fullscreen .bm-player__srs,
.bm-player:fullscreen .bm-player__voice,
.bm-player:fullscreen .bm-player__ab,
.bm-player.is-fullscreen .bm-player__transcript,
.bm-player.is-fullscreen .bm-player__quiz,
.bm-player.is-fullscreen .bm-player__srs,
.bm-player.is-fullscreen .bm-player__voice,
.bm-player.is-fullscreen .bm-player__ab {
	display: none;
}

.bm-player:-webkit-full-screen .bm-player__transcript,
.bm-player:-webkit-full-screen .bm-player__quiz,
.bm-player:-webkit-full-screen .bm-player__srs,
.bm-player:-webkit-full-screen .bm-player__voice,
.bm-player:-webkit-full-screen .bm-player__ab {
	display: none;
}

/* ステータスは全画面では視覚的に隠すが、aria-live の読み上げは生かす。 */
.bm-player:fullscreen .bm-player__status,
.bm-player.is-fullscreen .bm-player__status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.bm-player:-webkit-full-screen .bm-player__status {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

.bm-player:fullscreen .bm-player__caption-en,
.bm-player.is-fullscreen .bm-player__caption-en {
	font-size: 1.3rem;
}

.bm-player:-webkit-full-screen .bm-player__caption-en {
	font-size: 1.3rem;
}

.bm-player:fullscreen .bm-player__caption-ja,
.bm-player.is-fullscreen .bm-player__caption-ja {
	font-size: 1.05rem;
}

.bm-player:-webkit-full-screen .bm-player__caption-ja {
	font-size: 1.05rem;
}

/* ---------------------------------------------------------------------
 * モーション配慮： アニメーションを無効化
 * ------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.bm-player *,
	.bm-player *::before,
	.bm-player *::after {
		animation: none !important;
		transition: none !important;
		scroll-behavior: auto !important;
	}
}
