/**
 * Interactive Video Learning — Front-end Player Styles
 *
 * All classes are prefixed with `ivl-` to avoid theme conflicts.
 * v1.1.0 — Fixed: mobile caption overlap, dictation footer sticky, fullscreen
 *
 * @package InteractiveVideoLearning
 */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&family=DM+Sans:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ── */
.ivl-player {
	--ivl-red: #f47b7b;
	--ivl-red-light: #fde8e8;
	--ivl-red-dark: #e05c5c;
	--ivl-navy: #1a2340;
	--ivl-g1: #f8f9fb;
	--ivl-g2: #eef0f4;
	--ivl-g3: #d8dce6;
	--ivl-g4: #9aa0b5;
	--ivl-g6: #5a6278;
	--ivl-g8: #2d3452;
	--ivl-white: #fff;
	--ivl-ok: #52b788;
	--ivl-ng: #e05c5c;

	font-family: 'DM Sans', sans-serif;
	color: var(--ivl-g8);
	box-sizing: border-box;
	position: relative;
}

.ivl-player *,
.ivl-player *::before,
.ivl-player *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* ── Main Layout: Desktop 2-column ── */
.ivl-main {
	display: grid;
	grid-template-columns: 1fr 460px;
	height: 85vh;
	min-height: 520px;
	overflow: hidden;
	background: var(--ivl-g1);
	border-radius: 12px;
	border: 1px solid var(--ivl-g2);
}

.ivl-left {
	display: flex;
	flex-direction: column;
	overflow-y: auto;
	padding: 16px 16px 0;
}

.ivl-right {
	background: var(--ivl-white);
	border-left: 1px solid var(--ivl-g2);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* ── Mobile: Single column ── */
@media (max-width: 820px) {
	.ivl-main {
		grid-template-columns: 1fr;
		height: auto;
		overflow: visible;
	}

	.ivl-left {
		overflow: visible;
		padding: 8px 8px 0;
	}

	.ivl-right {
		border-left: none;
		border-top: 2px solid var(--ivl-g2);
		height: calc(100vh - 56px);
		height: calc(100dvh - 56px);
		min-height: 400px;
	}
}

/* ── Video Embed ── */
.ivl-vwrap {
	background: #000;
	flex-shrink: 0;
	border-radius: 10px;
	overflow: hidden;
	max-width: 820px;
}

.ivl-vwrap iframe,
.ivl-ytframe {
	width: 100%;
	aspect-ratio: 16 / 9;
	border: none;
	display: block;
}

/* ── Video title + author bar (under video, left side) ── */
.ivl-vmeta {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	padding: 8px 4px 6px;
	gap: 8px;
}

.ivl-vmeta-left {
	flex: 1;
	min-width: 0;
}

.ivl-vtitle {
	font-size: 15px;
	font-weight: 700;
	color: var(--ivl-navy);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ivl-vauthor {
	font-size: 11px;
	color: var(--ivl-g4);
	margin-top: 1px;
}

@media (max-width: 820px) {
	.ivl-vtitle {
		font-size: 13px;
	}
}

/* ── Fullscreen button ── */
.ivl-fs-btn {
	flex-shrink: 0;
	width: 36px;
	height: 36px;
	border-radius: 8px;
	border: 1px solid var(--ivl-g3);
	background: var(--ivl-white);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 16px;
	color: var(--ivl-g6);
	transition: all 0.15s;
}

.ivl-fs-btn:hover {
	background: var(--ivl-g1);
	border-color: var(--ivl-red);
	color: var(--ivl-red);
}

/* ── Language Bar — now inside .ivl-right, above tabs ── */
.ivl-vlang {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	padding: 8px 10px;
	border-bottom: 1px solid var(--ivl-g2);
	background: var(--ivl-g1);
	flex-shrink: 0;
}

.ivl-vlang .ivl-fb {
	width: 34px;
	height: 26px;
	border-radius: 6px;
	border: 2px solid var(--ivl-g3);
	cursor: pointer;
	font-size: 15px;
	background: var(--ivl-white);
	display: flex;
	align-items: center;
	justify-content: center;
	transition: all 0.12s;
}

.ivl-vlang .ivl-fb:hover {
	border-color: var(--ivl-red);
	transform: scale(1.08);
}

.ivl-vlang .ivl-fb.active {
	border-color: var(--ivl-red);
	background: var(--ivl-red-light);
	box-shadow: 0 0 0 2px rgba(244, 123, 123, 0.2);
}

.ivl-vlang .ivl-fb img {
	width: 18px;
	height: auto;
	border-radius: 2px;
}

/* ── Tabs ── */
.ivl-tabs {
	display: flex;
	padding: 8px 8px 0;
	gap: 2px;
	border-bottom: 1px solid var(--ivl-g2);
	flex-shrink: 0;
}

.ivl-tab {
	flex: 1;
	padding: 8px 4px;
	border: none;
	background: none;
	font-family: 'DM Sans', sans-serif;
	font-size: 13px;
	font-weight: 600;
	color: var(--ivl-g4);
	cursor: pointer;
	border-bottom: 3px solid transparent;
	margin-bottom: -1px;
	transition: all 0.15s;
	border-radius: 7px 7px 0 0;
}

.ivl-tab.active {
	color: var(--ivl-red);
	border-bottom-color: var(--ivl-red);
	background: var(--ivl-red-light);
}

/* ── Standard Panel ── */
.ivl-sp {
	flex: 1;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.ivl-cl {
	flex: 1;
	overflow-y: auto;
	padding: 3px 0;
	-webkit-overflow-scrolling: touch;
}

.ivl-cl::-webkit-scrollbar {
	width: 3px;
}

.ivl-cl::-webkit-scrollbar-thumb {
	background: var(--ivl-g3);
	border-radius: 3px;
}

/* Caption item */
.ivl-ci {
	padding: 9px 12px;
	cursor: pointer;
	border-left: 3px solid transparent;
	transition: all 0.12s;
}

.ivl-ci:hover {
	background: var(--ivl-g1);
}

.ivl-ci.active {
	border-left-color: var(--ivl-red);
	background: var(--ivl-red-light);
}

.ivl-ct {
	font-size: 10px;
	color: var(--ivl-g4);
	font-family: 'DM Mono', monospace;
	margin-bottom: 2px;
}

.ivl-cx {
	font-family: 'Noto Sans JP', sans-serif;
	font-size: 13px;
	line-height: 1.6;
	color: var(--ivl-g8);
}

.ivl-ctr {
	font-size: 11px;
	color: var(--ivl-g4);
	margin-top: 2px;
	line-height: 1.5;
}

/* ── Dictation Panel — uses flex column with sticky footer ── */
.ivl-dp {
	flex: 1;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.ivl-dtop {
	display: flex;
	gap: 5px;
	padding: 6px 8px;
	border-bottom: 1px solid var(--ivl-g2);
	flex-shrink: 0;
}

.ivl-dtyp {
	padding: 4px 12px;
	border-radius: 6px;
	border: 1px solid var(--ivl-g3);
	background: none;
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	color: var(--ivl-g6);
	transition: all 0.12s;
	font-family: 'DM Sans', sans-serif;
}

.ivl-dtyp.active {
	background: var(--ivl-red);
	border-color: var(--ivl-red);
	color: #fff;
}

/* Stats bar */
.ivl-dstats {
	display: grid;
	grid-template-columns: 1fr 1fr 1fr;
	padding: 6px 8px;
	background: var(--ivl-g1);
	border-bottom: 1px solid var(--ivl-g2);
	flex-shrink: 0;
}

.ivl-sb {
	text-align: center;
}

.ivl-sl {
	font-size: 9px;
	font-weight: 700;
	letter-spacing: 0.06em;
	color: var(--ivl-g4);
	text-transform: uppercase;
}

.ivl-sv {
	font-size: 17px;
	font-weight: 700;
	color: var(--ivl-red);
	font-family: 'DM Mono', monospace;
}

.ivl-sv-n {
	color: var(--ivl-g8);
}

.ivl-ab {
	height: 3px;
	background: var(--ivl-g2);
	border-radius: 2px;
	overflow: hidden;
	margin-top: 2px;
}

.ivl-af {
	height: 100%;
	background: linear-gradient(90deg, var(--ivl-red), var(--ivl-ok));
	transition: width 0.4s;
}

/* Navigation */
.ivl-dnav {
	display: flex;
	align-items: center;
	padding: 4px 8px;
	border-bottom: 1px solid var(--ivl-g2);
	gap: 1px;
	flex-shrink: 0;
}

.ivl-dnav button {
	background: none;
	border: none;
	cursor: pointer;
	font-size: 14px;
	color: var(--ivl-g6);
	padding: 3px 7px;
	border-radius: 5px;
}

.ivl-dnav button:hover {
	background: var(--ivl-g1);
}

.ivl-dpos {
	margin-left: auto;
	font-size: 10px;
	color: var(--ivl-g4);
	font-family: 'DM Mono', monospace;
}

/* Dictation body — scrollable middle area, shrinks to make room for footer */
.ivl-db {
	flex: 1;
	overflow-y: auto;
	padding: 10px;
	min-height: 0;
	-webkit-overflow-scrolling: touch;
}

.ivl-db::-webkit-scrollbar {
	width: 3px;
}

.ivl-db::-webkit-scrollbar-thumb {
	background: var(--ivl-g3);
	border-radius: 3px;
}

.ivl-dcur {
	background: var(--ivl-red-light);
	border: 2px solid var(--ivl-red);
	border-radius: 10px;
	padding: 11px;
	margin-bottom: 8px;
}

.ivl-dclbl {
	font-size: 9px;
	font-weight: 700;
	color: var(--ivl-red-dark);
	text-transform: uppercase;
	letter-spacing: 0.06em;
	margin-bottom: 6px;
}

.ivl-bw {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	align-items: flex-end;
}

.ivl-wb {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1px;
}

.ivl-wh {
	font-size: 9px;
	color: var(--ivl-g4);
	font-family: 'DM Mono', monospace;
}

.ivl-ws {
	font-family: 'Noto Sans JP', sans-serif;
	font-size: 14px;
	color: var(--ivl-g8);
	padding: 2px 2px;
}

.ivl-wi {
	border: none;
	border-bottom: 2px solid var(--ivl-red);
	background: transparent;
	text-align: center;
	font-family: 'Noto Sans JP', sans-serif;
	font-size: 14px;
	color: var(--ivl-navy);
	outline: none;
	padding: 2px 3px;
	min-width: 32px;
	transition: border-color 0.15s;
}

.ivl-wi:focus {
	border-bottom-color: #4eb3b3;
}

.ivl-wi.ok {
	border-bottom-color: var(--ivl-ok);
	color: var(--ivl-ok);
}

.ivl-wi.ng {
	border-bottom-color: var(--ivl-ng);
	color: var(--ivl-ng);
}

.ivl-wi.rv {
	border-bottom-color: var(--ivl-g3);
	color: var(--ivl-g4);
	font-style: italic;
}

/* Sentence input */
.ivl-si2 {
	width: 100%;
	border: 2px solid var(--ivl-red);
	border-radius: 8px;
	padding: 9px;
	font-family: 'Noto Sans JP', sans-serif;
	font-size: 13px;
	color: var(--ivl-navy);
	outline: none;
	resize: none;
	min-height: 64px;
	background: rgba(255, 255, 255, 0.7);
	transition: border 0.15s;
}

.ivl-si2.ok {
	border-color: var(--ivl-ok);
	color: var(--ivl-ok);
}

.ivl-si2.ng {
	border-color: var(--ivl-ng);
	color: var(--ivl-ng);
}

.ivl-dhi {
	font-size: 11px;
	color: var(--ivl-g4);
	margin-top: 3px;
}

/* Translation box */
.ivl-dtr {
	background: var(--ivl-g1);
	border-radius: 8px;
	padding: 8px;
	font-size: 12px;
	color: var(--ivl-g6);
	margin-bottom: 8px;
	line-height: 1.5;
}

.ivl-dtrl {
	font-size: 9px;
	font-weight: 700;
	color: var(--ivl-g4);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	margin-bottom: 3px;
}

/* Footer buttons — STICKY at bottom, never scrolls away */
.ivl-dfoot {
	display: flex;
	gap: 5px;
	padding: 8px;
	border-top: 1px solid var(--ivl-g2);
	flex-shrink: 0;
	background: var(--ivl-white);
	/* mt-auto pushes to bottom when content is short */
	margin-top: auto;
}

.ivl-dfoot button {
	flex: 1;
	padding: 8px 4px;
	border-radius: 8px;
	border: 1px solid var(--ivl-g3);
	background: var(--ivl-white);
	font-family: 'DM Sans', sans-serif;
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	color: var(--ivl-g6);
	transition: all 0.15s;
}

.ivl-dfoot button:hover {
	background: var(--ivl-g1);
}

.ivl-bchk {
	background: var(--ivl-red) !important;
	border-color: var(--ivl-red) !important;
	color: #fff !important;
}

.ivl-bchk:hover {
	background: var(--ivl-red-dark) !important;
}

/* ── Mobile dictation footer — safe-area aware ── */
@media (max-width: 820px) {
	.ivl-dfoot {
		padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
	}
}


/* ══════════════════════════════════════════════════
   FULLSCREEN STYLES
   ══════════════════════════════════════════════════ */

/* Native fullscreen (PC, Android) */
.ivl-player:fullscreen {
	background: var(--ivl-white);
	border-radius: 0;
}

.ivl-player:fullscreen .ivl-main {
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
	border: none;
}

.ivl-player:-webkit-full-screen {
	background: var(--ivl-white);
	border-radius: 0;
}

.ivl-player:-webkit-full-screen .ivl-main {
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
	border: none;
}

/* Pseudo-fullscreen (iOS fallback) */
.ivl-player.ivl-pseudo-fs {
	position: fixed !important;
	top: 0 !important;
	left: 0 !important;
	width: 100vw !important;
	height: 100vh !important;
	height: 100dvh !important;
	z-index: 999999 !important;
	background: var(--ivl-white);
	border-radius: 0;
	overflow: auto;
	-webkit-overflow-scrolling: touch;
}

.ivl-player.ivl-pseudo-fs .ivl-main {
	height: 100vh;
	height: 100dvh;
	border-radius: 0;
	border: none;
}

/* Fullscreen mobile override: single column */
@media (max-width: 820px) {
	.ivl-player:fullscreen .ivl-main,
	.ivl-player:-webkit-full-screen .ivl-main,
	.ivl-player.ivl-pseudo-fs .ivl-main {
		grid-template-columns: 1fr;
		height: auto;
		min-height: 100vh;
		min-height: 100dvh;
	}

	.ivl-player:fullscreen .ivl-right,
	.ivl-player:-webkit-full-screen .ivl-right,
	.ivl-player.ivl-pseudo-fs .ivl-right {
		height: calc(100vh - 56px);
		height: calc(100dvh - 56px);
	}
}

/* Fullscreen desktop: expand left panel */
@media (min-width: 821px) {
	.ivl-player:fullscreen .ivl-main,
	.ivl-player:-webkit-full-screen .ivl-main,
	.ivl-player.ivl-pseudo-fs .ivl-main {
		grid-template-columns: 1fr 500px;
	}
}

/* FS button state change when active */
.ivl-fs-btn.active {
	background: var(--ivl-red-light);
	border-color: var(--ivl-red);
	color: var(--ivl-red);
}


/* ── Pause Indicator — scoped to container, not fixed ── */
.ivl-pind {
	display: none;
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: rgba(26, 35, 64, 0.82);
	color: #fff;
	padding: 12px 26px;
	border-radius: 100px;
	font-size: 14px;
	font-weight: 600;
	z-index: 99;
	pointer-events: none;
	backdrop-filter: blur(4px);
}

.ivl-pind.show {
	display: block;
}

/* ── Toast — scoped to container ── */
.ivl-toast {
	position: absolute;
	bottom: 14px;
	left: 50%;
	transform: translateX(-50%) translateY(10px);
	background: var(--ivl-navy);
	color: #fff;
	padding: 8px 20px;
	border-radius: 100px;
	font-size: 12px;
	font-weight: 500;
	opacity: 0;
	transition: all 0.25s;
	z-index: 999;
	pointer-events: none;
}

.ivl-toast.show {
	opacity: 1;
	transform: translateX(-50%) translateY(0);
}
